-
Notifications
You must be signed in to change notification settings - Fork 17
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fixed an issue with stable_distribute and stable_distribute_inplace
when the total size is less than the number of processes. Also added a test that was failing before the fix.
- Loading branch information
commit b90b7f9124048dfb0bb45c96df6152f45780cfa7
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,15 +111,18 @@ void stable_distribute(_InIterator begin, _InIterator end, _OutIterator out, con | |
size_t prefix = mxx::exscan(local_size, comm); | ||
|
||
// 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the line that leads to an error if |
||
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? | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} | ||
|
||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 astotal_size
if the processes with rank lower than the current process have all the input elements.