Skip to content

Commit

Permalink
Various minor changes to support FLeCSI
Browse files Browse the repository at this point in the history
- adding more constructors to resource::partitioner (aligned with hpx::init)
- adding hpx::parallel::execution::pool_executor alias (for consistency)
- adding default constructor for pool-executor
- adding support to request minimal number of cores (threads) (hpx.force_min_os_threads)
  • Loading branch information
hkaiser committed Feb 17, 2018
1 parent d4e461f commit 17a0ba8
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 33 deletions.
3 changes: 2 additions & 1 deletion hpx/include/thread_executors.hpp
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2015 Hartmut Kaiser
// Copyright (c) 2007-2018 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 All @@ -8,6 +8,7 @@

#include <hpx/runtime/threads/executors/current_executor.hpp>
#include <hpx/runtime/threads/executors/default_executor.hpp>
#include <hpx/runtime/threads/executors/pool_executor.hpp>
#include <hpx/runtime/threads/executors/service_executors.hpp>
#include <hpx/runtime/threads/executors/thread_pool_executors.hpp>
#include <hpx/runtime/threads/executors/thread_pool_os_executors.hpp>
Expand Down
1 change: 1 addition & 0 deletions hpx/parallel/executors.hpp
Expand Up @@ -22,6 +22,7 @@
#include <hpx/parallel/executors/default_executor.hpp>
#include <hpx/parallel/executors/distribution_policy_executor.hpp>
#include <hpx/parallel/executors/parallel_executor.hpp>
#include <hpx/parallel/executors/pool_executor.hpp>
#include <hpx/parallel/executors/sequenced_executor.hpp>
#include <hpx/parallel/executors/service_executors.hpp>
#include <hpx/parallel/executors/this_thread_executors.hpp>
Expand Down
24 changes: 24 additions & 0 deletions hpx/parallel/executors/pool_executor.hpp
@@ -0,0 +1,24 @@
// Copyright (c) 2007-2018 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/pool_executor.hpp

#if !defined(HPX_PARALLEL_EXECUTORS_POOL_EXECUTOR_FEB_17_2018_0327PM)
#define HPX_PARALLEL_EXECUTORS_POOL_EXECUTOR_FEB_17_2018_0327PM

#include <hpx/config.hpp>
#include <hpx/parallel/executors/execution_parameters.hpp>
#include <hpx/parallel/executors/thread_execution.hpp>
#include <hpx/parallel/executors/thread_execution_information.hpp>
#include <hpx/parallel/executors/thread_timed_execution.hpp>
#include <hpx/runtime/threads/executors/pool_executor.hpp>

namespace hpx { namespace parallel { namespace execution
{
///////////////////////////////////////////////////////////////////////////
using pool_executor = threads::executors::pool_executor;
}}}

#endif
38 changes: 38 additions & 0 deletions hpx/runtime/resource/detail/create_partitioner.hpp
Expand Up @@ -10,6 +10,7 @@
#include <hpx/runtime/resource/partitioner_fwd.hpp>
#include <hpx/runtime/runtime_mode.hpp>
#include <hpx/util/find_prefix.hpp>
#include <hpx/util/function.hpp>

#include <boost/program_options.hpp>

Expand All @@ -24,6 +25,13 @@ int hpx_main(boost::program_options::variables_map& vm);
typedef int (*hpx_main_type)(boost::program_options::variables_map&);
#endif

namespace hpx { namespace detail
{
HPX_EXPORT int init_helper(
boost::program_options::variables_map&,
util::function_nonser<int(int, char**)> const&);
}}

