//Simple C++ Example //p 71, 72 from tutorial slides #include #include int main(int argc, char **argv) { int i, rank, size, dest; int to, src, from, count, tag; int st_count, st_source, st_tag; double data[100]; MPI::Status status; MPI::Init(argc, argv); rank = MPI::COMM_WORLD.Get_rank(); size = MPI::COMM_WORLD.Get_size(); cout << "Process " << rank << " of " << size << " is alive" << endl; dest = size - 1; src = 0; if (rank == src) { to = dest; count = 100; tag = 2001; for (i = 0; i < 100; i++) data[i] = i; MPI::COMM_WORLD.Send(data, count, MPI::DOUBLE, to, tag); } else if (rank == dest) { tag = MPI::ANY_TAG; count = 100; from = MPI::ANY_SOURCE; MPI::COMM_WORLD.Recv(data, count, MPI::DOUBLE, from, tag, status); st_count = status.Get_count(MPI::DOUBLE); st_source= status.Get_source(); st_tag= status.Get_tag(); cout << "Status info: source = " << st_source << ", tag = " << st_tag << ", count = " << st_count << endl; cout << rank << " received: "; for (i = 0; i < st_count; i++) cout << data[i] << " "; cout << endl; } MPI::Finalize(); return 0; } /* mpiCC -o simple3MpiCpp simple3Mpi.cpp lamboot -v lamhosts LAM 6.5.6/MPI 2 C++/ROMIO - University of Notre Dame Executing hboot on n0 (helium.tjhsst.edu - 1 CPU)... Executing hboot on n1 (sulfur.tjhsst.edu - 1 CPU)... Executing hboot on n2 (phosphorus.tjhsst.edu - 1 CPU)... Executing hboot on n3 (magnesium.tjhsst.edu - 1 CPU)... topology done mpirun N simple3MpiCpp Process 1 of 4 is alive Process 3 of 4 is alive Process 2 of 4 is alive Process 0 of 4 is alive Status info: source = 0, tag = 2001, count = 100 3 received: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 lamclean lamhalt */