Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with Compiling MPI Program #162

Open
bernardopacini opened this issue Dec 21, 2021 · 3 comments
Open

Issues with Compiling MPI Program #162

bernardopacini opened this issue Dec 21, 2021 · 3 comments

Comments

@bernardopacini
Copy link
Contributor

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!

@jameskermode
Copy link
Owner

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.

@jameskermode
Copy link
Owner

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.

@bernardopacini
Copy link
Contributor Author

bernardopacini commented Jan 10, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants