Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tasks/mpi/example/include/ops_mpi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ class TestTaskMPI : public ppc::core::Task {
private:
std::vector<int> input_, output_;
int rc_size_{};

void MultiplyMatrixBasedOnRank();
void MultiplyRowMajor();
void MultiplyColumnMajor();
};

} // namespace nesterov_a_test_task_mpi
42 changes: 28 additions & 14 deletions tasks/mpi/example/src/ops_mpi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,40 @@
}

bool nesterov_a_test_task_mpi::TestTaskMPI::RunImpl() {
MultiplyMatrixBasedOnRank();
return true;
}

void nesterov_a_test_task_mpi::TestTaskMPI::MultiplyMatrixBasedOnRank() {
int rank = -1;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);

auto multiply = [this](bool row_major) {
for (int i = 0; i < rc_size_; ++i) {
for (int j = 0; j < rc_size_; ++j) {
int sum = 0;
for (int k = 0; k < rc_size_; ++k) {
int a = input_[(row_major ? i : k) * rc_size_ + (row_major ? k : i)];
int b = input_[(row_major ? k : j) * rc_size_ + (row_major ? j : k)];
sum += a * b;
}
output_[(i * rc_size_) + j] += sum;
if (rank == 0) {
MultiplyRowMajor();
} else {
MultiplyColumnMajor();

Check warning on line 39 in tasks/mpi/example/src/ops_mpi.cpp

View check run for this annotation

Codecov / codecov/patch

tasks/mpi/example/src/ops_mpi.cpp#L39

Added line #L39 was not covered by tests
}
MPI_Barrier(MPI_COMM_WORLD);
}

void nesterov_a_test_task_mpi::TestTaskMPI::MultiplyRowMajor() {
for (int i = 0; i < rc_size_; ++i) {
for (int j = 0; j < rc_size_; ++j) {
for (int k = 0; k < rc_size_; ++k) {
output_[(i * rc_size_) + j] += input_[(i * rc_size_) + k] * input_[(k * rc_size_) + j];
}
}
};
}
}

multiply(rank == 0);
MPI_Barrier(MPI_COMM_WORLD);
return true;
void nesterov_a_test_task_mpi::TestTaskMPI::MultiplyColumnMajor() {

Check warning on line 54 in tasks/mpi/example/src/ops_mpi.cpp

View check run for this annotation

Codecov / codecov/patch

tasks/mpi/example/src/ops_mpi.cpp#L54

Added line #L54 was not covered by tests
for (int j = 0; j < rc_size_; ++j) {
for (int k = 0; k < rc_size_; ++k) {
for (int i = 0; i < rc_size_; ++i) {
output_[(i * rc_size_) + j] += input_[(i * rc_size_) + k] * input_[(k * rc_size_) + j];

Check warning on line 58 in tasks/mpi/example/src/ops_mpi.cpp

View check run for this annotation

Codecov / codecov/patch

tasks/mpi/example/src/ops_mpi.cpp#L58

Added line #L58 was not covered by tests
}
}
}
}

bool nesterov_a_test_task_mpi::TestTaskMPI::PostProcessingImpl() {
Expand Down
Loading