Skip to content

Commit

Permalink
Copies all private variables in ygm::container::detail::array_impl co…
Browse files Browse the repository at this point in the history
…py constructor (#189)
  • Loading branch information
steiltre authored Dec 14, 2023
1 parent d402c52 commit 0baced1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
4 changes: 3 additions & 1 deletion include/ygm/container/detail/array_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class array_impl {
: m_default_value(rhs.m_default_value),
m_comm(rhs.m_comm),
m_global_size(rhs.m_global_size),
m_small_block_size(rhs.m_small_block_size),
m_large_block_size(rhs.m_large_block_size),
m_local_start_index(rhs.m_local_start_index),
m_local_vec(rhs.m_local_vec),
pthis(this) {}

Expand All @@ -52,7 +55,6 @@ class array_impl {
m_global_size = size;
m_small_block_size = size / m_comm.size();
m_large_block_size = m_small_block_size + ((size / m_comm.size()) > 0);
m_comm.cout0(m_small_block_size, " : ", m_large_block_size);

m_local_vec.resize(
m_small_block_size + (m_comm.rank() < (size % m_comm.size())),
Expand Down
35 changes: 35 additions & 0 deletions test/test_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,40 @@ int main(int argc, char **argv) {
});
}

// Test copy constructor
{
int size = 64;

ygm::container::array<int> arr(world, size);

if (world.rank0()) {
for (int i = 0; i < size; ++i) {
arr.async_set(i, 2 * i);
}
}

world.barrier();

ygm::container::array<int> arr_copy(arr);

arr_copy.for_all([&arr](const auto &index, const auto &value) {
arr.async_visit(
index,
[](const auto &index, const auto &my_value, const auto &other_value) {
ASSERT_RELEASE(my_value == other_value);
},
value);
});

arr.for_all([&arr_copy](const auto &index, const auto &value) {
arr_copy.async_visit(
index,
[](const auto &index, const auto &my_value, const auto &other_value) {
ASSERT_RELEASE(my_value == other_value);
},
value);
});
}

return 0;
}

0 comments on commit 0baced1

Please sign in to comment.