#include #include #include #include #include int main(int argc, char** argv) { MPI_Init(&argc, &argv); int nof_processes; MPI_Comm_size(MPI_COMM_WORLD, &nof_processes); int rank; MPI_Comm_rank(MPI_COMM_WORLD, &rank); using namespace hpc::matvec; using namespace hpc::mpi; using namespace hpc::aux; using Matrix = GeMatrix; int share = 3; int num_rows = nof_processes * share + 1; int num_cols = 5; Matrix A(num_rows, num_cols); /* entire matrix */ MPI_Datatype rowtype_A = get_row_type(A); UniformSlices slices(nof_processes, num_rows); Matrix B(slices.size(rank), num_cols, Order::RowMajor); /* individual share */ MPI_Datatype rowtype_B = get_row_type(B); if (rank == 0) { for (auto [i, j, Aij]: A) { Aij = i * 100 + j; } } scatter_by_row(A, B, 0, MPI_COMM_WORLD); for (auto [i, j, Bij]: B) { Bij += 10000 * (rank + 1); (void) i; (void) j; // suppress gcc warning } gather_by_row(B, A, 0, MPI_COMM_WORLD); MPI_Finalize(); if (rank == 0) { print(A, " %6g"); } }