| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "guseva_a_hypercube/mpi/include/ops_mpi.hpp" | ||
| 2 | |||
| 3 | #include <mpi.h> | ||
| 4 | |||
| 5 | #include <algorithm> | ||
| 6 | #include <guseva_a_hypercube/mpi/include/hypercube.hpp> | ||
| 7 | |||
| 8 | #include "guseva_a_hypercube/common/include/common.hpp" | ||
| 9 | |||
| 10 | namespace guseva_a_hypercube { | ||
| 11 | |||
| 12 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
16 | GusevaAHypercubeMine::GusevaAHypercubeMine(const InType &in) { |
| 13 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 14 | GetInput() = in; | ||
| 15 | GetOutput(); | ||
| 16 | 16 | } | |
| 17 | |||
| 18 | 16 | bool GusevaAHypercubeMine::ValidationImpl() { | |
| 19 | 16 | return std::get<0>(GetInput()) < std::get<1>(GetInput()); | |
| 20 | } | ||
| 21 | |||
| 22 | 16 | bool GusevaAHypercubeMine::PreProcessingImpl() { | |
| 23 | 16 | return true; | |
| 24 | } | ||
| 25 | |||
| 26 | 16 | bool GusevaAHypercubeMine::RunImpl() { | |
| 27 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
32 | hypercube_handler_ = Hypercube::Create(); |
| 28 | const auto &[a, b, func, unused] = GetInput(); | ||
| 29 | |||
| 30 |
1/2✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
|
16 | if (hypercube_handler_) { |
| 31 |
1/2✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
|
16 | const auto &rank = hypercube_handler_->GetRank(); |
| 32 | const auto &size = hypercube_handler_->GetSize(); | ||
| 33 | |||
| 34 | 16 | const auto &length = b - a + 1; | |
| 35 | 16 | const auto &base = length / size; | |
| 36 | 16 | const auto &remainder = length % size; | |
| 37 |
1/2✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
|
16 | const auto &offset = (rank * base) + std::min(rank, remainder); |
| 38 |
1/2✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
|
16 | const auto &local_size = base + (rank < remainder ? 1 : 0); |
| 39 | |||
| 40 | 16 | const auto &local_start = a + offset; | |
| 41 | 16 | const auto &local_end = local_start + local_size; | |
| 42 | |||
| 43 | double local_result = 0; | ||
| 44 | |||
| 45 |
2/2✓ Branch 0 taken 8000 times.
✓ Branch 1 taken 16 times.
|
8016 | for (int xx = local_start; xx < local_end; xx++) { |
| 46 | 8000 | local_result += func(xx); | |
| 47 | } | ||
| 48 | |||
| 49 | 16 | double result = 0; | |
| 50 | |||
| 51 | 16 | hypercube_handler_->ReduceSum(local_result, MPI_DOUBLE, result); | |
| 52 | 16 | GetOutput() = result; | |
| 53 | } | ||
| 54 | |||
| 55 | 16 | MPI_Bcast(&GetOutput(), 1, MPI_DOUBLE, 0, MPI_COMM_WORLD); | |
| 56 | 16 | return true; | |
| 57 | } | ||
| 58 | |||
| 59 | 16 | bool GusevaAHypercubeMine::PostProcessingImpl() { | |
| 60 | 16 | return true; | |
| 61 | } | ||
| 62 | |||
| 63 | } // namespace guseva_a_hypercube | ||
| 64 |