Beispiel #1
0
    def check_blas(self):

        print "Checking if provided BLAS works...",
        # This function simply generates a FORTRAN program
        # that contains few calls to BLAS routine and then
        # checks if compilation, linking and execution are succesful

        # Try to detect which BLAS is used
        if re.search('mkl', self.config.blaslib, re.IGNORECASE):
            self.config.blasname = "mkl"
        elif re.search('acml', self.config.blaslib, re.IGNORECASE):
            self.config.blasname = "acml"

        if self.config.blasname != "Unknown":
            if self.config.compiler == "Intel":
                self.config.cflags += ''  #" -openmp"
        #        self.config.ldflags_c  += " -openmp"
        #        self.config.ldflags_fc += " -openmp"
            elif self.config.compiler == "GNU":
                self.config.cflags += ''  #" -fopenmp"
        #        self.config.ldflags_c  += " -fopenmp"
        #        self.config.ldflags_fc += " -fopenmp"

        sys.stdout.flush()
        writefile(
            'tmpf.f', """
      program ftest
      double precision da, dx(1)
      dx(1)=1
      da = 2
      call dscal(1,da,dx,1)
      stop
      end\n""")

        #fcomm = self.config.fc+' -o tmpf '+'tmpf.f '+self.config.blaslib+' '+self.config.ldflags_fc+' -lm'
        fcomm = self.config.fc + ' -o tmpf ' + 'tmpf.f ' + self.config.blaslib + ' -lm'
        (output, error, retz) = shellcmd(fcomm)

        if (retz != 0):
            print '\n\nBLAS: provided BLAS cannot be used! aborting...'
            print 'error is:\n', '*' * 50, '\n', fcomm, '\n', error, '\n', '*' * 50
            sys.exit()

        comm = './tmpf'
        (output, error, retz) = shellcmd(comm)
        if (retz != 0):
            print '\n\nBLAS: provided BLAS cannot be used! aborting...'
            print 'error is:\n', '*' * 50, '\n', comm, '\n', error, '\n', '*' * 50
            sys.exit()

        delfiles(['tmpf.f', 'tmpf'])
        print 'yes'

        return 0
Beispiel #2
0
    def set_mangling(self):
        """ Sets the INTFACE variable in Bmake.inc """
        # This one generates a program equivalent to that in BLACS/INSTALL
        # that checks the mangling in FORTRAN function symbols
        print 'Setting Fortran mangling...',
        sys.stdout.flush()
        writefile(
            'tmpf.f', """
      program intface
      external c_intface
      integer i
      call c_intface(i)
      stop
      end\n""")
        writefile(
            'tmpc.c', """
      #include <stdio.h>
      void c_intface_(int *i){fprintf(stdout, \"-DADD_\");fflush(stdout);}
      void c_intface(int *i){fprintf(stdout, \"-DNOCHANGE\");fflush(stdout);}
      void c_intface__(int *i){fprintf(stdout, \"-DfcIsF2C\");fflush(stdout);}
      void C_INTFACE(int *i){fprintf(stdout, \"-DUPCASE\");fflush(stdout);}\n"""
        )

        ccomm = self.config.cc + ' ' + self.config.cflags + ' -c tmpc.c -o tmpc.o'
        fcomm = self.config.fc + ' ' + self.config.fflags + '  tmpf.f tmpc.o -o xintface'

        (output, error, retz) = shellcmd(ccomm)
        if retz:
            print '\n\nCOMMON: in set_mangling: cannot compile'
            print 'error is:\n', '*' * 50, '\n', error, '\n', '*' * 50
            #sys.exit()

        (output, error, retz) = shellcmd(fcomm)
        if retz:
            print '\n\nCOMMON: in set_mangling: cannot compile'
            print 'error is:\n', '*' * 50, '\n', error, '\n', '*' * 50
            #sys.exit()

        comm = os.path.join(os.getcwd(), 'xintface')
        (output, error, retz) = shellcmd(comm)
        if retz:
            print '\n\nCOMMON: in set_mangling: cannot run xintface'
            print 'error is:\n', '*' * 50, '\n', error, '\n', '*' * 50
            #sys.exit()

        self.mangling = output
        delfiles(['xintface', 'tmpf.f', 'tmpf.o', 'tmpc.c', 'tmpc.o'])

        print self.mangling
        return 1
