Lab 1. MPI - Getting Started


Task 0 – Get Organised.

-          Create a folder CS4402 plus a sub-folder Lab01.

-          For each program you develop create a distinct subfolder.

-          Create a folder hellos and save the files hellos.c and Makefile.

-          Observe the names of the machines around you and create a file called machines with those names.

-          Generate ssh certificates that would allow running mpi programs (see instructions).


Task 1 - How to compile and execute a MPI program.

-          Compile and run the file:

o   Compile: make.

o   Run: mpirun –np 4 hello or mpirun –np 4 –machinefile machines hello

o   Understand each argument of the command line.

-          Change the program to printf the name of the machines.

o   Remove the comments.

o   Save the file with a different name e.g. hello1.

o   Change in the file Makefile hello with hello1.


Task 2 – Find the Number of Primes <= n.

-          Create a folder week1/prime and save the file prime.c to this folder.

-          Compile and run the file:

o   Compile: make.

o   Run: mpirun –np 4 prime or mpirun –np 4 –machinefile machines prime

o   Observe the execution times and explain why they are not even.

-          Understand the data partition e.g. what numbers are tested by processor rank.

-          Change the loop “for” to cover the iterations in a cyclic manner.

o   Processor 0 gets: 1, size+1, 2*size+1

o   Processor 1 gets: 2, size+2, 2*size+2

o   What about Processor rank?

o   Run the program now and observe the execution times.

– Check the Amdahl’s Laws.

o   Run the program for np = 1, 2, 3, 4, 5, 6 processors.

o   Observe and note the overall execution times.

o   Bring this exec times to an excel-like application.

o   Table these values to find:

§   The speedup values.

o   Check whether the execution times reduce and speedup increases.