SPECFEM / specfem2d

SPECFEM2D simulates forward and adjoint seismic wave propagation in two-dimensional acoustic, (an)elastic, poroelastic or coupled acoustic-(an)elastic-poroelastic media, with Convolution PML absorbing conditions.
https://specfem.org
GNU General Public License v3.0
203 stars 147 forks source link

gfortran - type mismatch / rank mismatch while compiling #1181

Open HakunanMatatat opened 1 year ago

HakunanMatatat commented 1 year ago

The following errors occur as gcc-11 gfortran-11.

gfortran -g -O2 -std=f2008 -fimplicit-none -fmax-errors=10 -pedantic -pedantic-errors -Waliasing -Wampersand -Wcharacter-truncation -Wline-truncation -Wsurprising -Wno-tabs -Wunderflow -ffpe-trap=invalid,zero,overflow -Wunused -O3 -finline-functions -DWITH_MPI -J./obj -I./obj -I. -I./setup -c -o obj/define_external_model_from_tomo_file.spec.o src/specfem2D/define_external_model_from_tomo_file.f90 src/shared/parallel.F90:340:17:

340 | call MPI_BCAST(buffer,1,MPI_INTEGER,0,my_local_mpi_comm_world,ier) | 1 ...... 395 | call MPI_BCAST(buffer,1,MPI_LOGICAL,0,my_local_mpi_comm_world,ier) | 2 Error: Type mismatch between actual argument at (1) and actual argument at (2) (INTEGER(4)/LOGICAL(4)). src/shared/parallel.F90:368:17:

368 | call MPI_BCAST(buffer,countval,MPI_LOGICAL,0,my_local_mpi_comm_world,ier) | 1 ...... 395 | call MPI_BCAST(buffer,1,MPI_LOGICAL,0,my_local_mpi_comm_world,ier) | 2 Error: Rank mismatch between actual argument at (1) and actual argument at (2) (scalar and rank-1)

export FCFLAGS="-w -fallow-argument-mismatch -O2" export FFLAGS="-w -fallow-argument-mismatch -O2" This Flag adding didn't work.

Errors still as gcc-9 gfortran-9

gfortran: error: unrecognized command line option ‘-fallow-invalid-boz’ gfortran: error: unrecognized command line option ‘-fallow-argument-mismatch’; did you mean ‘-Wno-argument-mismatch’? make: *** [src/shared/rules.mk:102: obj/parallel.sharedmpi.o] Error 1

Hoping your help. Thanks very much.

danielpeter commented 1 year ago

this is an annoying GCC "feature" introduced in newer versions with stricter argument checking in single files.

please see the comment here: https://github.com/SPECFEM/specfem3d/discussions/1584#discussioncomment-4795279

add either the -std=legacy or the -fallow-argument-mismatch to the compilation flags for GCC compiler versions >= 10 in a line like:

./configure FC=gfortran CC=gcc MPIFC=mpif90 --with-mpi FLAGS_CHECK="-O3 -fallow-argument-mismatch -Wall -Wno-conversion -Wno-maybe-uninitialized"

on older GCC versions <= 9, you won't need the -fallow-argument-mismatch flag, simply:

./configure FC=gfortran CC=gcc MPIFC=mpif90 --with-mpi FLAGS_CHECK="-O3 -Wall -Wno-conversion -Wno-maybe-uninitialized"

give it a try and let me know if this works on your system.

HakunanMatatat commented 1 year ago

hi, @daniel, thanks! It is too many warnings. ./run_this_example works fine.

specfem3D - https://ctxt.io/2/AACQ_JETFA specfem2d - https://ctxt.io/2/AACQ0ul1FA

I don't know the limination using CUDA with spcefem2d.

danielpeter commented 1 year ago

the compilation of the 2D version with CUDA support is the same as in the 3D version, thus in your case something like:

./configure .. --with-cuda=cuda11  CUDA_LIB=/usr/local/cuda-11.7/lib64 ..

you can follow the settings as described here: https://specfem3d.readthedocs.io/en/latest/02_getting_started/#using-the-gpu-version-of-the-code

note that the 2D version only has CUDA support, whereas the 3D version also supports HIP now.

also, the setting --with-cuda=cuda11 refers to your target architecture, i.e., a Nvidida A100 card in this case. it doesn't refer to your CUDA toolkit version that you have installed on your system. for example, you can have a toolkit version 11 installed, but want to run the simulation on an older card, say a Pascal P100. in this case, you would use

./configure .. --with-cuda=cuda8  CUDA_LIB=/usr/local/cuda-11.7/lib64 ..