Skip to content

Commit

Permalink
Add a customization point for put_parcel so we can override actions (…
Browse files Browse the repository at this point in the history
…e.g. rdma)
  • Loading branch information
biddisco committed Nov 14, 2016
1 parent da93384 commit 29aceaa
Show file tree
Hide file tree
Showing 2 changed files with 179 additions and 64 deletions.
90 changes: 26 additions & 64 deletions hpx/runtime/applier/apply.hpp
Expand Up @@ -19,6 +19,7 @@
#include <hpx/runtime/naming/name.hpp>
#include <hpx/runtime/parcelset/put_parcel.hpp>
#include <hpx/runtime/parcelset/detail/parcel_await.hpp>
#include <hpx/traits/action_put_parcel.hpp>
#include <hpx/traits/component_type_is_compatible.hpp>
#include <hpx/traits/extract_action.hpp>
#include <hpx/traits/is_action.hpp>
Expand Down Expand Up @@ -54,15 +55,9 @@ namespace hpx
put_parcel(naming::id_type const& id, naming::address&& addr,
threads::thread_priority priority, Ts&&... vs)
{
typedef
typename hpx::traits::extract_action<Action>::type
action_type;
action_type act;

parcelset::put_parcel(id, complement_addr<action_type>(addr),
act, priority, std::forward<Ts>(vs)...);

return false; // destinations are remote
return hpx::traits::action_put_parcel<Action>::call(
id, std::forward<naming::address>(addr),
priority, std::forward<Ts>(vs)...);
}

template <typename Action, typename Continuation, typename ...Ts>
Expand All @@ -71,16 +66,9 @@ namespace hpx
threads::thread_priority priority,
Continuation && cont, Ts&&... vs)
{
typedef
typename hpx::traits::extract_action<Action>::type
action_type;
action_type act;

parcelset::put_parcel(id, complement_addr<action_type>(addr),
std::forward<Continuation>(cont),
act, priority, std::forward<Ts>(vs)...);

return false; // destinations are remote
return hpx::traits::action_put_parcel<Action>::call_cont(
id, std::forward<naming::address>(addr),
priority, std::forward<Continuation>(cont), std::forward<Ts>(vs)...);
}

template <typename Action, typename ...Ts>
Expand All @@ -89,34 +77,21 @@ namespace hpx
threads::thread_priority priority,
parcelset::parcelhandler::write_handler_type const& cb, Ts&&... vs)
{
typedef
typename hpx::traits::extract_action<Action>::type
action_type;
action_type act;

parcelset::put_parcel_cb(cb, id,
complement_addr<action_type>(addr),
act, priority, std::forward<Ts>(vs)...);

return false; // destinations are remote
}
return hpx::traits::action_put_parcel<Action>::call_cb(
id, std::forward<naming::address>(addr),
priority, cb, std::forward<Ts>(vs)...);
}

template <typename Action, typename ...Ts>
inline bool
put_parcel_cb(naming::id_type const& id, naming::address&& addr,
threads::thread_priority priority,
parcelset::parcelhandler::write_handler_type && cb, Ts&&... vs)
{
typedef
typename hpx::traits::extract_action<Action>::type
action_type;
action_type act;

parcelset::put_parcel_cb(std::move(cb), id,
complement_addr<action_type>(addr),
act, priority, std::forward<Ts>(vs)...);

return false; // destinations are remote
return hpx::traits::action_put_parcel<Action>::call_cb(
id, std::forward<naming::address>(addr),
priority, std::forward<parcelset::parcelhandler::write_handler_type>(cb),
std::forward<Ts>(vs)...);
}

template <typename Action, typename Continuation, typename ...Ts>
Expand All @@ -126,18 +101,11 @@ namespace hpx
Continuation && cont,
parcelset::parcelhandler::write_handler_type const& cb, Ts&&... vs)
{
typedef
typename hpx::traits::extract_action<Action>::type
action_type;
action_type act;

parcelset::put_parcel_cb(cb, id,
complement_addr<action_type>(addr),
std::forward<Continuation>(cont),
act, priority, std::forward<Ts>(vs)...);

return false; // destinations are remote
}
return hpx::traits::action_put_parcel<Action>::call_cont_cb(
id, std::forward<naming::address>(addr),
priority, std::forward<Continuation>(cont), cb,
std::forward<Ts>(vs)...);
}

template <typename Action, typename Continuation, typename ...Ts>
inline bool
Expand All @@ -146,18 +114,12 @@ namespace hpx
Continuation && cont,
parcelset::parcelhandler::write_handler_type && cb, Ts&&... vs)
{
typedef
typename hpx::traits::extract_action<Action>::type
action_type;
action_type act;

parcelset::put_parcel_cb(std::move(cb), id,
complement_addr<action_type>(addr),
std::forward<Continuation>(cont),
act, priority, std::forward<Ts>(vs)...);

return false; // destinations are remote
}
return hpx::traits::action_put_parcel<Action>::call_cont_cb(
id, std::forward<naming::address>(addr),
priority, std::forward<Continuation>(cont),
std::forward<parcelset::parcelhandler::write_handler_type>(cb),
std::forward<Ts>(vs)...);
}

