Fortran MPI on Windows

There are several methods available to get MPI on Windows, including:

  • Microsoft MPI (MS-MPI) with MSYS2 or MinGW: open-source, discussed below
  • Intel oneAPI MPI
  • Cygwin libopenmpi-devel
  • Windows Subsystem for Linux libopenmpi-dev

MPI + MSYS2

This procedure gives MPI via MSYS2 GCC / Gfortran compilers on Windows.

  1. Download and install Microsoft MS-MPI

  2. To make mpiexec.exe available, add to user PATH: C:\Program Files\Microsoft MPI\Bin – this is needed even when using MSYS2.

  3. Install MSYS2 MS-MPI library, from the MSYS2 Terminal

    pacman -S mingw-w64-x86_64-msmpi
    

MPI + MinGW

While we recommennd MSYS2, it’s also possible to use MS-MPI with MinGW. We will put the resulting artifacts under c:/lib/mpi

mkdir c:/lib/mpi/

Copy-Item -Path "C:/Program Files (x86)/Microsoft SDKs/MPI/Include" -Destination "c:/lib/mpi/" -Recurse

cd c:/lib/mpi

you may need to edit “include/mpi.f90” to have INCLUDE 'mpifptr.h'

gfortran include/mpi.f90 -c -fno-range-check -fallow-invalid-boz

Do NOT link with ar or MPI may only run with a single image. If you don’t compile the mpi.f90 as above, errors may result like:

use mpi

Fatal Error: Cannot open module file 'mpi.mod' for reading at (1): No such file or directory

Notes

OpenMPI is not currently available for native Windows.

IntelMPI clash with MinGW MS-MPI

Upon installing or updating Intel oneAPI compilers and libraries on Windows, you may experience CMake failing to find MPI for MinGW. This happens because Intel compilers put Intel MPI on the system PATH. Generally we remove Intel MPI from the system PATH and use the Intel Compiler shell instead, which provides all the needed directories. This is because we don’t typically use Intel MPI with Visual Studio, and if we did, we’d make a shell script for that.