/* 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; MPI_Status status; // 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); // send from id 0 to id 1 if (my_id == 0) { // construct the things to send int i, size = 96, tag = 101; int *my_values = (int *)malloc(size * sizeof(int)); for (i = 0; i < size; i++) my_values[i] = i; MPI_Send(my_values, size, MPI_INT, 1, tag, MPI_COMM_WORLD); free(my_values); } else if (my_id == 1) { // setup a recv buffer int max_size = 250; int *my_values = (int *)malloc(max_size * sizeof(int)); MPI_Recv(my_values, max_size, MPI_INT, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status); MPI_Get_count(&status, MPI_INT, &max_size); printf("\nstatus values: recv size: %d MPI_SOURCE: %d MPI_TAG: %d MPI_ERROR: %d\n\n", max_size, status.MPI_SOURCE, status.MPI_TAG, status.MPI_ERROR); free(my_values); } // finalize MPI MPI_Finalize(); return 0; }