Tutorial 3

Mini Tutorial: Where did that data come from?

Part 1:

You will recall in Tutorial 2 that the rank's purpose is to differentiate between processes because many modern machines are multi-core and can provide multiple processes per machine. There are still some circumstances where a programmer might want to know which machine in the cluster certian information came from.

Luckily, MPI and MPI4PY support retrieving the hosts machines information quite easily. This tutorial builds on Tutorial 2, so the code from Tutorial 2 can be reused here.

Original Code from Tutorial 2
Original Code From Tutorial 2

Part 2:

MPI.COMM_WORLD as mentioned in the previous tutorial, is the default communication MPI4PY provides. In the last tutorial we used it to retrieve the rank of our processes. MPI and the communicator actually contain several usefull pieces of data that could become relevant to a given program. In this tutorial, we will be using a function of the MPI that returns the hostname of the machine where a given process is being run.

This can be accessed through the MPI.Get_processor_name function call and it returns a string. so we can store that in a variable we'll just call name.

From this point we can just modify our print statement from Tutorial 2 such that:

print 'Rank: ',rank, 'Data: ', data

Is changed to:

print data, " from:",name," whose rank is ",rank

Now that the code is complete running the program on the cluster should result in the following output:

Final Tutorial 3 Output
Final Tutorial 3 Output

Alright, now on to Tutorial 4!