Show Menu
Cheatography

Parallel Cheat Sheet by

A cheat sheet for Introduction to algorithms and parallel computing course.

MPI (Basic)

Setup and Tear Down

void main(int argc, char *argv)
starts up the MPI runtime enviro­nment at the beginning of a run.
MPI_Fi­nal­ize()
shuts down the MPI runtime enviro­nment at the end of a run.

Gathering Inform­ation

MPI_Co­mm_­ran­k(M­PI_­COM­M_W­ORL­D,&myid)
gets the process ID that the current process uses, which is between 0 and Np-1 inclusive.
MPI_Co­mm_­siz­e(M­PI_­COM­M_W­ORL­D,&nu­mprocs)
gets the number of processes in a run.

MPI Data Types

MPI_CHAR
char
MPI_SHORT
short int
MPI_INT
int
MPI_FLOAT
float
MPI_DOUBLE
double
MPI_LO­NG_­DOUBLE
long double
MPI_BYTE
consists of a byte (8 binary digits)

Compile

mpicc -o file file.c
compiles MPI programs written in C.
mpiCC -o file file.cpp
compiles MPI programs written in C++.

Run

mpirun -np no_pro­cessors file
run MPI compiled file with no_pro­cessors

Time

MPI_Wt­ime()
Returns an elapsed time on the calling processor

int MPI_Bcast ( *b, c,d, root,M­PI_Comm )

b
The message to be broadc­asted
c
Number of elements in the message
d
The data type of the elements in the message
root
The process number that has the message to be broadc­asted to others
MPI_Comm
The commun­­ic­ation world

MPI_Recv( *b, c, d, sender, t, MPI_Comm, status)

b
Receive in buffer b
c
The number of element of data type d
d
The data type of element b
sender
The rank of the sender
t
The tag used in the commun­ication
MPI_Comm
The commun­ication world
status
the status of the reception operation

int MPI_Sc­att­er(­sb­,sc­,sd­,r­b,r­c,r­d,r­oot­,MP­I_Comm)

sb
The buffer containing the data to disptach from the root process.
sc
The number of elements to send to each process, not the total number of elements in the send buffer.
sd
The type of one send buffer element
rb
The buffer in which store the data dispat­ched.
rc
The number of elements in the receive buffer
rd
The type of one receive buffer element.
root
The rank of the root process
MPI_Comm
The commun­­­­­i­c­­ation world

Libraries

<mp­i.h>
For MPI implem­ent­ation
<st­dio.h>
C input&output
<ma­th.h­>
Handles Math
 

Terms

Blocking
return after their actions complete
Non-Bl­ocking
return immedi­ately.
Message Tag
carried within message and used to differ­entiate between different types of messages being sent
MPI_Status
represents the status of a reception operation.

MPI Point-­to-­Point Commun­ication

MPI_Send()
sends a message from the current process to some other process.
MPI_Recv()
receives a message on the current process from some other process.

Collective Commun­ication

MPI_Bc­ast()
Broadcast from root to all other processes
MPI_Ga­ther()
Gather values for group of processes
MPI_Sc­atter()
Scatters buffer in parts to group of processes
MPI_Al­lto­all()
Sends data from all processes to all processes
MPI_Re­duce()
Combine values on all processes to single value
MPI_Re­duc­e_s­cat­ter()
Combine values and scatter results

MPI Nonblo­cking Routines

MPI_Is­end()
Non-bl­ocking send; will return “immed­iately”
MPI_Ir­ecv()
Nonblo­cking receive; will return even if no message to accept.
MPI_Wait(request,status)
waits until operation completed and returns then.
MPI_Test()
returns with flag set indicating whether operation completed at that time.

MPI (Detailed)

MPI_Se­nd(*d, c, m, receiver, t, MPI_Comm)

d
Send Data from address d
c
The number of elements of d
m
The Datatype of d
receiver
The rank of the reciever
t
The commun­ication is marked with t tag
MPI_Co­mm_­World
The commun­ication world

int MPI_Ga­the­r(s­b,s­c,s­d,r­b,r­c,r­d,r­oot­,MP­I_Comm)

sb
The sender buffer
sc
The number of elements in the buffer
sd
The datatype of one element in the buffer
rb
The buffer in which store the gathered data for the root process
rc
The number of elements per message received, not the total number of elements to receive from all processes altoge­ther.
rd
The type of one receive buffer element.
root
MPI_Comm
The commun­­­i­c­ation world

int MPI_Re­duc­e(­sb,­rb­,c,­d,o­p,r­oot­,MP­I_C­omm);

sb
A pointer on the buffer to send for reduction.
rb
A pointer on the buffer in which store the result of the reduction
c
The number of elements in the send buffer
d
The type of a buffer element.
op
The operation to apply to combine messages received in the reduction
root
The rank of the MPI process that will collect the reduction result.
MPI_Comm
The commun­­­­­i­c­­ation world
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.