How to compile and run a simple MS-MPI program
Download MS-MPI SDK and Redist installers and install them. The download link can be found at our homepage https://msdn.microsoft.com/en-us/library/bb524831.aspx
After installation you can verify that the MS-MPI environment variables have been set (you will want to use these env vars in Visual Studio)
Open up Visual Studio and create a new Visual C++ Win32 Console Application project. Let’s name it MPIHelloWorld and use default settings.
Setup the include directories so that the compiler can find the MS-MPI header files. Note that we will be building for 64 bits so we will point the include directory to $(MSMPI_INC);$(MSMPI_INC)\x64. If you will be building for 32 bits please use $(MSMPI_INC);$(MSMPI_INC)\x86
Setup the linker lib (notice I add msmpi.lib to the additional dependencies and also add $(MSMPI_LIB64) to the Additional Library Directories). Note that we will be building for 64 bits so we will point the Additional Library Directories to $(MSMPI_LIB64). If you will be building for 32 bits please use $(MSMPI_LIB32)
If you see these error messages below it is most likely you're building for 32 bits yet specifying 64 bits linking libraries.
LNK1120: 5 unresolved externals
LNK2019: unresolved external symbol _MPI_Comm_rank@8 referenced in function _main
LNK2019: unresolved external symbol _MPI_Finalize@0 referenced in function _main
LNK2019: unresolved external symbol _MPI_Init@8 referenced in function _main
LNK2019: unresolved external symbol _MPI_Recv@28 referenced in function _main
LNK2019: unresolved external symbol _MPI_Send@24 referenced in function _mainWe recommend that our users use HPC Pack to run MPI across machines. However, you can still run jobs across different machines without HPC Pack, wherein you would need to install MS-MPI on all the machines and start SMPD daemon on each machine using the command smpd –d. Make sure you add the necessary firewall rules for your application. To launch the MPIHelloWorld.exe application with 2 processes, 1 on hostA and 1 on hostB, you can use the following command
mpiexec -hosts 2 hostA 1 hostB 1 -wdir \\hostA\c$\SomeDirectory MPIHelloWorld.exe
Alternatively, you can use the command line to compile and link your program (replacing steps 1-6 above). Note that I have added “C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64” to my path environment variable so that cl.exe and link.exe are available.
To compile your program into .obj files:
cl /I"C:\Program Files (x86)\Microsoft SDKs\MPI\Include" /I"C:\Program Files (x86)\Microsoft SDKs\MPI\Include\x64" /I. /I"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include" /I"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include" /c MPIHelloWorld.cpp
Linking the .obj files:
link /machine:x64 /out:MpiHelloWorld.exe /dynamicbase "msmpi.lib" /libpath:"C:\Program Files (x86)\Microsoft SDKs\MPI\Lib\x64" /LIBPATH:"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib\amd64" /LIBPATH:"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib\x64" MPIHelloWorld.obj
Please feel free to contact the MS-MPI team should you have any questions, or have suggestions for things you would like to see on this blog. You can reach us at [email protected]
Comments
- Anonymous
May 20, 2015
The latest MSMPI v6 (MSMPISetup) link is dead! - Anonymous
August 05, 2015
Hi,
Thanks for this tutorial. I'm running into some issue although :
1>c:program files (x86)microsoft sdksmpiincludempi.h(5113) : warning C4091: '' : ignored on left of 'int' when no variable is declared
1>c:program files (x86)microsoft sdksmpiincludempi.h(5113) : error C2143: syntax error : missing ';' before '['
and I can figure out what's going on. I've try with both version 5 and 6 of MSMPI and i'm using visual studio 2008.
Any idea will be great !
Regards - Anonymous
August 11, 2015
Hi Vivien. It will be easiest for us to help if you could email askmpi at Microsoft.com. It might take a little back and forth. Thank you. - Anonymous
September 11, 2015
I got these error
LNK1120: 5 unresolved externals
LNK2019: unresolved external symbol _MPI_Comm_rank@8 referenced in function _main
LNK2019: unresolved external symbol _MPI_Finalize@0 referenced in function _main
LNK2019: unresolved external symbol _MPI_Init@8 referenced in function _main
LNK2019: unresolved external symbol _MPI_Recv@28 referenced in function _main
LNK2019: unresolved external symbol _MPI_Send@24 referenced in function _main
can I solve it? - Anonymous
September 16, 2015
The comment has been removed- Anonymous
May 31, 2016
this gives me the error:" 'cl' is not recognized as an internal or external command, operable program or batch file. "
- Anonymous
- Anonymous
October 16, 2015
To those of you who have problem with LNK2019 (similar to what Abdallah was describing), it is likely that you're compiling a 32 bit program (which is the default for Visual Studio). If you do want to compile for 32 bits, make sure in step 4 and step 5 you point the Include to $(MSMPI_INC)x86 and the lib to $(MSMPI_LIB32). - Anonymous
January 12, 2016
Hi Alex, Vivian,
I get exactly the same issue:
1>C:Program Files (x86)Microsoft SDKsMPIIncludempi.h(5897) : warning C4091: '' : ignored on left of 'int' when no variable is declared
1>C:Program Files (x86)Microsoft SDKsMPIIncludempi.h(5897) : error C2143: syntax error : missing ';' before '['
I got something very similar trying to build boost to the current version of MPI. I worked the example here to clarify the issues and got identical messages (cut and pasted here). Just in case anyone says why do you need vs2008 the answer is that the standard versions of CPython 2.7 is built with it.
I will copy this to [email protected] but solutions to common problems are best placed on the web for all.
Terry
INFO
Microsoft Visual Studio 2008
Version 9.0.30729.1 SP
Microsoft .NET Framework
Version 3.5 SP1
Installed Edition: Professional
Microsoft Visual Basic 2008 91605-270-1139194-60888
Microsoft Visual Basic 2008
Microsoft Visual C# 2008 91605-270-1139194-60888
Microsoft Visual C# 2008
Microsoft Visual C++ 2008 91605-270-1139194-60888
Microsoft Visual C++ 2008
Microsoft Visual Studio 2008 Tools for Office 91605-270-1139194-60888
Microsoft Visual Studio 2008 Tools for Office
Microsoft Visual Web Developer 2008 91605-270-1139194-60888
Microsoft Visual Web Developer 2008
Fully patched - Anonymous
January 13, 2016
defining MSMPI_NO_DEPRECATE_20
gets rid of this problem as a work around.
I added the define to mpi.jam in boost for the msvc toolset and it removed a vast array of build errors when I tried ot build boost with the microsoft MPI. The only problems in that project now seem to be that list<> is not defined in various cpp files from the graph modules of boost used with mpi - but that is a different problem. - Anonymous
January 18, 2016
The comment has been removed - Anonymous
January 30, 2016
The comment has been removed - Anonymous
May 22, 2016
I can't run program with mpiexec,I type in the command and it has no response, the smpd isn't running. I'm unable to start the smpd by double click it.