How to compile and run a simple MS-MPI program


  1. 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

  2. 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)

  3. Open up Visual Studio and create a new Visual C++ Win32 Console Application project. Let’s name it MPIHelloWorld and use default settings.

  4. 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


  5. 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 _main

  6. Code and build a simple Hello World program

  7. Test run the program on the command line

  8. We 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 askmpi@microsoft.com

Comments (12)

  1. james says:

    The latest MSMPI v6 (MSMPISetup) link is dead!

  2. Vivien says:

    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

  3. Alex Sutton says:

    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.

  4. Abdallah says:

    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?

  5. Xing Wang says:

    Here is the link for the latest MS-MPI v6
    https://www.microsoft.com/en-us/download/confirmation.aspx?id=47259

    To compile the source code in command line:
    cl MPIHelloWorld.cpp /I"C:Program Files (x86)Microsoft SDKsMPIInclude" "C:Program Files (x86)Microsoft SDKsMPILibx86msmpi.lib"

    1. Sandu says:

      this gives me the error:
      " 'cl' is not recognized as an internal or external command, operable program or batch file. "

  6. Anh.Vo says:

    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).

  7. 8Ika1oikXJA8H says:

    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 askmpi@microsoft.com 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

  8. 8Ika1oikXJA8H says:

    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.

  9. D Prieto says:

    Hello I installed and built the suggested MPIHelloWorld. However, when I try to execute from the command prompt , nothing appears there (I am sure I wrote the directory and mpiexec function correctly). I am wondering what am I doing wrong. I have not installed
    the HPC cluster package but you mentioned that I might not need it. How can I see the results in the command prompt without installing the cluster package? I am using Visual Studio 2010 and Windows 7 Professional. Your help is greatly appreciated.

  10. Sanjaya says:

    When running the program as "mpiexec -n 4 hellompi.exe" it gives me an error saying
    mpiexec on XXX-PC is unable to connect to the smpd manager of localhost:5746 error 5
    ERROR: Failed to connect to SMPD Manager Instance error 5

    I have two command windows open both in administrator mode. First I started SMPD using smpd -d. It does not show any message however. In the next command window, I executed my mpi program.

  11. haha says:

    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.

Skip to main content