Skip to content

Commit

Permalink
added get_ to all getter functions of the distributed array class
Browse files Browse the repository at this point in the history
  • Loading branch information
hamsteri15 committed Jan 26, 2024
1 parent 09b42f4 commit 47ed807
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 40 deletions.
50 changes: 25 additions & 25 deletions include/bits/communication/distributed_array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ template <size_t N, class T> 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();
}

Expand All @@ -52,7 +52,7 @@ template <size_t N, class T> struct DistributedArray {
///@return std::vector<BoxRankPair<N>> A vector of box-rank pairs where the
/// rank is always m_rank.
///
std::vector<BoxRankPair<N>> local_boxes() const {
std::vector<BoxRankPair<N>> get_local_boxes() const {
return m_topology.get_boxes(m_rank);
}

Expand All @@ -74,7 +74,7 @@ template <size_t N, class T> struct DistributedArray {
template <size_t N, class T>
static inline size_t local_element_count(const DistributedArray<N, T>& 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();
Expand Down Expand Up @@ -107,7 +107,7 @@ template <size_t N, class T>
static inline size_t local_capacity(const DistributedArray<N, T>& 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;
}

Expand All @@ -122,11 +122,11 @@ auto make_subspans(const DistributedArray<N, T>& array) {

std::vector<span_t> 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) {

Expand Down Expand Up @@ -154,11 +154,11 @@ template <size_t N, class T> auto make_subspans(DistributedArray<N, T>& array) {

std::vector<span_t> 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) {

Expand Down Expand Up @@ -191,7 +191,7 @@ serialize_local(const DistributedArray<N, T>& array) {

// Offsets in the output array where to begin writing
std::vector<size_t> offsets = [&]() {
std::vector<size_t> ret(array.local_subdomain_count(), 0);
std::vector<size_t> 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();
}
Expand Down Expand Up @@ -268,7 +268,7 @@ std::vector<T> to_vector(const DistributedArray<N, T>& array) {
std::vector<T> global(data.size());

std::vector<size_t> 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) {

Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -365,7 +366,7 @@ static inline void for_each_indexed(ExecutionPolicy&& policy,
DistributedArray<N, T>& 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;
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -583,5 +584,4 @@ static inline void tile_transform(const DistributedArray<N, ET1>& input,
tile_transform<Dir>(std::execution::seq, input, output, f);
}


} // namespace jada
30 changes: 15 additions & 15 deletions test/test_communication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);

}

Expand Down Expand Up @@ -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<int> correct(correct_size, mpi::get_world_rank() + 1);

CHECK(serial == correct);
Expand All @@ -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<int> correct(correct_size, mpi::get_world_rank() + 1);

CHECK(serial == correct);
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -1140,18 +1140,18 @@ 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);
}

tile_transform<0>( arr_a, arr_b, op);

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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand Down

0 comments on commit 47ed807

Please sign in to comment.