[petsc-users] How to configure PETSc with gcc-4.9

Satish Balay balay at mcs.anl.gov
Fri Apr 25 01:44:21 CDT 2014


On Fri, 25 Apr 2014, Justin Dong wrote:

> Hi Satish,
> 
> Thanks, that installation worked and it's now compiling with gcc-4.9.
> However, I'm still having the issue that OpenMP isn't working when I'm
> using PETSc in the same code. I'm including this segment at the beginning
> of my code:
> 
> int nthreads, tid;
> 
> #pragma omp parallel private(nthreads, tid)
>         {
> 
>   /* Obtain thread number */
>   tid = omp_get_thread_num();
> 
>   printf("Hello World from thread = %d\n", tid);
> 
>   /* Only master thread does this */
>   if (tid == 0)
>     {
>     nthreads = omp_get_num_threads();
>     printf("Number of threads = %d\n", nthreads);
>     }
> 
>   }
> 
> I have no problems getting this to run outside of PETSc, with typical
> output as follows:
> 
> Hello World from thread = 0
> 
> Hello World from thread = 1
> 
> Hello World from thread = 3
> 
> Hello World from thread = 2
> 
> Number of threads = 4
> 
> 
> But when I include that snippet of code in my larger PETSc code, all I get
> is
> 
> Hello World from thread = 0
> 
> Number of threads = 1
> 
> 
> My makefile is just
> 
> ALL:

Add the line:

CFLAGS = -fopenmp
> 
> include ${PETSC_DIR}/conf/variables
> 
> include ${PETSC_DIR}/conf/rules
> 
> include ${PETSC_DIR}/conf/test
> 
> 
> main: main.o
> 
> -${CLINKER} -fopenmp -o main main.o ${PETSC_LIB}

you can remove -fopenmp from here.

Satish

