Supercomputer Applications
MPI Projects Part 1, Spring 2006
MPI (Message Passing Interface) Programs, Parallel Programming
Message Passing Interface Forum,
MPI Standard (1995),
MPI routines,
Constants for C and Fortran
MPI Routines
- Example programs:
- Hello world
- Sending values between processors
- "Collective" operations - BCAST and REDUCE
- bcast.c (C), bcastF.f90 (Fortran) - "Broadcasts" pi from the root process to all other processors
- reduce.c (C), reduceF.f90 (Fortran) - Collects pi from all processors; sums up all the pi values in the root process.
- MPI
Program Lab05, "HelloCluster.c"
MPI_Init(),
MPI_Comm_size()
, MPI_Comm_rank(),
MPI_Finalize()
MPI_COMM_WORLD
(scroll down to "Communicators")
Lab 05 Report form, .doc
- MPI
Program Lab06, share.c
--Input a number with scanf, broadcast this value to other
"nodes"/processes
uses:
MPI_Send(),
and MPI_Recv()
(Vers. 1)
MPI_Bcast()
(Vers. 2)
also see MPI Data
types
NOTE: Place the call to MPI_Bcast outside of the "if (rank == 0)"
block:
if (rank == 0) {
scanf( ... );
}
MPI_Bcast( ... ); //MPI_Bcast is like a combination send/receive,
//so each process needs it
- MPI
Program Lab07, DinnerParty.c
Use MPI_Send(),
and MPI_Recv(),
INSTEAD OF MPI_Bcast()
Sample Output (with six processes):
mpirun -np 6 lab02
Process 0, Sending out random int 406999 to process 1
Process 2 received: 1252750, mysalary=380245, sending out 1632995 to process 3
Process 3 received: 1632995, mysalary=600007, sending out 2233002 to process 4
Process 1 received: 406999, mysalary=845751, sending out 1252750 to process 2
Process 0 received 3014004, mySalary=157838, average salary=$460807.17
Process 4 received: 2233002, mysalary=618007, sending out 2851009 to process 5
Process 5 received: 2851009, mysalary=162995, sending out 3014004 to process 0
- MPI
Program Lab08, IntervalSlicing.c - Calculate Pi,
--parallelize the program "gregory.c"
For an example of MPI_Reduce(), see reduce.c (C), reduceF.f90 (Fortran) - Collects pi from all processors; sums up all the pi values in the root process.
Use MPI_Reduce() to sum data that is local to each process
- MPI
Program Lab09, Parallel Programming Application - Array Search
--a parallelized search of a large array for a target value
- MPI Resources and Sample Programs