Skip to content

Commit

Permalink
Merge branch 'master' into fix_3134
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonBikineev committed Feb 11, 2018
2 parents 3cff7c8 + f0063c1 commit 0ab6e0e
Show file tree
Hide file tree
Showing 68 changed files with 1,091 additions and 742 deletions.
2 changes: 2 additions & 0 deletions docs/CMakeLists.txt
Expand Up @@ -47,6 +47,7 @@ set(doxygen_dependencies
"${PROJECT_SOURCE_DIR}/hpx/hpx_init.hpp"
"${PROJECT_SOURCE_DIR}/hpx/hpx_start.hpp"
"${PROJECT_SOURCE_DIR}/hpx/hpx_finalize.hpp"
"${PROJECT_SOURCE_DIR}/hpx/hpx_suspend.hpp"
"${PROJECT_SOURCE_DIR}/hpx/error.hpp"
"${PROJECT_SOURCE_DIR}/hpx/error_code.hpp"
"${PROJECT_SOURCE_DIR}/hpx/exception.hpp"
Expand Down Expand Up @@ -172,6 +173,7 @@ set(doxygen_dependencies
"${PROJECT_SOURCE_DIR}/hpx/runtime/threads/thread_enums.hpp"
"${PROJECT_SOURCE_DIR}/hpx/runtime/threads/thread_data_fwd.hpp"
"${PROJECT_SOURCE_DIR}/hpx/runtime/threads/thread_helpers.hpp"
"${PROJECT_SOURCE_DIR}/hpx/runtime/threads/thread_pool_base.hpp"
"${PROJECT_SOURCE_DIR}/hpx/lcos/barrier.hpp"
"${PROJECT_SOURCE_DIR}/hpx/lcos/broadcast.hpp"
"${PROJECT_SOURCE_DIR}/hpx/lcos/fold.hpp"
Expand Down
7 changes: 7 additions & 0 deletions docs/hpx.idx
Expand Up @@ -92,6 +92,9 @@ get_thread_priority_name "" "hpx\.threads\.get_thread_priority_name
get_thread_state_ex_name "" "hpx\.threads\.get_thread_state_ex_name.*"
get_stack_size_name "" "hpx\.threads\.get_stack_size_name.*"

# hpx/runtime/threads/thread_pool_base.hpp
thread_pool_base "" "hpx\.runtime\.threads\.thread_pool_base.*"

# hpx/components/component_storage/migrate_from_storage.hpp
migrate_from_storage "" "hpx\.components\.migrate_from_s.*"

Expand Down Expand Up @@ -588,6 +591,10 @@ init "" "hpx\.init_id.*"
# hpx/hpx_start.hpp
start "" "hpx\.start_id.*"

# hpx/hpx_suspend.hpp
resume "" "hpx\.suspend.*"
suspend "" "hpx\.resume.*"

# hpx/performance_counters/manage_counter_type.hpp
install_counter_type "" "hpx\.performance_counters\.install_counter_type.*"

Expand Down
46 changes: 46 additions & 0 deletions docs/manual/applications.qbk
Expand Up @@ -187,4 +187,50 @@ available, such as for instance to provide your own entry point function instead
of [funcref hpx_main `hpx_main`]. Please refer to the function documentation for
more details (see: [headerref hpx/hpx_start.hpp `hpx/hpx_start.hpp`]).

[heading:flexible Suspending and resuming the __hpx__ runtime]

In some applications it is required to combine __hpx__ with other runtimes. To
support this use case __hpx__ provides two functions: [funcref hpx::suspend
`hpx::suspend`] and [funcref hpx::resume `hpx::resume`]. [funcref hpx::suspend
`hpx::suspend`] is a blocking call which will wait for all scheduled tasks to
finish executing and then put the thread pool OS threads to sleep. [funcref
hpx::resume `hpx::resume`] simply wakes up the sleeping threads so that they are
ready to accept new work. [funcref hpx::suspend `hpx::suspend`] and [funcref
hpx::resume `hpx::resume`] can be found in the header [headerref
hpx/hpx_suspend.hpp `hpx/hpx_suspend.hpp`].

#include <``[headerref hpx/hpx_start.hpp `hpx/hpx_start.hpp`]``>
#include <``[headerref hpx/hpx_suspend.hpp `hpx/hpx_suspend.hpp`]``>

int main(int argc, char* argv[])
{
// Initialize HPX, don't run hpx_main
``[funcref hpx::start `hpx::start`]``(nullptr, argc, argv);

// Schedule a function on the HPX runtime
``[funcref hpx::async `hpx::async`]``(&my_function, ...);

// Wait for all tasks to finish, and suspend the HPX runtime
``[funcref hpx::suspend `hpx::suspend`]``();

// Execute non-HPX code here

// Resume the HPX runtime
``[funcref hpx::resume `hpx::resume`]``();

// Schedule more work on the HPX runtime

// Wait for hpx::finalize being called.
return ``[funcref hpx::stop `hpx::stop`]``();
}

[note [funcref hpx::suspend `hpx::suspend`] does not wait for [funcref
hpx::finalize `hpx::finalize`] to be called. Only call [funcref
hpx::finalize `hpx::finalize`] when you wish to fully stop the __hpx__
runtime.]

__hpx__ also supports suspending individual thread pools and threads. For
details on how to do that see the documentation for [classref
hpx::threads::thread_pool_base `thread_pool_base`].

[endsect]
Expand Up @@ -275,7 +275,7 @@ int main(int argc, char* argv[])
[](hpx::threads::policies::callback_notifier& notifier,
std::size_t num_threads, std::size_t thread_offset,
std::size_t pool_index, std::string const& pool_name)
-> std::unique_ptr<hpx::threads::detail::thread_pool_base>
-> std::unique_ptr<hpx::threads::thread_pool_base>
{
std::cout << "User defined scheduler creation callback "
<< std::endl;
Expand All @@ -287,7 +287,7 @@ int main(int argc, char* argv[])
auto mode = scheduler_mode(scheduler_mode::do_background_work |
scheduler_mode::delay_exit);

std::unique_ptr<hpx::threads::detail::thread_pool_base> pool(
std::unique_ptr<hpx::threads::thread_pool_base> pool(
new hpx::threads::detail::scheduled_thread_pool<
high_priority_sched
>(std::move(scheduler), notifier,
Expand All @@ -310,7 +310,7 @@ int main(int argc, char* argv[])
[](hpx::threads::policies::callback_notifier& notifier,
std::size_t num_threads, std::size_t thread_offset,
std::size_t pool_index, std::string const& pool_name)
-> std::unique_ptr<hpx::threads::detail::thread_pool_base>
-> std::unique_ptr<hpx::threads::thread_pool_base>
{
std::cout << "User defined scheduler creation callback "
<< std::endl;
Expand All @@ -320,7 +320,7 @@ int main(int argc, char* argv[])

auto mode = scheduler_mode(scheduler_mode::delay_exit);

std::unique_ptr<hpx::threads::detail::thread_pool_base> pool(
std::unique_ptr<hpx::threads::thread_pool_base> pool(
new hpx::threads::detail::scheduled_thread_pool<
high_priority_sched
>(std::move(scheduler), notifier,
Expand Down
8 changes: 4 additions & 4 deletions examples/resource_partitioner/simple_resource_partitioner.cpp
Expand Up @@ -277,7 +277,7 @@ int main(int argc, char* argv[])
[](hpx::threads::policies::callback_notifier& notifier,
std::size_t num_threads, std::size_t thread_offset,
std::size_t pool_index, std::string const& pool_name)
-> std::unique_ptr<hpx::threads::detail::thread_pool_base>
-> std::unique_ptr<hpx::threads::thread_pool_base>
{
std::cout << "User defined scheduler creation callback "
<< std::endl;
Expand All @@ -289,7 +289,7 @@ int main(int argc, char* argv[])
auto mode = scheduler_mode(scheduler_mode::do_background_work |
scheduler_mode::delay_exit);

std::unique_ptr<hpx::threads::detail::thread_pool_base> pool(
std::unique_ptr<hpx::threads::thread_pool_base> pool(
new hpx::threads::detail::scheduled_thread_pool<
high_priority_sched
>(std::move(scheduler), notifier,
Expand All @@ -310,7 +310,7 @@ int main(int argc, char* argv[])
[](hpx::threads::policies::callback_notifier& notifier,
std::size_t num_threads, std::size_t thread_offset,
std::size_t pool_index, std::string const& pool_name)
-> std::unique_ptr<hpx::threads::detail::thread_pool_base>
-> std::unique_ptr<hpx::threads::thread_pool_base>
{
std::cout << "User defined scheduler creation callback "
<< std::endl;
Expand All @@ -320,7 +320,7 @@ int main(int argc, char* argv[])

auto mode = scheduler_mode(scheduler_mode::delay_exit);

std::unique_ptr<hpx::threads::detail::thread_pool_base> pool(
std::unique_ptr<hpx::threads::thread_pool_base> pool(
new hpx::threads::detail::scheduled_thread_pool<
high_priority_sched
>(std::move(scheduler), notifier,
Expand Down
24 changes: 12 additions & 12 deletions hpx/lcos/detail/async_implementations.hpp
Expand Up @@ -23,6 +23,7 @@
#include <hpx/traits/future_access.hpp>
#include <hpx/util/assert.hpp>

#include <cstddef>
#include <utility>

namespace hpx { namespace detail
Expand Down Expand Up @@ -157,10 +158,13 @@ namespace hpx { namespace detail
template <typename Action>
bool can_invoke_locally()
{
return !traits::action_decorate_function<Action>::value &&
this_thread::get_stack_size() >= threads::get_stack_size(
std::ptrdiff_t requested_stack_size =
threads::get_stack_size(
static_cast<threads::thread_stacksize>(
traits::action_stacksize<Action>::value));
return !traits::action_decorate_function<Action>::value &&
this_thread::get_stack_size() >= requested_stack_size &&
this_thread::has_sufficient_stack_space(requested_stack_size);
}

template <typename Action>
Expand Down Expand Up @@ -363,11 +367,9 @@ namespace hpx { namespace detail
return sync_local_invoke<action_type, result_type>::call(
id, std::move(addr), std::forward<Ts>(vs)...);
}
else
{
f = hpx::async(action_invoker<action_type>(),
addr.address_, addr.type_, std::forward<Ts>(vs)...);
}

f = hpx::async(action_invoker<action_type>(),
addr.address_, addr.type_, std::forward<Ts>(vs)...);

return keep_alive(std::move(f), id, std::move(r.second));
}
Expand All @@ -379,11 +381,9 @@ namespace hpx { namespace detail
return sync_local_invoke<action_type, result_type>::call(
id, std::move(addr), std::forward<Ts>(vs)...);
}
else
{
f = hpx::async(action_invoker<action_type>(),
addr.address_, addr.type_, std::forward<Ts>(vs)...);
}

f = hpx::async(action_invoker<action_type>(),
addr.address_, addr.type_, std::forward<Ts>(vs)...);

return keep_alive(std::move(f), id);
}
Expand Down
2 changes: 1 addition & 1 deletion hpx/lcos/latch.hpp
Expand Up @@ -41,7 +41,7 @@ namespace hpx { namespace lcos

/// Extension: Create a client side representation for the existing
/// \a server#latch instance with the given global id \a id.
latch(naming::id_type id)
latch(naming::id_type const& id)
: base_type(id)
{}

Expand Down
17 changes: 8 additions & 9 deletions hpx/lcos/local/futures_factory.hpp
Expand Up @@ -111,15 +111,14 @@ namespace hpx { namespace lcos { namespace local
threads::thread_priority_boost, get_worker_thread_num(),
stacksize, ec);
}
else {
threads::register_thread_nullary(
util::deferred_call(
&base_type::run_impl, std::move(this_)),
util::thread_description(f_, "task_object::apply"),
threads::pending, false, priority, std::size_t(-1),
stacksize, ec);
return threads::invalid_thread_id;
}

threads::register_thread_nullary(
util::deferred_call(
&base_type::run_impl, std::move(this_)),
util::thread_description(f_, "task_object::apply"),
threads::pending, false, priority, std::size_t(-1),
stacksize, ec);
return threads::invalid_thread_id;
}
};

Expand Down
43 changes: 0 additions & 43 deletions hpx/runtime/actions/action_support.hpp
Expand Up @@ -20,7 +20,6 @@
#include <hpx/runtime/threads/thread_helpers.hpp>
#include <hpx/runtime/threads/thread_init_data.hpp>
#include <hpx/traits/action_remote_result.hpp>
#include <hpx/traits/is_bitwise_serializable.hpp>
#include <hpx/util/detail/pp/cat.hpp>
#include <hpx/util/detail/pp/nargs.hpp>
#include <hpx/util/tuple.hpp>
Expand All @@ -36,47 +35,6 @@
#include <hpx/config/warnings_prefix.hpp>

/// \cond NOINTERNAL
namespace hpx { namespace actions { namespace detail
{
struct action_serialization_data
{
action_serialization_data()
: parent_locality_(naming::invalid_locality_id)
, parent_id_(static_cast<std::uint64_t>(0))
, parent_phase_(0)
, priority_(static_cast<threads::thread_priority>(0))
, stacksize_(static_cast<threads::thread_stacksize>(0))
{}

action_serialization_data(std::uint32_t parent_locality,
threads::thread_id_type parent_id,
std::uint64_t parent_phase,
threads::thread_priority priority,
threads::thread_stacksize stacksize)
: parent_locality_(parent_locality)
, parent_id_(reinterpret_cast<std::uint64_t>(parent_id.get()))
, parent_phase_(parent_phase)
, priority_(priority)
, stacksize_(stacksize)
{}

std::uint32_t parent_locality_;
std::uint64_t parent_id_;
std::uint64_t parent_phase_;
threads::thread_priority priority_;
threads::thread_stacksize stacksize_;

template <class Archive>
void serialize(Archive& ar, unsigned)
{
ar & parent_id_ & parent_phase_ & parent_locality_
& priority_ & stacksize_;
}
};
}}}

HPX_IS_BITWISE_SERIALIZABLE(hpx::actions::detail::action_serialization_data)

namespace hpx { namespace traits
{
namespace detail
Expand All @@ -90,7 +48,6 @@ namespace hpx { namespace traits
};
}
}}

/// \endcond

///////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 0ab6e0e

Please sign in to comment.