Lab05 - Using MPI (Message Passing Interface)
CRAY SV1 Version: Hello Parallelism

Objective
To run an MPI program. Topics include printf, MPI_Init, MPI_Finalize, MPI_Rank, MPI_Size, MPI_COMM_WORLD.

Background
Check the page on running MPI programs (this is for the Cray SV1).
  1. On the Cray SV1: cc -o filename filename.c, where filename is the name of the .c file you are going to run.
    In Lab00, this filename is hello.c
    When using a workstation use MPICH Mpi:
  2. mpirun -np 15 filename (-np 15 runs 15 processes)
    ON A WORKSTATION USE: "mpirun -all-local -np 5 filename")
  3. Try timing: time mpirun -np 15 filename, use 2 - 16 processes, see if there's a difference

Assignment
Create a file named hello.c that contains the program shown below. Run the program using the steps given above.

hello.c
#include <stdio.h>
#include "mpi.h"

int main( int argc, char** argv )
{
  int rank, size;
  char name[80]; // character array to hold the name of each processor
  int len; // length of the name of the processor
  MPI_Init( &argc, &argv );
  MPI_Comm_size( MPI_COMM_WORLD, &size );
  MPI_Comm_rank( MPI_COMM_WORLD, &rank );
  MPI_Get_processor_name(name, &len);
  printf( "Hello from process %d of %d. Name=%s\n", rank, size, name );
  MPI_Finalize();
  return 0;
}

Sample Output
cc -o lab00 lab00.c
mpirun -np 5 lab00

Hello from process 1 of 5. Name=sn3313
Hello from process 2 of 5. Name=sn3313
Hello from process 4 of 5. Name=sn3313
Hello from process 3 of 5. Name=sn3313
Hello from process 0 of 5. Name=sn3313

mpirun -np 16 lab00
Hello from process 0 of 16. Name=sn3313
Hello from process 2 of 16. Name=sn3313
Hello from process 3 of 16. Name=sn3313
Hello from process 4 of 16. Name=sn3313
Hello from process 5 of 16. Name=sn3313
Hello from process 6 of 16. Name=sn3313
Hello from process 7 of 16. Name=sn3313
Hello from process 8 of 16. Name=sn3313
Hello from process 9 of 16. Name=sn3313
Hello from process 10 of 16. Name=sn3313
Hello from process 14 of 16. Name=sn3313
Hello from process 1 of 16. Name=sn3313
Hello from process 11 of 16. Name=sn3313
Hello from process 13 of 16. Name=sn3313
Hello from process 12 of 16. Name=sn3313