| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "romanova_v_linear_histogram_stretch/all/include/ops_all.hpp" | ||
| 2 | |||
| 3 | #include <mpi.h> | ||
| 4 | |||
| 5 | #include <algorithm> | ||
| 6 | #include <cstddef> | ||
| 7 | #include <cstdint> | ||
| 8 | #include <utility> | ||
| 9 | #include <vector> | ||
| 10 | |||
| 11 | #include "romanova_v_linear_histogram_stretch/common/include/common.hpp" | ||
| 12 | |||
| 13 | namespace romanova_v_linear_histogram_stretch_threads { | ||
| 14 | |||
| 15 |
1/2✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
|
12 | RomanovaVLinHistogramStretchALL::RomanovaVLinHistogramStretchALL(const InType &in) { |
| 16 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 17 |
1/2✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
|
12 | GetInput() = in; |
| 18 | GetOutput().clear(); | ||
| 19 | 12 | } | |
| 20 | |||
| 21 | 12 | bool RomanovaVLinHistogramStretchALL::ValidationImpl() { | |
| 22 | 12 | bool status = true; | |
| 23 | 12 | int rank = 0; | |
| 24 | 12 | MPI_Comm_rank(MPI_COMM_WORLD, &rank); | |
| 25 | |||
| 26 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
|
12 | if (rank == 0) { |
| 27 | 6 | status = !GetInput().empty(); | |
| 28 | } | ||
| 29 | |||
| 30 | 12 | MPI_Bcast(&status, 1, MPI_C_BOOL, 0, MPI_COMM_WORLD); | |
| 31 | 12 | return status; | |
| 32 | } | ||
| 33 | |||
| 34 | 12 | bool RomanovaVLinHistogramStretchALL::PreProcessingImpl() { | |
| 35 | 12 | int rank = 0; | |
| 36 | 12 | int n = 0; | |
| 37 | |||
| 38 | 12 | MPI_Comm_rank(MPI_COMM_WORLD, &rank); | |
| 39 | 12 | MPI_Comm_size(MPI_COMM_WORLD, &n); | |
| 40 | |||
| 41 | 12 | size_t size = 0; | |
| 42 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
|
12 | if (rank == 0) { |
| 43 | 6 | size = GetInput().size(); | |
| 44 | } | ||
| 45 | 12 | MPI_Bcast(&size, 1, MPI_UNSIGNED_LONG_LONG, 0, MPI_COMM_WORLD); | |
| 46 | 12 | GetOutput().resize(size); | |
| 47 | |||
| 48 | 12 | size_t delta = size / n; | |
| 49 | 12 | size_t extra = size % n; | |
| 50 | |||
| 51 |
1/2✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
|
12 | local_size_ = delta + (std::cmp_less(rank, extra) ? 1 : 0); |
| 52 | |||
| 53 | 12 | vector_counts_.resize(n); | |
| 54 | 12 | vector_displs_.resize(n); | |
| 55 | |||
| 56 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
|
12 | if (rank == 0) { |
| 57 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
|
18 | for (int i = 0; i < n; i++) { |
| 58 | 12 | vector_counts_[i] = static_cast<int>(delta + (std::cmp_less(i, extra) ? 1 : 0)); | |
| 59 | } | ||
| 60 | |||
| 61 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
|
12 | for (int i = 1; i < n; i++) { |
| 62 | 6 | vector_displs_[i] = vector_displs_[i - 1] + vector_counts_[i - 1]; | |
| 63 | } | ||
| 64 | } | ||
| 65 | |||
| 66 | 12 | MPI_Bcast(vector_counts_.data(), n, MPI_INT, 0, MPI_COMM_WORLD); | |
| 67 | 12 | MPI_Bcast(vector_displs_.data(), n, MPI_INT, 0, MPI_COMM_WORLD); | |
| 68 | |||
| 69 | 12 | local_data_.resize(local_size_); | |
| 70 | |||
| 71 | 12 | MPI_Scatterv(rank == 0 ? GetInput().data() : nullptr, vector_counts_.data(), vector_displs_.data(), MPI_UNSIGNED_CHAR, | |
| 72 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
|
12 | local_data_.data(), static_cast<int>(local_size_), MPI_UNSIGNED_CHAR, 0, MPI_COMM_WORLD); |
| 73 | |||
| 74 | 12 | local_out_ = OutType(local_size_); | |
| 75 | 12 | return !GetOutput().empty(); | |
| 76 | } | ||
| 77 | |||
| 78 | 12 | bool RomanovaVLinHistogramStretchALL::RunImpl() { | |
| 79 | 12 | uint8_t loc_min_v = 255; | |
| 80 | 12 | uint8_t loc_max_v = 0; | |
| 81 | |||
| 82 | 12 | #pragma omp parallel for default(none) /*shared(local_data_, local_size_)*/ reduction(min : loc_min_v) \ | |
| 83 | reduction(max : loc_max_v) | ||
| 84 | for (size_t i = 0; i < local_size_; i++) { | ||
| 85 | loc_min_v = std::min(loc_min_v, local_data_[i]); | ||
| 86 | loc_max_v = std::max(loc_max_v, local_data_[i]); | ||
| 87 | } | ||
| 88 | |||
| 89 | 12 | uint8_t min_v = 255; | |
| 90 | 12 | uint8_t max_v = 0; | |
| 91 | |||
| 92 | 12 | MPI_Allreduce(static_cast<void *>(&loc_min_v), static_cast<void *>(&min_v), 1, MPI_UNSIGNED_CHAR, MPI_MIN, | |
| 93 | MPI_COMM_WORLD); | ||
| 94 | 12 | MPI_Allreduce(static_cast<void *>(&loc_max_v), static_cast<void *>(&max_v), 1, MPI_UNSIGNED_CHAR, MPI_MAX, | |
| 95 | MPI_COMM_WORLD); | ||
| 96 | |||
| 97 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 8 times.
|
12 | if (min_v == max_v) { |
| 98 | 4 | #pragma omp parallel for default(none) // shared(local_out_, local_data_, local_size_) | |
| 99 | for (size_t i = 0; i < local_size_; i++) { | ||
| 100 | local_out_[i] = local_data_[i]; | ||
| 101 | } | ||
| 102 | 4 | return true; | |
| 103 | } | ||
| 104 | |||
| 105 | 8 | const uint8_t diff = max_v - min_v; | |
| 106 | 8 | const double ratio = 255.0 / diff; | |
| 107 | |||
| 108 | 8 | #pragma omp parallel for default(none) shared(min_v, ratio) | |
| 109 | for (size_t i = 0; i < local_size_; i++) { | ||
| 110 | uint8_t pix = local_data_[i]; | ||
| 111 | local_out_[i] = (std::clamp(static_cast<int>((pix - min_v) * ratio), 0, 255)); | ||
| 112 | } | ||
| 113 | |||
| 114 | 8 | return true; | |
| 115 | } | ||
| 116 | |||
| 117 | 12 | bool RomanovaVLinHistogramStretchALL::PostProcessingImpl() { | |
| 118 | 12 | MPI_Allgatherv(local_out_.data(), static_cast<int>(local_size_), MPI_UNSIGNED_CHAR, GetOutput().data(), | |
| 119 | vector_counts_.data(), vector_displs_.data(), MPI_UNSIGNED_CHAR, MPI_COMM_WORLD); | ||
| 120 | 12 | return true; | |
| 121 | } | ||
| 122 | |||
| 123 | } // namespace romanova_v_linear_histogram_stretch_threads | ||
| 124 |