Author Topic: How to run this C++ MPI program?  (Read 15374 times)

Offline a6146319

  • Single posting newcomer
  • *
  • Posts: 5
How to run this C++ MPI program?
« 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.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7591
    • My Best Post
Re: How to run this C++ MPI program?
« Reply #1 on: June 23, 2014, 04:02:08 am »
Did you try "Project" -> "Set Programs' Arguments"?

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline a6146319

  • Single posting newcomer
  • *
  • Posts: 5
Re: How to run this C++ MPI program?
« Reply #2 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.

ToApolytoXaos

  • Guest
Re: How to run this C++ MPI program?
« Reply #3 on: June 23, 2014, 02:24:56 pm »
You should read more about this here http://stackoverflow.com/a/5171191

Offline a6146319

  • Single posting newcomer
  • *
  • Posts: 5
Re: How to run this C++ MPI program?
« Reply #4 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?

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7591
    • My Best Post
Re: How to run this C++ MPI program?
« Reply #5 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.
« Last Edit: June 24, 2014, 12:33:57 am by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: How to run this C++ MPI program?
« Reply #6 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).
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]