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 a strange thing in parallel::detail::handle_exception. (Fix #2834.) #3089
Conversation
There are some changes in parallel::sort for fixing STEllAR-GROUP#2834. And this commit also fixes STEllAR-GROUP#3088.
…::handle_exception.
@taeguk Thanks for looking into this! It's overdue that you get access to the repository - I've sent you an invite. |
hpx/parallel/algorithms/sort.hpp
Outdated
@@ -201,19 +202,22 @@ namespace hpx { namespace parallel { inline namespace v1 | |||
result = execution::async_execute(policy.executor(), | |||
&sort_thread<ExPolicy, RandomIt, Compare>, | |||
std::ref(policy), first, last, comp); | |||
|
|||
return result; |
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.
Wouldn't a simple
return execution::async_execute(policy.executor(),
&sort_thread<ExPolicy, RandomIt, Compare>,
std::ref(policy), first, last, comp);
do the trick here?
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.
@hkaiser You're right. That code was derived from just moving return result;
into inside of try block. I'll fix that like you said.
hpx/parallel/algorithms/sort.hpp
Outdated
catch (...) { | ||
return hpx::make_exceptional_future<RandomIt>( | ||
std::current_exception()); | ||
} |
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.
Hmmm, do we really have to use nested try/catch blocks here? handle_local_exceptions
only rethrows the current exception as an exception list. Couldn't we directly call make_exceptional_future
with a exception list constructed from the current exception?
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.
@hkaiser handle_local_exceptions()
handles an exception differently when std::current_exception()
means std::bad_alloc
. In that case, handle_local_exceptions()
just rethrows std::bad_alloc
without wrapping into exception_list
.
We need to handle the exception differently according to what is the exception which we handles. And for that, I used handle_local_exception()
.
And nested catch (Line216-219) is needed for wrapping an exception which is threw properly from handle_local_exception()
.
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.
@taeguk yes, I understand. Still, there might be a better way.
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.
@hkaiser Aha, okay i got it.
https://github.com/taeguk/hpx/blob/9d72e4de54495987597bc2e6bbe609bc8125a01c/hpx/parallel/algorithms/sort.hpp#L249-L260
If we move that exception handling from Line208 to above lines, we can avoid nested try/catch blocks with just calling detail::handle_exception()
.
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.
hpx/parallel/exception_list.hpp
Outdated
catch (hpx::exception_list const& el) { | ||
throw el; | ||
catch (hpx::exception_list const&) { | ||
throw; | ||
} | ||
catch (...) { | ||
throw hpx::exception_list(std::current_exception()); |
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.
Hmm, this looks really strange (it probably was strange all along). I'm sure this can be done with one level of try/catch blocks.
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.
@hkaiser Yes, we can do that with only one level of try/catch blocks.
flyby: Consistent usage between exception_list and hpx::exception_list.
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.
Very nice, thanks a lot!
Fixes #2834 .
flyby: Fixes #3088 .