Hi all,
I am using Codeblock IDE to write and compile my Fortran program. Right now I want to include MPI to my GNU Fortran Compiler. After following some guides on GNU GCC Compiler, it occurs to me that I need to set up the following for MPICH2 (there are two guides about that):
(1) add mpi.lib to the linker setting
(2) add include file to the search directory
However, these setting won’t compile due to error on this line below, and saying that it has an unexpected EoF:
use mpi
So, then I tried to use Cygwin include file (with mpi.lib from MPICH2), strangely, it compiles fine, even with the:
call mpi_init (ierr)
call mpi_comm_rank (mpi_comm_world,rank,ierr)
call mpi_finalize (ierr)
However, when I tried to run the program. It won’t perform pass the:
call mpi_init (ierr)
Then I tried to manually compile the program, and it shows:
C:\Users\7931\AppData\Local\Temp\cclYnhYq.o:main.f90:(.text+0x18c): undefined reference to mpi_init_' C:\Users\7931\AppData\Local\Temp\cclYnhYq.o:main.f90:(.text+0x1fd): undefined reference to
mpi_comm_rank_’
C:\Users\7931\AppData\Local\Temp\cclYnhYq.o:main.f90:(.text+0x276): undefined reference to `mpi_finalize_’
collect2.exe: error: ld returned 1 exit status
Maybe there is a setting that I have not set up yet for the MPI environment, or I need to get the Cygwin mpi.lib, which I can’t found after installing the complete MPI package from the Cygwin.
After trying many other things, I realized that. Why there is no include folder on Cygwin64
Anyone can please help me here?
Many thanks
1 Like
Hello @fallenengineer,
MPICH2 has not been supported for a long time on MS Windows, but it is the starting library that Microsoft developed MS-MPI from, so it’s compatible. I suggest you install MS-MPI instead of MPICH2.
Here’s a batch script that takes the .dll
from the MS-MPI folder and builds a static mpi library which you can use to link against when building Fortran codes with GNU gcc/gfortran:
rem Create a static MS-MPI library for linking Fortran programs
set MSMPI
rem Ensure MS-MPI folder is in the search path
set PATH=%PATH%;%MSMPI_BIN%
rem Copy Fortran include files
mkdir include
copy "%MSMPI_INC%" include
copy "%MSMPI_INC%\x64\mpifptr.h" include
rem Get mpi library file;
copy "%MSMPI_LIB64%"\msmpi.lib .
copy %SYSTEMROOT%\System32\msmpi.dll .
rem Make static lib
gendef msmpi.dll
dlltool -d msmpi.def -l libmsmpi.a -D msmpi.dll
Notes:
- the
include/
folder will also contain mpi.f90
which you can also now compile after linking the dll.
- you need
gendef
and dlltool
from cygwin!
1 Like
Hello Federico,
Thanks a lot for your help. When I want to try the method you explained, I got denied in access to create the include file:
mkdir include
Currently, I have no access to the C directory. Could you help me here. However, I already have MS-MPI installed on my computer.
Since I have limited access on C, I found that it is much easier to use Cygwin than MPICH2 or MS-MPI. May I ask if you have any other method where I could compile the MPI program with only Cygwin?
Many thanks for your help
The script is just trying to put all include files in a folder named include/
right where you’re launching the script. You can of course change that to any other folders! For example, if you replace include
with .
, it will put everything in the current folder.
I have no experience with Cygwin+MPI but it seems like it does offer openmpi as an option.
Hi Federico,
It appears these commands returns “The system cannot find the file specified.”
copy “%MSMPI_INC%” include
copy “%MSMPI_INC%\x64\mpifptr.h” include
copy “%MSMPI_LIB64%”\msmpi.lib .
After I checked my MS-MPI on: C:\Program Files\Microsoft MPI\Bin
there are only 4 files: mpiexec.exe, mpitrace.man, msmpilaunchsvc.exe, smpd.exe
Do you think the installation of MS-MPI is not complete? I need to ask permission with my superior if I need to reinstall the MS-MPI
thanks again~
If you have no include/
folder, I believe you may have not installed the MS-MPI SDK, but only the run-time executables. Please check the MS-MPI installation first, then the %MSMPI_INC% variable should be available
Hi Federico,
It looks like my access to create and copy files using command windows is denied. But, I still can create or copy files manually. Do you have the guide for manually do it?
Many thanks
I’m sorry I guess I don’t understand what are you asking me here. You mean you want to copy the same files using “Windows Explorer” instead of the command line?