| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "kurpiakov_a_elem_vec_sum/mpi/include/ops_mpi.hpp" | ||
| 2 | |||
| 3 | #include <mpi.h> | ||
| 4 | |||
| 5 | #include <cmath> | ||
| 6 | #include <utility> | ||
| 7 | #include <vector> | ||
| 8 | |||
| 9 | #include "kurpiakov_a_elem_vec_sum/common/include/common.hpp" | ||
| 10 | |||
| 11 | namespace kurpiakov_a_elem_vec_sum { | ||
| 12 | |||
| 13 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
20 | KurpiakovAElemVecSumMPI::KurpiakovAElemVecSumMPI(const InType &in) { |
| 14 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 15 | GetInput() = in; | ||
| 16 | 20 | GetOutput() = 0; | |
| 17 | 20 | } | |
| 18 | |||
| 19 | 20 | bool KurpiakovAElemVecSumMPI::ValidationImpl() { | |
| 20 |
2/4✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 20 times.
|
20 | bool res = (GetOutput() == 0) && (std::cmp_equal((std::get<1>(GetInput()).size()), std::get<0>(GetInput()))); |
| 21 | 20 | return res; | |
| 22 | } | ||
| 23 | |||
| 24 | 20 | bool KurpiakovAElemVecSumMPI::PreProcessingImpl() { | |
| 25 | 20 | GetOutput() = 0; | |
| 26 | 20 | return true; | |
| 27 | } | ||
| 28 | |||
| 29 | 20 | bool KurpiakovAElemVecSumMPI::RunImpl() { | |
| 30 | 20 | int rank = 0; | |
| 31 | 20 | int size = 0; | |
| 32 | 20 | MPI_Comm_rank(MPI_COMM_WORLD, &rank); | |
| 33 | 20 | MPI_Comm_size(MPI_COMM_WORLD, &size); | |
| 34 | |||
| 35 | 20 | int total_size = 0; | |
| 36 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
|
20 | if (rank == 0) { |
| 37 | 10 | total_size = std::get<0>(GetInput()); | |
| 38 | } | ||
| 39 | |||
| 40 | 20 | MPI_Bcast(&total_size, 1, MPI_INT, 0, MPI_COMM_WORLD); | |
| 41 | |||
| 42 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 16 times.
|
20 | if (total_size == 0) { |
| 43 | 4 | GetOutput() = 0LL; | |
| 44 | 4 | return true; | |
| 45 | } | ||
| 46 | |||
| 47 | 16 | std::vector<int> batch(size); | |
| 48 |
1/4✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
16 | std::vector<int> displs(size); |
| 49 | 16 | int batch_size = total_size / size; | |
| 50 | 16 | int remainder = total_size % size; | |
| 51 |
2/2✓ Branch 0 taken 32 times.
✓ Branch 1 taken 16 times.
|
48 | for (int i = 0; i < size; ++i) { |
| 52 |
4/4✓ Branch 0 taken 22 times.
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 16 times.
✓ Branch 3 taken 16 times.
|
54 | batch[i] = batch_size + (i < remainder ? 1 : 0); |
| 53 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 16 times.
|
32 | displs[i] = (i == 0) ? 0 : displs[i - 1] + batch[i - 1]; |
| 54 | } | ||
| 55 | |||
| 56 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
16 | int local_size = batch[rank]; |
| 57 |
1/4✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
16 | std::vector<int> local_data(local_size); |
| 58 | |||
| 59 | int *sendbuf = nullptr; | ||
| 60 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 8 times.
|
16 | if (rank == 0) { |
| 61 | sendbuf = const_cast<int *>(std::get<1>(GetInput()).data()); | ||
| 62 | } | ||
| 63 | |||
| 64 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
16 | MPI_Scatterv(sendbuf, batch.data(), displs.data(), MPI_INT, local_data.data(), local_size, MPI_INT, 0, |
| 65 | MPI_COMM_WORLD); | ||
| 66 | |||
| 67 | 16 | OutType local_sum = 0LL; | |
| 68 |
2/2✓ Branch 0 taken 21 times.
✓ Branch 1 taken 16 times.
|
37 | for (int i = 0; i < local_size; ++i) { |
| 69 | 21 | local_sum += static_cast<OutType>(local_data[i]); | |
| 70 | } | ||
| 71 | |||
| 72 | 16 | OutType global_sum = 0LL; | |
| 73 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
16 | MPI_Reduce(&local_sum, &global_sum, 1, MPI_LONG_LONG, MPI_SUM, 0, MPI_COMM_WORLD); |
| 74 | |||
| 75 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
16 | MPI_Bcast(&global_sum, 1, MPI_LONG_LONG, 0, MPI_COMM_WORLD); |
| 76 | |||
| 77 | 16 | GetOutput() = global_sum; | |
| 78 | |||
| 79 |
1/2✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
|
16 | MPI_Barrier(MPI_COMM_WORLD); |
| 80 | |||
| 81 | return true; | ||
| 82 | } | ||
| 83 | |||
| 84 | 20 | bool KurpiakovAElemVecSumMPI::PostProcessingImpl() { | |
| 85 | 20 | return true; | |
| 86 | } | ||
| 87 | |||
| 88 | } // namespace kurpiakov_a_elem_vec_sum | ||
| 89 |