hello_mpi.c
and submit a job on both machines.
3. Write a simple MPI program that does the following,
* generate a random integer array, with 100 elements per process, on all processes. hint: initialize the RNG using some function of the rank of the process.
* broadcast one value (say the first) from the root (rank 0 or any process really) to all other processes. lets call this the pivot.
c
int root = 0;
int pivot = array[0];
MPI_Bcast( &pivot, 1, MPI_INT, root, MPI_COMM_WORLD );
* on each process compute how many elements are less than the pivot.
* Now reduce to obtain the total number of elements (globally) less than the pivot. Reduce to receive the result on the root and print it out.
c
int localLessThan, globalLessThan;
MPI_Reduce(&localLessThan, &globalLessThan, 1, MPI_INT, MPI_SUM, root, MPI_COMM_WORLD);
* run on [Tangent][] & [Stampede][] with increasing values of \(p\), i.e., the number of processes. Since we are fixing the number of elements per process to 100, this is a weak scalability experiment. What can you infer about the complexity of MPI_Reduce
? Time only the reduction.
[Tangent]: https://wiki.chpc.utah.edu/display/DOCS/Tangent+User+Guide [Stampede]: https://portal.tacc.utexas.edu/user-guides/stampede