Sunday, March 30, 2008

MPICH2 under Windows Vista

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.

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: , , , ,

30 Comments:

Anonymous Anonymous said...

This tutorial is very useful! Thank you a lot!!!

April 18, 2008 3:31 AM  
Anonymous Anonymous said...

hi, i tried to debug this code but i received this error : cannot open iclude file : mpi.h, no such file or directory. please help!

May 3, 2008 11:01 PM  
Blogger curveto said...

use <> instead of ""s for #includes

and make sure you add the lib files correctly.
if the problem still exists, send the problem to me[at]curveto[doot]com

May 4, 2008 4:49 PM  
Anonymous Anonymous said...

hi, its me again!
well, i tried <> instead of " but i received the same error, maybe i did something wrong. i m using Visual Studio 2009 and windows vista. any idea??? thanks

May 5, 2008 4:48 PM  
Anonymous Anonymous said...

sorry =vs 2008*

May 5, 2008 4:49 PM  
Blogger curveto said...

ummm .. i'm not familiar with VS2008, but it should work the same.
try
adding "using namespace std;"
excluding .h for header files with combination of "" or <>s !

double check that you did the steps in tutorial for adding .h and .lib files correctly ;)

May 5, 2008 9:00 PM  
Anonymous Anonymous said...

This is useful. I am still having a problem though. After I input mpiexec -n 2 cpi.exe to test it, it states : "Please specify an authentication passphrase for smpd:". Did you ever encounter this?

June 12, 2008 2:31 AM  
Blogger curveto said...

