// MPI code in C++. // See [Gropp/Lusk/Skjellum, "Using MPI", p.33/41 etc.] // and /opt/mpich/include/mpi2c++/comm.h for details #include "vec_func.h" #include // MPI #include using namespace std; int main(int argc, char *argv[]) { MPI_Comm icomm = MPI_COMM_WORLD; MPI_Init(&argc, &argv); int myrank; MPI_Comm_rank(icomm, &myrank); // E5 vector x(10,3); if(myrank==0) {cout << endl << "E5" << endl;} vecdebug(x, icomm); // E6 vector y(10,1.0/3); double res = par_scalar(x,y,icomm); if(myrank==0) { cout << endl << endl << "E6" << endl; cout << " = " << res << endl << endl; } // E7 vector a{myrank*10, myrank*10-1, myrank*10-2}; if(myrank==0) {cout << "E7\n" << "original vector" << endl;} vecdebug(a, icomm); double min_val, max_val; min_max_exch(a, min_val, max_val, icomm); if(myrank==0) {cout << "min = " << min_val << "\tmax = " << max_val << endl << endl << "vector after changing min-max" << endl;} vecdebug(a, icomm); // E8 int n = 20; vector c(n); for(size_t i=0; i recv(n); MPI_Alltoall(c.data(), 5, MPI_DOUBLE, recv.data(), 5, MPI_DOUBLE, icomm); if(myrank==0) {cout << endl << "Ex 8\n" << "Alltoall" << endl;} vecdebug(recv, icomm); MPI_Alltoall(MPI_IN_PLACE, 0, MPI_DATATYPE_NULL, c.data(), 5, MPI_DOUBLE, icomm); if(myrank==0) {cout << endl << "Ex 8\n" << "Alltoall - IN_PLACE" << endl;} vecdebug(c, icomm); MPI_Finalize(); return 0; }