MPI basics Flashcards
initialize
int MPI_Init(int* argc, char*** argv);
MPI_Init(&argc, &argv);
call as soon as possible
finalize
int MPI_Finalize(void);
MPI_Finalize();
releases resources
communicators basics
MPI_COMM_WORLD
MPI_COMM_SELF: only you
- any communciation is done in the conte4xt of a comm
- no communciatorion across comms
get size
int MPI_Comm_size(MPI_Comm comm, int* size);
MPI_Comm_size(MPI_COMM_WORLD, &comm_size);
get the total n of processes
get rank
int MPI_Comm_rank(MPI_Comm comm,int* rank);
MPI_Comm_rank(MPI_COMM_WORLD, &comm_rank);
own rank
basic send
int MPI_Send(const void* buffer,
int count,
MPI_Datatype datatype,
int recipient,
int tag,
MPI_Comm communicator);
MPI_Send(&buffer_sent, 1, MPI_INT, RECEIVER, 0, MPI_COMM_WORLD);
basic receive
int MPI_Recv(void* buffer,
int count,
MPI_Datatype datatype,
int sender,
int tag,
MPI_Comm communicator,
MPI_Status* status);
MPI_Recv(&received, 1, MPI_INT, SENDER, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
match
send and recv must match
- tag
- source
however you can also use MPI_ANY_TAG and MPI_ANY_SOURCE
also messages in same channel signature (source, dest, tag, comm) are ordered!!
status
status of a reception operation
MPI_SOURCE
MPI_TAG
MPI_ERROR
what is blocking and non blocking
bl can reuse buffer
nonbl cannot
send variants
Bsend: buffered
pro cannot deadlock, con must allocate buffer of excat size
Ssend sych
pro sure it has received, con costly an extra sync
Rsend ready
bypasses the recv Q since receive has been posted
pro fast, con must be sure its there
probe
int MPI_Probe(int source,
int tag,
MPI_Comm communicator,
MPI_Status* status);
blocks until a matching msg is found
useful to know how to receive it, buffer size
or to check UMQ for wildcard receives
int MPI_Iprobe(int source,
int tag,
MPI_Comm communicator,
int* flag,
MPI_Status* status);
also non blocking version
eager vs rendevouz protocol
eager
- sends directly
- good for low short messages
- but many copies
- low overhead
rendevouz
- extra handshake
- first sends envelope
- when receives the clear to send with address it copies data directly into receiver
cross over point: switches protocol
send receive
int MPI_Sendrecv(const void* buffer_send,
int count_send,
MPI_Datatype datatype_send,
int recipient,
int tag_send,
void* buffer_recv,
int count_recv,
MPI_Datatype datatype_recv,
int sender,
int tag_recv,
MPI_Comm communicator,
MPI_Status* status);
does bothso no deadlock
also the MPI_Sendrecv_replace
nonblockign send
int MPI_Isend(const void* buffer,
int count,
MPI_Datatype datatype,
int recipient,
int tag,
MPI_Comm communicator,
MPI_Request* request);
MPI_Request request; MPI_Isend(&buffer_sent, 1, MPI_INT, 1, 0, MPI_COMM_WORLD, &request);