2014-08-22

Compiling OpenMPI with the NAG Fortran Compiler

As the most popular search engine was only partially useful when looking for information about compiling OpenMPI with the NAG compiler, below a short summary of my recent (successful) efforts. I've tried to get something working out of the following components:
  • NAG Fortran Compiler Release 6.0(Hibiya) Build 107
  • OpenMPI 1.8.1
  • GCC 4.8.2
  • Ubuntu 14.4 (x86_64/Linux)

Configuration and compilation

The configure combination working was the following:

./configure FC=nagfor FCFLAGS="-mismatch" --enable-static --disable-shared --prefix=${HOME}/local/opt/openmpi/1.8.1-nag6.0

The rationale behind the options:
  • FC=nagfor: Use the NAG Fortran compiler
  • FCFLAGS="-mismatch": Convince the excellent NAG compiler not to be too picky about calling conventions. Otherwise one ends up with error messages like

    Error: mpi_comm_spawn_multiple_f90.f90: Argument 3 to MPI_COMM_SPAWN_MULTIPLE has data type DOUBLE PRECISION in reference from MPI_COMM_SPAWN_MULTIPLEN and CHARACTER in reference from MPI_COMM_SPAWN_MULTIPLEA
     
  •  --enable-static --disable-shared: Apparently, libtool passes the inappropriate option -shared to the NAG compiler, resulting in the error

    Option error: Unrecognised option -shared

    during the compilation process. Probably, it can be fixed somehow within libtool itself. My preference was to build only a static version of OpenMPI rather than messing around with the innards of libtool.

Fixing the wrapper options

Unfortunately, libtools inability to cope with the NAG compiler had further consequences. When compiling the parallel version of our DFTB+ code,I've ended up with the error message:

gcc: error: unrecognized command line option ‘-rpath’

Fortunately, a similar issue has been already discussed on the OpenMPI mailing list. Accordingly, I've replaced in all Fortran related wrapper files the -Wl, flag in the linker options to -Wl,-Wl,,. This was easily achieved by executing the following bash commands in the shared/openmpi directory (relative to the root directory of the installed OpenMPI).

for file in mpifort-vt-wrapper-data.txt mpifort-wrapper-data.txt shmemfort-wrapper-data.txt;  do
  cp $file ${file}.orig
  sed -e 's/-Wl,/-Wl,-Wl,,/g' $file.orig > $file
done


This fixes the broken linking workflow: OpenMPI passes the options meant for the linker to the NAG compiler with the -Wl,-Wl,, prefix. The NAG compiler subsequently passes them to GCC with the -Wl prefix, so that GCC can finally properly pass them to the linker itself (without any suffix). Without the changes above, the linker options would arrive already at GCC without any prefix, causing GCC to raise an error about unknown options.

After that, OpenMPI and the NAG Fortran compiler worked together like charm.