How it works...

For each process, the output should read as follows: if neighbour_processes = -1, then it has no topological proximity, otherwise, neighbour_processes shows the rank of the process closely.

The resulting topology is a mesh of 2×2 (refer to the previous diagram for a mesh representation), the size of which is equal to the number of processes in the input; that is, four:

grid_row = int(np.floor(np.sqrt(comm.size))) 
grid_column = comm.size // grid_row 
if grid_row*grid_column > size: 
    grid_column -= 1 
if grid_row*grid_column > size: 
    grid_rows -= 1

Then, the Cartesian topology is built using the comm.Create_cart function (note also the parameter, periods = (False,False)):

cartesian_communicator = comm.Create_cart(   
    (grid_row, grid_column), periods=(False, False), reorder=True) 

To know the position of the process, we use the Get_coords() method in the following form:

my_mpi_row, my_mpi_col = 
                cartesian_communicator.Get_coords(cartesian_communicator.rank ) 

For the processes, in addition to getting their coordinates, we must calculate and find out which processes are topologically closer. For this purpose, we use the comm.Shift (rank_source,rank_dest) function:


neighbour_processes[UP], neighbour_processes[DOWN] =
cartesian_communicator.Shift(0, 1) neighbour_processes[LEFT], neighbour_processes[RIGHT] =
cartesian_communicator.Shift(1, 1)

The topology obtained is as follows:

The virtual mesh 2x2 topology

As the diagram shows, the P0 process is chained to the P1 (RIGHT) and P2 (DOWN) processes. The P1 process is chained to the P3 (DOWN) and P0 (LEFT) processes, the P3 process is chained to the P1 (UP) and P2 (LEFT) processes, and the P2 process is chained to the P3 (RIGHT) and P0 (UP) processes.

Finally, by running the script, we obtain the following result:

C:>mpiexec -n 4 python virtualTopology.py
Building a 2 x 2 grid topology:
Process = 0 row = 0 column = 0
---->
neighbour_processes[UP] = -1
neighbour_processes[DOWN] = 2
neighbour_processes[LEFT] =-1
neighbour_processes[RIGHT]=1

Process = 2 row = 1 column = 0
---->
neighbour_processes[UP] = 0
neighbour_processes[DOWN] = -1
neighbour_processes[LEFT] =-1
neighbour_processes[RIGHT]=3

Process = 1 row = 0 column = 1
---->
neighbour_processes[UP] = -1
neighbour_processes[DOWN] = 3
neighbour_processes[LEFT] =0
neighbour_processes[RIGHT]=-1

Process = 3 row = 1 column = 1
---->
neighbour_processes[UP] = 1
neighbour_processes[DOWN] = -1
neighbour_processes[LEFT] =2
neighbour_processes[RIGHT]=-1

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.146.255.127