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
Add this_thread_executors #1669
Changes from 2 commits
e2f290e
1aa7090
f1f2d38
68f2ede
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Copyright (c) 2007-2015 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) | ||
|
||
/// \file parallel/executors/thread_pool_executors.hpp | ||
|
||
#if !defined(HPX_PARALLEL_EXECUTORS_THIS_THREAD_EXECUTORS_JUL_16_2015_0809PM) | ||
#define HPX_PARALLEL_EXECUTORS_THIS_THREAD_EXECUTORS_JUL_16_2015_0809PM | ||
|
||
#include <hpx/config.hpp> | ||
#include <hpx/parallel/config/inline_namespace.hpp> | ||
#include <hpx/parallel/executors/executor_traits.hpp> | ||
#include <hpx/parallel/executors/detail/thread_executor.hpp> | ||
#include <hpx/runtime/threads/executors/this_thread_executors.hpp> | ||
#include <hpx/util/move.hpp> | ||
|
||
#include <type_traits> | ||
|
||
namespace hpx { namespace parallel { HPX_INLINE_NAMESPACE(v3) | ||
{ | ||
/////////////////////////////////////////////////////////////////////////// | ||
#if defined(HPX_HAVE_LOCAL_SCHEDULER) | ||
struct this_thread_local_queue_executor | ||
#if !defined(DOXYGEN) | ||
: detail::threads_executor | ||
#endif | ||
{ | ||
/// Creates a new local_queue_executor | ||
/// | ||
/// \param max_punits [in] The maximum number of processing units to | ||
/// associate with the newly created executor. | ||
/// \param min_punits [in] The minimum number of processing units to | ||
/// associate with the newly created executor | ||
/// (default: 1). | ||
/// | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like a copy and paste error. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, forgot to update the comments |
||
explicit this_thread_local_queue_executor() | ||
: threads_executor( | ||
threads::executors::this_thread_local_queue_executor()) | ||
{} | ||
}; | ||
#endif | ||
|
||
#if defined(HPX_HAVE_STATIC_PRIORITY_SCHEDULER) | ||
struct this_thread_static_priority_queue_executor | ||
#if !defined(DOXYGEN) | ||
: detail::threads_executor | ||
#endif | ||
{ | ||
/// Creates a new static_priority_queue_executor | ||
/// | ||
/// \param max_punits [in] The maximum number of processing units to | ||
/// associate with the newly created executor. | ||
/// \param min_punits [in] The minimum number of processing units to | ||
/// associate with the newly created executor | ||
/// (default: 1). | ||
/// | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
explicit this_thread_static_priority_queue_executor() | ||
: threads_executor( | ||
threads::executors::this_thread_static_priority_queue_executor()) | ||
{} | ||
}; | ||
#endif | ||
|
||
namespace detail | ||
{ | ||
/// \cond NOINTERNAL | ||
#if defined(HPX_HAVE_LOCAL_SCHEDULER) | ||
template <> | ||
struct is_executor<this_thread_local_queue_executor> | ||
: std::true_type | ||
{}; | ||
#endif | ||
|
||
#if defined(HPX_HAVE_STATIC_PRIORITY_SCHEDULER) | ||
template <> | ||
struct is_executor<this_thread_static_priority_queue_executor> | ||
: std::true_type | ||
{}; | ||
#endif | ||
/// \endcond | ||
} | ||
}}} | ||
|
||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright (c) 2007-2015 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) | ||
|
||
#if !defined(HPX_RUNTIME_THREADS_DETAIL_THREAD_NUM_TSS_JUL_17_2015_0811PM) | ||
#define HPX_RUNTIME_THREADS_DETAIL_THREAD_NUM_TSS_JUL_17_2015_0811PM | ||
|
||
#include <hpx/config.hpp> | ||
#include <hpx/util/thread_specific_ptr.hpp> | ||
|
||
#include <cstdarg> | ||
|
||
namespace hpx { namespace threads { namespace detail | ||
{ | ||
/////////////////////////////////////////////////////////////////////////// | ||
class thread_num_tss | ||
{ | ||
public: | ||
std::size_t set_tss_threadnum(std::size_t num); | ||
void init_tss(std::size_t num); | ||
void deinit_tss(); | ||
|
||
std::size_t get_worker_thread_num() const; | ||
|
||
private: | ||
// the TSS holds the number associated with a given OS thread | ||
struct tls_tag {}; | ||
static hpx::util::thread_specific_ptr<std::size_t, tls_tag> thread_num_; | ||
}; | ||
|
||
// the TSS holds the number associated with a given OS thread | ||
extern thread_num_tss thread_num_tss_; | ||
|
||
/////////////////////////////////////////////////////////////////////////// | ||
struct reset_tss_helper | ||
{ | ||
reset_tss_helper(std::size_t thread_num) | ||
: thread_num_(thread_num_tss_.set_tss_threadnum(thread_num)) | ||
{} | ||
|
||
~reset_tss_helper() | ||
{ | ||
thread_num_tss_.set_tss_threadnum(thread_num_); | ||
} | ||
|
||
std::size_t previous_thread_num() const | ||
{ | ||
return thread_num_; | ||
} | ||
|
||
private: | ||
std::size_t thread_num_; | ||
}; | ||
}}} | ||
|
||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright (c) 2015 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) | ||
|
||
#if !defined(HPX_RUNTIME_THREADS_EXECUTORS_MANAGE_THREAD_EXECUTOR_JUL_16_2015_0745PM) | ||
#define HPX_RUNTIME_THREADS_EXECUTORS_MANAGE_THREAD_EXECUTOR_JUL_16_2015_0745PM | ||
|
||
#include <hpx/config.hpp> | ||
#include <hpx/error.hpp> | ||
#include <hpx/runtime/threads/thread_executor.hpp> | ||
|
||
#include <cstdarg> | ||
|
||
namespace hpx { namespace threads { namespace executors { namespace detail | ||
{ | ||
/////////////////////////////////////////////////////////////////////////// | ||
template <typename ExecutorImpl> | ||
class manage_thread_executor | ||
: public threads::detail::manage_executor | ||
{ | ||
public: | ||
manage_thread_executor(ExecutorImpl& sched) | ||
: sched_(sched) | ||
{} | ||
|
||
protected: | ||
// Return the requested policy element. | ||
std::size_t get_policy_element(threads::detail::executor_parameter p, | ||
error_code& ec) const | ||
{ | ||
return sched_.get_policy_element(p, ec); | ||
} | ||
|
||
// Return statistics collected by this scheduler | ||
void get_statistics(executor_statistics& stats, error_code& ec) const | ||
{ | ||
sched_.get_statistics(stats, ec); | ||
} | ||
|
||
// Provide the given processing unit to the scheduler. | ||
void add_processing_unit(std::size_t virt_core, std::size_t thread_num, | ||
error_code& ec) | ||
{ | ||
sched_.add_processing_unit(virt_core, thread_num, ec); | ||
} | ||
|
||
// Remove the given processing unit from the scheduler. | ||
void remove_processing_unit(std::size_t thread_num, error_code& ec) | ||
{ | ||
sched_.remove_processing_unit(thread_num, ec); | ||
} | ||
|
||
private: | ||
ExecutorImpl& sched_; | ||
}; | ||
}}}} | ||
|
||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are the pending closures really the number of OS threads? wouldn't this rather return
false
for stateless executors?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, that's a bug (copy&paste problem).