











































































Studirajte zahvaljujući brojnim resursima koji su dostupni na Docsity-u
Zaradite bodove pomažući drugim studentima ili ih kupite uz Premium plan
Ova stranica nije vidljiva u pregledu
Ne propustite važne delove!












































































MPI Interface
MPI was designed to be a standard implementation of the message-passing model of parallel computing
MPI itself is not a library
There are many implementations of MPI:
MPICH, MPICH2, OpenMPI(we will use this), LAM/MPI, HP/MPI
MPI header files contain the prototypes for:
functions/subroutines definitions of macros constants datatypes used by MPI
The names of all MPI entities (routines, constants, types,…) begin with MPI_
MPI_Xxxxx(parameter, ... )
Example:
MPI_Init(&argc, &argv) MPI_COMM_WORLD MPI_REAL
MPI allows automatic translation between its own datatypes and corresponding datatypes in C
As a general rule, the MPI datatype given in a receive must match the MPI datatype specified in the send Basic MPI Datatypes MPI_CHAR MPI_INT MPI_DOUBLE
Special MPI Datatypes MPI_COMM MPI_STATUS
The initialization routine MPI_INIT must be the first MPI routine called in any MPI program
MPI_INIT must be called by all processes
int err; ... err = MPI_Init(&argc, &argv);
Ranks are consecutive and start with 0
A given processor may have different ranks in the various communicators to which it belongs int MPI_Comm_rank(MPI_Comm comm, int *rank);
MPI_COMM - a communicator
A processor can determine the size : MPI_COMM_SIZE int MPI_Comm_size(MPI_Comm comm, int *size);
MPI_COMM, a communicator
*size - address of the integer variable size
If the communicator is MPI_COMM_WORLD, the number of processors returned from MPI_COMM_SIZE equals the number defined by: % mpirun -np 4 primer
#include "mpi.h" #include <stdio.h> int main(int argc, char *argv[]) { int id; int p; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &id); MPI_Comm_size(MPI_COMM_WORLD, &p); printf("Hello, world, from process %d\n", id); MPI_Finalize(); return 0; }
Point-to-point communication is the fundamental communication facility provided by the MPI library
Conceptually it is simple: one process sends a message another process receives it
It is not that simple
Crucial issue is what message to receive?
Another issue is whether send and receive routines initiate communication operations and return immediately (nonblocking), or wait for the initiated communication operation to complete before returning (blocking).
Messages consist of two parts: the envelope and the message body
The envelope of an MPI message has four parts: Source — the sending process Destination — the receiving process Communicator — specifies a group of processes to which both source and destination belong Tag — used to classify messages
The message body has three parts: Buffer — the message data Datatype — the type of the message data Count — the number of items of type datatype in buffer
The source (the identity of the sender) is determined implicitly
Envelope and body is given explicitly by the sending process
pending messages
Pending messages are not maintained in a simple FIFO queue
To receive a message, a process specifies a message envelope that MPI compares to the envelopes of pending messages
The receiving process must be careful to provide enough storage for the entire message
The message body contains the data to be sent: count items of type datatype int MPI_Send(void *buf, int count, MPI_Datatype dtype, int dest, int tag, MPI_Comm comm);
All arguments are input arguments
An error code is returned by the function
The arguments in the message envelope determine what messages can be received
The source , tag , and communicator arguments must match
If the received message has more data than the receiving process is prepared to accept, it is an error and the program will abort
If the sender and receiver use incompatible message datatypes, the results are undefined