Поделиться через


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

 MPI03

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

MPI04

3 – Add Linker Additional Library Directories as following:

MPI05

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

MPI06

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

 #include<iostream>
#include<mpi.h>
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;

    MPI_Finalize();
    return 0;
}

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

MPI07

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:

MPI08

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

Cheers – RAM

Comments

  • Anonymous
    January 03, 2009
    PingBack from http://www.codedstyle.com/ms-mpi-with-visual-studio-2008/

  • Anonymous
    January 13, 2009
    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

  • Anonymous
    February 10, 2009
    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) Thanks Regards Asanka

  • Anonymous
    February 17, 2009
    Hi, 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?

  • Anonymous
    March 12, 2009
    thanks a lot for the demo. worked fine for me. i wonder how do i debug that application?

  • Anonymous
    October 11, 2011
    The comment has been removed

  • Anonymous
    May 18, 2013
    I got 3 msgs like this mycodescppmympiprojectmympiprojectemr.cpp(4): error C2065: 'argc' : undeclared identifier