mpi_instructions 1. Getting started with "Hello World" 2. Sending in a ring (broadcast by ring) 3. Finding PI using MPI collective operations 4. An exaple of your choice. ***************************************************************************** ***************************************************************************** 1. Exercise - Getting Started Objective: Learn how to login, write, compile, and run a simple MPI program. Install ssh key: 1. cd 2. cd .ssh 3. ssh-keygen -t rsa cat id_rsa.pub >> authorized_keys2 ln -s authorized_keys2 authorized_keys -Write the code for hello.c. -Compile with: mpicc.mpich -o hello hello.c -Run with: mpirun.mpich -np 2 hello -Try more different parallel computers. -What does the output look like? -Try to improve your program to give you the information on the outputting process (rank and processor name). ***************************************************************************** 2. Sending in a ring (broadcast by ring) Find the code on: http://www-unix.mcs.anl.gov/mpi/tutorial/mpiexmpl/ follow the instructions and try to understand how the program works. ***************************************************************************** 3. Exercise - Calculating PI - Collective communication Objective: Experiment with Send/Receive and Bcast/Reduce -Study compile and Run the program for PI. OPTION: -Write new versions that replace the calls to MPI_Bcast and MPI_Reduce with MPI_Send and MPI_Recv. Test this program. -The MPI broadcast and reduce operations use at most log(p) send and receive operations on each process where p is the size of MPI_COMM_WORLD. How many operations do your versions use? ***************************************************************************** 4. Proposal for your HW2 Excercise - Measuring bandwidth - bw Write a program to measure the time it takes to send 1, 2, 4, ..., 1M C doubles from one processor to another using MPI_Send and MPI_Recv. Use more trials to average out variations and overhead in MPI_Wtime. Print the size, time, and rate in MB/sec for each test. Make sure that both sender and reciever are ready when you begin the test. Describe how the program works. *****Alternativelly, you can select an example from the list! An initial version of the bw program is given below. #include #include #include "mpi.h" #define NUMBER_OF_TESTS 5 /* Number of tests for more reliable average.*/ int main( argc, argv ) int argc; char **argv; { double *buf; int rank, numprocs; int n; double t1, t2, tmin; int j, k, nloop; MPI_Status status; MPI_Init( &argc, &argv ); MPI_Comm_size(MPI_COMM_WORLD,&numprocs); if (numprocs != 2) { printf( "The number of processes has to be exactly two!\n" ); return(0); } MPI_Comm_rank( MPI_COMM_WORLD, &rank ); if (rank == 0) printf( "Kind\t\tn\ttime (sec)\tRate (Mb/sec)\n" ); for (n=1; n<110000; n*=2) { /* Message lengths doubles each time */ if (n == 0) nloop = 100; else nloop = 100/n; if (nloop < 1) nloop = 1; buf = (double *) malloc( n * sizeof(double) ); if (!buf) { fprintf( stderr, "Could not allocate send/recv buffer of size %d\n", n ); MPI_Abort( MPI_COMM_WORLD, 1 ); } tmin = 1000; for (k=0; k 0) rate = n * sizeof(double) * 1.0e-6 * 8/tmin; /* in Mb/sec */ else rate = 0.0; printf( "Send/Recv\t%d\t%f\t%f\n", n, tmin, rate ); } free( buf ); } MPI_Finalize( ); return 0; }