GCC Code Coverage Report


Directory: ./
File: tasks/ashihmin_d_sum_of_elem/mpi/src/ops_mpi.cpp
Date: 2026-01-10 02:40:41
Exec Total Coverage
Lines: 35 35 100.0%
Functions: 5 5 100.0%
Branches: 17 28 60.7%

Line Branch Exec Source
1 #include "ashihmin_d_sum_of_elem/mpi/include/ops_mpi.hpp"
2
3 #include <mpi.h>
4
5 #include <cstddef>
6 #include <vector>
7
8 #include "ashihmin_d_sum_of_elem/common/include/common.hpp"
9
10 namespace ashihmin_d_sum_of_elem {
11
12
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 AshihminDElemVecsSumMPI::AshihminDElemVecsSumMPI(const InType &in) {
13 SetTypeOfTask(GetStaticTypeOfTask());
14
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 GetInput() = in;
15 6 GetOutput() = 0;
16 6 }
17
18 6 bool AshihminDElemVecsSumMPI::ValidationImpl() {
19 6 return !GetInput().empty();
20 }
21
22 6 bool AshihminDElemVecsSumMPI::PreProcessingImpl() {
23 6 return true;
24 }
25
26 6 bool AshihminDElemVecsSumMPI::RunImpl() {
27 const auto &vec = GetInput();
28
29 6 int size = 0;
30 6 int rank = 0;
31 6 MPI_Comm_size(MPI_COMM_WORLD, &size);
32 6 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
33
34 6 std::vector<int> counts(size);
35
1/4
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
6 std::vector<int> displs(size);
36
37 size_t n = vec.size();
38 6 int base = static_cast<int>(n / size);
39 6 int rem = static_cast<int>(n % size);
40
41
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for (int i = 0; i < size; ++i) {
42
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 counts[i] = base;
43
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if (i < rem) {
44 6 counts[i]++;
45 }
46 }
47
48 6 displs[0] = 0;
49
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 for (int i = 1; i < size; ++i) {
50 6 displs[i] = displs[i - 1] + counts[i - 1];
51 }
52
53
1/4
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
6 std::vector<int> local(counts[rank]);
54
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 MPI_Scatterv(vec.data(), counts.data(), displs.data(), MPI_INT, local.data(), counts[rank], MPI_INT, 0,
55 MPI_COMM_WORLD);
56
57 6 OutType local_sum = 0;
58
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 6 times.
21 for (int x : local) {
59 15 local_sum += x;
60 }
61
62 6 OutType global_sum = 0;
63
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 MPI_Allreduce(&local_sum, &global_sum, 1, MPI_LONG_LONG, MPI_SUM, MPI_COMM_WORLD);
64
65
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 GetOutput() = global_sum;
66 6 return true;
67 }
68
69 6 bool AshihminDElemVecsSumMPI::PostProcessingImpl() {
70 6 return true;
71 }
72
73 } // namespace ashihmin_d_sum_of_elem
74