> 
> ${RM} -f main.o
> 
> 
> I don't get any errors when compiling, as far as I can tell. This is the
> output when compiling:
> 
> gcc-4.9 -o main.o -c -fPIC -Wall -Wwrite-strings -Wno-strict-aliasing
> -Wno-unknown-pragmas -g3 -fno-inline -O0
> -I/Users/justindong/Classes/CAAMResearch/petsc-3.4.4/include
> -I/Users/justindong/Classes/CAAMResearch/petsc-3.4.4/arch-gcc/include
> -I/Users/justindong/Classes/CAAMResearch/petsc-3.4.4/include/mpiuni
> -D__INSDIR__= main.c
> 
> gcc-4.9 -Wl,-multiply_defined,suppress -Wl,-multiply_defined -Wl,suppress
> -Wl,-commons,use_dylibs -Wl,-search_paths_first  -fPIC -Wall
> -Wwrite-strings -Wno-strict-aliasing -Wno-unknown-pragmas -g3 -fno-inline
> -O0  -fopenmp -o main main.o
> -L/Users/justindong/Classes/CAAMResearch/petsc-3.4.4/arch-gcc/lib
> -L/Users/justindong/Classes/CAAMResearch/petsc-3.4.4/arch-gcc/lib  -lpetsc
> -llapack -lblas -lpthread
> -L/usr/local/lib/gcc/x86_64-apple-darwin13.1.0/4.9.0 -L/usr/local/lib -ldl
> -lgfortran -lgfortran -lquadmath -lm -lm -lSystem -lgcc_ext.10.5 -ldl
> 
> /bin/rm -f -f main.o
> 
> 
> On Fri, Apr 25, 2014 at 12:46 AM, Satish Balay <balay at mcs.anl.gov> wrote:
> 
> > if you are primarily intesrested in -fopenmp - and not mpi - just
> > configure petsc with --with-mpi=0
> >
> > If you have currently working build with clang - and would
> > like to just compile your code with gcc-4.9 - you can try:
> >
> > export MPICH_CC=gcc-4.9
> > make [your-target]
> >
> > It might work. Or you might get link errors. [If you get
> > errors - its best to rebuild PETSc with gcc-4.9]
> >
> > BTW: you can use a different PETSC_ARCH for each of your builds - so
> > that they don't overwrite each other..
> >
> > ./configure PETSC_ARCH=arch-gcc --with-cc=gcc-4.9 --with-cxx=0 --with-mpi=0
> >
> > [on osx petsc can use VecLib so --download-f-blas-lapack shouldn't be
> > needed]
> >
> > Satish
> >
> > On Fri, 25 Apr 2014, Justin Dong wrote:
> >
> > > I'll leave it running for a few hours and see what happens.
> > >
> > > In the meantime, is it possible to tell PETSc to compile a specific .c
> > file
> > > using gcc-4.9? Something along the lines of this:
> > >
> > > ALL:
> > >
> > > include ${PETSC_DIR}/conf/variables
> > > include ${PETSC_DIR}/conf/rules
> > > include ${PETSC_DIR}/conf/test
> > >
> > > main: main.o
> > > gcc-4.9 -${CLINKER} -fopenmp -o main main.o ${PETSC_LIB}
> > > ${RM} -f main.o
> > >
> > > The main reason I want to compile with gcc-4.9 is because I need to use
> > > openmp for a simple parallel for loop. With the gcc compiler I have now
> > > (clang), there's no support for openmp. I can get gcc-4.9 to work outside
> > > of PETSc, but am not sure how to get it to work here if I want to do it
> > for
> > > a single example, or if that's even possible.
> > >
> > >
> > > On Thu, Apr 24, 2014 at 10:03 PM, Barry Smith <bsmith at mcs.anl.gov>
> > wrote:
> > >
> > > >
> > > >    Leave it to run for several hours it could be that gcc-4.9 is just
> > > > taking a very long time on mpich.
> > > >
> > > >    Barry
> > > >
> > > > On Apr 24, 2014, at 8:35 PM, Matthew Knepley <knepley at gmail.com>
> > wrote:
> > > >
> > > > > On Thu, Apr 24, 2014 at 9:27 PM, Justin Dong <jsd1 at rice.edu> wrote:
> > > > > Hi all,
> > > > >
> > > > > I'm trying to configure PETSc on Mac OS X with gcc-4.9. Currently,
> > it's
> > > > configured with gcc that comes with Xcode, but I want to use gcc-4.9
> > that I
> > > > installed myself. I try:
> > > > >
> > > > >
> > > > > ./configure --with-cc=gcc-4.9 --with-fc=gfortran
> > > > --download-f-blas-lapack --download-mpich
> > > > >
> > > > >
> > > > >
> > > > > But while configuring MPICH it gets stuck indefinitely. I've included
> > > > the output below after I terminate the process. I don't have this
> > issue if
> > > > I just configure with cc=gcc. Any ideas what the problem is here?
> > > > >
> > > > > From the stack trace, its just taking a long time. If it overruns the
> > > > timeout, it should just die. You can try
> > > > > running using -useThreads=0 if you suspect the timeout is not
> > working.
> > > > >
> > > > >    Matt
> > > > >
> > > > > ^CTraceback (most recent call last):
> > > > >
> > > > >   File "./configure", line 10, in <module>
> > > > >
> > > > >     execfile(os.path.join(os.path.dirname(__file__), 'config',
> > > > 'configure.py'))
> > > > >
> > > > >   File "./config/configure.py", line 372, in <module>
> > > > >
> > > > >     petsc_configure([])
> > > > >
> > > > >   File "./config/configure.py", line 287, in petsc_configure
> > > > >
> > > > >     framework.configure(out = sys.stdout)
> > > > >
> > > > >   File
> > > >
> > "/Users/justindong/Classes/CAAMResearch/petsc-3.4.4/config/BuildSystem/config/framework.py",
> > > > line 933, in configure
> > > > >
> > > > >     child.configure()
> > > > >
> > > > >   File
> > > >
> > "/Users/justindong/Classes/CAAMResearch/petsc-3.4.4/config/BuildSystem/config/package.py",
> > > > line 558, in configure
> > > > >
> > > > >     self.executeTest(self.configureLibrary)
> > > > >
> > > > >   File
> > > >
> > "/Users/justindong/Classes/CAAMResearch/petsc-3.4.4/config/BuildSystem/config/base.py",
> > > > line 115, in executeTest
> > > > >
> > > > >     ret = apply(test, args,kargs)
> > > > >
> > > > >   File
> > > >
> > "/Users/justindong/Classes/CAAMResearch/petsc-3.4.4/config/BuildSystem/config/packages/MPI.py",
> > > > line 748, in configureLibrary
> > > > >
> > > > >     config.package.Package.configureLibrary(self)
> > > > >
> > > > >   File
> > > >
> > "/Users/justindong/Classes/CAAMResearch/petsc-3.4.4/config/BuildSystem/config/package.py",
> > > > line 486, in configureLibrary
> > > > >
> > > > >     for location, directory, lib, incl in self.generateGuesses():
> > > > >
> > > > >   File
> > > >
> > "/Users/justindong/Classes/CAAMResearch/petsc-3.4.4/config/BuildSystem/config/package.py",
> > > > line 232, in generateGuesses
> > > > >
> > > > >     d = self.checkDownload(1)
> > > > >
> > > > >   File
> > > >
> > "/Users/justindong/Classes/CAAMResearch/petsc-3.4.4/config/BuildSystem/config/packages/MPI.py",
> > > > line 351, in checkDownload
> > > > >
> > > > >     return config.package.Package.checkDownload(self,
> > requireDownload)
> > > > >
> > > > >   File
> > > >
> > "/Users/justindong/Classes/CAAMResearch/petsc-3.4.4/config/BuildSystem/config/package.py",
> > > > line 340, in checkDownload
> > > > >
> > > > >     return self.getInstallDir()
> > > > >
> > > > >   File
> > > >
> > "/Users/justindong/Classes/CAAMResearch/petsc-3.4.4/config/BuildSystem/config/package.py",
> > > > line 187, in getInstallDir
> > > > >
> > > > >     return os.path.abspath(self.Install())
> > > > >
> > > > >   File
> > > >
> > "/Users/justindong/Classes/CAAMResearch/petsc-3.4.4/config/BuildSystem/config/packages/MPI.py",
> > > > line 366, in Install
> > > > >
> > > > >     return self.InstallMPICH()
> > > > >
> > > > >   File
> > > >
> > "/Users/justindong/Classes/CAAMResearch/petsc-3.4.4/config/BuildSystem/config/packages/MPI.py",
> > > > line 544, in InstallMPICH
> > > > >
> > > > >     output,err,ret  = config.base.Configure.executeShellCommand('cd
> > > > '+mpichDir+' && ./configure '+args, timeout=2000, log =
> > self.framework.log)
> > > > >
> > > > >   File
> > > >
> > "/Users/justindong/Classes/CAAMResearch/petsc-3.4.4/config/BuildSystem/script.py",
> > > > line 254, in executeShellCommand
> > > > >
> > > > >     (output, error, status) = runInShell(command, log, cwd)
> > > > >
> > > > >   File
> > > >
> > "/Users/justindong/Classes/CAAMResearch/petsc-3.4.4/config/BuildSystem/script.py",
> > > > line 243, in runInShell
> > > > >
> > > > >     thread.join(timeout)
> > > > >
> > > > >   File
> > > >
> > "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py",
> > > > line 958, in join
> > > > >
> > > > >     self.__block.wait(delay)
> > > > >
> > > > >   File
> > > >
> > "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py",
> > > > line 358, in wait
> > > > >
> > > > >     _sleep(delay)
> > > > >
> > > > >
> > > > > KeyboardInterrupt
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > Sincerely,
> > > > >
> > > > > Justin
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > What most experimenters take for granted before they begin their
> > > > experiments is infinitely more interesting than any results to which
> > their
> > > > experiments lead.
> > > > > -- Norbert Wiener
> > > >
> > > >
> > >
> >
> >
> 



More information about the petsc-users mailing list