Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes bug in block_partitioner determination of large block size #225

Merged
merged 1 commit into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions include/ygm/container/array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,10 @@ class array
std::vector<std::pair<const key_type, const mapped_type>> tmp_values;
tmp_values.reserve(local_size());
local_for_all(
[&tmp_values](const key_type& index, const mapped_type& value) {
tmp_values.push_back(std::make_pair(index, value));
[&tmp_values, size](const key_type& index, const mapped_type& value) {
if (index < size) {
tmp_values.push_back(std::make_pair(index, value));
}
});

m_global_size = size;
Expand All @@ -368,23 +370,21 @@ class array

// Repopulate array values
for (const auto& [index, value] : tmp_values) {
if (index < size) {
async_set(index, value);
}
async_set(index, value);
}

m_comm.barrier();
}

void resize(const size_type size) { resize(size, m_default_value); }

size_t local_size() { return partitioner.local_size(); }

size_t size() const {
m_comm.barrier();
return m_global_size;
}

void resize(const size_type size) { resize(size, m_default_value); }

void local_clear() { resize(0); }

void local_swap(self_type& other) {
Expand Down
4 changes: 2 additions & 2 deletions include/ygm/container/detail/block_partitioner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct block_partitioner {
m_partitioned_size(partitioned_size) {
m_small_block_size = partitioned_size / m_comm_size;
m_large_block_size =
m_small_block_size + ((partitioned_size / m_comm_size) > 0);
m_small_block_size + ((partitioned_size % m_comm_size) > 0);

if (m_comm_rank < (partitioned_size % m_comm_size)) {
m_local_start_index = m_comm_rank * m_large_block_size;
Expand Down Expand Up @@ -62,7 +62,7 @@ struct block_partitioner {

index_type local_index(const index_type &global_index) {
index_type to_return = global_index - m_local_start_index;
ASSERT_RELEASE((to_return >= 0) && (to_return <= m_small_block_size));
ASSERT_RELEASE((to_return >= 0) && (to_return < m_local_size));
return to_return;
}

Expand Down