/* Jonathan Hauenstein - University of Notre Dame Center for Applied Mathematics Minicourse on Parallel Computing April 24, May 1, May 8, 2008 Sample programs are designed for educational use */ #include #include #include int main(int argc, char **argv) { int my_id, num_proc, my_value, tag = 101; MPI_Status status; MPI_Request request; // initialize MPI MPI_Init(&argc, &argv); // find unique id MPI_Comm_rank(MPI_COMM_WORLD, &my_id); // find the number of processes running MPI_Comm_size(MPI_COMM_WORLD, &num_proc); // setup my_value & print it my_value = pow(my_id + 1, num_proc); printf("id: %d num: %d value: %d\n", my_id, num_proc, my_value); // send from id 0 to id 1 if (my_id == 0) { MPI_Isend(&my_value, 1, MPI_INT, 1, tag, MPI_COMM_WORLD, &request); // Perform extra processing while waiting on the communication to complete MPI_Wait(&request, &status); } else if (my_id == 1) MPI_Recv(&my_value, 1, MPI_INT, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status); // print my_value printf("id: %d num: %d value: %d\n", my_id, num_proc, my_value); if (my_id == 1) printf("source: %d tag: %d error: %d\n", status.MPI_SOURCE, status.MPI_TAG, status.MPI_ERROR); // finalize MPI MPI_Finalize(); return 0; }