c++ - mpi hello world not working -
i write simple hello-world programme on visual c++ 2010 express mpi library , cant understand, why code not working.
mpi_init( null, null ); mpi_comm_size(mpi_comm_world,&size); mpi_comm_rank(mpi_comm_world,&rank); int a, b = 5; mpi_status st; mpi_send( &b, 1, mpi_int, 0,0, mpi_comm_world ); mpi_recv( &a, 1, mpi_int, 0,0, mpi_comm_world, &st );
mpi_send tells me "deadlock: attempting send message local process without prior matching receive". if write recv first, programme stucks there (no data, blocking receive). i`m doint wrong?
my studio visual c++ 2010 express. mpi hpc sdk 2008 (32 bit).
you need this:
assert(size >= 2); if (rank == 0) mpi_send( &b, 1, mpi_int, 1,0, mpi_comm_world ); if (rank == 1) mpi_recv( &a, 1, mpi_int, 0,0, mpi_comm_world, &st );
the thought of mpi whole scheme operates in lockstep. , need aware of participant in "world." in case, assuming have 2 members (as per assert), need create 1 of them send , other receive.
note changed "dest" parameter of send, because 0 needs send 1 hence 1 needs receive 0.
you can later other way around if wish (if each needs tell other something), in such case may find more efficient ways using "collective operations" can exchange (both send , receive) peers.
c++ mpi
No comments:
Post a Comment