#include #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); assert(nof_processes == 2); using namespace hpc::matvec; using namespace hpc::mpi; using namespace hpc::aux; unsigned int nof_rows = 3; unsigned int nof_cols = 7; if (rank == 0) { GeMatrix A(nof_rows, nof_cols, StorageOrder::RowMajor); using Index = GeMatrix::Index; apply(A, [](double& val, Index i, Index j) -> void { val = i * 100 + j; }); auto row = A.row(2); auto col = A.col(0); MPI_Send(/* row to rank 1 */); MPI_Send(/* col to rank 1 */); /* receive it back for verification */ DenseVector vec1(nof_cols), vec2(nof_rows); MPI_Status status; MPI_Recv(/* vec1 from rank 1 */); MPI_Recv(/* vec2 from rank 1 */); /* verify it */ apply(vec1, [=](double& val, Index i) { if (val != row(i)) { printf("verification failed for row(%d): %lg vs %lg\n", (int)i, val, row(i)); } }); apply(vec2, [=](double& val, Index i) { if (val != col(i)) { printf("verification failed for col(%d): %lg vs %lg\n", (int)i, val, col(i)); } }); } else { DenseVector vec1(nof_cols), vec2(nof_rows); MPI_Status status; MPI_Recv(/* vec1 from rank 0 */); MPI_Recv(/* vec2 from rank 0 */); /* send it back for verification */ MPI_Send(/* vec1 to rank 0 */); MPI_Send(/* vec2 to rank 0 */); } MPI_Finalize(); }