Skip to content

Commit

Permalink
Fixing exception handling for sequential shim execution policies
Browse files Browse the repository at this point in the history
  • Loading branch information
hkaiser committed May 26, 2015
1 parent 08818f9 commit 36faedc
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 53 deletions.
76 changes: 51 additions & 25 deletions hpx/parallel/algorithms/detail/dispatch.hpp
Expand Up @@ -15,6 +15,7 @@
#include <hpx/util/invoke.hpp>
#include <hpx/util/invoke_fused.hpp>
#include <hpx/util/tuple.hpp>
#include <hpx/util/void_guard.hpp>

This comment has been minimized.

Copy link
@K-ballo

K-ballo May 27, 2015

Member

Where is this used?

This comment has been minimized.

Copy link
@hkaiser

hkaiser May 27, 2015

Author Member

Not at all anymore :|

#include <hpx/parallel/exception_list.hpp>
#include <hpx/parallel/execution_policy.hpp>
#include <hpx/parallel/util/detail/algorithm_result.hpp>
Expand Down Expand Up @@ -59,6 +60,7 @@ namespace hpx { namespace parallel { HPX_INLINE_NAMESPACE(v1) { namespace detail
: name_(name)
{}

///////////////////////////////////////////////////////////////////////
template <typename ExPolicy, typename... Args>
typename parallel::util::detail::algorithm_result<
ExPolicy, local_result_type
Expand All @@ -68,72 +70,96 @@ namespace hpx { namespace parallel { HPX_INLINE_NAMESPACE(v1) { namespace detail
try {
return parallel::util::detail::algorithm_result<
ExPolicy, local_result_type
>::get(Derived::sequential(policy, std::forward<Args>(args)...));
>::get(Derived::sequential(policy,
std::forward<Args>(args)...));
}
catch (...) {
detail::handle_exception<ExPolicy, local_result_type>::call();
}
}

template <typename... Args>
///////////////////////////////////////////////////////////////////////
template <typename ExPolicy, typename... Args>
typename parallel::util::detail::algorithm_result<
sequential_task_execution_policy, local_result_type
ExPolicy, local_result_type
>::type
operator()(sequential_task_execution_policy policy,
Args&&... args) const
operator()(ExPolicy policy, Args&&... args) const
{
try {
return parallel::util::detail::algorithm_result<
sequential_task_execution_policy, local_result_type
>::get(Derived::sequential(policy, std::forward<Args>(args)...));
ExPolicy, local_result_type
>::get(Derived::sequential(policy,
std::forward<Args>(args)...));
}
catch (...) {
return detail::handle_exception<
sequential_task_execution_policy, local_result_type
ExPolicy, local_result_type
>::call();
}
}

template <typename... Args>
///////////////////////////////////////////////////////////////////////
template <typename ExPolicy, typename... Args>
typename parallel::util::detail::algorithm_result<
sequential_task_execution_policy, local_result_type
ExPolicy, local_result_type
>::type
call(sequential_task_execution_policy policy, boost::mpl::true_,
Args&&... args) const
call_sequential(ExPolicy policy, Args&&... args) const
{
try {
hpx::future<local_result_type> result =
hpx::async(derived(), policy, std::forward<Args>(args)...);

return parallel::util::detail::algorithm_result<
sequential_task_execution_policy, local_result_type
ExPolicy, local_result_type
>::get(std::move(result));
}
catch (...) {
return detail::handle_exception<
sequential_task_execution_policy, local_result_type
ExPolicy, local_result_type
>::call();
}
}


template <typename... Args>
typename parallel::util::detail::algorithm_result<
sequential_task_execution_policy, local_result_type
>::type
call(sequential_task_execution_policy policy, boost::mpl::true_,
Args&&... args) const
{
return call_sequential(policy, std::forward<Args>(args)...);
}

template <typename Executor, typename... Args>
typename parallel::util::detail::algorithm_result<
sequential_task_execution_policy_shim<Executor>, local_result_type
>::type
call(sequential_task_execution_policy_shim<Executor> policy,
boost::mpl::true_, Args&&... args) const
{
return call_sequential(policy, std::forward<Args>(args)...);
}

///////////////////////////////////////////////////////////////////////
template <typename... Args>
typename parallel::util::detail::algorithm_result<
parallel_task_execution_policy, local_result_type
>::type
call(parallel_task_execution_policy policy, boost::mpl::true_,
Args&&... args) const
{
try {
return parallel::util::detail::algorithm_result<
parallel_task_execution_policy, local_result_type
>::get(Derived::sequential(policy,
std::forward<Args>(args)...));
}
catch (...) {
return detail::handle_exception<
parallel_task_execution_policy, local_result_type
>::call();
}
return call_sequential(policy, std::forward<Args>(args)...);
}

template <typename Executor, typename... Args>
typename parallel::util::detail::algorithm_result<
parallel_task_execution_policy_shim<Executor>, local_result_type
>::type
call(parallel_task_execution_policy_shim<Executor> policy,
boost::mpl::true_, Args&&... args) const
{
return call_sequential(policy, std::forward<Args>(args)...);
}

template <typename ExPolicy, typename... Args>
Expand Down
34 changes: 32 additions & 2 deletions hpx/parallel/exception_list.hpp
Expand Up @@ -15,8 +15,14 @@

namespace hpx { namespace parallel { HPX_INLINE_NAMESPACE(v1)
{
///////////////////////////////////////////////////////////////////////////
// forward declarations, see execution_policy.hpp
struct sequential_task_execution_policy;
template <typename Executor> struct sequential_task_execution_policy_shim;

struct parallel_task_execution_policy;
template <typename Executor> struct parallel_task_execution_policy_shim;

struct parallel_vector_execution_policy;

namespace detail
Expand All @@ -25,6 +31,8 @@ namespace hpx { namespace parallel { HPX_INLINE_NAMESPACE(v1)
template <typename ExPolicy, typename Result = void>
struct handle_exception
{
typedef void type;

HPX_ATTRIBUTE_NORETURN static void call()
{
try {
Expand All @@ -44,6 +52,8 @@ namespace hpx { namespace parallel { HPX_INLINE_NAMESPACE(v1)
template <typename Result>
struct handle_exception<sequential_task_execution_policy, Result>
{
typedef future<Result> type;

static future<Result> call()
{
try {
Expand All @@ -60,14 +70,24 @@ namespace hpx { namespace parallel { HPX_INLINE_NAMESPACE(v1)
}
}
catch (...) {
return hpx::make_exceptional_future<Result>(boost::current_exception());
return hpx::make_exceptional_future<Result>(
boost::current_exception());
}
}
};

template <typename Executor, typename Result>
struct handle_exception<
sequential_task_execution_policy_shim<Executor>, Result>
: handle_exception<sequential_task_execution_policy, Result>
{};

///////////////////////////////////////////////////////////////////////
template <typename Result>
struct handle_exception<parallel_task_execution_policy, Result>
{
typedef future<Result> type;

static future<Result> call()
{
try {
Expand All @@ -84,14 +104,24 @@ namespace hpx { namespace parallel { HPX_INLINE_NAMESPACE(v1)
}
}
catch (...) {
return hpx::make_exceptional_future<Result>(boost::current_exception());
return hpx::make_exceptional_future<Result>(
boost::current_exception());
}
}
};

template <typename Executor, typename Result>
struct handle_exception<
parallel_task_execution_policy_shim<Executor>, Result>
: handle_exception<parallel_task_execution_policy, Result>
{};

///////////////////////////////////////////////////////////////////////
template <typename Result>
struct handle_exception<parallel_vector_execution_policy, Result>
{
typedef void type;

HPX_ATTRIBUTE_NORETURN static void call()
{
// any exceptions thrown by algorithms executed with the
Expand Down
27 changes: 1 addition & 26 deletions tests/unit/parallel/algorithms/foreach_executors.cpp
Expand Up @@ -8,31 +8,6 @@

#include "foreach_tests.hpp"

// template <typename IteratorTag>
// void test_for_each_exec()
// {
// using namespace hpx::parallel;
//
// {
// hpx::threads::executors::local_priority_queue_executor exec;
// test_for_each(par(exec), IteratorTag());
// }
// {
// hpx::threads::executors::local_priority_queue_executor exec;
// test_for_each(task(exec), IteratorTag());
// }
//
// {
// hpx::threads::executors::local_priority_queue_executor exec;
// test_for_each(execution_policy(par(exec)), IteratorTag());
// }
// {
// hpx::threads::executors::local_priority_queue_executor exec;
// test_for_each(execution_policy(task(exec)), IteratorTag());
// }
// }


////////////////////////////////////////////////////////////////////////////////
template <typename ExPolicy>
void test_executors(ExPolicy && policy)
Expand All @@ -59,6 +34,7 @@ void test_executors_async(ExPolicy && p)
void for_each_executors_test()
{
using namespace hpx::parallel;

{
parallel_executor exec;

Expand All @@ -70,7 +46,6 @@ void for_each_executors_test()
sequential_executor exec;

test_executors(seq.on(exec));
//ERROR FROM BELOW, not handline errors correctly
test_executors_async(seq(task).on(exec));

test_executors(par.on(exec));
Expand Down

0 comments on commit 36faedc

Please sign in to comment.