Computer Systems Lab
Collaboration and Distance Learning Ideas 2003
MPI Sample Programs
- 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)
- 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)
- 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)
- 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()
- greetings.cpp -
C++ version, (note: Cray SV1 only compiles the C version)
- sendInt1.c -
Uses scanf(),
MPI_Send() and
MPI_Recv()
to send an integer to all the processes
- reciprocalMPI.c
- Uses MPI_Send() and MPI_Recv(),
- send a random integer to all processes, each process sends back the
reciprocal
- 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
- sendArray1MPI.c -
Uses srand(), rand(), MPI_Send() and
MPI_Recv()
to send an array to all the processes
- sendArray1Bcast.c -
Uses srand(), rand(), and MPI_Bcast()
to send an array to all the processes
- 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
- 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
- sendMatrix1MPI.c
- uses MPI_Send() and MPI_Recv() to send an entire matrix
- sendMatrix2MPI.c
- uses MPI_Send() and MPI_Recv() to send one row at a time out of a matrix
- 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:
- introC.c
Running an
MPI Program