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 global_scan and global_scan_inplace. #24

Merged
merged 2 commits into from
Mar 3, 2020

Conversation

asrivast28
Copy link
Contributor

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 using min on an array if the minimum element in the array is greater than zero.
Solution: The result of local_scan on process 0 should not be updated with the presum.

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));
Copy link
Contributor Author

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.

T sum = T();
if (n > 0)
sum = *(out+(n-1));
T sum = *(out+(n-1));
T presum = exscan(sum, func, nonzero_comm, commutative);
Copy link
Contributor Author

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);
Copy link
Contributor Author

@asrivast28 asrivast28 Mar 2, 2020

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.

Copy link
Owner

@patflick patflick left a 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.

Copy link
Owner

@patflick patflick left a 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)?

Copy link
Owner

@patflick patflick left a comment

Choose a reason for hiding this comment

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

Thanks. LGTM

@patflick patflick merged commit 1c0ab9f into patflick:master Mar 3, 2020
@asrivast28 asrivast28 deleted the FixScan branch March 3, 2020 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants