Code::Blocks Forums

User forums => Help => Topic started by: a6146319 on June 23, 2014, 03:04:12 am

Title: How to run this C++ MPI program?
Post by: a6146319 on June 23, 2014, 03:04:12 am
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();
}
The output is just

Code
Hello world from process 0 of 1

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

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
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.
Title: Re: How to run this C++ MPI program?
Post by: stahta01 on June 23, 2014, 04:02:08 am
Did you try "Project" -> "Set Programs' Arguments"?

Tim S.
Title: Re: How to run this C++ MPI program?
Post by: a6146319 on June 23, 2014, 01:10:36 pm
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.
Title: Re: How to run this C++ MPI program?
Post by: ToApolytoXaos on June 23, 2014, 02:24:56 pm
You should read more about this here http://stackoverflow.com/a/5171191 (http://stackoverflow.com/a/5171191)
Title: Re: How to run this C++ MPI program?
Post by: a6146319 on June 24, 2014, 12:04:09 am
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?
Title: Re: How to run this C++ MPI program?
Post by: stahta01 on June 24, 2014, 12:32:13 am
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?

Please quote anywhere you read what you said you did; because it sounds very wrong.

FYI: I would guess you need to use mpiexec.exe as the "Host application"; but, this is just a guess.
I have never used the "Host application" part of "Set Programs' Arguments".

Tim S.
Title: Re: How to run this C++ MPI program?
Post by: oBFusCATed on June 24, 2014, 12:53:04 am
I guess this looks like another use case for the embedded target patches, but here there is nothing embedded...
But this will probably be possible in the future...

At the moment you can probably setup a tool to start you executable using mpiexe and pass all the parameters.
But I guess you'll loose the possibility to debug your program easily (you'll have to attach to it).