| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "dorogin_v_contrast_enhancement/mpi/include/ops_mpi.hpp" | ||
| 2 | |||
| 3 | #include <mpi.h> | ||
| 4 | |||
| 5 | #include <algorithm> | ||
| 6 | #include <cstdint> | ||
| 7 | #include <vector> | ||
| 8 | |||
| 9 | #include "dorogin_v_contrast_enhancement/common/include/common.hpp" | ||
| 10 | |||
| 11 | namespace dorogin_v_contrast_enhancement { | ||
| 12 | |||
| 13 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
20 | DoroginVContrastEnhancementMPI::DoroginVContrastEnhancementMPI(const InType &in) { |
| 14 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 15 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
20 | GetInput() = in; |
| 16 | GetOutput() = {}; | ||
| 17 | 20 | } | |
| 18 | |||
| 19 | 20 | bool DoroginVContrastEnhancementMPI::ValidationImpl() { | |
| 20 | 20 | MPI_Comm_rank(MPI_COMM_WORLD, &world_rank_); | |
| 21 | 20 | MPI_Comm_size(MPI_COMM_WORLD, &world_size_); | |
| 22 | |||
| 23 | 20 | int valid_flag = 0; | |
| 24 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
|
20 | if (world_rank_ == 0) { |
| 25 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 | valid_flag = !GetInput().empty() ? 1 : 0; |
| 26 | } | ||
| 27 | |||
| 28 | 20 | MPI_Bcast(&valid_flag, 1, MPI_INT, 0, MPI_COMM_WORLD); | |
| 29 | 20 | return valid_flag == 1; | |
| 30 | } | ||
| 31 | |||
| 32 | 20 | bool DoroginVContrastEnhancementMPI::PreProcessingImpl() { | |
| 33 | 20 | MPI_Comm_rank(MPI_COMM_WORLD, &world_rank_); | |
| 34 | 20 | MPI_Comm_size(MPI_COMM_WORLD, &world_size_); | |
| 35 | |||
| 36 | 20 | int global_size = 0; | |
| 37 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
|
20 | if (world_rank_ == 0) { |
| 38 | 10 | image_ = GetInput(); | |
| 39 | 10 | global_size = static_cast<int>(image_.size()); | |
| 40 | } | ||
| 41 | |||
| 42 | 20 | MPI_Bcast(&global_size, 1, MPI_INT, 0, MPI_COMM_WORLD); | |
| 43 | |||
| 44 | 20 | std::vector<int> counts(world_size_, 0); | |
| 45 |
1/4✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
20 | std::vector<int> displs(world_size_, 0); |
| 46 | |||
| 47 | 20 | int base = global_size / world_size_; | |
| 48 | 20 | int rem = global_size % world_size_; | |
| 49 |
2/2✓ Branch 0 taken 40 times.
✓ Branch 1 taken 20 times.
|
60 | for (int i = 0; i < world_size_; ++i) { |
| 50 |
2/2✓ Branch 0 taken 38 times.
✓ Branch 1 taken 2 times.
|
78 | counts[i] = base + (i < rem ? 1 : 0); |
| 51 | } | ||
| 52 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 20 times.
|
40 | for (int i = 1; i < world_size_; ++i) { |
| 53 | 20 | displs[i] = displs[i - 1] + counts[i - 1]; | |
| 54 | } | ||
| 55 | |||
| 56 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
20 | local_size_ = counts[world_rank_]; |
| 57 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
20 | local_image_.resize(local_size_); |
| 58 | |||
| 59 |
3/4✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
✓ Branch 3 taken 20 times.
✗ Branch 4 not taken.
|
30 | MPI_Scatterv(world_rank_ == 0 ? image_.data() : nullptr, counts.data(), displs.data(), MPI_UNSIGNED_CHAR, |
| 60 | local_image_.data(), local_size_, MPI_UNSIGNED_CHAR, 0, MPI_COMM_WORLD); | ||
| 61 | |||
| 62 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
20 | result_.resize(global_size); |
| 63 | |||
| 64 | 20 | return true; | |
| 65 | } | ||
| 66 | |||
| 67 | 20 | bool DoroginVContrastEnhancementMPI::RunImpl() { | |
| 68 | 20 | unsigned char local_min = 255; | |
| 69 | 20 | unsigned char local_max = 0; | |
| 70 | |||
| 71 |
2/2✓ Branch 0 taken 19 times.
✓ Branch 1 taken 1 times.
|
20 | if (local_size_ > 0) { |
| 72 |
1/2✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
|
19 | local_min = *std::ranges::min_element(local_image_); |
| 73 | 19 | local_max = *std::ranges::max_element(local_image_); | |
| 74 | } | ||
| 75 | |||
| 76 | 20 | unsigned char global_min = 255; | |
| 77 | 20 | unsigned char global_max = 0; | |
| 78 | |||
| 79 | 20 | MPI_Allreduce(&local_min, &global_min, 1, MPI_UNSIGNED_CHAR, MPI_MIN, MPI_COMM_WORLD); | |
| 80 | 20 | MPI_Allreduce(&local_max, &global_max, 1, MPI_UNSIGNED_CHAR, MPI_MAX, MPI_COMM_WORLD); | |
| 81 | |||
| 82 | 20 | std::vector<uint8_t> local_result(local_size_); | |
| 83 | |||
| 84 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 16 times.
|
20 | if (global_min == global_max) { |
| 85 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | local_result = local_image_; |
| 86 | } else { | ||
| 87 | 16 | int range = global_max - global_min; | |
| 88 |
2/2✓ Branch 0 taken 1030 times.
✓ Branch 1 taken 16 times.
|
1046 | for (int i = 0; i < local_size_; ++i) { |
| 89 | 1030 | local_result[i] = static_cast<uint8_t>(((local_image_[i] - global_min) * 255) / range); | |
| 90 | } | ||
| 91 | } | ||
| 92 | |||
| 93 | 20 | int global_size = static_cast<int>(result_.size()); | |
| 94 | |||
| 95 |
1/4✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
20 | std::vector<int> counts(world_size_, 0); |
| 96 |
1/4✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
20 | std::vector<int> displs(world_size_, 0); |
| 97 | |||
| 98 | 20 | int base = global_size / world_size_; | |
| 99 | 20 | int rem = global_size % world_size_; | |
| 100 |
2/2✓ Branch 0 taken 40 times.
✓ Branch 1 taken 20 times.
|
60 | for (int i = 0; i < world_size_; ++i) { |
| 101 |
2/2✓ Branch 0 taken 38 times.
✓ Branch 1 taken 2 times.
|
78 | counts[i] = base + (i < rem ? 1 : 0); |
| 102 | } | ||
| 103 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 20 times.
|
40 | for (int i = 1; i < world_size_; ++i) { |
| 104 | 20 | displs[i] = displs[i - 1] + counts[i - 1]; | |
| 105 | } | ||
| 106 | |||
| 107 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
20 | MPI_Gatherv(local_result.data(), local_size_, MPI_UNSIGNED_CHAR, result_.data(), counts.data(), displs.data(), |
| 108 | MPI_UNSIGNED_CHAR, 0, MPI_COMM_WORLD); | ||
| 109 | |||
| 110 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
20 | MPI_Bcast(result_.data(), global_size, MPI_UNSIGNED_CHAR, 0, MPI_COMM_WORLD); |
| 111 | |||
| 112 | 20 | return true; | |
| 113 | } | ||
| 114 | |||
| 115 | 20 | bool DoroginVContrastEnhancementMPI::PostProcessingImpl() { | |
| 116 | 20 | GetOutput() = result_; | |
| 117 | 20 | return true; | |
| 118 | } | ||
| 119 | |||
| 120 | } // namespace dorogin_v_contrast_enhancement | ||
| 121 |