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