michelosca / epoch-ltp

Particle-in-cell code for plasma physics simulations
GNU General Public License v3.0
2 stars 0 forks source link

Compiling with PETSc support Fails #2

Open TomGoffrey opened 10 months ago

TomGoffrey commented 10 months ago

The Makefile doesn't automatically pick up the required PETSc flags.

Looking at the Makefile I'm assuming variables such as PETSC_DIR should be set.

The use of pkg-config removes the requirement of the user to set these variable:

$ git diff Makefile
diff --git a/epoch1d/Makefile b/epoch1d/Makefile
index 50acc5db..32d943e0 100644
--- a/epoch1d/Makefile
+++ b/epoch1d/Makefile
@@ -376,11 +376,13 @@ main: $(FULLTARGET)
 endif

 #PETSc
--include $(PETSC_DIR)/lib/petsc/conf/variables
--include $(PETSC_DIR)/lib/petsc/conf/rules
-CFLAGS = $(PETSC_CC_INCLUDES)
-FFLAGS += $(PETSC_FC_INCLUDES) -fopenmp
-LDFLAGS +=$(PETSC_LIB)
+PETSC_GOT := $(shell pkg-config --exists PETSc && echo 0)
+ifeq ($(PETSC_GOT),0)
+  PETSC_FFLAGS := $(shell pkg-config --cflags PETSc)
+  PETSC_LDFLAGS := $(shell pkg-config --libs PETSc)
+  FFLAGS += $(PETSC_FFLAGS)
+  LDFLAGS += $(PETSC_LDFLAGS)
+endif
michelosca commented 9 months ago

Using pkg-config does not work for me. When adding it I get the following error when compiling

$ make COMPILER=gfortran
mpif90 -c -O3 -g -std=f2003 -ffpe-summary=invalid,zero,overflow -I../SDF/FORTRAN/include -Iobj -Jobj -I/usr/include  -o obj/electrostatic.o  -DPER_SPECIES_WEIGHT -DELECTROSTATIC -DNEUTRAL_COLLISIONS -DPETSC -DSEE -DPART_PERP_POSITION -D_COMMIT='"v4.17.14-386-g8a55b28e-dirty"' -D_DATE=1706880367 -D_MACHINE='"login1.viking2.yor.alces.network"' -Isrc/include src/physics_packages/electrostatic.F90
src/physics_packages/electrostatic.F90:22:6:

   22 |   USE petscvec
      |      1
Fatal Error: Cannot open module file ‘petscvec.mod’ for reading at (1): No such file or directory
compilation terminated.
make[1]: *** [Makefile:416: electrostatic.o] Error 1
make[1]: Leaving directory '/mnt/scratch/users/moe505/epoch/epoch1d'
make: *** [Makefile:474: commit] Error 2

I do not get this error when using the current setup. Note that the right Makefile is the one in the epoch_ltp_1d branch.

TomGoffrey commented 9 months ago

Looks to me like pkgconfig can't find your PETSc installation. I've always used this method when including PETSc - given it's listed as the recommended method on the getting started page:

https://petsc.org/release/manual/getting_started/

Suspect you need to add the PETSc location to your PKG_CONFIG_PATH variable.

Don't have strong preference for which option we go for (beyond following PETSc's own recommendations), but should be documented.