Docsity

Virtual Topologies-Message Passing Interface Library-Lecture Slides, Slides of Microprocessor and Interfacing

Partial preview of the text

Download Virtual Topologies-Message Passing Interface Library-Lecture Slides and more Slides Microprocessor and Interfacing in PDF only on Docsity!

Dr. Hanif Durad

Lecture Outline

^

Virtual Topologies

^

Topology Types

^

Creating a Cartesian Virtual Topology

^

Cartesian Example

^

Cartesian Mapping Functions^ 

MPI_CART_RANK  MPI_CART_COORDS  MPI_CART_SHIFT

^

Cartesian Partitioning

IntroMPI.ppt

Virtual Topologies

^

Convenient process naming

^

Naming scheme to fit the communication pattern

^

Simplifies writing of code

^

Can allow MPI to optimize communications

^

Rationale: access to useful topology routines

Dr. Hanif Durad

Example - 2D Torus

Dr. Hanif Durad

Topology types

^

Cartesian topologies^ 

Each process is connected to its neighbors in a virtualgrid 

Boundaries can be cyclic

^

Processes can be identified by Cartesian coordinates

^

Graph topologies^ 

General graphs 

Will not be covered here

Dr. Hanif Durad

Arguments

Dr. Hanif Durad

comm_old

existing communicator

ndims

number of dimensions

periods

logical array indicating whether a dimension is cyclic(If TRUE, cyclic boundary conditions)

reorder

logical(If FALSE, rank preserved)(If TRUE, possible rank reordering)

comm_cart

new cartesian communicator

Cartesian Example

MPI_Comm vu;int dim[2], period[2], reorder;dim[0]=4; dim[1]=3;period[0]=TRUE; period[1]=FALSE;reorder=TRUE;MPI_Cart_create(MPI_COMM_WORLD,2,dim,period,reorder,&vu);

Cartesian Mapping Functions

^

Mapping ranks to process grid coordinates^ 

C:

^

int MPI_Cart_coords (MPI_Comm comm, int rank, intmaxdims, int *coords)

^

Fortran:^ 

INTEGER COMM,RANK,MAXDIMS,COORDS(*),IERROR  CALLMPI_CART_COORDS(COMM,RANK,MAXDIMS,COORDS,IERROR)

Dr. Hanif Durad

Example using C

#include <stdio.h>#include <mpi.h>/* Run with 12 processes */void main (int argc, char *argv[]) {int rank;MPI_Comm vu;int dim[2], period[2], reorder;int coord[2] , id;int TRUE=1,FALSE=0;MPI_Init(&argc, &argv);MPI_Comm_rank(MPI_COMM_WORLD,&rank);dim[0]=4; dim[1]=3;period[0]=TRUE; period[1]=FALSE;reorder=TRUE;MPI_Cart_create(MPI_COMM_WORLD,2,dim,period,reorder,&vu);if(rank==5){MPI_Cart_coords(vu,rank,2,coord);printf("P:%d My coordinates are %d %d\n",rank,coord[0],coord[1]);} if(rank==0) {coord[0]=3; coord[1]=1;MPI_Cart_rank(vu,coord,&id);printf("The processor at position (%d, %d) has rank %d\n",coord[0],coord[1],id);} MPI_Finalize();}^

cart.c

Cartesian Mapping Functions

^

Computing ranks of neighboring processes^ 

C:

^

int MPI_Cart_shift (MPI_Comm comm, int direction, intdisp, int *rank_source, int *rank_dest)

^

Fortran:^ 

INTEGERCOMM,DIRECTION,DISP,RANK_SOURCE,RANK_DEST,IERROR  CALLMPI_CART_SHIFT(COMM,DIRECTION,DISP,RANK_SOURCE,RANK_DEST,IERROR

MPI_Cart_shift

^

Does not actually shift data: returns the correct ranks for a shiftwhich can be used in subsequent communication calls

^

Arguments:

Dr. Hanif Durad

^

If shift off of the topology, MPI_Proc_null is returned

direction

dimension in which the shift should be made

disp

length of the shift in processor coordinates (+ or -)

rank_source

where calling process should receive a message from during theshift

rank_dest

where calling process should send a message to during the shift

Example using FORTRAN

cartshift.f

Groups and Communicators

^

How to partition a group of processes into sub-groups?

^

Group by color (different communicators).

^

Sort by key (new ranks in the sub-groups)

Dr. Hanif Durad

10a-MVP06-slides.pdf

Example using C (1/2)

#include <stdio.h>#include "mpi.h"#include <math.h>main(int argc, char* argv[]) {int

p; int^

my_rank; MPI_Comm my_row_comm;int^

my_row; int^

q; int^

test; int^

my_rank_in_row; MPI_Init(&argc, &argv);MPI_Comm_size(MPI_COMM_WORLD, &p);MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);q = (int) sqrt((double) p);

comm_split.c

Try different nodes?

Pacheco

Example using C (2/2)

q = (int) sqrt((double) p);/* my_rank is rank in MPI_COMM_WORLD.* q*q = p /my_row = my_rank/q;MPI_Comm_split(MPI_COMM_WORLD, my_row, my_rank,&my_row_comm);/ Test the new communicators /MPI_Comm_rank(my_row_comm, &my_rank_in_row);if (my_rank_in_row == 0)test = my_row;elsetest = 0;MPI_Bcast(&test, 1, MPI_INT, 0, my_row_comm);printf("Process %d > my_row = %d, my_rank_in_row = %d, test = %d\n",my_rank, my_row, my_rank_in_row, test);MPI_Finalize();} / main */