CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Main CFD Forum (https://www.cfd-online.com/Forums/main/)
-   -   Please help me about MPI and c++ (https://www.cfd-online.com/Forums/main/78416-please-help-me-about-mpi-c.html)

gholamghar July 21, 2010 10:26

Please help me about MPI and c++
 
Hello
I am a total beginner in parallel programming and I have the simplest C++ code which prints "Hello World" message.this is what i did in order to run my code: I have windows xp,microsoft visual studio 2008,then i installed MPICH2 and then opened my C++ code and went to properties and added "...\MPICH2\include" and "...\MPICH2\lib" and "...\MPICH2\lib\mpi.lib" to my code. then i compiled it and it was comiled with no errors,then i pressed "Ctrl+F5" (in Microsoft Visual studio 2008 it runs the program) and the output i got was:

node 0: Hello, world
Press any key to continue . . .

But it seems parallel codes should not be ran in the way i did and i should use "mpirun" so that i get a message like this:

node 0: Hello, world
node 1: Hello, world
node 2: Hello, world
node 3: Hello, world
Press any key to continue . . .

and all my 4 cpu cores are used,but i have no idea how and where i should use mpirun, some guy told me i should go to command prompt but as i told i have no idea how i should use mpirun,Please help me about this problem.
Thanks in advance

MechE July 30, 2010 12:32

I would first make sure you are compiling with the mpi command. I think the command is mpicc in for c programs and mpicpp for c++ programs. you must run the code using mpirun in order for it to run within more than one core. I run my code on linux systems with mpi installed and run the code from the terminal:

ie: $: mpirun name_of_program.x

valgrinda August 1, 2010 09:00

Mpich2
 
Hei,

There is nothing wrong with the way your compile your program, but in the way you execute it. First of all, since you use MPICH on a Windows machine, the command is not 'mpirun', but 'mpiexec'.
Also 'C:\Program Files\MPICH2\bin' needs to be in the PATH environment variable, so that the location of the excutable 'mpiexec.exe' is known to your system. If you have problems with this, you can also put your compiled program into MPICH's bin folder. Then you can use the DOS command window and start it from there.


Regards
Hans

gholamghar August 1, 2010 10:45

Thank you valgrinda it helped a lot.Thank you MechE too.


All times are GMT -4. The time now is 04:49.