MS-MPI with Visual Studio 2008

This is a step-by-step guide for you to write MPI program using MS-MPI and Visual Studio 2008. I want to introduce MS-MPI as many of my blog posts will be related to parallelism both shared memory and distributed in C/C++ and C#. You can use any OS to write, compile and test MPI program and in additional to that, and of course you also need:

HPC Pack SDK 2008
– VC++ Compiler and IDE (VC++ 2008 Express is okay)

What you have to know in this SDK is the location of MPI header and lib files. MPI header file (mpi.h) contains all the definitions of MPI types and operations, while the lib file is the main MPI libraries. By default HPC Pack SDK installation, it will be located at :

C:\Program Files\Microsoft HPC Pack 2008 SDK\ in the Include and Lib folders.

Once you able to locate MS-MPI header and lib files, you are ready to write and compile MPI program using Visual Studio 2008. Open VC++ 2008 and create an empty C++ project then follow these steps.

1 – Create an Empty C++ Project


2 – Change the Linker’s System configuration to CONSOLE(/SUBSYSTEM:CONSOLE)


3 – Add Linker Additional Library Directories as following:


4 – Add Linker’s Input Additional Dependencies. Type msmpi.lib to the list.


5 – Add a C++ file to write your first MPI program and write the following codes as a test:

using namespace std;

int main(int argc, char** argv){

    int mynode, totalnodes;

    MPI_Init(&argc, &argv); 
    MPI_Comm_size(MPI_COMM_WORLD, &totalnodes);
    MPI_Comm_rank(MPI_COMM_WORLD, &mynode);
    cout << "Hello world from process " << mynode;
    cout << " of " << totalnodes << endl;

    return 0;

6 – Add the location of header file to C++ Compiler property:


7 – Build your first program and if no error found, you can test it by running MPIEXEC (MPI launcher) :

mpiexec –n 10 MyMPIProject.exe

It will create 10 independent processes (you can say 10 nodes), without communication between nodes applied for now. I will discuss later about the inter-process communication inside MPI. The normal result of your program will be:


Congratulation is you reach this stage. You are ready to learn deeper about MS-MPI!.

Cheers – RAM

Comments (7)

  1. pebbie@INDC says:

    baru tau kalo MS punya implementasi MPI (MSMPI) setelah baca tulisan di sini jadinya penasaran. langsung deh googling dan ternyata Pak Risman sempat menulis di sini. setelah mengunduh HPC SDK, hal pertama yang dicoba adalah menjalankan executable yang

  2. asankadias says:

    Hi mate,

    I develop this program and compiled without any errors. But I can’t understand where I type this command (mpiexec –n 10 MyMPIProject.exe).

    I tried with the command window but it says Command "mpiexec" is not valid.

    When I debug the program it does not stays on; just appears and then disappears.

    Can you please tell me how I can debug the program for get the proper output and how I can find MPIEXEX (MPI launcher)




  3. harshdeep says:


    It’s nice to be able to write MPI programs in the coziness of Visual Studio.

    However, when I try to run the sample program with mpiexec, I get an error dialog with the title "smpd.exe – Entry Point Not Found". The body of the dialog says "The procedure entry point GetProcessIdOfThread could not be located in the dynamic link library kernel32.lib".

    I checked kernel32.lib on my machine and it does not export this function. According to MSDN, it is a Vista addition.

    The SDK download page, however, says that it is compatible with XP.

    Any ideas?

  4. mezhaka says:

    thanks a lot for the demo.

    worked fine for me.

    i wonder how do i debug that application?

  5. bahare says:

    thanks alot….

    Now,i had written a mpi program in Visual Studio 2008 & i wana to debug my program in hpc cluster.

    my cluster has a head node & tow compute node.

    what can i do?

    please help me….

  6. AbeerN says:

    I got 3 msgs like this

    mycodescppmympiprojectmympiprojectemr.cpp(4): error C2065: 'argc' : undeclared identifier