Issues with Compiling MPI Program
bernardopacini opened this issue · comments
Hello, I am trying to update my code wrapped in f90wrap to be MPI parallel instead of OpenMP. From your paper and linked code packages it seems this is possible, but I am struggling to get it to work.
Following the f2py documentation, I am trying to wrap the example code:
! file: helloworld.f90
subroutine sayhello(comm)
use mpi
implicit none
integer :: comm, rank, size, ierr
call MPI_Comm_size(comm, size, ierr)
call MPI_Comm_rank(comm, rank, ierr)
print *, 'Hello, World! I am process ',rank,' of ',size,'.'
end subroutine sayhello
It can be called from Python with:
from mpi4py import MPI
import helloworld
fcomm = MPI.COMM_WORLD.py2f()
helloworld.sayhello(fcomm)
For f2py, this compiles and runs using the command:
f2py -c --f90exec=mpif90 helloworld.f90 -m helloworld
With f90wrap, I tried to use the commands:
f90wrap -m test helloworld.f90 -P -v
f2py-f90wrap --fcompiler=mpif90 --build-dir . -c -m _test -L. -lsrc f90wrap*.f90
But it results in the error:
.
.
.
running build_ext
customize UnixCCompiler
customize UnixCCompiler using build_ext
don't know how to compile Fortran code on platform 'posix' with 'ompi_fc' compiler. Supported compilers are: gnu,gnu95,compaq,intel,intelv,intele,intelev,intelvem,intelem,none,nag,nagfor,pg,flang,ibm,sun,nv,lahey,g95,mips,hpux,pathf95,fujitsu,absoft,vast)
warning: build_ext: f77_compiler=mpif90 is not available.
building '_test' extension
error: extension '_test' has Fortran sources but no Fortran compiler found
.
.
Do you have any guidance or instructions on how to compile this code correctly?
Thanks in advance!
Looks like f2py
can't find your MPI Fortran compiler. Try f2py-f90wrap -c --help-fcompiler
to see what is auto-detected, and then try setting the F90
environment variable to the correct compiler, or pass additional options to f2py-f90wrap
.
Maybe you need
f2py-f90wrap --build-dir . -c --f90exec=mpif90 -m _test -L. -lsrc f90wrap*.f90
to be equivalent to your working f2py
example? Note that f2py-f90wrap
is only a very thin wrapper over f2py
, so it shouldn't change how compiler arguments are handled.
Thank you for the guidance! As you suggest, I ended up having it work with the following call:
f90wrap -m $(PYTHON_MODN) $(wrap_files) --only $(wrap_subroutines) -k $(KIND_MAP) -P -v --py-max-line-length 120
f2py-f90wrap --f90exec=mpif90 --build-dir . -c -m _${PYTHON_MODN} -L. -lsrc f90wrap*.f90 $(INCLUDES) -lgfortran
This works without issue on Ubuntu 20.04, but on Mac I get the error:
ld: file not found: /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation for architecture x86_64
collect2: error: ld returned 1 exit status
This may be due to my environment though, I have not been keeping up to date with the latest Mac changes.