-
Notifications
You must be signed in to change notification settings - Fork 20
Fix in global_scan and global_scan_inplace. #24
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
Conversation
Updating the elements on the first processor after exscan may lead to erroneous results.
| T sum = T(); | ||
| if (n > 0) | ||
| sum = *(out+(n-1)); | ||
| T sum = *(out+(n-1)); |
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.
n is always greater than 0 because of the check on line 739.
| if (n > 0) | ||
| sum = *(out+(n-1)); | ||
| T sum = *(out+(n-1)); | ||
| T presum = exscan(sum, func, nonzero_comm, commutative); |
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.
exscan returns T() on process 0.
| T presum = exscan(sum, func, nonzero_comm, commutative); | ||
| // accumulate previous sum on all local elements | ||
| for (size_t i = 0; i < n; ++i) { | ||
| *o = func(presum, *o); |
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.
If func is min, and T is a numeric type, T() will replace all the correct results on process 0 if all the elements of the array are greater than 0.
patflick
left a comment
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.
👍 great catch. How did I miss this?? 😮
Thanks for the fix.
patflick
left a comment
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.
optimally, can you add a failing test case in test/test_reductions.cpp (ie, failing before the fix)?
patflick
left a comment
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.
Thanks. LGTM
Problem: Currently, in the
mxx::global_scan*functions, the local scan results are updated on every process with the prefix sum from the previous process. However, the prefix sum on process 0 is just the zero-initialized value corresponding to the type. This may lead to erroneous results on process 0 in some cases, e.g. while scanning usingminon an array if the minimum element in the array is greater than zero.Solution: The result of
local_scanon process 0 should not be updated with thepresum.