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 Task.parallel_for_reduce on empty loop #67

Merged

Conversation

jmid
Copy link
Contributor

@jmid jmid commented Mar 9, 2022

Task.parallel_for_reduce gives the wrong result for the corner-case of an empty loop with start:0 and finish:-1.
For a simple (in this case: empty) loop that adds an array of 1s, it returns 1 rather than the expected init = 0.

The current code builds on a reasonable assumption of non-empty parallel loops.
The PR tests for the corner-case only once per invocation ("at top-level")
and hence should not affect the performance of such loops noticeably.

`Task.parallel_for_reduce` gives the wrong result for a the corner-case
of an empty loop with `start:0` and `finish:-1`.

For a simple (in this case: empty) loop that adds an array of 1s,
it returns `1` rather than the expected `init = 0`.

The current code builds on a reasonable assumption of non-empty parallel loops.
The PR tests for the corner-case only once per invocation ("at top-level")
and hence should not affect performance.
Copy link
Contributor

@Sudha247 Sudha247 left a comment

Choose a reason for hiding this comment

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

Thanks @jmid! This looks good to me.

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

3 participants