Skip to content

Commit

Permalink
Adding hpx::launch::lazy
Browse files Browse the repository at this point in the history
- this new policy allows to dynamically generate the required launch policy
- this fixes #2800
  • Loading branch information
hkaiser committed Aug 9, 2017
1 parent 8719307 commit 24187a2
Show file tree
Hide file tree
Showing 6 changed files with 318 additions and 89 deletions.
29 changes: 22 additions & 7 deletions hpx/async.hpp
Expand Up @@ -39,7 +39,7 @@ namespace hpx { namespace detail
>::value
, lcos::future<typename util::detail::invoke_deferred_result<F>::type>
>::type
call_sync(F&& f, std::false_type)
call_sync(F && f, std::false_type)
{
typedef typename util::detail::invoke_deferred_result<F>::type result_type;
try
Expand All @@ -59,7 +59,7 @@ namespace hpx { namespace detail
>::value
, lcos::future<typename util::detail::invoke_deferred_result<F>::type>
>::type
call_sync(F&& f, std::false_type) //-V659
call_sync(F && f, std::false_type) //-V659
{
typedef typename util::detail::invoke_deferred_result<F>::type result_type;
try
Expand All @@ -74,7 +74,7 @@ namespace hpx { namespace detail
template <typename F>
HPX_FORCEINLINE
lcos::future<typename util::detail::invoke_deferred_result<F>::type>
call_sync(F&& f, std::true_type)
call_sync(F && f, std::true_type)
{
try
{
Expand Down Expand Up @@ -126,6 +126,21 @@ namespace hpx { namespace detail
return p.get_future();
}

// template <typename Pred, typename F, typename ...Ts>
// HPX_FORCEINLINE static
// typename std::enable_if<
// traits::detail::is_deferred_invocable<F, Ts...>::value,
// hpx::future<
// typename util::detail::invoke_deferred_result<F, Ts...>::type
// >
// >::type
// call(hpx::detail::lazy_policy<Pred> const& policy, F && f,
// Ts&&... ts)
// {
// return call(policy.policy(), std::forward<F>(f),
// std::forward<Ts>(ts)...);
// }

template <typename F, typename ...Ts>
HPX_FORCEINLINE static
typename std::enable_if<
Expand Down Expand Up @@ -194,7 +209,7 @@ namespace hpx { namespace detail
typename util::detail::invoke_deferred_result<F, Ts...>::type
>
>::type
call(hpx::detail::deferred_policy, F && f, Ts&&... ts)
call(hpx::detail::deferred_policy, F && f, Ts &&... ts)
{
typedef typename util::detail::invoke_deferred_result<F, Ts...>::type
result_type;
Expand All @@ -219,7 +234,7 @@ namespace hpx { namespace detail
typename util::detail::invoke_deferred_result<F, Ts...>::type
>
>::type
call(F&& f, Ts&&... ts)
call(F && f, Ts &&... ts)
{
return async_dispatch<hpx::detail::async_policy>::call(
launch::async, std::forward<F>(f), std::forward<Ts>(ts)...);
Expand All @@ -241,7 +256,7 @@ namespace hpx { namespace detail
typename util::detail::invoke_deferred_result<F, Ts...>::type
>
>::type
call(Executor_ && sched, F&& f, Ts&&... ts)
call(Executor_ && sched, F && f, Ts &&... ts)
{
typedef typename util::detail::invoke_deferred_result<F, Ts...>::type
result_type;
Expand Down Expand Up @@ -270,7 +285,7 @@ namespace hpx { namespace detail
typename util::detail::invoke_deferred_result<F, Ts...>::type
>
>::type
call(Executor& exec, F&& f, Ts&&... ts)
call(Executor& exec, F && f, Ts &&... ts)
{
return parallel::executor_traits<Executor>::async_execute(
exec, std::forward<F>(f), std::forward<Ts>(ts)...);
Expand Down
39 changes: 22 additions & 17 deletions hpx/lcos/async.hpp
Expand Up @@ -32,14 +32,19 @@ namespace hpx { namespace detail
template <typename Action>
struct async_action_client_dispatch
{
template <typename Client, typename Stub, typename ...Ts>
HPX_FORCEINLINE lcos::future<
typename traits::promise_local_result<
typename traits::extract_action<
Action
>::remote_result_type
>::type>
operator()(launch launch_policy,
template <typename Policy, typename Client, typename Stub, typename ...Ts>
HPX_FORCEINLINE
typename std::enable_if<
traits::is_launch_policy<Policy>::value,
lcos::future<
typename traits::promise_local_result<
typename traits::extract_action<
Action
>::remote_result_type
>::type
>
>::type
operator()(Policy const& launch_policy,
components::client_base<Client, Stub> const& c, Ts &&... ts) const
{
HPX_ASSERT(c.is_ready());
Expand All @@ -65,7 +70,7 @@ namespace hpx { namespace detail
Action
>::remote_result_type
>::type>
call(Policy launch_policy, naming::id_type const& id, Ts&&... ts)
call(Policy const& launch_policy, naming::id_type const& id, Ts&&... ts)
{
return hpx::detail::async_impl<Action>(launch_policy, id,
std::forward<Ts>(ts)...);
Expand All @@ -79,7 +84,7 @@ namespace hpx { namespace detail
Action
>::remote_result_type
>::type>
call(Policy launch_policy,
call(Policy const& launch_policy,
components::client_base<Client, Stub> c, Ts&&... ts)
{
// make sure the action is compatible with the component type
Expand Down Expand Up @@ -118,8 +123,7 @@ namespace hpx { namespace detail
>::type
>
>::type
call(Policy launch_policy,
DistPolicy const& policy, Ts&&... ts)
call(Policy const& launch_policy, DistPolicy const& policy, Ts&&... ts)
{
return policy.template async<Action>(launch_policy,
std::forward<Ts>(ts)...);
Expand Down Expand Up @@ -208,9 +212,10 @@ namespace hpx { namespace detail
template <typename Policy, typename ...Ts>
HPX_FORCEINLINE static
lcos::future<result_type>
call(Policy launch_policy, Action const&, Ts &&... ts)
call(Policy const& launch_policy, Action const&, Ts &&... ts)
{
static_assert(traits::is_launch_policy<Policy>::value,
static_assert(
traits::is_launch_policy<Policy>::value,
"Policy must be a valid launch policy");
return async<Action>(launch_policy, std::forward<Ts>(ts)...);
}
Expand Down Expand Up @@ -307,7 +312,7 @@ namespace hpx { namespace detail
{
template <typename F, typename ...Ts>
HPX_FORCEINLINE static auto
call(Policy launch_policy, F && f, Ts &&... ts)
call(Policy const& launch_policy, F && f, Ts &&... ts)
-> decltype(detail::async_launch_policy_dispatch<
typename util::decay<F>::type
>::call(launch_policy, std::forward<F>(f), std::forward<Ts>(ts)...))
Expand All @@ -326,7 +331,7 @@ namespace hpx { namespace detail
Derived
>::remote_result_type
>::type>
call(Policy launch_policy,
call(Policy const& launch_policy,
hpx::actions::basic_action<Component, Signature, Derived> const&,
components::client_base<Client, Stub> const& c, Ts&&... ts)
{
Expand Down Expand Up @@ -354,7 +359,7 @@ namespace hpx { namespace detail
>::remote_result_type
>::type>
>::type
call(Policy launch_policy,
call(Policy const& launch_policy,
hpx::actions::basic_action<Component, Signature, Derived> const&,
DistPolicy const& policy, Ts&&... ts)
{
Expand Down

0 comments on commit 24187a2

Please sign in to comment.