MPI Installation help

Hi guys, so I have decided to use MPI. I have been using codeblock and compile using MinGW of GNU Fortran Compiler. When I compile the program, there is a fatal error flag that the mpi.mod can not be find. I am wondering which MPI should I use. I don’t have an administrator access so microsoft one is hard. And I’m kinda stuck with codeblock and MinGW/GNU Fortran Compiler so Intel MPI is also hard. My only option is kinda MPICH but the guide provided on youtube is already out of date and the starting guide provided by them is built towards linux, which I don’t understand at all. Can anyone here help me?

Many thanks

1 Like

On windows, for Fortran + MPI, I have tried the below 3 ways which all work.

  1. you can install cygwin64,
    Cygwin

and install openmpi package in it.
https://sourceware.org/legacy-ml/cygwin/2014-06/msg00410.html

You can google “cygwin64 openmpi” a little bit. Also don’t forget to add some include or lib folder in the environmental variables. I remember I successfully installed cygwin64 and openmpi and it runs.

  1. On windows, I recommend install MS visual studio (the community version is free) + intel OneAPI (free), This seems to be the best solution. Gfortran is pretty good on Mac and Linux. But sometimes gfortran’s performance on Windows may not be too good compare with its performance on linux/mac, and dIfferent versions of gfortran on windows may give different performance.

  2. Another good solution is to install Ubuntu in WSL, and then run gfortran + mpich just the same as in native Linux,
    Install WSL | Microsoft Docs
    If you want GUI of your WSL Ubuntu, you can check out many instructions from youtube,
    WSL2 Ubuntu GUI - YouTube
    https://www.youtube.com/results?search_query=wsl+windows+10+gui
    I also installed gfortran + mpich in WSL Ubuntu with GUI in Windows 10, and it runs fine.

1 Like

Out of curiosity, is your program supposed to run on a distributed-memory cluster of Windows servers (e.g. using something like Microsoft HPC, Microsoft Cluster Server, or Microsoft Azure)?

If not, you could perhaps investigate other SPMD programming models including OpenMP or Fortran coarrays.

2 Likes

I just tested the openmpi in cygwin64 for you.

Make sure that in cygwin64, in the below screenshot, those openmpi stuff with version number 4.1.2xxx are installed.

Of course you also need the gfortran 11.3.0-1 I think, as below,

also make sure those gcc stuff with version number 11.3.0-1, as below,

Notice that, at least in my test, I use the cygwin64 shell to do all the compiling and run the code, just like in linux,

Now, about compiling.
if in some of your f90 files, say you have a file called mympi.f90,
in it, you have

use mpi

Then for this mympi.f90, since you install openmpi, you would need to use mpif90 to complie your file. Also you need to have a -I flag. For example

mpif90 -Ofast -march=native -flto -w -c mympi.f90 -IC:\cygwin64\lib

Now you see at the end I did

-IC:\cygwin64\lib

There is is -I, which means -include. Then followed with C:\cygwin64\lib, this is because the mpi.mod file is under my C:\cygwin64\lib directory. So combine them -IC:\cygwin64\lib, then mpif90 can find mpi.mod. Otherwise mpif90 will not be able to find mpi.mod and it will throw an error.

2 Likes

Thank you so much for your/masters help. It is very helpful~

1 Like

Umm, I followed your instruction up to before compiling. Right now, I am using codeblock with MinGW installed. My Open MPI version (as using cygwin) is 4.1.2-1 (newest). It says I can’t open the mpi.mod since it was created by different version of fortran. I am installing new MinGW, yet it still says the same. Is there a way to usie the Open MPI with MinGW? Thanks :slight_smile:

I am also thinking to not use MinGW but directly use the Gfortran inside the cygwin, but somehow, the codeblock won’t detect it.

Not very sure about mingw, if you need to use mingw, I think you need to install the openmpi from the mingw terminal. Then that openmpi version will be compatible with your mingw gfortran. Also need to add the directory in your environmental variables. I almost never used codeblock, but perhaps it cannot detect cygwin gfortran is because cygwin gfortran’s directory is not in the environmental variables perhaps.

In fact using gfortran + mpi is headache on windows for me, and I have to write makefile to compile and build the code. Cumbersome.

Now, my point is
On windows, if you can use intel fortran just use intel Fortran, the intel OneAPI and Visual Studio community version are both free, and are really good, fast and convenient. MPI, C/C++/Fortran, MKL, etc, are all included in OneAPI, really good. This is my solution. Or if you do not like visual studio, you can also use VS code, @gnikit is the author of the modern Fortran addon for VS code, perhaps he may give you some suggestions as well.

