Computer Systems Lab
Collaboration and Distance Learning Ideas 2003
MPI Sample Programs

  1. simpleMPI.c - "Hello world" from each process
    Uses MPI_Init() and MPI_Finalize()
    simpleMPI.cpp - C++ version (note: Cray SV1 only compiles the C version)
  2. simple2MPI.c - "Hello world" from each process + identifies the rank of the process
    Uses MPI_Init(), MPI_Comm_size() , MPI_Comm_rank(), and MPI_Finalize()
    simple2MPI.cpp - C++ version (note: Cray SV1 only compiles the C version)
  3. broadcastMPI.c - Uses a "broadcast" to send information to each process
    Uses MPI_Init(), MPI_Comm_size() , MPI_Comm_rank(), MPI_Bcast(), and MPI_Finalize()
    broadcastMPI.cpp - C++ version, (note: Cray SV1 only compiles the C version)
  4. greetings.c - Sending a string greeting from each process back to the "master"
    Uses MPI_Init(), MPI_Comm_size() , MPI_Comm_rank(),
    MPI_Send(), MPI_Recv(), and MPI_Finalize()
  5. greetings.cpp - C++ version, (note: Cray SV1 only compiles the C version)
  6. sendInt1.c - Uses scanf(), MPI_Send() and MPI_Recv() to send an integer to all the processes
  7. reciprocalMPI.c - Uses MPI_Send() and MPI_Recv(),
    - send a random integer to all processes, each process sends back the reciprocal
  8. reduceMPI.c - Uses MPI_Send(), MPI_Recv(), and MPI_Reduce()
    - send a random integer to all processes, each process calculates the reciprocal,
    - MPI_Reduce() calculates the sum of all the reciprocals
  9. sendArray1MPI.c - Uses srand(), rand(), MPI_Send() and MPI_Recv() to send an array to all the processes
  10. sendArray1Bcast.c - Uses srand(), rand(), and MPI_Bcast() to send an array to all the processes
  11. sendArray2MPI.c - Uses srand(), rand(), MPI_Send(), MPI_Recv(), and MPI_Reduce() to send an array to all the processes and sum the values from all processes
  12. sendArray3MPI.c - Uses srand(), rand(), MPI_Bcast(), and MPI_Reduce() to send an array to all the processes and sum the values from all processes
  13. sendMatrix1MPI.c - uses MPI_Send() and MPI_Recv() to send an entire matrix
  14. sendMatrix2MPI.c - uses MPI_Send() and MPI_Recv() to send one row at a time out of a matrix
  15. Examples: Vary the Trapezoid program, trap.c (or trap.cpp)
    Joshua Blake's example program (sums the square roots of 1 - n)
  • SYNTAX for MPI Functions
  • C Sample Programs:
    1. introC.c
  • Running an MPI Program