#define _MPI_CPP_BINDINGS #include #include using std::cout; using std::endl; int main(int argc, char* argv[]) { MPI::Init(argc, argv); const int size = MPI::COMM_WORLD.Get_size(); if (size != 2) return MPI::ERR_SIZE; //check for 2 processes const int rank = MPI::COMM_WORLD.Get_rank(); if (rank==0) //the sender { double toSend = 13.13; const int cnt = 1; const int dest = 1; const int tag = 0; cout << "process " << rank << " sends "<< toSend << " to process " << dest << endl; MPI::COMM_WORLD.Send(&toSend, cnt, MPI::DOUBLE, dest, tag); } else //the receiver { double toRecv; const int cnt = 1; const int from = 0; const int tag = 0; MPI::COMM_WORLD.Recv(&toRecv, cnt, MPI::DOUBLE, from, tag); cout << "process " << rank << " received "<< toRecv << " from process " << from << endl; } MPI::Finalize(); }