Tuesday, 15 March 2011

c++ - Running MPI programs with multiple processes with Code::Blocks -



c++ - Running MPI programs with multiple processes with Code::Blocks -

i new mpi , trying run 'hello world' program. here 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 process " << mynode; cout << " of " << totalnodes << endl; mpi_finalize(); }

the output just

hello world process 0 of 1

i have multi-core cpu , think there should @ to the lowest degree 4 processes running. output should be:

hello world process 0 of 4 hello world process 1 of 4 hello world process 2 of 4 hello world process 3 of 4

or similar. can comment did miss in programme or compile command? way running on windows, msmpi, gcc compiler on code::blocks ide. thanks.

it worked me.

i re-create pasted code mpi_app.cpp. mpicxx compiler wrapper script provided mpi implementers takes care of includes , libs. mpirun wrapper script launching mpi programs provided mpi implementers. mpi implementation i'm using mpich2.

$ mpicxx -o0 -o mpi_app mpi_app.cpp $ mpirun -n 4 ./mpi_app hello world prochello world process 2 hello world process hello world process 0 oess 1 of 4 of 4 3 of 4 f 4

note: "f 4" not re-create paste error. when multiple processes writing stdout should expect garbled or interspersed messages.

it sounds getting compile, if not, looks on windows have manually add together include , lib: http://blogs.msdn.com/b/risman/archive/2009/01/04/ms-mpi-with-visual-studio-2008.aspx

from same link, looks command on windows command line is:

mpiexec –n 10 mympiproject.exe

to run within code::blocks need tell code::blocks run command above. blog post linked below, looks code::blocks uses 'cb_console_runner.exe' run compiled programs. blog post has modified version of programme take -mpi flag telling mpiexec is.

http://www.blog.kubiak.co.uk/post/44

setting -mpi flag:

"argument must define in codeblocks menu in project -> set programs’ arguments?

-mpi <path mpiexec> -n <number of processes>

example:

-mpi c:/progra~1/mpich2/bin/mpiexec -n 8

"

c++ gcc mpi codeblocks

1 comment: