0

I have an account on a cluster which I access through SSH. The cluster uses Red Hat. My account does not have root privileges.

I do not have gfortran installed but I need it to compile a program that I will be using. This program is a Python wrapper of a Fortran code, which uses MPI.

I followed this brilliant answer to create a conda environment with Fortran compilers.

I activate the environment and then try to run python setup.py install for my Python code. I get this error:

/disk/username/bin/x86_64-conda-linux-gnu-gfortran -ffree-line-length-none -cpp -fPIC -fno-stack-arrays  -Ofast -DMPI -c utils.F90
utils.F90:5: Error: Can't open included file 'mpif.h'

Then I try to modify the Makefile of the original Fortran code, including an explicit reference to where mpif.h is, with -I/path/to/conda/environment/include, following this other brilliant SO answer. This helps, and the installation is then complete.

However, when I try to import the Python package I get the following error:

ImportError: undefined symbol: mpi_allreduce_

What is going wrong? Incidentally, if I compile the Fortran code without MPI, everything works fine.

francescalus
  • 30,576
  • 16
  • 61
  • 96
johnhenry
  • 1,293
  • 5
  • 21
  • 43
  • This isn't really a gfortran problem but your MPI+Python(+gfortran?) environment configuration problem. You ned to provide details about that. – Vladimir F Героям слава Jan 05 '23 at 16:28
  • In general about the undefined symbol errors https://stackoverflow.com/questions/66855252/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix The linker or the Python part that loads libraries must load the correct libmpi library. – Vladimir F Героям слава Jan 05 '23 at 16:30
  • If you believe it has something to do with the actual compilation by gfortran (unlikely) you have to show how you compile the code with gfortran and the output of the compilation command. – Vladimir F Героям слава Jan 05 '23 at 16:32
  • 1
    BTW to install gfortran without root, you can just compile the GCC sources, I did it many times.The MPI library should then be compiled for that specific compiler and shoud be made aware of any sheduling system on the cluster and of any high-speed interconnects on the cluster during compilation. The mpirun or mpiexec command or any other similar executios performed by Python should always use the same MPI library version, that was used to compile the code being executed. Otherwise bad things happen. – Vladimir F Героям слава Jan 05 '23 at 16:40
  • @VladimirFГероямслава Compile from sources can even be made easier by using a package manager such as homebrew. – Victor Eijkhout Jan 05 '23 at 19:20
  • make sure the shared library you are building (and that is loaded by the `import ...` python statement depends on the MPI Fortran library (e.g. `libmpi_mpifh.so` if you use Open MPI) – Gilles Gouaillardet Jan 06 '23 at 07:04
  • Yes, the actual compilation command is really needed. Normally, one uses the `mpif90` command (or equivalent), not the `gfortran` command. – Vladimir F Героям слава Jan 06 '23 at 07:40

0 Answers0