=============== Sample solution [TOC] =============== This solution works with additional template functions in `hpc/mpi/matrix.hpp` that support scatter and gather operations for matrices. These are one-to-many communications where a master distributes partitions of a matrix to other processes (scatter) and where the other processes send back their updated partitions which are sent back to the master process and merged (gather). MPI supports following operations: ---- CODE (type=cpp) ---------------------------------------------------------- int MPI_Scatterv(const void* sendbuf, int* sendcounts, int* displs, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm); int MPI_Gatherv(const void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int* recvcounts, int* displs, MPI_Datatype recvtype, int root, MPI_Comm comm); ------------------------------------------------------------------------------- There exists also operations `MPI_Scatter` and `MPI_Gather` which unfortunately do not support cases where slices can differ in their extents. These two operations are wrapped into `scatter_by_row` and `gather_by_row`: ---- CODE (type=cpp) ---------------------------------------------------------- template typename MA, template typename MB, Require>> = true, Require>> = true> int scatter_by_row(const MA& A, MB& B, int root, MPI_Comm comm) { /* ... */ } template typename MA, template typename MB, Require>> = true, Require>> = true> int gather_by_row(const MA& A, MB& B, int root, MPI_Comm comm) { /* ... */ } ------------------------------------------------------------------------------- We will see more about this communication pattern in the next session. :import:session06/jacobi.cpp :import:session06/step03/hpc/mpi/matrix.hpp :navigate: up -> doc:index back -> doc:session06/page07