From 47ed8076f91c39c6dd29d2616cbf0dd686d77ae8 Mon Sep 17 00:00:00 2001 From: Petteri Peltonen Date: Fri, 26 Jan 2024 09:56:56 +0200 Subject: [PATCH] added get_ to all getter functions of the distributed array class --- .../bits/communication/distributed_array.hpp | 50 +++++++++---------- test/test_communication.cpp | 30 +++++------ 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/include/bits/communication/distributed_array.hpp b/include/bits/communication/distributed_array.hpp index d8f14db..e03bc15 100644 --- a/include/bits/communication/distributed_array.hpp +++ b/include/bits/communication/distributed_array.hpp @@ -30,16 +30,16 @@ template struct DistributedArray { } const auto& topology() const { return m_topology; } - const auto& local_data() const { return m_data; } - auto& local_data() { return m_data; } + const auto& get_local_data() const { return m_data; } + auto& get_local_data() { return m_data; } - auto begin_padding() const { return m_begin_padding; } - auto end_padding() const { return m_end_padding; } + auto get_begin_padding() const { return m_begin_padding; } + auto get_end_padding() const { return m_end_padding; } - size_t local_subdomain_count() const { return m_data.size(); } + size_t get_local_subdomain_count() const { return m_data.size(); } // Note this does not in general equal to number of processes - size_t global_subdomain_count() const { + size_t get_global_subdomain_count() const { return m_topology.get_boxes().size(); } @@ -52,7 +52,7 @@ template struct DistributedArray { ///@return std::vector> A vector of box-rank pairs where the /// rank is always m_rank. /// - std::vector> local_boxes() const { + std::vector> get_local_boxes() const { return m_topology.get_boxes(m_rank); } @@ -74,7 +74,7 @@ template struct DistributedArray { template static inline size_t local_element_count(const DistributedArray& array) { - auto boxes = array.local_boxes(); + auto boxes = array.get_local_boxes(); size_t size = 0; for (auto box : boxes) { auto ext = box.get_extent(); @@ -107,7 +107,7 @@ template static inline size_t local_capacity(const DistributedArray& array) { size_t size = 0; - for (const auto& v : array.local_data()) { size += v.size(); } + for (const auto& v : array.get_local_data()) { size += v.size(); } return size; } @@ -122,11 +122,11 @@ auto make_subspans(const DistributedArray& array) { std::vector ret; - const auto& data = array.local_data(); - auto boxes = array.local_boxes(); + const auto& data = array.get_local_data(); + auto boxes = array.get_local_boxes(); - auto bpad = array.begin_padding(); - auto epad = array.end_padding(); + auto bpad = array.get_begin_padding(); + auto epad = array.get_end_padding(); for (size_t i = 0; i < data.size(); ++i) { @@ -154,11 +154,11 @@ template auto make_subspans(DistributedArray& array) { std::vector ret; - auto& data = array.local_data(); - auto boxes = array.local_boxes(); + auto& data = array.get_local_data(); + auto boxes = array.get_local_boxes(); - auto bpad = array.begin_padding(); - auto epad = array.end_padding(); + auto bpad = array.get_begin_padding(); + auto epad = array.get_end_padding(); for (size_t i = 0; i < data.size(); ++i) { @@ -191,7 +191,7 @@ serialize_local(const DistributedArray& array) { // Offsets in the output array where to begin writing std::vector offsets = [&]() { - std::vector ret(array.local_subdomain_count(), 0); + std::vector ret(array.get_local_subdomain_count(), 0); for (size_t i = 1; i < ret.size(); ++i) { ret[i] = ret[i - 1] + spans[i - 1].size(); } @@ -268,7 +268,7 @@ std::vector to_vector(const DistributedArray& array) { std::vector global(data.size()); std::vector sizes; - sizes.reserve(array.global_subdomain_count()); + sizes.reserve(array.get_global_subdomain_count()); for (int rank = 0; rank <= array.topology().get_max_rank(); ++rank) { @@ -320,15 +320,16 @@ array) { return distribute(data, new_topology, array.get_rank(), - array.begin_padding(), - array.end_padding()); + array.get_begin_padding(), + array.get_end_padding()); // return global; } */ /// @brief Applies the given function object f to every element of the input -/// array. The algorithm is executed according to policy (not necessarily in order). +/// array. The algorithm is executed according to policy (not necessarily in +/// order). /// @param policy the execution policy to use. See execution policy for details. /// @param arr the input array. /// @param f function object, to be applied to the result of subspan(md_idx). @@ -365,7 +366,7 @@ static inline void for_each_indexed(ExecutionPolicy&& policy, DistributedArray& arr, BinaryIndexFunction f) { - auto boxes = arr.local_boxes(); + auto boxes = arr.get_local_boxes(); auto subspans = make_subspans(arr); for (size_t i = 0; i < subspans.size(); ++i) { auto offset = boxes[i].box.begin; @@ -461,7 +462,7 @@ static inline void transform_indexed(ExecutionPolicy&& policy, auto i_subspans = make_subspans(input); auto o_subspans = make_subspans(output); - const auto boxes = input.local_boxes(); + const auto boxes = input.get_local_boxes(); for (size_t i = 0; i < i_subspans.size(); ++i) { auto i_span = i_subspans[i]; @@ -583,5 +584,4 @@ static inline void tile_transform(const DistributedArray& input, tile_transform(std::execution::seq, input, output, f); } - } // namespace jada diff --git a/test/test_communication.cpp b/test/test_communication.cpp index 25bd4e3..7cf0243 100644 --- a/test/test_communication.cpp +++ b/test/test_communication.cpp @@ -680,7 +680,7 @@ static inline auto make_test_array(bool add_padding){ DistributedArray<2, int> arr(myrank, topo, bpad, epad); - for (auto& v : arr.local_data()){ + for (auto& v : arr.get_local_data()){ std::fill(v.begin(), v.end(), myrank + 1); } @@ -698,8 +698,8 @@ TEST_CASE("Test DistributedArray") SECTION("local_element_count/local_capacity"){ auto arr = make_test_array(true); - CHECK(local_element_count(arr) == arr.local_subdomain_count() * DistributedTestData::unpadded_subspan_size); - CHECK(local_capacity(arr) == arr.local_subdomain_count() * DistributedTestData::padded_subspan_size); + CHECK(local_element_count(arr) == arr.get_local_subdomain_count() * DistributedTestData::unpadded_subspan_size); + CHECK(local_capacity(arr) == arr.get_local_subdomain_count() * DistributedTestData::padded_subspan_size); } @@ -740,7 +740,7 @@ TEST_CASE("Test DistributedArray") auto arr = make_test_array(false); auto serial = serialize_local(arr); - size_t correct_size = arr.local_subdomain_count() * DistributedTestData::unpadded_subspan_size; + size_t correct_size = arr.get_local_subdomain_count() * DistributedTestData::unpadded_subspan_size; std::vector correct(correct_size, mpi::get_world_rank() + 1); CHECK(serial == correct); @@ -749,7 +749,7 @@ TEST_CASE("Test DistributedArray") auto arr = make_test_array(true); auto serial = serialize_local(arr); - size_t correct_size = arr.local_subdomain_count() * DistributedTestData::unpadded_subspan_size; + size_t correct_size = arr.get_local_subdomain_count() * DistributedTestData::unpadded_subspan_size; std::vector correct(correct_size, mpi::get_world_rank() + 1); CHECK(serial == correct); @@ -1080,10 +1080,10 @@ TEST_CASE("Test DistributedArray") auto arr_a = distribute(a, topo, mpi::get_world_rank(), bpad, epad); auto arr_b = distribute(b, topo, mpi::get_world_rank(), bpad, epad); - for (auto& data : arr_a.local_data()){ + for (auto& data : arr_a.get_local_data()){ std::fill(data.begin(), data.end(), 1); } - for (auto& data : arr_b.local_data()){ + for (auto& data : arr_b.get_local_data()){ std::fill(data.begin(), data.end(), -1); } @@ -1098,10 +1098,10 @@ TEST_CASE("Test DistributedArray") auto arr_a = distribute(a, topo, mpi::get_world_rank(), bpad, epad); auto arr_b = distribute(b, topo, mpi::get_world_rank(), bpad, epad); - for (auto& data : arr_a.local_data()){ + for (auto& data : arr_a.get_local_data()){ std::fill(data.begin(), data.end(), 1); } - for (auto& data : arr_b.local_data()){ + for (auto& data : arr_b.get_local_data()){ std::fill(data.begin(), data.end(), -1); } @@ -1140,10 +1140,10 @@ TEST_CASE("Test DistributedArray") auto arr_a = distribute(a, topo, mpi::get_world_rank(), bpad, epad); auto arr_b = distribute(b, topo, mpi::get_world_rank(), bpad, epad); - for (auto& data : arr_a.local_data()){ + for (auto& data : arr_a.get_local_data()){ std::fill(data.begin(), data.end(), 1); } - for (auto& data : arr_b.local_data()){ + for (auto& data : arr_b.get_local_data()){ std::fill(data.begin(), data.end(), -1); } @@ -1151,7 +1151,7 @@ TEST_CASE("Test DistributedArray") CHECK(to_vector(arr_b) == correct); - for (auto& data : arr_b.local_data()){ + for (auto& data : arr_b.get_local_data()){ std::fill(data.begin(), data.end(), -3); } @@ -1164,10 +1164,10 @@ TEST_CASE("Test DistributedArray") auto arr_a = distribute(a, topo, mpi::get_world_rank(), bpad, epad); auto arr_b = distribute(b, topo, mpi::get_world_rank(), bpad, epad); - for (auto& data : arr_a.local_data()){ + for (auto& data : arr_a.get_local_data()){ std::fill(data.begin(), data.end(), 1); } - for (auto& data : arr_b.local_data()){ + for (auto& data : arr_b.get_local_data()){ std::fill(data.begin(), data.end(), -1); } @@ -1176,7 +1176,7 @@ TEST_CASE("Test DistributedArray") CHECK(to_vector(arr_b) == correct); - for (auto& data : arr_b.local_data()){ + for (auto& data : arr_b.get_local_data()){ std::fill(data.begin(), data.end(), -3); }