Research Profile

Seek and you shall find...

MPIFORT Compilation Error on macOS

Recently, I have built Open MPI version 4.0.4 with the Intel Parallel Studio XE 2018 (icc, icpc and ifort version 18.0.6.243) on macOS Sierra 10.12.6. The compilation and installation were successful with the following commands:
./configure --prefix=/usr/local CC=icc CXX=icpc F77=ifort FC=ifort
make all
sudo make install

However, when I try to compile a simple MPI FORTRAN program with mpifort, I always get the following error:
Undefined symbols for architecture x86_64:
"_ompi_buffer_detach_f08", referenced from:
import-atom in libmpi_usempif08.dylib
ld: symbol(s) not found for architecture x86_64

It is worth to note that by default, Open MPI will attempt to build all 3 Fortran bindings: mpif.h, the "mpi" module, and the "mpi_f08" module. So what is the problem here and how to fix it?

After doing some research and tests, I found out, that from version 4.0.3, building of the 'use mpi_f08' MPI bindings has been changed slightly to avoid the weirdness (e.g., https://github.com/open-mpi/ompi/issues/7253). However, when libtool is created by invoking the configure script, the way to pass a linker flag through the compiler is not done properly. As a result, the argument being passed '-force-load' cannot be accepted by the Intel FORTRAN compiler, causing the library libmpi_usempif08.dylib to be missing some (or all?) of the F90 symbols. A workaround solution is either to add '-Wl,' to 'wl' variable (i.e., wl="-Wl,") in the libtool file for the FORTRAN part after invoking the configure script or to modify the configure script before invoking it as follows:

The original code block:
darwin* | rhapsody*)
# PIC is the default on this platform
# Common symbols not allowed in MH_DYLIB files
lt_prog_compiler_pic_FC='-fno-common'
case $cc_basename in
nagfor*)
# NAG Fortran compiler
lt_prog_compiler_wl_FC='-Wl,-Wl,,'
lt_prog_compiler_pic_FC='-PIC'
lt_prog_compiler_static_FC='-Bstatic'
;;
esac
;;

Should be replaced by a new code block:
darwin* | rhapsody*)
# PIC is the default on this platform
# Common symbols not allowed in MH_DYLIB files
lt_prog_compiler_pic_FC='-fno-common'
case $cc_basename in
icc* | ifort*)
# Intel Fortran compiler
lt_prog_compiler_wl_FC='-Wl,'
lt_prog_compiler_pic_FC='-fno-common -fPIC'
lt_prog_compiler_static_FC=''
;;
nagfor*)
# NAG Fortran compiler
lt_prog_compiler_wl_FC='-Wl,-Wl,,'
lt_prog_compiler_pic_FC='-PIC'
lt_prog_compiler_static_FC='-Bstatic'
;;
esac
;;

Now, the mpifort wrapper compiler is working properly.