MPI stands for Message Passing Interface and it’s widely used in Parallel Processing. This is a tutorial about installing and testing MPICH2 on Windows Vista with Microsoft Visual Studio 2005.
In this page I introduce MPI and the way it works briefly and then I’ll show you how to install and test MPICH2.
Introduction:
We want an application to be run on several machines (processors) to get better performance (i.e. less execution time). You can imagine a computer network with N computer that running an application that compute PI for example! Remember that it’s “an” application that runs on a “network”.
We develop an application that executes on different machines (different instances) and pass messages with other instances. I think the model must be clear now! For this “message passing”, I know two method:
1- Using Socket programming and working with OS APIs directly.
2- Using MPI!!
You’ll get more power with socket programming but MPIs are easier to use and they are actually widely used in parallel processing. You can think of MPI as a set of functions for message passing. I know one free implementation of MPI, that is MPICH2 and you can download it for free from here.
There are lots of tutorials and web pages out there about MPI functions but I can’t find anything about installing MPICH2 on Windows Vista and compiling applications with Microsoft Visual Studio 2005. Here I want to show you my experience step-by-step. You must have an account with administrative permission. Note that I’m using MS Windows Vista Business.
Install :
1. Download MPICH2 from here.
2. Run the .msi package, you might got this error : “you must install C-Runtime (SP1) ..” go to Microsoft Website and download it. Note that you must install SP1 version! That is the point! Or you might got other errors about installing .NET Framework or things like that.. but because I installed VS 2005, I didn’t see these errors.
3. That’s it! If you follow the installation process correctly, you now have MPICH2 installed.
4. You must turn your firewall off or you can add rules to your firewall to allow “mpiexec” and “smpd”. This process depends on your firewall.
5. You may need to add MPICH2 folder to your PATH. This is the way :
a. right-click on “computer” and select “properties”
b. select “Advance system settings” on left pan.
c. Select “environment variables..”
d. On “system variables” select “Path”. You may need to scroll down.
e. At the end of the text-box, enter “C:\MPICH2\bin\;” with semi-colon! If you installed MPICH2 in “C:\MPICH2\”
6. Turn off UAC (User control account). When I turned it on, mpiexec returned with an error..
a. Open Start>User Accounts
b. Click on “Turn User control account on or off”
c. Turn it off!
Test:
you run your applications with mpiexec! Let’s do it for the first time! You can test your applications on your local machine without a network.. if you have a multi-core CPU, you’ll get full advantage of your multi-core system with utilizing it to 100% .
1- Start command-line. Start>cmd
2- Locate examples folder. If you installed it on C:\MPICH2\, it’s the examples folder “C:\MPICH2\examples”. Change directory to it.
3- Run the example with this command : “mpiexec –n 2 cpi.exe”. if you did everything correctly, CPI.exe will ask you for the number of intervals, use a large number and see you have 100% CPU-utilization on a single and dual-core. If you have a quad-core, enter “-n 4” instead of “-n 2”. This number shows the number of instances. If you test your application on a network you must enter the computer names.. I don’t want to mention these things here, you can find them here!
Build your own application with Microsoft Visual Studio 2005:
Now it’s the time for writing a hello-MPI !
1- Open MS VS.
2- Create an empty Win32 console application.
3- Add .h and .lib files to your project:
a. Tools>Options
b. Select “VC++ Directories” under “Projects and solutions” in the left pan.
c. Select “Include files” under “Show directories for:” drop-down list.
d. Add “C:\MPICH2\Include”. Assuming you installed it in that directory.
e. Select “Library files”, again under “Show directory for:” drop-down list.
f. Add “C:\MPICH2\Lib”.
g. In Solution Explorer, right-click on your project and select “add>existing item” and then select all .lib files under Lib folder. (C:\MPICH2\Lib)
h. Add a .cpp file with the code shown bellow.
i. Ctrl+F5.
j. Run the application using mpiexec and see the results!
4- Finished!
Although this was a tutorial for Windows Vista and Visual Studio 2005, you can use it for Win XP and VS2003 as well with some changes.. there are some good tutorials and documentations at MPICH2 official website. you can find my presentation file here.
if you have any question, just feel free to ask!
Code:
#include "mpi.h"
#include "iostream.h"
int main(int argc,char *argv [])
{
int numtasks, rank, rc;
rc = MPI_Init(&argc,&argv);
if (rc != MPI_SUCCESS) {
printf ("Error starting MPI program. Terminating.\n");
MPI_Abort(MPI_COMM_WORLD, rc);
}
MPI_Comm_size(MPI_COMM_WORLD,&numtasks);
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
printf ("Number of tasks= %d My rank= %d\n", numtasks,rank);
MPI_Finalize();}
Labels: MPI, MPICH2, Parallel, Vista, Visual Studio 2005