Skip to content

Commit

Permalink
Merge pull request #2731 from STEllAR-GROUP/fixing_2729
Browse files Browse the repository at this point in the history
Adding on_migrated event handler to migratable component instances
  • Loading branch information
hkaiser committed Jul 4, 2017
2 parents 7bfaa3f + 3953ac6 commit a226213
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 26 deletions.
8 changes: 5 additions & 3 deletions hpx/runtime/components/component_factory.hpp
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2015 Hartmut Kaiser
// Copyright (c) 2007-2017 Hartmut Kaiser
// Copyright (c) 2011 Bryce Lelbach
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand Down Expand Up @@ -214,17 +214,19 @@ namespace hpx { namespace components
/// \param assign_gid [in] The GID to assign to the newly created object.
/// \param ctor [in] The constructor function to call in order to
/// initialize the newly allocated object.
/// \param p [in] Used to return the address of the newly
/// created object (if non-zero)
///
/// \return Returns the GID of the first newly created component
/// instance (this is the same as assign_gid, if successful).
naming::gid_type create_with_args(
naming::gid_type const& assign_gid,
util::unique_function_nonser<void(void*)> const& ctor)
util::unique_function_nonser<void(void*)> const& ctor, void **p)
{
if (isenabled_)
{
naming::gid_type id =
server::create<Component>(assign_gid, ctor);
server::create<Component>(assign_gid, ctor, p);
if (id)
++refcnt_;
return id;
Expand Down
10 changes: 6 additions & 4 deletions hpx/runtime/components/component_factory_base.hpp
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2015 Hartmut Kaiser
// Copyright (c) 2007-2017 Hartmut Kaiser
//
// 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)
Expand Down Expand Up @@ -81,14 +81,16 @@ namespace hpx { namespace components
/// GID to the new object.
///
/// \param assign_gid [in] The GID to assign to the newly created object.
/// \param f [in] The constructor function to call in order to
/// initialize the newly allocated object.
/// \param f [in] The constructor function to call in order to
/// initialize the newly allocated object.
/// \param p [in] Used to return the address of the newly
/// created object (if non-zero)
///
/// \return Returns the GID of the first newly created component
/// instance (this is the same as assign_gid, if successful).
virtual naming::gid_type create_with_args(
naming::gid_type const& assign_gid,
util::unique_function_nonser<void(void*)> const& f) = 0;
util::unique_function_nonser<void(void*)> const& f, void **p) = 0;

/// \brief Destroy one or more component instances
///
Expand Down
13 changes: 8 additions & 5 deletions hpx/runtime/components/derived_component_factory.hpp
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2015 Hartmut Kaiser
// Copyright (c) 2007-2017 Hartmut Kaiser
// Copyright (c) 2011 Bryce Lelbach
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand Down Expand Up @@ -199,19 +199,22 @@ namespace hpx { namespace components
/// GID to the new object.
///
/// \param assign_gid [in] The GID to assign to the newly created object.
/// \param f [in] The constructor function to call in order to
/// initialize the newly allocated object.
/// \param f [in] The constructor function to call in order to
/// initialize the newly allocated object.
/// \param p [in] Used to return the address of the newly
/// created object (if non-zero)
///
/// \return Returns the GID of the first newly created component
/// instance (this is the same as assign_gid, if successful).
naming::gid_type create_with_args(
naming::gid_type const& assign_gid,
util::unique_function_nonser<void(void*)> const& ctor)
util::unique_function_nonser<void(void*)> const& ctor,
void** p)
{
if (isenabled_)
{
naming::gid_type id =
server::create<Component>(assign_gid, ctor);
server::create<Component>(assign_gid, ctor, p);
if (id)
++refcnt_;
return id;
Expand Down
6 changes: 4 additions & 2 deletions hpx/runtime/components/server/create_component.hpp
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2012 Hartmut Kaiser
// Copyright (c) 2007-2017 Hartmut Kaiser
// Copyright (c) 2011 Thomas Heller
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand Down Expand Up @@ -81,7 +81,7 @@ namespace hpx { namespace components { namespace server

template <typename Component>
naming::gid_type create(naming::gid_type const& gid,
util::unique_function_nonser<void(void*)> const& ctor)
util::unique_function_nonser<void(void*)> const& ctor, void** p)
{
void * cv = Component::heap_type::alloc(1);
try {
Expand All @@ -98,6 +98,8 @@ namespace hpx { namespace components { namespace server
if (assigned_gid && assigned_gid == gid)
{
// everything is ok, return the new id
if (p != nullptr)
*p = c; // return the raw address as well
return gid;
}

Expand Down
4 changes: 2 additions & 2 deletions hpx/runtime/components/server/create_component_fwd.hpp
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2012 Hartmut Kaiser
// Copyright (c) 2007-2017 Hartmut Kaiser
// Copyright (c) 2011 Thomas Heller
// Copyright (c) 2015 Hartmut Kaiser
//
Expand Down Expand Up @@ -29,7 +29,7 @@ namespace hpx { namespace components { namespace server

template <typename Component>
naming::gid_type create(naming::gid_type const& gid,
util::unique_function_nonser<void(void*)> const& ctor);
util::unique_function_nonser<void(void*)> const& ctor, void** p);

template <typename Component, typename ...Ts>
naming::gid_type create_with_args(Ts&&... ts);
Expand Down
12 changes: 10 additions & 2 deletions hpx/runtime/components/server/fixed_component_base.hpp
@@ -1,5 +1,5 @@
// Copyright (c) 2011 Bryce Lelbach
// Copyright (c) 2007-2016 Hartmut Kaiser
// Copyright (c) 2007-2017 Hartmut Kaiser
//
// 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)
Expand Down Expand Up @@ -99,7 +99,7 @@ class fixed_component_base : public traits::detail::fixed_component_tag

template <typename Component_>
friend naming::gid_type server::create(naming::gid_type const& gid,
util::unique_function_nonser<void(void*)> const& ctor);
util::unique_function_nonser<void(void*)> const& ctor, void** p);

// Return the component's fixed GID.
naming::gid_type get_base_gid(
Expand Down Expand Up @@ -185,6 +185,14 @@ class fixed_component_base : public traits::detail::fixed_component_tag
HPX_ASSERT(false);
}

void on_migrated()
{
// If this assertion is triggered then this component instance is being
// migrated even if the component type has not been enabled to support
// migration.
HPX_ASSERT(false);
}

private:
mutable naming::gid_type gid_;
std::uint64_t msb_;
Expand Down
12 changes: 10 additions & 2 deletions hpx/runtime/components/server/managed_component_base.hpp
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2016 Hartmut Kaiser
// Copyright (c) 2007-2017 Hartmut Kaiser
// Copyright (c) 2011 Thomas Heller
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand Down Expand Up @@ -260,6 +260,14 @@ namespace hpx { namespace components
HPX_ASSERT(false);
}

void on_migrated()
{
// If this assertion is triggered then this component instance is being
// migrated even if the component type has not been enabled to support
// migration.
HPX_ASSERT(false);
}

protected:
template <typename>
friend struct detail_adl_barrier::init;
Expand Down Expand Up @@ -621,7 +629,7 @@ namespace hpx { namespace components

template <typename Component_>
friend naming::gid_type server::create(naming::gid_type const& gid,
util::unique_function_nonser<void(void*)> const& ctor);
util::unique_function_nonser<void(void*)> const& ctor, void** p);

template <typename Component_, typename ...Ts>
friend naming::gid_type server::create_with_args(Ts&&... ts);
Expand Down
6 changes: 5 additions & 1 deletion hpx/runtime/components/server/migration_support.hpp
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2016 Hartmut Kaiser
// Copyright (c) 2007-2017 Hartmut Kaiser
//
// 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)
Expand Down Expand Up @@ -150,6 +150,10 @@ namespace hpx { namespace components
});
}

/// This hook is invoked on the newly created object after the migration
/// has been finished
void on_migrated() {}

/// This is the hook implementation for decorate_action which makes
/// sure that the object becomes pinned during the execution of an
/// action.
Expand Down
13 changes: 10 additions & 3 deletions hpx/runtime/components/server/runtime_support.hpp
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2015 Hartmut Kaiser
// Copyright (c) 2007-2017 Hartmut Kaiser
// Copyright (c) 2011 Bryce Lelbach
// Copyright (c) 2011 Thomas Heller
//
Expand Down Expand Up @@ -799,11 +799,14 @@ namespace hpx { namespace components { namespace server
}

typedef typename Component::wrapping_type wrapping_type;
typename wrapping_type::derived_type* new_instance = nullptr;

naming::gid_type id = factory->create_with_args(migrated_id,
detail::construct_function<wrapping_type>(std::move(*p)));
detail::construct_function<wrapping_type>(std::move(*p)),
reinterpret_cast<void**>(&new_instance));

// sanity checks
if (!id)
if (!id || new_instance == nullptr)
{
// we should not get here (id should not be invalid)
HPX_THROW_EXCEPTION(hpx::invalid_status,
Expand All @@ -825,13 +828,17 @@ namespace hpx { namespace components { namespace server
<< " of type: " << components::get_component_type_name(type)
<< " to locality: " << find_here();

// inform the newly created component that it has been migrated
new_instance->on_migrated();

// At this point the object has been fully migrated. We now remove
// the object from the AGAS table of migrated objects. This is
// necessary as this object might have been migrated off this locality
// before it was migrated back.
agas::unmark_as_migrated(id);

to_migrate.make_unmanaged();

return id;
}
}}}
Expand Down
12 changes: 10 additions & 2 deletions hpx/runtime/components/server/simple_component_base.hpp
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2016 Hartmut Kaiser
// Copyright (c) 2007-2017 Hartmut Kaiser
// Copyright (c) 2011 Bryce Lelbach
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand Down Expand Up @@ -130,7 +130,7 @@ namespace hpx { namespace components

template <typename Component_>
friend naming::gid_type server::create(naming::gid_type const& gid,
util::unique_function_nonser<void(void*)> const& ctor);
util::unique_function_nonser<void(void*)> const& ctor, void** p);

template <typename Component_, typename ...Ts>
friend naming::gid_type server::create_with_args(Ts&&... ts);
Expand Down Expand Up @@ -246,6 +246,14 @@ namespace hpx { namespace components
HPX_ASSERT(false);
}

void on_migrated()
{
// If this assertion is triggered then this component instance is being
// migrated even if the component type has not been enabled to support
// migration.
HPX_ASSERT(false);
}

protected:
mutable naming::gid_type gid_;
};
Expand Down

0 comments on commit a226213

Please sign in to comment.