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

Fix in stable_distribute and stable_distribute_inplace #25

Merged
merged 1 commit into from
Mar 29, 2020
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
19 changes: 11 additions & 8 deletions include/mxx/distribution.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,18 @@ void stable_distribute(_InIterator begin, _InIterator end, _OutIterator out, con
size_t prefix = mxx::exscan(local_size, comm);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefix may be the same as total_size if the processes with rank lower than the current process have all the input elements.


// calculate where to send elements
// if there are any elements to send
std::vector<size_t> send_counts(comm.size(), 0);
blk_dist part(total_size, comm.size(), comm.rank());
int first_p = part.rank_of(prefix);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the line that leads to an error if prefix is the same as the total_size.

size_t left_to_send = local_size;
for (; left_to_send > 0 && first_p < comm.size(); ++first_p) {
size_t nsend = std::min<size_t>(part.iprefix_size(first_p) - prefix, left_to_send);
send_counts[first_p] = nsend;
left_to_send -= nsend;
prefix += nsend;
if (local_size > 0) {
blk_dist part(total_size, comm.size(), comm.rank());
int first_p = part.rank_of(prefix);
size_t left_to_send = local_size;
for (; left_to_send > 0 && first_p < comm.size(); ++first_p) {
size_t nsend = std::min<size_t>(part.iprefix_size(first_p) - prefix, left_to_send);
send_counts[first_p] = nsend;
left_to_send -= nsend;
prefix += nsend;
}
}
std::vector<size_t> recv_counts = mxx::all2all(send_counts, comm);
// TODO: accept iterators in mxx::all2all?
Expand Down
10 changes: 10 additions & 0 deletions test/test_distribution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,16 @@ TEST(MxxDistribution, DistributeVector) {

test_distribute<std::vector<int>>(size, gen, c);
test_stable_distribute<std::vector<int>>(size, gen, c);

// create a distribution of total size smaller than
// the total number of processes and zero elements on the last process
size = (c.rank() % 2 == 0) ? 1 : 0;
if (c.is_last()) {
size = 0;
}
// XXX: test_distribute fails with an assertion error in mxx::sort
// test_distribute<std::vector<int>>(size, gen, c);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to fail with an assertion error in sample_distribute. Is that expected?

test_stable_distribute<std::vector<int>>(size, gen, c);
}


Expand Down