// We know it is remote.
template <typename Action, typename ...Ts>
Expand Down
153 changes: 153 additions & 0 deletions hpx/traits/action_put_parcel.hpp
@@ -0,0 +1,153 @@
// Copyright (c) 2016 John Biddiscombe
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#if !defined(HPX_TRAITS_ACTION_PUT_PARCEL_AUG_2016)
#define HPX_TRAITS_ACTION_PUT_PARCEL_AUG_2016

#include <hpx/config.hpp>
#include <hpx/runtime/threads/thread_enums.hpp>
#include <hpx/runtime/naming/id_type.hpp>
#include <hpx/runtime/naming/address.hpp>
#include <hpx/runtime/parcelset/put_parcel.hpp>
#include <hpx/runtime/parcelset/policies/message_handler.hpp>
#include <hpx/traits/extract_action.hpp>
#include <utility>

namespace hpx { namespace traits
{
namespace detail {

///////////////////////////////////////////////////////////////////////
template <typename Action>
inline naming::address&& complement_addr(naming::address& addr)
{
if (components::component_invalid == addr.type_)
{
addr.type_ = components::get_component_type<
typename Action::component_type>();
}
return std::move(addr);
}
}

///////////////////////////////////////////////////////////////////////////
// Customization point for action put parcel
template <typename Action, typename Enable = void>
struct action_put_parcel
{
template <typename ...Ts>
static inline bool
call(naming::id_type const& id, naming::address&& addr,
threads::thread_priority priority, Ts&&... vs)
{
typedef
typename hpx::traits::extract_action<Action>::type
action_type;
action_type act;

parcelset::put_parcel(id, detail::complement_addr<action_type>(addr),
act, priority, std::forward<Ts>(vs)...);

return false; // destinations are remote
}

template <typename Continuation, typename ...Ts>
static inline bool
call_cont(naming::id_type const& id, naming::address&& addr,
threads::thread_priority priority,
Continuation && cont, Ts&&... vs)
{
typedef
typename hpx::traits::extract_action<Action>::type
action_type;
action_type act;

parcelset::put_parcel(id, detail::complement_addr<action_type>(addr),
std::forward<Continuation>(cont),
act, priority, std::forward<Ts>(vs)...);

return false; // destinations are remote
}

template <typename ...Ts>
static inline bool
call_cb(naming::id_type const& id, naming::address&& addr,
threads::thread_priority priority,
hpx::parcelset::write_handler_type const& cb, Ts&&... vs)
{
typedef
typename hpx::traits::extract_action<Action>::type
action_type;
action_type act;

parcelset::put_parcel_cb(cb, id,
detail::complement_addr<action_type>(addr),
act, priority, std::forward<Ts>(vs)...);

return false; // destinations are remote
}

template <typename ...Ts>
static inline bool
call_cb(naming::id_type const& id, naming::address&& addr,
threads::thread_priority priority,
parcelset::policies::message_handler::write_handler_type && cb, Ts&&... vs)
{
typedef
typename hpx::traits::extract_action<Action>::type
action_type;
action_type act;

parcelset::put_parcel_cb(std::move(cb), id,
detail::complement_addr<action_type>(addr),
act, priority, std::forward<Ts>(vs)...);

return false; // destinations are remote
}

template <typename Continuation, typename Handler, typename ...Ts>
static inline bool
call_cont_cb(naming::id_type const& id,
naming::address&& addr, threads::thread_priority priority,
Continuation && cont,
Handler const & cb, Ts&&... vs)
{
typedef
typename hpx::traits::extract_action<Action>::type
action_type;
action_type act;

parcelset::put_parcel_cb(cb, id,
detail::complement_addr<action_type>(addr),
std::forward<Continuation>(cont),
act, priority, std::forward<Ts>(vs)...);

return false; // destinations are remote
}

template <typename Continuation, typename Handler, typename ...Ts>
static inline bool
call_cont_cb(naming::id_type const& id,
naming::address&& addr, threads::thread_priority priority,
Continuation && cont,
Handler &&cb, Ts&&... vs)
{
typedef
typename hpx::traits::extract_action<Action>::type
action_type;
action_type act;

parcelset::put_parcel_cb(std::move(cb), id,
detail::complement_addr<action_type>(addr),
std::forward<Continuation>(cont),
act, priority, std::forward<Ts>(vs)...);

return false; // destinations are remote
}
};
}}

#endif

0 comments on commit 29aceaa

Please sign in to comment.