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,
- 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” .
- 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.