相同的代码在我的本地计算机上运行,​​但不在集群

时间:2016-07-11 06:45:09

标签: c++ fortran cluster-computing fortran90

所以我有一个c ++代码(带有来自netlib.org的fortran子程序),我使用这些指令进行接口和编译:

g++ -c new.cpp
g++ -o new new.o 3j6j9jlib.a -lgfortran

库3j6j9jlib.a由drc3jm.f,drc6j.f和依赖项(从http://www.netlib.org/slatec/src/获得)的编译版本以及使用这些的几个代码(clebsch.f ninej.f90)组成作为计算其他数量的基础:

clebsch.o  drc3jm.o  fdump.o   j4save.o  ninej.o   test9j.o  xerhlt.o  xerprn.o  xgetua.o   d1mach.o   drc6j.o   i1mach.o  new.o     r1mach.o  xercnt.o  xermsg.o  xersve.o

我用于编译库的编译指令是:

gfortran -c *.f
gfortran -c *.f90
ar rv 3j6j9jlib.a *.o

现在,当我尝试编译目标文件new.o时,它给出的错误如下:

-bash-4.1$ g++ -o new new.o 3j6j9jlib.a -lgfortran
3j6j9jlib.a(ninej.o): In function `w9j_':
ninej.f90:(.text+0xc9): undefined reference to `_gfortran_transfer_character_write'
ninej.f90:(.text+0x129): undefined reference to `_gfortran_transfer_character_write'
ninej.f90:(.text+0x147): undefined reference to `_gfortran_transfer_integer_write'
ninej.f90:(.text+0x165): undefined reference to `_gfortran_transfer_integer_write'
ninej.f90:(.text+0x183): undefined reference to `_gfortran_transfer_integer_write'
ninej.f90:(.text+0x1a1): undefined reference to `_gfortran_transfer_integer_write'
ninej.f90:(.text+0x1bf): undefined reference to `_gfortran_transfer_integer_write'
3j6j9jlib.a(ninej.o):ninej.f90:(.text+0x1dd): more undefined references to `_gfortran_transfer_integer_write' follow
3j6j9jlib.a(ninej.o): In function `w9j_':
ninej.f90:(.text+0xeb5): undefined reference to `_gfortran_transfer_character_write'
3j6j9jlib.a(xermsg.o): In function `xermsg_':
xermsg.f:(.text+0xbdd): undefined reference to `_gfortran_transfer_integer_write'
3j6j9jlib.a(xerprn.o): In function `xerprn_':
xerprn.f:(.text+0x2bd): undefined reference to `_gfortran_transfer_character_write'
xerprn.f:(.text+0x7e3): undefined reference to `_gfortran_transfer_character_write'
3j6j9jlib.a(xersve.o): In function `xersve_':
xersve.f:(.text+0x1c7): undefined reference to `_gfortran_transfer_character_write'
xersve.f:(.text+0x1f2): undefined reference to `_gfortran_transfer_character_write'
xersve.f:(.text+0x227): undefined reference to `_gfortran_transfer_character_write'
xersve.f:(.text+0x252): undefined reference to `_gfortran_transfer_integer_write'
xersve.f:(.text+0x27d): undefined reference to `_gfortran_transfer_integer_write'
xersve.f:(.text+0x2a8): undefined reference to `_gfortran_transfer_integer_write'
xersve.f:(.text+0x33d): undefined reference to `_gfortran_transfer_integer_write'
3j6j9jlib.a(d1mach.o): In function `d1mach_':
d1mach.f:(.text+0x644): undefined reference to `_gfortran_stop_numeric_f08'
d1mach.f:(.text+0x6aa): undefined reference to `_gfortran_stop_numeric_f08'
d1mach.f:(.text+0x6d4): undefined reference to `_gfortran_stop_numeric_f08'
d1mach.f:(.text+0x744): undefined reference to `_gfortran_transfer_character_write'
d1mach.f:(.text+0x762): undefined reference to `_gfortran_transfer_integer_write'
d1mach.f:(.text+0x77b): undefined reference to `_gfortran_transfer_character_write'
3j6j9jlib.a(i1mach.o): In function `i1mach_':
i1mach.f:(.text+0x1c0): undefined reference to `_gfortran_stop_numeric_f08'
i1mach.f:(.text+0x51e): undefined reference to `_gfortran_stop_numeric_f08'
i1mach.f:(.text+0x6c8): undefined reference to `_gfortran_transfer_character_write'
i1mach.f:(.text+0x6e6): undefined reference to `_gfortran_transfer_integer_write'
i1mach.f:(.text+0x6ff): undefined reference to `_gfortran_transfer_character_write'
collect2: ld returned 1 exit status

我的本​​地计算机上没有此错误。它编译得很好。 我安装了g ++版本4.8.4和gfortran版本4.8.4。 集群g ++版本为4.4.6,gfortran版本为4.4.6。 如果有人需要代码(可能不是问题),那么:

#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <fstream>
#include <vector>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#define pi 3.14159

using namespace std;

extern "C"
{
    double drc3jm_ (double*, double*, double*, 
                double*, double*, double*, double*, int*, int*);

    double drc6j_ (double*, double*, double*, double*, double*, 
                double*, double*, double*, int*, int*);

    double w9j_ (int*, int*, int*, int*, int*, 
                int*, int*, int*, int*, int*, int*, double*);

    double clebsch_ (int*, double*, double*, 
                double*, double*, double*, double*, double*);



}

class imaginary
{
    public:
        double re;
        double im;

        imaginary prod ( imaginary a, imaginary b )
        {
            imaginary c;
            c.re = (a.re*b.re) - (a.im*b.im);
            c.im = (a.im*b.re) + (a.re*b.im);
            return c;
        }

        imaginary add ( imaginary a, imaginary b )
        {
            imaginary c;
            c.re = a.re + b.re;
            c.im = a.im + b.im;
            return c;
        }
        imaginary prod ( imaginary a, double b )
        {
            imaginary c;
            c.re = a.re*b;
            c.im = a.im*b;
            return c;
        }
        void reset (imaginary &a)
        {
            a.re = 0;
            a.im = 0;
//          return a;           
        }


};

//extraction of mask

//change if condition according to what point you want to read it

void extract (vector < vector <imaginary> >& BipoSH)
{
    ifstream wlm;
    wlm.open("wlm.dat");

    if(wlm.is_open())
    {
        double c;
        int l = 0, k = 0; 

        imaginary obj;
        vector <imaginary> lval,lvalf;


        while (!wlm.eof())
        {
            for(int m = 0; m < l+1; m++)
            {
                wlm >> c;
                obj.re = c;
                wlm >> c;
                obj.im = c;

                lval.push_back(obj);
                obj.re = pow(-1,-m)*obj.re;
                obj.im = pow(-1,-m-1)*obj.im;
                lvalf.insert(lvalf.begin(),obj);

            }
            lvalf.insert(lvalf.end(),lval.begin()+1,lval.end());
            BipoSH.push_back(lvalf);
            lval.clear();
            lvalf.clear();

            l++;
            if( l > 500 )       //this is the condition we need to change. here l is l1
                return ;

        }
        return ;


    }
    else 
        cout<<"File isn't open"<<endl;
    wlm.close();
}

//extraction of power coeffs

//change m maximum value in for loop according to what point you wish to read the power spepctrum values

void power(vector <double>& Power)
{
    ifstream Cl;
    Cl.open("Cl_val.dat");
    double c;
    if(Cl.is_open())
    {
        while(!Cl.eof())
        {
            for(int m =0; m < 1000; m++)            //change the condition m<65 to any other condition
            {
                Cl >> c;
                Cl >> c;
                Power.push_back(c);
            }
            return ;
        }
    }
    else
        cout<<"File didn't open"<<endl;
    Cl.close();
}

//links clebsch function of fortran to c++

double* cleb ( double L, double L1, double L2, double M, double & Mmin, double & Mmax )
{
    double* clebsch;
    int N = 500;

    clebsch = new double [ N ];

    clebsch_ ( &N, &L, &L1, &L2, &M, &Mmin, &Mmax, clebsch );  

    return clebsch ;
}
/*

F and Hcalc calculate the shape function.

*/

double F(int l1,int L, int l2)
{
    return (l1*(l1+1)+L*(L+1)-l2*(l2+1))/2;
}


double Hcalc(int L, int l1, int l2, vector <double> c)
{
    double Gmod,Gabr;
    double Mmin,Mmax;
    double *clebsch = cleb(L, l1, l2, 0, Mmin, Mmax);
    double b = 3.0;
    Gmod = clebsch[0];
    Gmod*=pow(2*l1+1,0.5)*pow(2*l2+1,0.5)/pow(2*L+1,0.5);
    Gmod*=pow(4*pi,-0.5)*(c.at(l1)+c.at(l2));
    Gabr = pow(4*pi,-0.5)*((c.at(l1)*F(l1,L,l2))+(c.at(l2)*F(l2,L,l1)));
    return (b*Gmod) - Gabr;
}


int main()
{

   clock_t t;
    t = clock();

    int ier, k, N = 500;

    double* coef9j;
    double h;
    double M2min = 0, M2max = 0, Mmin = 0, Mmax = 0, M1min = 0, M1max = 0;

    imaginary temp, temp1, temp2, ugabuga;
    temp.re = 0;
    temp.im = 0;

    vector < vector < vector < vector <imaginary> > > > Lvec;
    vector < vector < vector <imaginary> > > L1vec;
    vector < vector <imaginary> > L2vec, Kvec;
    vector <imaginary> Mvec, Kl2vec;

    vector < vector <imaginary> > Bip;
    vector <double> c_val;
    extract(Bip);
    power(c_val);

    cout<<"extraction is done"<<endl;

    //now I begin calculation of mask

    int L, Lmax = 10, L1, L1max = 30, L2, L2max, M, L5max = 30;


    //change L1max, L5max according to what you want to calculate

    //they are computationally epensive so don't go above L1max = 50, L5max = 50

    //L5max must be equal to L1max

    //Lmax is fed according to what mask value we want to calculate upto


    for ( L = 0; L < Lmax; L++ )
    {
        for ( L1 = 0; L1 < L1max; L1++ )
        {
            for ( L2 = abs(L - L1); L2 < abs(L + L1)+1; L2++ )
            {
                for(M = -L;M<L+1;M++)
                {
                    double* clebsch = cleb( L, L1, L2, M, M1min, M1max );
                    for ( int i = (int)M1min; i < (int)M1max + 1; i++ )
                    {

                        temp1.re = Bip.at(L1).at(i+L1).re*clebsch[i-(int)M1min];
                        temp1.im = Bip.at(L1).at(i+L1).im*clebsch[i-(int)M1min];

                        temp2.re = Bip.at(L2).at(M-i+L2).re;
                        temp2.im = Bip.at(L2).at(M-i+L2).im;

                        temp = ugabuga.add( temp, ugabuga.prod( temp1, temp2 ) );

                    }
                    Mvec.push_back(temp);
                    temp.re = 0;
                    temp.im = 0;
                }
                L2vec.push_back(Mvec);
            }
            L1vec.push_back(L2vec);
            L2vec.clear();
        }
        Lvec.push_back(L1vec);
        L1vec.clear();
    }
    //delete *L1vec, *L2vec, *Mvec;
    vector< vector < vector <imaginary> > >().swap(L1vec);
    vector< vector <imaginary> >().swap(L2vec);
    vector <imaginary>().swap(Mvec);

    cout<<"Mask parsed into vector"<<endl;

    double temporary;
    imaginary im,sum;
    int Lprime, Mprime;
    int m=0,x=0;
    int t1,t2;


    ugabuga.reset(sum);

    //now I begin calculation of the MSF

    //L1max, L5max take the value previously declared


    L = 1; M = 0; Lprime = 1, Mprime = 0;
    for (L1 =0; L1 < L1max;L1++)
    {
        for (L2 = abs(L1-L);L2<abs(L1+L)+1; L2++)
        {
            for(int l5=0;l5<L5max;l5++)
            {
                for(int J=abs(L-Lprime);J<abs(L+Lprime)+1;J++)
                {
                    for(int l6=abs(l5-J);l6<abs(l5+J)+1;l6++)
                    {
                        for(int l3=min(abs(L1-l5),(int)c_val.size()-L);l3<min((L1+l5),(int)c_val.size()-L)+1;l3++)
                        {
                            if(abs(L1-l5)>(int)c_val.size()-L)
                            {
                                return 0;
                            }

                            t2 = min(l3+Lprime,L2+l6);
                            t1 = max(abs(l3-Lprime),abs(L2-l6));
                            N = t2-t1+1;

                            if(N<1)
                                continue;

                            coef9j = new double [ N ];

                            w9j_ ( &Lprime, &l3, &l6, &J, &l5, &L2, &L, &L1, &t1, &t2, &N, coef9j );

                            for(int l4 = max(abs(l3-Lprime),abs(L2-l6));l4<min(l3+Lprime,L2+l6)+1;l4++)
                            {
                                //cout<<"l4 "<<l4<<endl;
                                h=pow(2*Lprime+1,0.5)*pow(2*l3+1,0.5)*pow(2*l4+1,0.5)*pow(4*pi,-0.5);
                                //cout<<"power mult "<<h<<endl;
                                h*=Hcalc(Lprime,l3,l4,c_val);
                                //cout<<"after Hcalc "<<h<<endl;

                                temporary = h*pow(2*l5+1,0.5)*pow(2*l6+1,0.5)*pow(4*pi,-0.5);
                                //cout<<"temporary "<<temporary<<endl; 
                                double* cleb1 = cleb( L1, l3, l5, m, M1min, M1max );
                                //cout<<"cleb1"<<endl;

                                //cout<<"L2, l4, l6, m:"<<L2<<" "<<l4<<" "<<l6<<" "<<m<<endl;

                                double* cleb2 = cleb( L2, l4, l6, m, M2min, M2max );
                                //cout<<"cleb2"<<endl;

                                temporary = temporary*cleb1[0]*cleb2[0];
                                double* cleb3 = cleb( L, Lprime, J, M, Mmin, Mmax );
                                //cout<<"cleb3"<<endl;

                                temporary = temporary*coef9j[l4-max(abs(l3-L),abs(L2-l6))]*pow(2*J+1,0.5);
                                //cout<<"temporary after w9j multi "<<temporary<<endl;
                                //cout<<"coef9j hoga pakka se"<<endl;
                                temporary = temporary*cleb3[Mprime-(int)Mmin];
                                //cout<<"last temp "<<temporary<<endl;
                                im = ugabuga.prod(Lvec.at(J).at(l5).at(l6-abs(l5-J)).at(M-Mprime),temporary);
                                sum = ugabuga.add(sum,im);
                                //cout<<"this is the sum"<<sum.re<<endl;
                                delete cleb1;
                                delete cleb2;
                                delete cleb3;
                            }
                            delete coef9j;

                        }
                    }
                }
            }
            Kl2vec.push_back(sum);
            ugabuga.reset(sum);
        }
        Kvec.push_back(Kl2vec);
        Kl2vec.clear();
        //if(L1%5==0)
            cout<<"MSF upto l1 = "<<L1<<" is done"<<endl;
    }

    cout<<"MSF parsed into a vector"<<endl;

    //now I start writing the results into a file

    //filename is stored in string s

    fstream foo;

    string s;
    char g[10],j[100];
    int b=0;

    sprintf(j,"L_%dLprime_%dM_%dMprime_%d",L,Lprime,M,Mprime);
    for(int i=0;i<(int)strlen(j);i++)
        s.push_back(j[i]);

    int l=0;
    l=s.size();

    s+=".dat";

    foo.open(s.c_str(), ios::out | ios::binary );
    b = 0;

    if(foo.is_open())   
    for(L1=0;L1<L1max;L1++)
    {
        foo << L1<<"    ";

        for(L2 = abs(L-L1);L2<abs(L+L1)+1;L2++)
        {           
                foo <<" "<<Kvec.at(L1).at(L2-abs(L-L1)).re<<"   "<<Kvec.at(L1).at(L2-abs(L-L1)).im;         
        }
        foo<<endl;
    }
    else
    {
        cout<<"not open"<<endl;
    }

    foo.close();


    cout<<"file writing done"<<endl;

    //displaying the time taken for the process now

    t = clock() - t;
    cout<<"Time = "<<(float)t/CLOCKS_PER_SEC<<endl;

}

非常感谢任何帮助。出于错误的可能原因,抓出我的头发。请评论我应该提供的其他信息,因为我一无所知。

0 个答案:

没有答案