News:

When registered with our forums, feel free to send a "here I am" post here to differ human beings from SPAM bots.

Main Menu

How to run this C++ MPI program?

Started by a6146319, June 23, 2014, 03:04:12 AM

Previous topic - Next topic

a6146319

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

#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

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:

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

stahta01

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

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

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


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?

stahta01

#5
Quote from: 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?

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.
C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

oBFusCATed

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!]