-
Notifications
You must be signed in to change notification settings - Fork 113
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
Bugfix for set_intersection copying from second iterator range #983
Bugfix for set_intersection copying from second iterator range #983
Conversation
test/parallel_api/algorithm/alg.sorting/alg.set.operations/set.pass.cpp
Outdated
Show resolved
Hide resolved
I'm investigating the failure for windows, cl, but I'm thus far unable to reproduce it... |
I'm still unable to reproduce the failure in practice. However, examining the code a bit more, I think that our usage of For a zip_iterator, It seems that we need a specialization for zip_iterator which results in a placement I believe there are other places in the code which will also require similar changes. In Also, we have similar usage in Unless I am missing something, all of these are affected and may be broken for zip_iterators. |
I was missing something in I am still investigating the source of the error for windows-2019, cl and tbb. (Also the general issue of |
359b770
to
4a05536
Compare
Signed-off-by: Dan Hoeflinger <[email protected]>
Signed-off-by: Dan Hoeflinger <[email protected]>
Signed-off-by: Dan Hoeflinger <[email protected]>
Signed-off-by: Dan Hoeflinger <[email protected]>
Signed-off-by: Dan Hoeflinger <[email protected]>
4a05536
to
69cf08c
Compare
Signed-off-by: Dan Hoeflinger <[email protected]>
Signed-off-by: Dan Hoeflinger <[email protected]>
After rebasing with current main, it seems the failure for windows-2019, cl and tbb is no longer there. I think we can go ahead and re-review the PR and consider merging. |
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.
I have looked through both the patch and testing changes and they LGTM.
@SergeyKopienko (since you have left feedback already) and others: |
Signed-off-by: Dan Hoeflinger <[email protected]>
Signed-off-by: Dan Hoeflinger <[email protected]>
Signed-off-by: Dan Hoeflinger <[email protected]>
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.
LGTM
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.
LGTM
Thanks all for the reviews. With merging with the existing approvals. |
Bug Description
As implemented before this PR,
set_intersection
usingoneapi::dpl::execution::par
has a bug which results in incorrect semantics for some situations.For performance reasons, in some situations, we would prefer to reverse the order of arguments in the parallel loop for input iterators. However, this results in copying from the second set of iterators which is against semantics found here:
https://en.cppreference.com/w/cpp/algorithm/set_intersection
..."elements will be copied from [first1, last1) to the output range, preserving order."
In cases where the comparator does not compare ALL of the input type, this can be very important. For instance, a comparator for a key value pair which only considers the key.
Fix Summary
This PR fixes this bug by passing a functor to
__set_intersection_construct
which selects which element to copy to the output range. This allows us to keep the structure of the reversed iterator arguments without the issue of copying from the wrong input set.This PR also adds a test which fails to compile without this fix using a key value pair example which only compares the key. It uses a
oneapi::dpl::counting_iterator<int>
as a "value" for the first set of iterators, aoneapi::dpl::discard_iterator
as a "value" for the second set of iterators, and a sequence of integers for the output "values". If the implementation were to attempt to copy from the second set of iterators, a compiler error will occur when attempting to assign the dereferencedoneapi::dpl::discard_iterator
to an integer.