Beispiel #3
0
    def check_cc(self):
        """ checking if cc works """
        # simply generates a C program containing a couple of calls
        # to MPI routines and checks if the compilation and execution
        # are succesful
        print 'Checking if cc works...',
        sys.stdout.flush()
        # generate
        writefile(
            'tmpc.c', """
            #include <stdio.h>
            int main(int argc, char **argv){
            int iam;
            fprintf(stdout, \"success\" );fflush(stdout);
            return 0;
            }\n""")

        # compile
        #ccomm = self.config.cc+" "+self.config.cflags+" "+self.config.ldflags_c+" -o tmpc "+os.path.join(os.getcwd(),"tmpc.c")
        import re
        cflags_ = re.sub(
            '-O3', '-O0', self.config.cflags
        )  # -O3 would take too much time. Do not need optimization here....
        ccomm = self.config.cc + " " + cflags_ + "  -o tmpc " + os.path.join(
            os.getcwd(), "tmpc.c")
        (output, error, retz) = shellcmd(ccomm)

        if retz:
            print '\n\nCOMMON: C compiler not working! aborting...'
            print 'stderr:\n', '*' * 50, '\n', error, '\n', '*' * 50
            sys.exit()

        # run
        comm = './tmpc'
        (output, error, retz) = shellcmd(comm)
        if retz:
            print '\n\nCOMMON: cc not working! aborting...'
            print 'error is:\n', '*' * 50, '\n', error, '\n', '*' * 50
            sys.exit()

        # cleanup
        delfiles(['tmpc.c', 'tmpc'])
        print 'yes'
        return 0
Beispiel #4
0
    def check_fc(self):
        """ check if the Fortran compiler works """
        # simply generates a F77 program and checks if the compilation and execution
        # are succesful
        print "Checking if the Fortran compiler works...",
        sys.stdout.flush()
        # generate
        writefile(
            "tmpf.f", """
      program ftest
      integer i
      print*,'success'
      stop
      end\n""")

        # compile
        #fcomm = self.config.fc+' '+self.config.fcflags+" "+self.config.ldflags_fc+' -o tmpf '+'tmpf.f'
        fcomm = self.config.fc + ' ' + self.config.fflags + '  -o tmpf ' + 'tmpf.f'
        (output, error, retz) = shellcmd(fcomm)

        if retz:
            print '\n\nCOMMON: the Fortran compiler is not working! aborting...'
            print 'error is:\n', '*' * 50, '\n', error, '\n', '*' * 50
            sys.exit()

        # run
        comm = './tmpf'
        (output, error, retz) = shellcmd(comm)
        if retz:
            print '\n\nCOMMON: the Fortran compiler is not working! aborting...'
            print 'error is:\n', '*' * 50, '\n', error, '\n', '*' * 50
            sys.exit()

        # cleanup
        delfiles(['tmpf.f', 'tmpf', 'tmpf.o'])
        print 'yes'

        return 0
Beispiel #5
0
    def check_linking(self):
        """ Check if C main can be linked to Fortran subroutine """

        # This one checks if the linking command works out of the box or
        # if any specific flag is required. For example if the linker if the
        # Intel FORTRAN compiler, then the "-nofor_main" is usually required.
        # This function only checks if linker works but does not automatically
        # detect the required flags
        print 'Checking loader...',
        sys.stdout.flush()
        writefile(
            'tmpf.f', """
      subroutine fsub()
      write(*,*)'success'
      stop
      end\n""")
        writefile(
            'tmpc.c', """
      #if defined ADD_
      #define fsub fsub_
      #elif defined NOCHANGE
      #define fsub fsub
      #elif defined fcIsF2C
      #define fsub fsub_
      #elif defined UPCASE
      #define fsub FSUB
      #endif
      void main(){
      fsub();}\n""")

        #ccomm = self.config.cc+' '+self.config.ccflags+' '+self.mangling+' -c -o tmpc.o tmpc.c'
        #fcomm = self.config.fc+' '+self.config.fcflags+' -c -o tmpf.o tmpf.f'
        #lcomm = self.config.fc+' '+self.config.ldflags_fc+' '+self.config.ld_fcmain+' -o lnk tmpf.o tmpc.o'
        ccomm = self.config.cc + ' ' + self.config.cflags + ' -c -o tmpc.o tmpc.c'
        fcomm = self.config.fc + ' ' + self.config.fflags + ' -c -o tmpf.o tmpf.f'
        lcomm = self.config.fc + '   -o lnk tmpf.o tmpc.o'

        (output, error, retz) = shellcmd(ccomm)
        if retz:
            print '\n\nCOMMON: in check_linking: cannot compile'
            print 'command is: ', ccomm
            print 'error is:\n', '*' * 50, '\n', error, '\n', '*' * 50
            #sys.exit()

        (output, error, retz) = shellcmd(fcomm)
        if retz:
            print '\n\nCOMMON: in check_linking: cannot compile'
            print 'command is: ', fcomm
            print 'error is:\n', '*' * 50, '\n', error, '\n', '*' * 50
            #sys.exit()

        (output, error, retz) = shellcmd(lcomm)
        if retz:
            print """\n\nCOMMON: in check_linking: cannot link
            Cannot link a C main program to a Fortran77 subroutine
            Make sure that the appropriate flags are passed to the linker."""
            print 'command is: ', lcomm
            print 'error is:\n', '*' * 50, '\n', error, '\n', '*' * 50
            #sys.exit()

        delfiles(['lnk', 'tmpf.f', 'tmpf.o', 'tmpc.c', 'tmpc.o'])

        print 'works'
        return 1
