Wednesday, June 25, 2008

Parallel Computing with MPI - Part V: MPICH2 and Visual Studio

Now that we have covered the sequential code for the finite difference solution of the 2D heat equation, It is time to start thinking in parallel. But first, we have to set the grounds for this adventure. This will be the topic of this post.

MPI, aka the Message Passing Interface, is a standard that defines a set of functions that allow a programmer to instruct their code to execute tasks in parallel. Of course, for this set of functions to be portable, they have to be compiled as a library. Then, the functions will be visible inside the code and used as necessary. I will defer my discussion on parallel computing to the next post as the sole purpose of this post is to have MPI ready so that we can experiment with it in our next post.

One thing that you have to understand is that MPI is a only a standard, but the implementations vary. This means that you will find several "MPI implementations" out there, some of them are free while others require the purchase of license, but nonetheless, they all offer the same functionality, function names, and datatypes as dictated by the MPI standard.

Fortunately, God created some people who are believe that science is not personal and are willing to take the time and put the effort to implement the MPI standard for free. The most popular implementations are the MPICH and the LamMPI. I use MPICH for windows and LamMPI for MacOSX.

For users of Unix based systems, I am going to assume that they have already enough knowledge on how to compile/install/link a library to their codes. Just do the same for MPI. You can download the MPICH2 implementation here and the LamMPI implementation here.

Now for windows users, I will outline the installation process of MPICH2 so that it is streamlined with Microsoft Visual Studio 2008. Both the express and professional editions can be used. Remember that the express edition can be downloaded for free!

I assume that you already have visual studio setup. There are two versions of MPICH2, namely, the 32 bit and 64 bit. For the time being, let us focus on the 32 bit version. Let us first setup the environment for MPI
  1. Download and install MPICH2 32 bit edition
  2. Add the following to your path
    C:\Program Files\MPICH2\bin
    (in Vista: right click My Computer/Properties/Advanced System Settings/Advanced/Environment Variables and edit the path variable for either the system or user variables - Do the same in XP, but you dont have to go through advanced system setting because it doesnt exist)
  3. Add the following exceptions to your firewall:
    C:\Program Files\MPICH2\bin\mpiexec.exe
    C:\Program Files\MPICH2\bin\smpd.exe
    Usually, you will receive a message to unblock these programs. But in case you don't, you have to add them manually
  4. Register a user account with MPI. Go to
    C:\Program Files\MPICH2\bin\wmpiregister
    and type in the user account and password that will be used to start MPI jobs. You should have the same user account and password on all your cluster machines
  5. Open port 8676. Go to
    C:\Program Files\MPICH2\bin\wmpiconfig
    and select "port" at the top of the list
Note that if you install the 32 bit MPICH2 on a 64 bit windows, the MPICH installation directory will be under "Program Files (x86)".

Now, to setup the environment in Visual Studio we have to tell the compiler where to find the MPI header files and libraries, do the following
  1. Start Visual Studio
  2. Go to: Tools/Options/Projects and Solutions/Visual C++ Directories
  3. In the platform combo box, select win32
  4. In the Directories combo box, select "Include files" and add the following entry
    C:\Program Files\MPICH2\include (or Program Files (x86) for 64 bit windows)
  5. Select "Library files" and add the following entry
    C:\Program Files\MPICH2\lib\ (or Program Files (x86) for 64 bit windows)
Voila!

Now your visual studio should be working like a charm! We'll test these settings in the next post.

Cite as:
Saad, T. "Parallel Computing with MPI - Part V: MPICH2 and Visual Studio". Weblog entry from Please Make A Note. https://pleasemakeanote.blogspot.com/2008/06/parallel-computing-with-mpi-part-v.html

8 comments:

  1. Thank you man. This guide was very useful.

    ReplyDelete
  2. Thank you so much! You saved me a lot of time....

    ReplyDelete
  3. Thanks! Why doesn't everyone write clear and concise guides like this?

    ReplyDelete
  4. hi,

    I followed your steps. but when I ran the simple program you wrote, I got error:
    MSVCR80.dll cannot found.

    What could be the reason? I am not sure path files are modified well.

    ReplyDelete
  5. hi,

    I followed your steps. but when I ran the simple program you wrote, I got error:
    MSVCR80.dll cannot found.

    What could be the reason? I am not sure path files are modified well.

    ReplyDelete
  6. Do you know how should I link with Fortran? I have installed intel fortran on visual studio 2008 and added the path for include and libraries but it seems that an specific library should be named somewhere and I don't know how to link it, I have already found the file. Can you please help me?
    If yes email it to me at hosseinali.ir@gmail.com

    ReplyDelete
  7. I have an error message with is "error LNK2001: unresolved external symbol _MPI_Comm_size", can you help me ? please..

    ReplyDelete