MPI Part2 Updated
MPI Part2 Updated
MPI Overview
MPI Communicators
MPI_COMM_WORLD: Name of default MPI Communicator
A communication universe (communication domain,
communication group) for a group of processes
Stored in variables of type MPI_COMM
Communicators are used as arguments to all message
transfer MPI routines
Each process within communicator has a rank; a unique
integer identifier ranging between [0, #processors − 1]
Multiple communicators can be established in a single MPI
program
Intra-Communicator: Used for communication within a
single group
Inter-Communicator: Used for communication between two
disjoint groups
Parallel & Distributed Systems
Distributed Memory Programming Model: MPI Communicators
MPI_COMM_WORLD
P2 COMM 2
COMM 1
COMM 4
P1
P0
COMM 3
P3
COMM 5
#include <stdio.h>
#include <mpi.h>
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
MPI_Finalize();
return 0 ;
}
mpicc hellompi.c # Compilation (mpiCC f o r C++, a l s o gcc h e llo mp i. c -lmpi )
mpirun -np 4 -h o s t f i l e filename a.out # Execution
Requirements
SSH Server
apt-get inst all openssh-server
OpenMPI Library
apt-get inst a l l openmpi-bin openmpi-doc
libopenmpi-dev
NFS Network File System
apt-get inst a l l nfs-server nfs-client
Transfering Files
Sending/Receiving
Approaches to Send/Receive
Non-Blocking Send/Receive
Return from Send/Receive operation before it is “safe” to return.
Programmer responsibility to ensure that “sending data” is not altered immediately
Blocking Operations: Safe and Easy Programming (at cost of overhead and risk of
deadlocks)
Non-Blocking Operations: Useful for Performance optimization, and breaking
deadlocks (but brings in plenty of race-conditions if programmer not careful)
The tag of the message (to distinguish between different types of messages)
Receiving
int MPI_Recv(void * b u ffe r , int count, MPI_DATATYPE datatype,
int source, int tag, MPI_Comm comm,
MPI_Status * s t a t u s );
one-to-all: sends data to all processes from one - uses Broadcast and Scatter
combining results: get results from every process and do something with it. -
uses Reduce
Communication Domains
A communicator object specifies a communication domain
which can be used for point-to-point communications.