Beispiel #6
0
    def check_lapack(self):
        print "Checking if provided LAPACK works...",
        # This function simply generates a C program
        # that contains few calls to LAPACK routine and then
        # checks if compilation, linking and execution are succesful

        sys.stdout.flush()
        writefile(
            'tmpf.f', """
      program ftest
      integer  N
      parameter (N = 1)
      double precision A(N, N), B(N)
      integer  I(N)
      integer  INFO
      B(:)   = 1
      A(:,:) = 2
      I(:)   = 0
      call cheevd( 'N', 'U', N, A, N, B, B, -1,
     $     B, -1, I, -1, INFO)
      stop
      end\n""")

        ldflg = self.config.lapacklib + ' ' + self.config.blaslib + '  -lm'
        ccomm = self.config.fc + ' -o tmpf ' + 'tmpf.f ' + ldflg
        (output, error, retz) = shellcmd(ccomm)

        if (retz != 0):
            if self.dmft.verbose:
                print '\n\nLAPACK: provided LAPACK cannot be used! aborting...'
                print 'error is:\n', '*' * 50, '\n', ccomm, '\n', error, '\n', '*' * 50
            else:
                print "no"
            return -1

        comm = './tmpf'
        (output, error, retz) = shellcmd(comm)
        if (retz != 0):
            if self.dmft.verbose:
                print '\n\nLAPACK: provided LAPACK cannot be used! aborting...'
                print 'error is:\n', '*' * 50, '\n', comm, '\n', error, '\n', '*' * 50
            else:
                print "no"
            return -1

        delfiles(['tmpf.f', 'tmpf'])
        print 'yes'

        #        print "Checking if provided LAPACK contains functions for test works...",
        # This function simply generates a C program
        # that contains few calls to LAPACK routine and then
        # checks if compilation, linking and execution are succesful

        sys.stdout.flush()
        writefile(
            'tmpf.f', """
      program ftest
        double precision D(1), A(1:1), B(2)
        integer          ISEED( 4 )
        integer          INFO
        B(1)   = 1

        do  I = 1, 4
            ISEED( I ) = 1
        enddo
        call dlarnv( 1, ISEED, 1, D )
        call dlagsy( 1, 0, D, A, 1, ISEED, B, INFO )
        stop
      end\n""")

        ccomm = self.config.fc + ' -o tmpf ' + 'tmpf.f ' + ldflg
        (output, error, retz) = shellcmd(ccomm)

        if (retz != 0):
            print 'no'
            self.dmft.needtmg = 1
        else:
            comm = './tmpf'
            (output, error, retz) = shellcmd(comm)
            if (retz != 0):
                print 'no'
                self.dmft.needtmg = 1
            else:
                self.dmft.needtmg = 0
#               print 'yes'
        delfiles(['tmpf.f', 'tmpf'])

        return 0
