int main(void) { int p, my_rank; MPI_Comm comm; int x; int total; MPI_Init(NULL, NULL); comm = MPI_COMM_WORLD; MPI_Comm_size(comm, &p); MPI_Comm_rank(comm, &my_rank); srandom(my_rank+1); x = random() % MAX_CONTRIB; printf("Proc %d > x = %d\n", my_rank, x); total = Global_sum(x, my_rank, p, comm); if (my_rank == 0) printf("The total is %d\n", total); MPI_Finalize(); return 0; } /* main */
int main(void) { int p, my_rank; MPI_Comm comm; int my_contrib; int sum; MPI_Init(NULL, NULL); comm = MPI_COMM_WORLD; MPI_Comm_size(comm, &p); MPI_Comm_rank(comm, &my_rank); /* Generate a random int */ srandom(my_rank); my_contrib = random() % MAX_CONTRIB; Print_results("Process Values", my_contrib, my_rank, p, comm); sum = Global_sum(my_contrib, my_rank, p, comm); Print_results("Process Totals", sum, my_rank, p, comm); MPI_Finalize(); return 0; }