If you are familiar and comfortable with coding in Linux (again you may need VS code), then perhaps the best choice is to use WSL on windows, install Ubuntu and install the GUI, use the windows intrinsic remote desktop (RDP) to login in you Ubuntu, then you can just in Linux in the terminal type

sudo apt install gfortran mpich

everything is ready. Just use mpif90 to compile you code, no need to include any folder or lib, it is already configured and ready to use, really convenient. I honestly do not like gfortran on Windows (gfortran and openmpi/mpich are just not build for Windows), however, I have to say, gfortran on Linux and Mac are really god damn good.


PS.
Uhm, if you have to use gfortran and mpi on windows. I believe Microsoft MPI (MS-MPI) is a good way to go. I know some commerical medical software such as NONMEM uses MS-MPI,
https://www.mail-archive.com/nmusers@globomaxnm.com/msg07447.html

MS-MPI,

Below is a link in Chinese about to how to compile and link C/C++/Fortran with MS-MPI, but you could translate it into English,

There is a English version,

The idea is simple. Just say the Fortran part,

  1. use gfortran, like your mingw version, from the mpi.f90 in MS-MPI, generate the mpi.mod file which is needed when compiling code in which use mpi is used.
    Like, when you compile the code using Makefile with mpif90, say your mpi.mod is under C:\msmpi you need a flag like below,

-I “c:\msmpi” .

  1. also, you need to generate a libmsmpi.a, which will be used at the linking stage. If this libmsmpi.a , and the mpi.mod file, and your hello world f90 code are in the same folder, then you do things like

mpif90 -o hello.exe hello.f90 ibmsmpi.a

If mpi.mod and libmsmpi.a are both in C:\msmpi , then you do things (the grammer may not be exactly right, but you know you need -I to include the folder which contain mpi.mod at compiling stage, and -L to include the folder which contain the library libmsmpi.a ) like,
mpif90 -o hello.exe hello.f90 libmsmpi.a -I "c:\msmpi" -L"c:\msmpi"

However, if you are in linux and you already did

sudo apt install gfortran mpich

Then all you need is just
mpif90 -o hello.exe hello.f90
because those -I and -L are already configured automatically so you do not need to specify them.

If you use msys2, https://www.msys2.org/
It contains mingw64. In the msys2 terminal you can do

pacman -S mingw-w64-x86_64-msmpi

https://packages.msys2.org/package/mingw-w64-x86_64-msmpi
and install MS-MPI, all the files will be already ready to use, including mpif90, mpi.mod, libmsmpi.dll.a`, so you do not need to regenerate them using your mingw64 gfortran again.

Thank so much for your help. I already install the IntelAPI, but somehow my company don’t allow to use VS community ver. I will try the VS code I guess. Good luck on me and thanks a lot for you~

1 Like

No problem, about MPI, you can also use MPICH2, it has not been updated for 10 years, but it still work fine on windows 10,
https://www.mpich.org/static/downloads/1.4.1p1/
This version natively support windows. You can read the pdf file there for installation guide etc,
In the below folder,
https://www.mpich.org/static/downloads/1.4/
There is a mpich2-1.4-README.txt file, it also gives you more information about how to use and compile the code etc.

Just don’t forget to add/allow the mpiexec.exe in the firewall, otherwise it will pause for a long time before the mpi runs,

No luck for me. MPICH can not be installed without administrator consent, and the intel fortran won’t work somehow with my vs code. I try to use intel MPI with the current version of MinGW (ver 6.3), it says:

||Fatal Error: Reading module ‘mpi’ at line 1 column 2: Unexpected EOF|

I also tried to use MPI inside cygwin64, it also can’t it says

Fatal Error: Cannot read module file ‘mpi.mod’ opened at (1), because it was created by a different version of GNU Fortran|

I also tried downloading MPI from the website (https://www.open-mpi.org/), no luck, there is no mpi.mod that can be used on code blocks (I downloaded Ver 4.1.4, 4.1.0, and 3.1.6)

I also tried downloading Microsoft MPI, similarly, I need administrator consent to install. I am really running out of option now.

In cygwin64 there are only 3 vers of MPI can be downloaded, idk if they are new one or old one, but the versions are only separated a little bit. Meanwhile, MinGW can only be downloaded on latest version (I believe right now is 6.3) from the MinGW-get software that connects internet. Does anyone know which MPI can be used with MinGW ver 6.3 or if someone know what should I do?