MPI MPI – a first example Point-to-point communication Point-to ... - KTH

20 downloads 33 Views 307KB Size Report
A distributed vector. Assume that we have a one-dimensional grid distributed over n processes. Let y be defined on the g
2D1263 : Scientific Computing

Lecture 10

(1)

2D1263 : Scientific Computing

(2)

MPI – a first example

MPI

#include #include int main(int argc, char **argv) { int rank; int size;

All communication occurs within a communicator (MPI Comm), or group of processes, where each process has a unique identifier. The predefined communicator MPI COMM WORLD contains all processes.

MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &size); MPI_Comm_rank(MPI_COMM_WORLD, &rank);

Each process can determine its rank, and the size of a group it belongs to: MPI Comm rank(MPI Comm comm, int *rank);

cout