Obviously, MPI_MAX isn't the only operation that may be useful in a global computation. Take a look at either of the sample codes below. Once the question mark is removed, either the C or Fortran version of the program will compile correctly. But to make the computed number match the answer calculated by the formula, you will need to substitute a different operation in the call to MPI_Allreduce. Can you deduce the correct operation?

MPI_Allreduce Exercise

If you don't recognize the formula, you can always try changing the MPI operation and testing the program with different numbers of processes until the answer always comes out right. Or, you can peek at the correct operation by hovering here.

On Frontera or Vista, copy and paste the sample code into a command line editor, then compile and run it using an interactive session. The Frontera CVW Topics explain these steps in more detail.

  • Compile using a command like those shown below:
    % mpif90 allreduce.f90 -o allreduce_f
    % mpicc allreduce.c -o allreduce_c
  • Start an interactive session using:
    % idev -N 1 -n8
  • Run the code using the ibrun MPI launcher wrapper. Try varying the number of processes from 2 to 8:
    % ibrun -np 8 allreduce_c
 
©  |   Cornell University    |   Center for Advanced Computing    |   Copyright Statement    |   Access Statement
CVW material development is supported by NSF OAC awards 1854828, 2321040, 2323116 (UT Austin) and 2005506 (Indiana University)