/* 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 int main(int argc, char **argv) { int my_id, num_proc, my_value[2] = {0, 0}, max_value[2] = {0, 0}, root = 0; // 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 my_value[0] = (my_id + 1) * num_proc; my_value[1] = - (my_id + 1) * num_proc; // print original values printf("id: %d num: %d values: %d & %d\n", my_id, num_proc, my_value[0], my_value[1]); // find the maximum MPI_Reduce(my_value, max_value, 2, MPI_INT, MPI_MAX, root, MPI_COMM_WORLD); // print maximum values printf("id: %d num: %d max values: %d & %d\n", my_id, num_proc, max_value[0], max_value[1]); // finalize MPI MPI_Finalize(); return 0; }