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

55 Comments:

Anonymous Anonymous said...

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

April 18, 2008 at 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 at 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 at 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 at 4:48 PM  
Anonymous Anonymous said...

sorry =vs 2008*

May 5, 2008 at 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 at 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 at 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 at 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 at 7:31 PM  
Anonymous Anonymous 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 at 2:22 AM  
Blogger curveto said...

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

September 24, 2008 at 11:02 AM  
Blogger Unknown 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 at 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 at 3:31 PM  
Blogger Unknown 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 at 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 at 9:39 AM  
Blogger Unknown 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 at 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 at 11:29 PM  
Anonymous Anonymous said...

Hi,

How can I use MPICH2 with Windows Forms Applications?

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

@Antonio

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

December 21, 2008 at 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 at 12:22 PM  
Blogger curveto said...

did you tried Keven's tip?!

January 21, 2009 at 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 at 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 at 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 at 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 at 10:11 PM  
Anonymous Anonymous said...

thanks for your quick useful answer.

February 19, 2009 at 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 at 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 at 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 at 6:41 PM  
Anonymous Anonymous said...

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

July 3, 2009 at 6:15 PM  
Blogger Unknown said...

Hi
I am a newbie to this and I have been having a hard time getting mpich2 to work on vista.
I keep getting the error message that it can't connect to my computer.I have disabled the firewall and user accounts etc.

September 7, 2009 at 11:38 PM  
Blogger curveto said...

@nims:
I don't have access to a windows machine now so I can't tell you the exact steps. but I think you should add your username+password to windows registry.
MPI have a tool (a .exe program) for that. you can find it under MPI folder in Start Menu>programs.

try it and tell us the outcome.
do you use Windows firewall? can you ping 127.0.0.1 ?

September 8, 2009 at 12:28 AM  
Blogger Unknown said...

I did try adding username + password to the windows registry through the wmpiregister.exe. :)

I do use a firewall, but I disabled it. And I pinged 127.0.0.1 and my computer name, I got the same data.

I do hear that mpich2 has issues with vista because of increased security features, is that true?

September 8, 2009 at 1:24 AM  
Blogger curveto said...

well,.. I used MPICH2 with vista about 2 years ago for a class project. at that time, there were no SP for vista. So these "security features" might be added to vista through SPs !

but it sounds strange. MPI do nothing but opening a port and connecting to it. i don't think that vista blocks MPI.

I do think it's a matter of firewall (and maybe anti-virus). what I do suggest to you is that you disable your anti-virus and check again. if it doesn't help, uninstall your firewall, disable windows firewall and check again. :D

you may check MPI logs, if any. that might help this troubleshooting.

share the outcome with the others! ;)

September 8, 2009 at 7:56 AM  
Blogger Unknown said...

Yeay! It worked.. tried all the steps that you mentioned again, and it worked.. guess I got it wrong somewhere..
But now its a new problem.. compiling my C++ prog on VS 2008 gives me the following error in my log file
"fatal error C1189: #error : "SEEK_SET is #defined but must not be for the C++ binding of MPI"
"
I know why it happens because it is defined twice in both mpi.h and iostream.h. But neither the manually setting the undef for seek_set,seek_end and seek_cur is working , nor is the command line definition for -DMPICH_IGNORE_CXX_SEEK working. Any ideas?

And thank you for your help on the previous issue. I really appreciate it :)

September 8, 2009 at 8:27 AM  
Blogger curveto said...

nice to hear that!

about the problem with VS. Is it the problem with the sample code that I provide above? or is it your own program?

Try:
1- did you use "using namespace std"?
2- if the 1 does not help, try using printf instead of cout, so you don't need iostream.h (i know this is not a real fix, but it can help you to see if it's the problem with iostream)

September 8, 2009 at 6:15 PM  
Blogger Unknown said...

Thank you very much...
can u put example to run mpich2 on network (2 pc only)?

September 9, 2009 at 11:11 PM  
Blogger curveto said...

@lithium:
your welcome!
this is really simple:

mpiexec -hosts 2 ip1 ip2 app.exe

where ip1 and ip2 are IP address of your PCs.

I also upload a presentation about doing message passing in parallel programming. it might be helpful:

http://curveto.com/Portfolio/Files/Message-Passing-issues-in-parallel-processing.ppt

September 10, 2009 at 12:06 AM  
Blogger Kartik said...

Thanks CURVETO ! but can u pls tell me that how the program will run on different machines and how'll they interact without using either IP address or MAC, i have seen mpi.h file there is no mention about IP address or MAC?

October 7, 2009 at 9:40 AM  
Blogger curveto said...

