New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TUTORIAL: Adapting MS-MPI for MinGW64 #85

miroi opened this Issue Aug 24, 2015 · 5 comments


None yet
2 participants

miroi commented Aug 24, 2015

MS-MPI with the MinGW64 gfortran

Hereby I am creating this thread in order to publicly demonstrate the adaptation of the MS-MPI suite for the MinGW64 gfortran.

Tested on 64-bit MS Windows 8.0; MinGW-W64 project 4.9.0.

  • Download and unpack the MS-MPI package (this is v4) . Do not install it otherwise you may face error as this one. All necessary files are unpacked from the mpi_x64.Msi archive and are in the corresponding directory !
C:\Users\milias\Documents\Dirac\software\autocmake-devel\ms-mpi>"C:\Program Files (x86)\7-Zip\7z.exe" x mpi_x64.Msi

7-Zip 9.22 beta  Copyright (c) 1999-2011 Igor Pavlov  2011-04-18

Processing archive: mpi_x64.Msi

Extracting  etl2clog.exe
Extracting  etl2otf.exe
Extracting  mpi.f90
Extracting  mpi.h
Extracting  mpicsync.exe
Extracting  mpiexec.exe
Extracting  mpif.h
Extracting  mpio.h
Extracting  msmpi.dll
Extracting  msmpi.lib
Extracting  msmpi64.dll
Extracting  msmpi64.lib
Extracting  msmpifec.lib
Extracting  msmpifec64.lib
Extracting  msmpifes.lib
Extracting  msmpifmc.lib
Extracting  msmpifmc64.lib
Extracting  msmpifms.lib
Extracting  msmpires.dll
Extracting  msmpires64.dll
Extracting  note_mpi.txt
Extracting  pmidbg.h
Extracting  smpd.exe

Everything is Ok

Files: 24
Size:       9720065
Compressed: 3613184
  • In the MS-MPI directory, create the libmsmpi64.a library with the MinGW64 tools gendef and dlltool:
C:\Users\milias\Documents\Dirac\software\autocmake-devel\ms-mpi>gendef msmpi64.dll
 * [msmpi64.dll] Found PE image
C:\Users\milias\Documents\Dirac\software\autocmake-devel\ms-mpi>dlltool -d msmpi64.def -l libmsmpi64.a -D msmpi64.dll
  • In the MS-MPI folder, rename mpi.f90 to mpi.F90 and modify its source code so that the gfortran compiler can accept traditional (C) preprocessor directives (changes are starting from line 344, see also Attachement 1) :
  • generate the Fortran90 mpi.mod file - you must use appropriate preprocessor statements and no-range checking (-D_WIN64 -D INT_PTR_KIND()=8 -fno-range-check)
C:\Users\milias\Documents\Dirac\software\autocmake-devel\ms-mpi>gfortran  -c  -D_WIN64  -D INT_PTR_KIND()=8 -fno-range-check   mpi.F90
  • compile and run the MPI example.F90 - see also the Attachement 3 - using the modified Fortran90 module mpi:
C:\Users\milias\Documents\Dirac\software\autocmake-devel\ms-mpi>gfortran  -o example.exe  -D USE_MPI_MODULE example.F90 libmsmpi64.a
C:\Users\milias\Documents\Dirac\software\autocmake-devel\ms-mpi>mpiexec.exe -n 2 example.exe
  • In the MS-MPI folder, modify the mpif.h include file so that Intel preprocessor directives are replaced by the traditional ones (changes starting from line 341), see the Attachement 2
  • now compile and run the MPI example.F90 file - see also the Attachement 3 - by using the modified include file "mpif.h" (use -D_WIN64 -D INT_PTR_KIND()=8 -fno-range-check flags as in the previous case):
C:\Users\milias\Documents\Dirac\software\autocmake-devel\ms-mpi>gfortran -o example.exe  -D_WIN64  -D INT_PTR_KIND()=8  -fno-range-check  example.F90   libmsmpi64.a
C:\Users\milias\Documents\Dirac\software\autocmake-devel\ms-mpi>mpiexec -n 2 example.exe

Note that you have to link the above generated libmsmpi64.a library. If you would link against the ms-mpi provided dynamical library, msmpi64.dll , you would get the error message of Fatal protocol error: check version between Mpiexec.exe, Msmpi.dll, and Smpd.exe.

Likewise I stress that linking against the delivered lib-file msmpi64.lib does not work, you must have your own prepared libmsmpi64.a library, as explained above:

C:\Users\milias\Documents\Dirac\software\autocmake-devel\ms-mpi>gfortran  -o example.exe  -D USE_MPI_MODULE example.F90 msmpi64.lib
C:\Users\milias\AppData\Local\Temp\ccmTxg9d.o:example.F90:(.text+0x1b): undefined reference to `mpi_init_'
C:\Users\milias\AppData\Local\Temp\ccmTxg9d.o:example.F90:(.text+0x3b): undefined reference to `mpi_comm_rank_'
C:\Users\milias\AppData\Local\Temp\ccmTxg9d.o:example.F90:(.text+0x5b): undefined reference to `mpi_comm_size_'
C:\Users\milias\AppData\Local\Temp\ccmTxg9d.o:example.F90:(.text+0x6a): undefined reference to `mpi_finalize_'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\milias\AppData\Local\Temp\ccmTxg9d.o: bad reloc address 0x0 in section `.pdata'
collect2.exe: error: ld returned 1 exit status

Attachement 1 - (mpi.f90 -> mpi.F90), modified lines


Attachement 2 - mpif.h, modified lines


Attachement 3 - example.F90


@miroi miroi changed the title from Adapt MPI+MinGW on MS Windows to MS-MPI with MinGW64 on MS Windows Aug 26, 2015

@miroi miroi changed the title from MS-MPI with MinGW64 on MS Windows to WIP: MS-MPI with MinGW64 on MS Windows Aug 26, 2015

@miroi miroi changed the title from WIP: MS-MPI with MinGW64 on MS Windows to TUTORIAL: Adapting MS-MPI for MinGW64 Aug 26, 2015


This comment has been minimized.


bast commented Aug 27, 2015

This is a nice tutorial but why is this an Autocmake issue? I don't think this is the right place for such documentation.


This comment has been minimized.


miroi commented Aug 27, 2015

I put it here due to #86 and also for Microsoft guys so that they fix their msmpi package to work with the MinGW64 gfortran.

If the MS-MPI will be adjusted accordingly and the related PR #86 accepted, I shall close this issue.


This comment has been minimized.


bast commented Aug 27, 2015

Fair enough. But please don't use issues for documentation. There are much better ways. Such issues
distract focus from the "real" issues.


This comment has been minimized.


bast commented Sep 8, 2015

Is this issue still relevant?


This comment has been minimized.


miroi commented Sep 8, 2015

Closing due to merged #118 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment