User forums > Help

How to run this C++ MPI program?

(1/2) > >>

a6146319:
I am new to MPI and trying to run 'hello world' program. Here is my program


--- Code: ---#include <iostream>
#include <mpi.h>
using namespace std;


int main(int argc, char ** argv)
{
int mynode, totalnodes;
MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD, &totalnodes);
MPI_Comm_rank(MPI_COMM_WORLD, &mynode);
cout << "Hello world from process " << mynode;
cout << " of " << totalnodes << endl;
MPI_Finalize();
}
--- End code ---
The output is just


--- Code: ---Hello world from process 0 of 1
--- End code ---

I have multi-core CPU and I think there should be at least 4 processes running. So Output should be:


--- Code: ---Hello world from process 0 of 4
Hello world from process 1 of 4
Hello world from process 2 of 4
Hello world from process 3 of 4
--- End code ---

or something similar. Can anyone comment what did I miss in the program or compile command? By the way I am running on Windows, MSMPI, gcc compiler on Code::Blocks IDE.
When I use

--- Code: ---mpiexec –n 10 file.exe
--- End code ---
to run, it runs properly. So I need to give some arguments to code::blocks and I am missing those. Can anyone tell me these settings in code::blocks for Windows?
Thanks in advance.
Thanks.

stahta01:
Did you try "Project" -> "Set Programs' Arguments"?

Tim S.

a6146319:
I tried putting in projects->arguments but it didn't help or may be I did something wrong. Can you please explain me how to do this correctly? Attached image of options.

ToApolytoXaos:
You should read more about this here http://stackoverflow.com/a/5171191

a6146319:
I changed the toolchain executables to mpiexec.exe, as per suggested in the post. However still I am not able to run the program as expected. Can anyone share comments?

Navigation

[0] Message Index

[#] Next page

Go to full version