[cmake-developers] Adding Microsoft MPI Fortran support in FindMPI

Christian P. cpfeiffer at live.de
Fri Apr 21 17:45:18 EDT 2017


Hi folks,

I’d like to implement support for MSMPI’s Fortran API in FindMPI so that it could be used to build ScaLAPACK and others. However, I’m looking for a bit of guidance on how to do this.

The Fortran 90 interfaces are contained in a file called mpi.f90 in the MSMPI include folder. This file has to be built with the Fortran compiler employed by the user and will generate the mpi module used by MPI code (there’s no mpi_f08 module provided). However, I don’t know how to handle this: If I add it to MPI::MPI_Fortran via INTERFACE_SOURCES, then it would break parallel builds as soon as two targets with the same module path were built, since the file could be overwritten at any time causing consuming build processes to read a partially written file.

In a way, FindMPI would need to compile the file itself as a static library and link the output and add the folder with the module to its includes. Yet, this can become a problem because of target visibility. My idea is therefore to add a static library in the FindMPI module containing just the mpi.f90 module and creating an imported target pointing to it in order to wrap up visibility.

Is this a good/bad idea or is there any way to do this in a proper fashion? The idea of adding an actual target to a Find module seems wrong to me, but I’m not seeing any way of doing it otherwise.


For reference, I’ve added the full list of steps that one needs to do for linking Fortran code with MSMPI below:

  1.  Add the x86/x64 include folder in the MSMPI folder containing mpifptr.h (not a problem at all)
  2.  Link one of msmpifec/es/mc/ms.lib – The difference between these libraries is that the ‘c’/’s’ versions are for Fortran implementations using the ‘cdecl’ and ‘stdcall’ calling conventions, respectively. The ’m’ versions are for Fortran implementations putting the size of a CHARACTER* argument immediately after the pointer in a call’s parameter list, and the ‘e’ ones for those that put them at the end of the parameter list.

For virtually all Fortran compilers (including PGI and Intel), the msmpifec is the right library and the msmpifms one is only needed for Compaq Visual Fortran (Intel Fortran predecessor) or when changing the default in ifort, see also https://software.intel.com/en-us/node/528352 for MKL’s handling of the matter.

I believe jus using the ‘ec’ version in all cases is therefore okay for CMake, and I wouldn’t know of a good way to otherwise detect a correct value.

  1.  (Only if the Fortran 90 mpi module is to be used. Not necessary for the F77 interfaces) Compile mpi.f90, link the output and include the folder containing the emitted Fortran module.

- Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20170421/1f81cd85/attachment.html>


More information about the cmake-developers mailing list