#include "MyMPI.hpp" #include using namespace MF; using std::cout; using std::endl; int main(int argc, char* argv[]) { const MyMPI* mpi = MyMPI::instance(); const int master = 0; if (mpi->rank() == master) //master { std::string str("a message from the master process"); const int tag = 0; for (int dest=1; destsize(); ++dest) { mpi->world().Send(&str[0], static_cast(str.size()), MPI::CHAR, dest, tag); } } else { MPI::Status status; unsigned int counter = 0; for(;;) { if(mpi->world().Iprobe(MPI::ANY_SOURCE, MPI::ANY_TAG, status)) { std::string str; const int msglen = status.Get_count(MPI::CHAR); str.resize(msglen); mpi->world().Recv(&str[0], msglen, MPI::CHAR, status.Get_source(), status.Get_tag()); cout << *MyMPI::instance() << " received: "; cout << str << " "; break; } // some things to do... ++counter; } cout << " Counter: " << counter << endl; } return 0; }