namespace hpx { namespace resource { namespace detail
{
// if the resource partitioner is accessed before the HPX runtime has started
Expand Down Expand Up @@ -56,6 +64,36 @@ namespace hpx { namespace resource { namespace detail
rpmode, mode, check);
}

inline partitioner& create_partitioner(
util::function_nonser<int(int, char**)> const& f, int argc, char** argv,
resource::partitioner_mode rpmode = resource::mode_default,
hpx::runtime_mode mode = hpx::runtime_mode_default, bool check = true)
{
boost::program_options::options_description desc_cmdline(
std::string("Usage: ") + HPX_APPLICATION_STRING + " [options]");

util::set_hpx_prefix(HPX_PREFIX);

return create_partitioner(util::bind_back(hpx::detail::init_helper, f),
desc_cmdline, argc, argv, std::vector<std::string>(), rpmode, mode,
check);
}

inline partitioner& create_partitioner(
util::function_nonser<int(int, char**)> const& f, int argc, char** argv,
std::vector<std::string> const& cfg,
resource::partitioner_mode rpmode = resource::mode_default,
hpx::runtime_mode mode = hpx::runtime_mode_default, bool check = true)
{
boost::program_options::options_description desc_cmdline(
std::string("Usage: ") + HPX_APPLICATION_STRING + " [options]");

util::set_hpx_prefix(HPX_PREFIX);

return create_partitioner(util::bind_back(hpx::detail::init_helper, f),
desc_cmdline, argc, argv, cfg, rpmode, mode, check);
}

inline partitioner &create_partitioner(
int argc, char **argv, std::vector<std::string> ini_config,
resource::partitioner_mode rpmode = resource::mode_default,
Expand Down
16 changes: 16 additions & 0 deletions hpx/runtime/resource/partitioner.hpp
Expand Up @@ -141,6 +141,22 @@ namespace hpx { namespace resource
{}

#if !defined(HPX_EXPORTS)
partitioner(util::function_nonser<int(int, char**)> const& f,
int argc, char** argv,
resource::partitioner_mode rpmode = resource::mode_default,
hpx::runtime_mode mode = hpx::runtime_mode_default)
: partitioner_(
detail::create_partitioner(f, argc, argv, rpmode, mode))
{}

partitioner(util::function_nonser<int(int, char**)> const& f,
int argc, char** argv, std::vector<std::string> const& cfg,
resource::partitioner_mode rpmode = resource::mode_default,
hpx::runtime_mode mode = hpx::runtime_mode_default)
: partitioner_(
detail::create_partitioner(f, argc, argv, cfg, rpmode, mode))
{}

partitioner(int argc, char** argv,
resource::partitioner_mode rpmode = resource::mode_default,
runtime_mode mode = runtime_mode_default)
Expand Down
8 changes: 5 additions & 3 deletions hpx/runtime/threads/executors/pool_executor.hpp
Expand Up @@ -95,12 +95,14 @@ namespace hpx { namespace threads { namespace executors
///////////////////////////////////////////////////////////////////////
struct HPX_EXPORT pool_executor : public scheduled_executor
{
pool_executor(const std::string& pool_name);
pool_executor() = default;

pool_executor(const std::string& pool_name,
pool_executor(std::string const& pool_name);

pool_executor(std::string const& pool_name,
thread_stacksize stacksize);

pool_executor(const std::string& pool_name,
pool_executor(std::string const& pool_name,
thread_priority priority,
thread_stacksize stacksize = thread_stacksize_default);
};
Expand Down
57 changes: 28 additions & 29 deletions src/runtime/threads/executors/pool_executor.cpp
Expand Up @@ -18,26 +18,25 @@ namespace hpx { namespace threads { namespace executors
{
namespace detail
{
pool_executor::pool_executor(
std::string const& pool_name)
: pool_(hpx::threads::get_thread_manager().get_pool(pool_name))
, stacksize_(thread_stacksize_default)
, priority_(thread_priority_default)
pool_executor::pool_executor(std::string const& pool_name)
: pool_(hpx::threads::get_thread_manager().get_pool(pool_name))
, stacksize_(thread_stacksize_default)
, priority_(thread_priority_default)
{}

pool_executor::pool_executor(const std::string& pool_name,
thread_stacksize stacksize)
: pool_(hpx::threads::get_thread_manager().get_pool(pool_name))
, stacksize_(stacksize)
, priority_(thread_priority_default)
pool_executor::pool_executor(std::string const& pool_name,
thread_stacksize stacksize)
: pool_(hpx::threads::get_thread_manager().get_pool(pool_name))
, stacksize_(stacksize)
, priority_(thread_priority_default)
{}

pool_executor::pool_executor(const std::string& pool_name,
thread_priority priority, thread_stacksize stacksize)
: pool_(hpx::threads::get_thread_manager().get_pool(pool_name))
, stacksize_(stacksize)
, priority_(priority)
{}
pool_executor::pool_executor(std::string const& pool_name,
thread_priority priority, thread_stacksize stacksize)
: pool_(hpx::threads::get_thread_manager().get_pool(pool_name))
, stacksize_(stacksize)
, priority_(priority)
{}

threads::thread_result_type
pool_executor::thread_function_nullary(closure_type func)
Expand Down Expand Up @@ -164,21 +163,21 @@ namespace hpx { namespace threads { namespace executors

namespace hpx { namespace threads { namespace executors
{
pool_executor::pool_executor(
const std::string& pool_name)
: scheduled_executor(new detail::pool_executor(pool_name))
{}
pool_executor::pool_executor(std::string const& pool_name)
: scheduled_executor(new detail::pool_executor(pool_name))
{
}

pool_executor::pool_executor(const std::string& pool_name,
pool_executor::pool_executor(std::string const& pool_name,
thread_stacksize stacksize)
: scheduled_executor(new detail::pool_executor(pool_name, stacksize))
{}
: scheduled_executor(new detail::pool_executor(pool_name, stacksize))
{
}

pool_executor::pool_executor(const std::string& pool_name,
pool_executor::pool_executor(std::string const& pool_name,
thread_priority priority, thread_stacksize stacksize)
: scheduled_executor(
new detail::pool_executor(pool_name, priority, stacksize))
{}


: scheduled_executor(
new detail::pool_executor(pool_name, priority, stacksize))
{
}
}}}
24 changes: 24 additions & 0 deletions src/util/command_line_handling.cpp
Expand Up @@ -352,6 +352,30 @@ namespace hpx { namespace util
#endif
}

// make sure minimal requested number of threads is observed
std::size_t min_os_threads = cfgmap.get_value<std::size_t>(
"hpx.force_min_os_threads", threads);

if (min_os_threads == 0)
{
throw hpx::detail::command_line_error(
"Number of hpx.force_min_os_threads must be greater than "
"0");
}

#if defined(HPX_HAVE_MAX_CPU_COUNT)
if (min_os_threads > HPX_HAVE_MAX_CPU_COUNT)
{
throw hpx::detail::command_line_error("Requested more than "
HPX_PP_STRINGIZE(HPX_HAVE_MAX_CPU_COUNT)
" hpx.force_min_os_threads "
"to use for this application, use the option "
"-DHPX_WITH_MAX_CPU_COUNT=<N> when configuring HPX.");
}
#endif

threads = (std::max)(threads, min_os_threads);

if (!initial && env.found_batch_environment() &&
using_nodelist && (threads > batch_threads))
{
Expand Down

0 comments on commit 17a0ba8

Please sign in to comment.