Beispiel #7
0
    def check_gsl(self):
        """ This function simply generates a C program
            that contains few GSL calls routine and then
            checks if compilation, linking and execution are succesful"""

        sys.stdout.flush()
        code = """#include <gsl/gsl_rng.h>
         const gsl_rng_type * T = gsl_rng_default; 
         gsl_rng * r = gsl_rng_alloc (T); 
         int main(void)
         {
           gsl_rng_env_setup();
           gsl_rng_set (r,1); 
           return 0;
         }
        """
        writefile('tmpc.cc', code)

        if self.config.gsl == "":  # just trying default == -lgsl
            self.config.gsl = '-lgsl'

        self.config.gslinc = includefromlib(self.config.gsl)
        ccomm = self.config.cxx + ' ' + self.config.gslinc + ' -o tmpc ' + 'tmpc.cc ' + self.config.gsl
        print 'checking with:', ccomm
        (output, error, retz) = shellcmd(ccomm)

        print "Checking if provided GSL works...",
        if (retz != 0):
            if self.dmft.verbose:
                print '\n\nlibgsl: provided GSL cannot be used! aborting...'
                print 'error is:\n', '*' * 50, '\n', ccomm, '\n', error, '\n', '*' * 50
                return -1
            else:
                print "no"
                return -1
                #sys.exit()

        comm = './tmpc'
        (output, error, retz) = shellcmd(comm)
        if (retz != 0):
            if self.dmft.verbose:
                print '\n\nlibgsl: provided GSL cannot be used! aborting...'
                print 'error is:\n', '*' * 50, '\n', comm, '\n', error, '\n', '*' * 50
                print retz
                return -1
            else:
                print "no"
                return -1
            # sys.exit()

        if self.config.gslinc == '':
            # It worked, but we do not know the include files, hence figuring it out
            ccomm = self.config.cc + ' -E  tmpc.cc |grep gsl | grep include'
            (output, error, retz) = shellcmd(ccomm)
            #print 'output=', output
            # compiler output in lines
            lines = output.split('\n')
            incl = {}
            for i, line in enumerate(lines):
                dat = line.split()
                for d in dat:
                    m = re.search('gsl', d)  # take out the directory
                    if m is not None:
                        incl[os.path.dirname(d[1:-1])] = True

            for inc in incl.keys():
                self.config.gslinc += ' -I' + inc[:
                                                  -4]  # path has extra gsl. Take it out

        delfiles(['tmpc.cc', 'tmpc'])
        print 'yes'

        return 0
Beispiel #8
0
    def check_fftw(self):
        """ This function simply generates a C program
            that contains few FFTW calls routine and then
            checks if compilation, linking and execution are succesful"""

        sys.stdout.flush()
        code = """
        #include<fftw3.h>
        #include<complex.h>
        int main(void)
        {
            int N;
            int i;
            N=1;
            fftw_complex *in, *out;
            fftw_plan my_plan;
            in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*N);
            out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*N);
            my_plan = fftw_plan_dft_1d(N, in, out, FFTW_FORWARD, FFTW_ESTIMATE);
            fftw_execute(my_plan);
            fftw_destroy_plan(my_plan);
            fftw_free(in);
            fftw_free(out);
            return 0;
         }
        """
        writefile('tmpc.c', code)

        if self.config.fftwlib == "":
            self.config.fftwlib = '-lfftw3'  # just trying default"

        self.config.fftwinc = includefromlib(self.config.fftwlib)
        ccomm = self.config.cc + ' ' + self.config.fftwinc + ' -o tmpc  tmpc.c ' + self.config.fftwlib
        print 'checking with:', ccomm

        (output, error, retz) = shellcmd(ccomm)

        print "Checking if provided FFTW works...",

        if (retz != 0):
            if self.dmft.verbose:
                print '\n\nlibfftw: provided FFTW cannot be used! aborting...'
                print 'error is:\n', '*' * 50, '\n', ccomm, '\n', error, '\n', '*' * 50
            else:
                print "no"
            return 1

        comm = './tmpc'
        (output, error, retz) = shellcmd(comm)
        if (retz != 0):
            if self.dmft.verbose:
                print '\n\nlibfftw: provided FFTW cannot be used! aborting...'
                print 'error is:\n', '*' * 50, '\n', comm, '\n', error, '\n', '*' * 50
                print rez
            else:
                print "no"
            return 1

        if self.config.fftwinc == '':
            # No include file given, hence checking which includes were used when compilation succeded
            ccomm = self.config.cc + ' -E ' + self.config.fftwinc + ' tmpc.c |grep fftw | grep include'
            (output, error, retz) = shellcmd(ccomm)
            # compiler output in lines
            lines = output.split('\n')
            incl = {}
            for i, line in enumerate(lines):
                dat = line.split()
                for d in dat:
                    m = re.search('fftw', d)  # take out the directory
                    if m is not None:
                        incl[os.path.dirname(
                            d[1:-1]
                        )] = True  # path has extra "xxx" so take them out

            for inc in incl.keys():
                self.config.fftwinc += ' -I' + inc
        delfiles(['tmpc.c', 'tmpc'])
        print 'yes'
        return 0