



























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This lecture is related to Message Passing Interface Library concepts. its helpful for Parallel Computing students. It was delivered by Dr. Hanif Durad at Pakistan Institute of Engineering and Applied Sciences, Islamabad (PIEAS). It includes: Virtual, Topologies, Cartesian, Mapping, Functions, Partitioning, Rationale, Graph, Boundaries, Cyclic
Typology: Slides
1 / 35
This page cannot be seen from the preview
Don't miss anything!




























^
^
^
^
^
^
^
^
^
^
^
^
^
^
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);
^
^
INTEGER COMM,RANK,MAXDIMS,COORDS(*),IERROR CALLMPI_CART_COORDS(COMM,RANK,MAXDIMS,COORDS,IERROR)
#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();}^
^
^
INTEGERCOMM,DIRECTION,DISP,RANK_SOURCE,RANK_DEST,IERROR CALLMPI_CART_SHIFT(COMM,DIRECTION,DISP,RANK_SOURCE,RANK_DEST,IERROR
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
^
^
^
#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);
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 */