No, i didn't..
but, what happened when you enter the "pass phrase"? (it's "behappy" by default)

please register your username and password, (your windows username and pass) using StartMenu>AllPrograms>MPICH2>wmpiregister.exe
it encrypt your user/pass and save the result to windows registery.

June 12, 2008 4:05 PM  
Anonymous Anonymous said...

Pls help. I install MPICH2 and did all this recomendations and whwn i try to execute cpi examples fro MPICH2 i got this
Please specify an authentication passphrase for smpd:
Unable to connect to 'ana-PC:8676',
sock error: generic socket failure, error stack:
MPIDU_Sock_post_connect(1228): unable to connect to ana-PC on port 8676, exhaus
ted all endpoints (errno -1)
MPIDU_Sock_post_connect(1275): unable to connect to ana-PC on port 8676, No con
nection could be made because the target machine actively refused it. (errno 100
61)
i had this problem before and i dont know how to fix this
if enyone knew pls write

September 17, 2008 7:31 PM  
Anonymous Keven said...

Ok for the user problem
username = your windows username pass = password windows

you pu them on mpich2 - register and that it !!!


You need to put a password on your windows sessionwithout : dont work!!!.

September 20, 2008 2:22 AM  
Blogger curveto said...

Ok, Seems that this problem is fixed.
Thank you Keven.

September 24, 2008 11:02 AM  
Blogger Hoda said...

Hi,
I'm still stuck at the Testing step. After registering I try to run wmpiexec.exe or even just use the command prompt with "mpiexec -n 2 cpi.exe". And it doesn't work. This is what I get:

MPIDU_Sock_post_connect failed.
[1] PMI_ConnectToHost failed: unable to post a connect to Hoda Hoda.lan fe80::3933:24e6:2a61:7818%14 10.0.0.11 :50681, error: Unknown error class, error stack:
MPIDU_Sock_post_connect(1228): unable to connect to Hoda Hoda.lan fe80::3933:24e6:2a61:7818%14 10.0.0.11 on port 50681, exhausted all endpoints (errno -1)
MPIDU_Sock_post_connect(1275): unable to connect to 10.0.0.11 on port 50681, No connection could be made because the target machine actively refused it. (errno 10061)
MPIDU_Sock_post_connect(1244): gethostbyname failed, The requested name is valid, but no data of the requested type was found. (errno 11004)
MPIDU_Sock_post_connect(1275): unable to connect to Hoda.lan on port 50681, No connection could be made because the target machine actively refused it. (errno 10061)
MPIDU_Sock_post_connect(1275): unable to connect to Hoda on port 50681, No connection could be made because the target machine actively refused it. (errno 10061)
uPMI_ConnectToHost returning PMI_FAIL
[1] PMI_Init failed.
Fatal error in MPI_Init: Other MPI error, error stack:
MPIR_Init_thread(294): Initialization failed
MPID_Init(82)........: channel initialization failed
MPID_Init(333).......: PMI_Init returned -1MPIDU_Sock_post_connect failed.
[0] PMI_ConnectToHost failed: unable to post a connect to Hoda Hoda.lan fe80::3933:24e6:2a61:7818%14 10.0.0.11 :50688, error: Unknown error class, error stack:
MPIDU_Sock_post_connect(1228): unable to connect to Hoda Hoda.lan fe80::3933:24e6:2a61:7818%14 10.0.0.11 on port 50688, exhausted all endpoints (errno -1)
MPIDU_Sock_post_connect(1275): unable to connect to 10.0.0.11 on port 50688, No connection could be made because the target machine actively refused it. (errno 10061)
MPIDU_Sock_post_connect(1244): gethostbyname failed, The requested name is valid, but no data of the requested type was found. (errno 11004)
MPIDU_Sock_post_connect(1275): unable to connect to Hoda.lan on port 50688, No connection could be made because the target machine actively refused it. (errno 10061)
MPIDU_Sock_post_connect(1275): unable to connect to Hoda on port 50688, No connection could be made because the target machine actively refused it. (errno 10061)
uPMI_ConnectToHost returning PMI_Fatal error in MPI_Init: Other MPI error, error stack:
MPIR_Init_thread(294): Initialization failed
MPID_Init(82)........: channel initialization failed
MPID_Init(333).......: PMI_Init returned -1

If anyone can help, I'd be very grateful. I'm trying to run MPICH2 on Vista with MS Visual Studio 2008.
Thanx

October 14, 2008 10:45 PM  
Blogger curveto said...

@Hoda

Hi,
did you add a rule to your firewall?
or did you disable your firewall?
before disabling, make sure your are not connecting to the internet or a LAN (just for security reasons)

let us know the outcome :D

October 15, 2008 3:31 PM  
Blogger Hoda said...

Hi,
Thanks for the quick reply but i had disabled the firewall when i disabled the UAC.
So i don't think that's the problem.
I'm open to any other ideas...

October 16, 2008 1:16 AM  
Blogger curveto said...

@Hoda

This idea seems stupid! but try ...

run command prompt as administrator.
in start menu, search "cmd", then right click on cmd and select "run as administrator". (since you already disabled UAC, it shouldn't ask you for password)

October 16, 2008 9:39 AM  
Blogger Hoda said...

mmm...
Thanx that may actually work coz when i couldn't get anything to work i used the cmd with Visual C 6.0 (instead of visual studio) with MPI (instead of MPICH2).

October 18, 2008 10:56 PM  
Blogger curveto said...

@Hoda

i'm happy you get it to work!

But i'm a little confused on how you did that! did you installed MPI and MPICH2 together?

anyway, have a good time with MPI/MPICH2 :D

October 18, 2008 11:29 PM  
Anonymous Antonio said...

Hi,

How can I use MPICH2 with Windows Forms Applications?

December 16, 2008 7:23 PM  
Blogger curveto said...

@Antonio

I think it should be the same as console apps ...
what's the problem?!

December 21, 2008 9:00 AM  
Anonymous Anonymous said...

Hi,

I've tried everything described in this (very useful) page, but nothing seems to work.

I get the same "unable to connect" error, as described above.

I've tried adding the rules for mpiexec and smpd, with disabled firewall, UAC off, cmd w/ administrator... Still the same error.

I'm getting desperate, please help!

January 16, 2009 12:22 PM  
Blogger curveto said...

did you tried Keven's tip?!

January 21, 2009 4:36 PM  
Anonymous Anonymous said...

Hi,
question 1 :
How does MPI work on single processor with 2 core?
for example: this structure "mpiexec -n 7 " creates 7 processes.
Do these 7 processes work as sequential? or parallel?
If it works as sequential, what is the deference between this one and "mpiexec –n1"?
But if they work as parallel, how does the single processor do it?

Question 2:
What is the operating system's job when MPI works? (except of creating process)

February 17, 2009 1:34 PM  
Blogger curveto said...

Hi,
1. It just creates n processes. If your system can handle them in different cores, you're getting parallelism! if not, OS will schedule them on a single core, and hence, it just adds some overhead...

2. I think it does nothing actually. processes that are created with MPI will be treated the same as other processes.

hope it helps

February 17, 2009 2:48 PM  
Anonymous Anonymous said...

1- When OS schedule them on a single core, it means that they work sequential? Like that "mpiexec –n 1"?

2- Did you mean MPI never use OS ?

February 17, 2009 3:43 PM  
Blogger curveto said...

1. Yes, they work sequential, but not like "-n 1". It will consume more times! because of more communication overhead.

2. What do you mean by "using OS"? Yes, of course it uses OS in the sense that it uses Socket APIs and all other features that an OS provide for a process to be run.

hope it helps
If these are not the answers you are searching for, Just feel free to ask ..

February 17, 2009 10:11 PM  
Anonymous Anonymous said...

thanks for your quick useful answer.

February 19, 2009 8:05 PM  
Anonymous Anonymous said...

To solve the Problem: "sock error: generic socket failure, error stack:
MPIDU_Sock_post_connect(1228)"..

you need to turn of UAC before installing MPICH2.

March 25, 2009 6:21 PM  
Blogger Sven Prevrhal said...

Nice, thank you!
Do you know how to configure and use the MPI cluster debugger in MSVC 2005? The Local Windows debugger works but it cannot be told how many processes to start etc.

June 26, 2009 11:23 PM  
Blogger curveto said...

@Sven:

Your welcome!
No i don't know...
Go for it and when you get the answer, we may add the result to this post :D

June 27, 2009 6:41 PM  
Anonymous Anonymous said...

Very nice tutorial (small but mighty). Thank you!

July 3, 2009 6:15 PM  

Post a Comment

Subscribe to Post Comments [Atom]

Links to this post:

Create a Link

<< Home