Skip to content
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

Modernize naming modules #5817

Merged
merged 1 commit into from Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -18,8 +18,7 @@
#include <cstddef>
#include <vector>

namespace hpx { namespace components
{
namespace hpx { namespace components {
///////////////////////////////////////////////////////////////////////////
class HPX_MIGRATE_TO_STORAGE_EXPORT component_storage
: public client_base<component_storage, server::component_storage>
Expand All @@ -29,23 +28,20 @@ namespace hpx { namespace components

public:
component_storage(hpx::id_type target_locality);
component_storage(hpx::future<naming::id_type> && f);
component_storage(hpx::future<hpx::id_type>&& f);

hpx::future<naming::id_type> migrate_to_here(std::vector<char> const&,
naming::id_type const&, naming::address const&);
naming::id_type migrate_to_here(launch::sync_policy,
std::vector<char> const&, naming::id_type const&,
hpx::future<hpx::id_type> migrate_to_here(std::vector<char> const&,
hpx::id_type const&, naming::address const&);
hpx::id_type migrate_to_here(launch::sync_policy,
std::vector<char> const&, hpx::id_type const&,
naming::address const&);

hpx::future<std::vector<char> > migrate_from_here(
naming::gid_type const&);
std::vector<char> migrate_from_here(launch::sync_policy,
hpx::future<std::vector<char>> migrate_from_here(
naming::gid_type const&);
std::vector<char> migrate_from_here(
launch::sync_policy, naming::gid_type const&);

future<std::size_t> size() const;
std::size_t size(launch::sync_policy) const;
};
}}



}} // namespace hpx::components
Expand Up @@ -41,14 +41,14 @@ namespace hpx { namespace components
///
template <typename Component>
#if defined(DOXYGEN)
future<naming::id_type>
future<hpx::id_type>
#else
inline typename std::enable_if<
traits::is_component<Component>::value, future<naming::id_type>
traits::is_component<Component>::value, future<hpx::id_type>
>::type
#endif
migrate_from_storage(naming::id_type const& to_resurrect,
naming::id_type const& target = naming::invalid_id)
migrate_from_storage(hpx::id_type const& to_resurrect,
hpx::id_type const& target = hpx::invalid_id)
{
typedef server::trigger_migrate_from_storage_here_action<Component>
action_type;
Expand Down
Expand Up @@ -40,14 +40,14 @@ namespace hpx { namespace components
///
template <typename Component>
#if defined(DOXYGEN)
future<naming::id_type>
future<hpx::id_type>
#else
inline typename std::enable_if<
traits::is_component<Component>::value, future<naming::id_type>
traits::is_component<Component>::value, future<hpx::id_type>
>::type
#endif
migrate_to_storage(naming::id_type const& to_migrate,
naming::id_type const& target_storage)
migrate_to_storage(hpx::id_type const& to_migrate,
hpx::id_type const& target_storage)
{
typedef server::trigger_migrate_to_storage_here_action<Component>
action_type;
Expand Down
Expand Up @@ -23,8 +23,7 @@
#include <vector>

///////////////////////////////////////////////////////////////////////////////
namespace hpx { namespace components { namespace server
{
namespace hpx { namespace components { namespace server {
///////////////////////////////////////////////////////////////////////////
class HPX_MIGRATE_TO_STORAGE_EXPORT component_storage
: public component_base<component_storage>
Expand All @@ -34,19 +33,22 @@ namespace hpx { namespace components { namespace server
public:
component_storage();

naming::gid_type migrate_to_here(std::vector<char> const&,
naming::id_type, naming::address const&);
naming::gid_type migrate_to_here(
std::vector<char> const&, hpx::id_type, naming::address const&);
std::vector<char> migrate_from_here(naming::gid_type const&);
std::size_t size() const { return data_.size(); }
std::size_t size() const
{
return data_.size();
}

HPX_DEFINE_COMPONENT_ACTION(component_storage, migrate_to_here)
HPX_DEFINE_COMPONENT_ACTION(component_storage, migrate_from_here)
HPX_DEFINE_COMPONENT_ACTION(component_storage, size)

private:
hpx::unordered_map<naming::gid_type, std::vector<char> > data_;
hpx::unordered_map<naming::gid_type, std::vector<char>> data_;
};
}}}
}}} // namespace hpx::components::server

HPX_REGISTER_ACTION_DECLARATION(
hpx::components::server::component_storage::migrate_to_here_action,
Expand All @@ -61,6 +63,3 @@ HPX_REGISTER_ACTION_DECLARATION(
typedef std::vector<char> hpx_component_storage_data_type;
HPX_REGISTER_UNORDERED_MAP_DECLARATION(
hpx::naming::gid_type, hpx_component_storage_data_type)



Expand Up @@ -23,8 +23,7 @@
#include <utility>
#include <vector>

namespace hpx { namespace components { namespace server
{
namespace hpx { namespace components { namespace server {
///////////////////////////////////////////////////////////////////////////
// Migrate given component from the specified storage component
//
Expand Down Expand Up @@ -58,51 +57,47 @@ namespace hpx { namespace components { namespace server
// migrated which will delete it once the shared pointer goes out of
// scope.
//
namespace detail
{
namespace detail {
///////////////////////////////////////////////////////////////////////
template <typename Component>
future<naming::id_type> migrate_from_storage_here_id(
naming::id_type const& target_locality,
future<hpx::id_type> migrate_from_storage_here_id(
hpx::id_type const& target_locality,
std::shared_ptr<Component> const& ptr,
naming::id_type const& to_resurrect)
hpx::id_type const& to_resurrect)
{
// and resurrect it on the specified locality
using hpx::components::runtime_support;
return runtime_support::migrate_component_async<Component>(
target_locality, ptr, to_resurrect)
.then(launch::sync,
[ptr, to_resurrect](future<id_type> && f)
{
ptr->mark_as_migrated();
return f.get();
});
target_locality, ptr, to_resurrect)
.then(launch::sync, [ptr, to_resurrect](future<id_type>&& f) {
ptr->mark_as_migrated();
return f.get();
});
}

template <typename Component>
future<naming::id_type> migrate_from_storage_here_address(
naming::address const& addr,
std::shared_ptr<Component> const& ptr,
naming::id_type const& to_resurrect)
future<hpx::id_type> migrate_from_storage_here_address(
naming::address const& addr, std::shared_ptr<Component> const& ptr,
hpx::id_type const& to_resurrect)
{
naming::id_type id(addr.locality_, id_type::unmanaged);
hpx::id_type id(
addr.locality_, id_type::management_type::unmanaged);
return migrate_from_storage_here_id(id, ptr, to_resurrect);
}

// convert the extracted data into a living component instance
template <typename Component>
future<naming::id_type> migrate_from_storage_here(
future<std::vector<char> > && f,
naming::id_type const& to_resurrect,
naming::address const& addr,
naming::id_type const& target_locality)
future<hpx::id_type> migrate_from_storage_here(
future<std::vector<char>>&& f, hpx::id_type const& to_resurrect,
naming::address const& addr, hpx::id_type const& target_locality)
{
// recreate the object
std::shared_ptr<Component> ptr;

{
std::vector<char> data = f.get();
serialization::input_archive archive(data, data.size(), nullptr);
serialization::input_archive archive(
data, data.size(), nullptr);
archive >> ptr;
}

Expand All @@ -111,34 +106,33 @@ namespace hpx { namespace components { namespace server

// if target locality is not specified, use the address of the last
// locality where the object was living before
if (target_locality == naming::invalid_id)
if (target_locality == hpx::invalid_id)
{
return migrate_from_storage_here_address<Component>(addr, ptr,
to_resurrect);
return migrate_from_storage_here_address<Component>(
addr, ptr, to_resurrect);
}

// otherwise directly refer to the locality where the object should
// be resurrected
return migrate_from_storage_here_id(target_locality, ptr,
to_resurrect);
return migrate_from_storage_here_id(
target_locality, ptr, to_resurrect);
}
}
} // namespace detail

///////////////////////////////////////////////////////////////////////////
// This is executed on the locality responsible for managing the address
// resolution for the given object.
template <typename Component>
future<naming::id_type> trigger_migrate_from_storage_here(
naming::id_type const& to_resurrect,
naming::id_type const& target_locality)
future<hpx::id_type> trigger_migrate_from_storage_here(
hpx::id_type const& to_resurrect, hpx::id_type const& target_locality)
{
if (!traits::component_supports_migration<Component>::call())
{
HPX_THROW_EXCEPTION(invalid_status,
"hpx::components::server::trigger_migrate_from_storage_here",
"attempting to migrate an instance of a component which "
"does not support migration");
return make_ready_future(naming::invalid_id);
return make_ready_future(hpx::invalid_id);
}

if (naming::get_locality_id_from_id(to_resurrect) != get_locality_id())
Expand All @@ -147,7 +141,7 @@ namespace hpx { namespace components { namespace server
"hpx::components::server::trigger_migrate_from_storage_here",
"this function has to be executed on the locality responsible "
"for managing the address of the given object");
return make_ready_future(naming::invalid_id);
return make_ready_future(hpx::invalid_id);
}

auto r = agas::begin_migration(to_resurrect).get();
Expand All @@ -156,26 +150,21 @@ namespace hpx { namespace components { namespace server
typedef typename server::component_storage::migrate_from_here_action
action_type;
return async<action_type>(r.first, to_resurrect.get_gid())
.then(hpx::bind_back(
&detail::migrate_from_storage_here<Component>,
.then(hpx::bind_back(&detail::migrate_from_storage_here<Component>,
to_resurrect, r.second, target_locality))
.then(
[to_resurrect](future<naming::id_type> && f) -> naming::id_type
{
[to_resurrect](future<hpx::id_type>&& f) -> hpx::id_type {
agas::end_migration(to_resurrect);
return f.get();
});
}

template <typename Component>
struct trigger_migrate_from_storage_here_action
: ::hpx::actions::action<
future<naming::id_type> (*)(naming::id_type const&,
naming::id_type const&)
, &trigger_migrate_from_storage_here<Component>
, trigger_migrate_from_storage_here_action<Component> >
{};
}}}



: ::hpx::actions::action<future<hpx::id_type> (*)(
hpx::id_type const&, hpx::id_type const&),
&trigger_migrate_from_storage_here<Component>,
trigger_migrate_from_storage_here_action<Component>>
{
};
}}} // namespace hpx::components::server