Lösungsvorschlag

template<typename Matrix>
void exchange_with_neighbors(Matrix& A,
      /* ranks of the neighbors */
      int previous, int next,
      /* data type for an inner row, i.e. without the border */
      MPI_Datatype rowtype) {
   MPI_Request requests[4]; int request_index = 0;
   MPI_Irecv(&A(0, 1), 1, rowtype, previous, 0,
      MPI_COMM_WORLD, &requests[request_index++]);
   MPI_Irecv(&A(A.numRows-1, 1), 1, rowtype, next, 0,
      MPI_COMM_WORLD, &requests[request_index++]);
   MPI_Isend(&A(1, 1), 1, rowtype, previous, 0,
      MPI_COMM_WORLD, &requests[request_index++]);
   MPI_Isend(&A(A.numRows-2, 1), 1, rowtype, next, 0,
      MPI_COMM_WORLD, &requests[request_index++]);

   for (auto& request: requests) {
      MPI_Status status;
      MPI_Wait(&request, &status);
   }
}
$shell> mpic++ -g -O3 -std=c++11 \
>    -I. -I/home/numerik/pub/hpc/session22 \
>    $(pkg-config --cflags gdk-pixbuf-2.0) \
>    -o jacobi jacobi.cpp $(pkg-config --libs gdk-pixbuf-2.0)
$shell> mpic++ -g -O3 -std=c++11 \
>    -I. -I/home/numerik/pub/hpc/session22 \
>    $(pkg-config --cflags gdk-pixbuf-2.0) \
>    -o jacobi-nb jacobi-nb.cpp $(pkg-config --libs gdk-pixbuf-2.0)
$shell> time mpirun -np 4 jacobi
5090 iterations

real	0m0.629s
user	0m2.028s
sys	0m0.115s
$shell> time mpirun -np 4 jacobi-nb
5090 iterations

real	0m0.662s
user	0m2.095s
sys	0m0.123s
$shell>