Introduction to Programming with MPI ------------------------------------ Practical Exercise 11 (Topologies) ---------------------------------- For general instructions, see the introduction to the collective practicals. You are recommended to include appropriate checking in all of this code, which is essential if you do this sort of thing in real programs. In all of these exercises, run the program with 20 processes unless stated otherwise. Question 1 ---------- 1.1 Write a program that creates a 3x5 Cartesian grid (i.e. not periodic) from MPI_COMM_WORLD; allow reordering, though that is unlikely to happen. Display the rank of the process in MPI_COMM_WORLD, and the dimensions, periodicities, rank and coordinates in the new communicator for each process. Remember to handle MPI_COMM_NULL correctly. Then experiment with running with 10 and 15 processes (no specimen output given). To display the information, write a function that takes the number of dimensions and the new communicator as arguments, and uses the enquiry functions to check that it is a 2-D Cartesian topology, display the rank of the process in MPI_COMM_WORLD, and the dimensions, periodicities, rank and coordinates in the new communicator for each process. It is easy enough to write one that can take any number of dimensions, but displaying the output neatly is messy in Fortran. 1.2 Change the program to display just the rank of the process in the new communicator and the ranks of all 8 neighbouring processes, instead of the information displayed in question 1.1. The specimen answer prints them out in the order (-1,-1), (-1,0), (-1,+1), (0,-1), (0,+1), (+1,-1), (+1,0), (+1,+1). Display -123 for a neighbour that doesn't exist (i.e. returns MPI_PROC_NULL). To calculate the rank of the neighbouring processes, write another function that takes a Cartesian communicator and an array of integers that can have values only -1, 0 or +1, which indicate which dimensions should be decremented, incremented or left alone, and which returns a rank or MPI_PROC_NULL. 1.3 Change the program to make the first dimension periodic, and run it. 1.4 Change the program to make both dimensions periodic, and run it. 1.5 Change the program to remove the displays, and create two subset communicators that correspond to rows and columns. Display the communicator size and rank in the 2-D Cartesian communicator and both subset communicators for all processes. Run the program. You can experiment with changing the periodicity if you like, but it will make no difference here, though it did in the previous one.