#include #include #include #include int main(int argc, char **argv) { int myrank, numprocs; int start, end; int i, first; /* set up same array in each process, otherwise need to broadcast array from root*/ int data[500]; for (i = 0; i < 500; i++) data[i] = 2; /* put some zeros in */ data[496] = 0; data[301] = 0; /* Initialize MPI */ MPI_Init(&argc, &argv); /* Find out my identity in the default communicator */ MPI_Comm_rank(MPI_COMM_WORLD, &myrank); start = myrank * 100; /* start each process at this */ end = start + 99; /* end each process at this */ for (i = start; i <= end; i++) { if (data[i] == 0) break; /* find first zero */ } if (i > end) i = 999; /* not found in this part of the array */ MPI_Reduce(&i, &first, 1, MPI_INT, MPI_MIN, 0, MPI_COMM_WORLD); if (myrank == 0) { printf("Test 1 part II program. Must use 5 processes in this code\n"); printf("First zero at position %i\n", first); } /* Shut down MPI */ MPI_Finalize(); return 0; }