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
taskflow find_if doesn't work with infinite ranges because std::distance is used #534
Labels
help wanted
Extra attention is needed
Comments
We are following the C++ standard algorithm (and parallel algorithms as well) that does not check if the given iterators are valid/invalid. Invalid range iterators will result in undefined behavior. |
An infinite range is not invalid. It is the taskflow code that is
problematic because it assumes that only finite ranges can be parallelized.
But I see no reason why they cannot. One just needs a constexpr test and
then branch to a different chunking strategy that is not based on the
number of items in the sequence.
…On Sat, 16 Dec 2023, 19:40 Tsung-Wei Huang, ***@***.***> wrote:
We are following the C++ standard algorithm (and parallel algorithms as
well) that does not check if the given iterators are valid/invalid. Invalid
range iterators will result in undefined behavior.
—
Reply to this email directly, view it on GitHub
<#534 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAEJ4SCWF25U7HS6JJDWADYJXTIBAVCNFSM6AAAAABACSVEECVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNJYHEYDEOJZGQ>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Also standard library does support infinite ranges. For example here is how to uses std::ranges::find to implement strlen https://godbolt.org/z/Efhsjndv6 #include <ranges>
#include <iostream>
template<class CharT>
constexpr std::size_t my_strlen(const CharT *s)
{
return std::ranges::find(s, std::unreachable_sentinel, CharT{}) - s;
}
int main(){
const char * foo = "hello world";
std::cout << my_strlen(foo) << std::endl;
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In taskflow::find_if doesn't work with infinite ranges.
However an infinite range is a reasonable input to find_if. For example
std::ranges::iota(0)
produces an infinite range starting from 0.
However taskflow::find_if calls std::distance on the two iterators which cannot work if the second iterator is a sentinel std::unreachable_sentinel
In this case taskflow::find_if should find a sensible alternative to chunking. In our case we explicitly pass StaticPartitioner(1) so we don't require chunking.
The text was updated successfully, but these errors were encountered: