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