@kartik:
you do not need to use IP or MAC address.
You should use "rank" in send command.
you can get the rank of the running node by MPI_Comm_rank

October 8, 2009 at 3:11 PM  
Blogger Sansar Choinyambuu said...

Hi,

tnx for the really helpful post.
After reading all these I was still having the error 10061.I had firewall disabled, antivirus disabled.

Then I executed "smpd -phrase behappy -install" in MPICH2/bin directory.

After that, it worked. Just wanted to share. Now it works, with the firewall (the exe's and the port 8676 included in exception list)

October 25, 2009 at 5:36 PM  
Blogger Unknown said...

Great article.

October 26, 2009 at 11:41 AM  
Blogger SHaHzAiB said...

I am using Visual C++ 2008 Express and AMD Turion X2 and Vista 64 bit.

When I compile i get these errors

1>main.obj : error LNK2019: unresolved external symbol _MPI_Finalize@0 referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _MPI_Comm_rank@8 referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _MPI_Comm_size@8 referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _MPI_Abort@8 referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _MPI_Init@8 referenced in function _main
1>C:\Users\Krypyc\Documents\Visual Studio 2008\Projects\MyMPI\Debug\MyMPI.exe : fatal error LNK1120: 5 unresolved externals
1>Build log was saved at "file://c:\Users\Krypyc\Documents\Visual Studio 2008\Projects\MyMPI\MyMPI\Debug\BuildLog.htm"
1>MyMPI - 6 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

October 26, 2009 at 1:16 PM  
Blogger curveto said...

@shahzaib:

I think you didn't add the libraries and/or header files. did you follow those steps correctly?

November 1, 2009 at 5:43 PM  
Blogger tabing said...

Hi I'm just wondering if your tutorial can be used to to run any application? For example transcoding or editing application such adobe premiere or canopus media encoder?

December 10, 2009 at 12:39 PM  
Blogger Unknown said...

Hi everyone.

This tutorial is great. I managed to run MPI on Windows Vista once. But for some unknown reason I get this error now.

Aborting: unable to connect to zara-PC, smpd version mismatch

Can anyone help?

Thank you, happy holidays ;)

December 26, 2009 at 7:46 PM  
Blogger Granoblastic Man said...

@shahzaib:
I had the same issue until I realized: Running Win7 64-bit (in my case) caused the installer to install the 64-bit libraries by default. If this is the same issue, you have two solutions:

1) You can change your build environment in VS2k8 to 64-bit
2) You can build/install the 32-bit libraries instead

February 24, 2010 at 10:30 AM  
Blogger curveto said...

@Granoblastic Man:

Thanks for helping!

February 24, 2010 at 10:32 AM  
Blogger doly s said...

hi
i have a problem with msv 2008 when i run the program this error appears 1>c:\program files\mpich2\include\mpicxx.h(26) : fatal error C1189: #error : "SEEK_SET is #defined but must not be for the C++ binding of MPI"
i tried to use printf instead of cout but it does not work i need your help to fix this problem

March 5, 2010 at 4:45 PM  
Blogger Unknown said...

Hi
Thanks for this detailed help.
I have a problem.
when I type: smpd -status
I get:
enter the passphrase: < here I enter "behappy" without quotes>
then I get the following message:-
ABORTING: Unable to connect to MYHOME

MYHOME is my pc name

I have already registered my windows account name and password with MPICH2 using wmpiregister. The log in name and password neither contain any spaces not any special characters.
i am using windows vista home sp2 32 bit with amd rm-70 dual core
I am waiting for your help.
Regards

March 10, 2010 at 2:10 PM  
Blogger Unknown said...

Well, looks like I found the solution. Silly:) I tried by just pressing enter and not entering any passphrase, and it worked.
Bye

March 10, 2010 at 2:19 PM  
Blogger curveto said...

@Wajahat:

So nice to hear that you've solved your problem!

March 10, 2010 at 4:12 PM  
Blogger Piyush Dokania said...

hi
i m new ti mpich2 i installed it and did evrythng as told by you in above steps

but when i am getting this


C:\Program Files\MPICH2\examples>mpiexec -n2 cpi.exe
'mpiexec' is not recognized as an internal or external command,
operable program or batch file.

help me out

August 18, 2010 at 10:01 PM  
Blogger sayed.dedota said...

thanks a lot, this is very usefull for me

December 12, 2010 at 3:08 AM  
Blogger Unknown said...

Thank you! It's more clear for me now.

November 11, 2011 at 5:57 PM  

Post a Comment

Subscribe to Post Comments [Atom]

<< Home