Alex Koshkarov <[email protected]> writes:

> Thanks for this. 
> I now use modified version of  `share/petsc/Makefile.user`. However, now I am 
> not sure if I do linking correctly. All my code is pure C, so I use
>
> $(OBJ) - variable with all object files
>
> driver: $(OBJ) 
>       $(LINK.c) $^ $(LDFLAGS) $(LDLIBS) -o $@
>
> I am not sure if I need to pass variable $(LDFLAGS) or not, since in 
> Makefile.user examples does not, it uses only $(LDLIBS). 

It's part of LINK.c:

$ make -p -f /dev/null | fgrep 'LINK.c ='
make: *** No targets.  Stop.
LINK.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)


The variables are being extracted according to conventions.

$ make -f share/petsc/Makefile.user print
CC=mpicc
CXX=mpicxx
FC=mpif90
CFLAGS=-fPIC -Wall -Wwrite-strings -Wno-strict-aliasing -Wno-unknown-pragmas 
-fstack-protector -fvisibility=hidden -O2 -march=native -ffp-contract=fast -g
CXXFLAGS=-Wall -Wwrite-strings -Wno-strict-aliasing -Wno-unknown-pragmas 
-fstack-protector -fvisibility=hidden -g -O -fPIC
FFLAGS=-fPIC -Wall -ffree-line-length-0 -Wno-unused-dummy-argument -g -O
CPPFLAGS=-I/home/jed/petsc/ompi-optg/include -I/home/jed/petsc/include
LDFLAGS=-L/home/jed/petsc/ompi-optg/lib -Wl,-rpath,/home/jed/petsc/ompi-optg/lib
LDLIBS=-lpetsc -lm
CUDAC=
CUDAC_FLAGS=
CUDA_LIB=
CUDA_INCLUDE=

> Also, after reading Jed's and mine petsc.pc, I noticed that I do not have 
> optimization flags, however I compile petsc with optimization flags. (I also 
> add additional -O3 into compilation rule when compile my code)
> Namely, I add during petsc configuration/compilation (I use gcc and openmpi):
>
> --with-debugging=0 COPTFLAGS='-O3 -march=native -mtune=native' 
> CXXOPTFLAGS='-O3 -march=native -mtune=native' FOPTFLAGS='-O3 -march=native 
> -mtune=native' 
>
> So how do I check if my petsc is compiled with optimizations?

petsc.pc only provides what is necessary to compile your code with PETSc. There 
are lots of circumstances in which you might want a debugging build of your 
application linked with release PETSc (suppose all your development is 
unrelated from PETSc).

> And my petsc.pc is:
>
> prefix=/home/kosh/Documents/NEPIC/libs/petsc-3.14.2/optim
> exec_prefix=${prefix}
> includedir=${prefix}/include
> libdir=${prefix}/lib
> ccompiler=mpicc
> cflags_extra=-fPIC -Wall -Wwrite-strings -Wno-strict-aliasing 
> -Wno-unknown-pragmas -fstack-protector -fvisibility=hidden
> cflags_dep=-MMD -MP
> ldflag_rpath=-Wl,-rpath,
> cxxcompiler=mpicxx
> cxxflags_extra=-Wall -Wwrite-strings -Wno-strict-aliasing 
> -Wno-unknown-pragmas -fstack-protector -fvisibility=hidden  -fPIC
> fcompiler=mpif90
> fflags_extra=-fPIC -Wall -ffree-line-length-0 -Wno-unused-dummy-argument
>
> Name: PETSc
> Description: Library to solve ODEs and algebraic equations
> Version: 3.14.2
> Cflags:   -I${includedir} 
> -I/home/kosh/Documents/NEPIC/libs/petsc-3.14.2/include
> Libs: -L${libdir} -lpetsc
> Libs.private: -L/home/kosh/Documents/NEPIC/libs/petsc-3.14.2/optim/lib 
> -L/usr/lib/openmpi -L/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0 -lHYPRE 
> -lscalapack -llapack -lblas -lX11 -lhdf5hl_fortran -lhdf5_fortran -lhdf5_hl 
> -lhdf5 -lm -lstdc++ -ldl -lmpi_usempif08 -lmpi_usempi_ignore_tkr -lmpi_mpifh 
> -lmpi -lgfortran -lm -lgfortran -lm -lgcc_s -lquadmath -lpthread -lquadmath 
> -lstdc++ -ldl
>
>
> Thank you and best regards,
> Alex.
>
> On 12/16/20, 9:15 AM, "Jed Brown" <[email protected]> wrote:
>
>     Alex Koshkarov <[email protected]> writes:
>
>     > Thanks Barry,
>     >
>     > It makes much more sense! And thanks for clarifying what “P” indicates. 
> I like this explicit approach over implicit because I am bad with makefile 
> syntax. However, share/petsc/Makefile.user looks much cleaner, but I need to 
> learn how pkg-config works to understand it.
>
>     Open a petsc.pc to see what is specified there. We define a number of 
> extra variables that can help with checking for common compilers/wrappers and 
> how to use RPATH if needed.
>
>     prefix=/home/jed/petsc/ompi-optg
>     exec_prefix=${prefix}
>     includedir=${prefix}/include
>     libdir=${prefix}/lib
>     ccompiler=mpicc
>     cflags_extra=-fPIC -Wall -Wwrite-strings -Wno-strict-aliasing 
> -Wno-unknown-pragmas -fstack-protector -fvisibility=hidden -O2 -march=native 
> -ffp-contract=fast -g
>     cflags_dep=-MMD -MP
>     ldflag_rpath=-Wl,-rpath,
>     cxxcompiler=mpicxx
>     cxxflags_extra=-Wall -Wwrite-strings -Wno-strict-aliasing 
> -Wno-unknown-pragmas -fstack-protector -fvisibility=hidden -g -O  -fPIC
>     fcompiler=mpif90
>     fflags_extra=-fPIC -Wall -ffree-line-length-0 -Wno-unused-dummy-argument 
> -g -O
>
>     Name: PETSc
>     Description: Library to solve ODEs and algebraic equations
>     Version: 3.13.99
>     Cflags:   -I${includedir} -I/home/jed/petsc/include
>     Libs: -L${libdir} -lpetsc
>     Libs.private: -L/home/jed/petsc/ompi-optg/lib -L/usr/lib/openmpi 
> -L/usr/lib/gcc/x86_64-pc-linux-gnu/10.1.0 -lHYPRE -lumfpack -lklu -lcholmod 
> -lbtf -lccolamd -lcolamd -lcamd -lamd -lsuitesparseconfig -lsuperlu 
> -lsuperlu_dist -lml -llapack -lblis -ltriangle -lX11 -lexodus -lnetcdf 
> -lpnetcdf -lcgns -lmedC -lmed -lhdf5hl_fortran -lhdf5_fortran -lhdf5_hl 
> -lhdf5 -lparmetis -lmetis -lm -lz -lstdc++ -ldl -lmpi_usempif08 
> -lmpi_usempi_ignore_tkr -lmpi_mpifh -lmpi -lgfortran -lm -lgfortran -lm 
> -lgcc_s -lquadmath -lpthread -lquadmath -lstdc++ -ldl

Reply via email to