Skip to content

Commit

Permalink
Fix running hpx_main only on locality 0 by default
Browse files Browse the repository at this point in the history
  • Loading branch information
hkaiser committed Aug 4, 2017
1 parent 75a2218 commit f54f94c
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 116 deletions.
114 changes: 87 additions & 27 deletions hpx/runtime/resource_partitioner.hpp
Expand Up @@ -15,14 +15,15 @@
#include <hpx/runtime/threads/threadmanager.hpp>
#include <hpx/runtime/threads/topology.hpp>
#include <hpx/util/command_line_handling.hpp>
#include <hpx/util/function.hpp>
#include <hpx/util/thread_specific_ptr.hpp>
//
#include <hpx/runtime/threads/detail/thread_pool_base.hpp>
#include <hpx/runtime/threads/policies/callback_notifier.hpp>
#include <hpx/runtime/threads/policies/scheduler_mode.hpp>

#include <boost/atomic.hpp>
#include <boost/format.hpp>
#include <boost/program_options.hpp>

#include <algorithm>
#include <cstddef>
Expand All @@ -32,6 +33,11 @@
#include <string>
#include <vector>

///////////////////////////////////////////////////////////////////////////////
// One of these functions must be implemented by the application for the
// console locality.
int hpx_main(boost::program_options::variables_map& vm);

namespace hpx {

namespace resource {
Expand All @@ -42,33 +48,86 @@ namespace resource {
// then on first access, this function should be used, to ensure that command line
// affinity binding options are honored. Use this function signature only once
// and thereafter use the parameter free version.
extern HPX_EXPORT resource::resource_partitioner& get_resource_partitioner(
int argc, char** argv);
extern HPX_EXPORT resource::resource_partitioner& get_resource_partitioner(
boost::program_options::options_description desc_cmdline, int argc,
char** argv, bool check = true);
extern HPX_EXPORT resource::resource_partitioner& get_resource_partitioner(
int argc, char** argv, std::vector<std::string> ini_config);
extern HPX_EXPORT resource::resource_partitioner& get_resource_partitioner(
int argc, char** argv, runtime_mode mode);
extern HPX_EXPORT resource::resource_partitioner& get_resource_partitioner(
boost::program_options::options_description desc_cmdline, int argc,
char** argv, std::vector<std::string> ini_config);
extern HPX_EXPORT resource::resource_partitioner& get_resource_partitioner(
boost::program_options::options_description desc_cmdline, int argc,
char** argv, runtime_mode mode);
extern HPX_EXPORT resource::resource_partitioner& get_resource_partitioner(
int argc, char** argv, std::vector<std::string> ini_config,
runtime_mode mode);
extern HPX_EXPORT resource::resource_partitioner& get_resource_partitioner(
boost::program_options::options_description desc_cmdline, int argc,
HPX_EXPORT resource::resource_partitioner& get_resource_partitioner(
util::function_nonser<
int(boost::program_options::variables_map& vm)
> const& f,
boost::program_options::options_description const& desc_cmdline, int argc,
char** argv, std::vector<std::string> ini_config, runtime_mode mode,
bool check = true);

#if !defined(HPX_EXPORTS)
inline resource::resource_partitioner& get_resource_partitioner(
int argc, char** argv)
{
boost::program_options::options_description desc_cmdline(
std::string("Usage: ") + HPX_APPLICATION_STRING + " [options]");

return get_resource_partitioner(static_cast<hpx_main_type>(::hpx_main),
desc_cmdline, argc, argv, std::vector<std::string>(),
runtime_mode_default);
}

inline resource::resource_partitioner &get_resource_partitioner(
boost::program_options::options_description const& desc_cmdline, int argc,
char **argv, bool check = true)
{
return get_resource_partitioner(static_cast<hpx_main_type>(::hpx_main),
desc_cmdline, argc, argv, std::vector<std::string>(),
runtime_mode_default, check);
}

inline resource::resource_partitioner &get_resource_partitioner(
int argc, char **argv, std::vector<std::string> ini_config)
{
boost::program_options::options_description desc_cmdline(
std::string("Usage: ") + HPX_APPLICATION_STRING + " [options]");

return get_resource_partitioner(static_cast<hpx_main_type>(::hpx_main),
desc_cmdline, argc, argv, std::move(ini_config), runtime_mode_default);
}

inline resource::resource_partitioner &get_resource_partitioner(
int argc, char **argv, runtime_mode mode)
{
boost::program_options::options_description desc_cmdline(
std::string("Usage: ") + HPX_APPLICATION_STRING + " [options]");

return get_resource_partitioner(static_cast<hpx_main_type>(::hpx_main),
desc_cmdline, argc, argv, std::vector<std::string>(0), mode);
}

inline resource::resource_partitioner &get_resource_partitioner(
boost::program_options::options_description const& desc_cmdline, int argc,
char **argv, std::vector<std::string> ini_config)
{
return get_resource_partitioner(static_cast<hpx_main_type>(::hpx_main),
desc_cmdline, argc, argv, std::move(ini_config), runtime_mode_default);
}

inline resource::resource_partitioner &get_resource_partitioner(
boost::program_options::options_description const& desc_cmdline, int argc,
char **argv, runtime_mode mode)
{
return get_resource_partitioner(static_cast<hpx_main_type>(::hpx_main),
desc_cmdline, argc, argv, std::vector<std::string>(), mode);
}

inline resource::resource_partitioner& get_resource_partitioner(int argc,
char** argv, std::vector<std::string> ini_config, runtime_mode mode)
{
boost::program_options::options_description desc_cmdline(
std::string("Usage: ") + HPX_APPLICATION_STRING + " [options]");

return get_resource_partitioner(static_cast<hpx_main_type>(::hpx_main),
desc_cmdline, argc, argv, std::move(ini_config), mode);
}
#endif

///////////////////////////////////////////////////////////////////////////////
// may be used anywhere in code and returns a reference to the
// single, global resource partitioner
extern HPX_EXPORT hpx::resource::resource_partitioner&
get_resource_partitioner();
HPX_EXPORT hpx::resource::resource_partitioner& get_resource_partitioner();

namespace resource {

Expand Down Expand Up @@ -204,9 +263,6 @@ namespace resource {
// but rather get_resource_partitioner
resource_partitioner();

void set_hpx_init_options(util::function_nonser<int(
boost::program_options::variables_map &vm)> const &f);

int call_cmd_line_options(
boost::program_options::options_description const &desc_cmdline,
int argc, char **argv);
Expand Down Expand Up @@ -293,7 +349,11 @@ namespace resource {
threads::mask_cref_type get_pu_mask(std::size_t num_thread) const;

bool cmd_line_parsed() const;
int parse(boost::program_options::options_description desc_cmdline,
int parse(
util::function_nonser<
int(boost::program_options::variables_map& vm)
> const& f,
boost::program_options::options_description desc_cmdline,
int argc, char **argv, std::vector<std::string> ini_config,
runtime_mode mode, bool fill_internal_topology = true);

Expand Down
11 changes: 3 additions & 8 deletions src/hpx_init.cpp
Expand Up @@ -577,9 +577,8 @@ namespace hpx
> const& f,
boost::program_options::options_description const& desc_cmdline,
int argc, char** argv, std::vector<std::string> && ini_config,
startup_function_type startup,
shutdown_function_type shutdown, hpx::runtime_mode mode,
bool blocking)
startup_function_type startup, shutdown_function_type shutdown,
hpx::runtime_mode mode, bool blocking)
{
#if !defined(HPX_HAVE_DISABLED_SIGNAL_EXCEPTION_HANDLERS)
set_error_handlers();
Expand Down Expand Up @@ -615,13 +614,9 @@ namespace hpx
// Construct resource partitioner if this has not been done yet
// and get a handle to it
// (if the command-line parsing has not yet been done, do it now)
auto& rp = hpx::get_resource_partitioner(desc_cmdline, argc,
auto& rp = hpx::get_resource_partitioner(f, desc_cmdline, argc,
argv, std::move(ini_config), mode, false);

// give the command_line_handling object the options the user
// may have passed as arguments of hpx_init(...)
rp.set_hpx_init_options(f);

// check whether HPX should be exited at this point
// (if the program options contain --hpx:help or --hpx:version)
if (rp.terminate_after_parse())
Expand Down
96 changes: 15 additions & 81 deletions src/runtime/resource_partitioner.cpp
Expand Up @@ -8,11 +8,15 @@
#include <hpx/runtime/thread_pool_helpers.hpp>
#include <hpx/runtime/threads/cpu_mask.hpp>
#include <hpx/runtime/threads/thread_data_fwd.hpp>
#include <hpx/util/function.hpp>
#include <hpx/util/static.hpp>

#include <boost/atomic.hpp>
#include <boost/program_options.hpp>

#include <cstddef>
#include <iosfwd>
#include <stdexcept>
#include <string>
#include <vector>
#include <utility>
Expand All @@ -39,79 +43,11 @@ resource::resource_partitioner &get_resource_partitioner()
return rp.get();
}

resource::resource_partitioner &get_resource_partitioner(int argc, char **argv)
{
using boost::program_options::options_description;

options_description desc_cmdline(
std::string("Usage: ") + HPX_APPLICATION_STRING + " [options]");

return get_resource_partitioner(desc_cmdline, argc, argv,
std::vector<std::string>(0), runtime_mode_default);
}

resource::resource_partitioner &get_resource_partitioner(
boost::program_options::options_description desc_cmdline, int argc,
char **argv, bool check)
{
return get_resource_partitioner(desc_cmdline, argc, argv,
std::vector<std::string>(0), runtime_mode_default, check);
}

resource::resource_partitioner &get_resource_partitioner(
int argc, char **argv, std::vector<std::string> ini_config)
{
using boost::program_options::options_description;

options_description desc_cmdline(
std::string("Usage: ") + HPX_APPLICATION_STRING + " [options]");

return get_resource_partitioner(
desc_cmdline, argc, argv, std::move(ini_config), runtime_mode_default);
}

resource::resource_partitioner &get_resource_partitioner(
int argc, char **argv, runtime_mode mode)
{
using boost::program_options::options_description;

options_description desc_cmdline(
std::string("Usage: ") + HPX_APPLICATION_STRING + " [options]");

return get_resource_partitioner(
desc_cmdline, argc, argv, std::vector<std::string>(0), mode);
}

resource::resource_partitioner &get_resource_partitioner(
boost::program_options::options_description desc_cmdline, int argc,
char **argv, std::vector<std::string> ini_config)
{
return get_resource_partitioner(
desc_cmdline, argc, argv, std::move(ini_config), runtime_mode_default);
}

resource::resource_partitioner &get_resource_partitioner(
boost::program_options::options_description desc_cmdline, int argc,
char **argv, runtime_mode mode)
{
return get_resource_partitioner(
desc_cmdline, argc, argv, std::vector<std::string>(0), mode);
}

resource::resource_partitioner &get_resource_partitioner(int argc, char **argv,
std::vector<std::string> ini_config, runtime_mode mode)
{
using boost::program_options::options_description;

options_description desc_cmdline(
std::string("Usage: ") + HPX_APPLICATION_STRING + " [options]");

return get_resource_partitioner(
desc_cmdline, argc, argv, std::move(ini_config), mode);
}

resource::resource_partitioner &get_resource_partitioner(
boost::program_options::options_description desc_cmdline, int argc,
util::function_nonser<
int(boost::program_options::variables_map& vm)
> const& f,
boost::program_options::options_description const& desc_cmdline, int argc,
char **argv, std::vector<std::string> ini_config, runtime_mode mode,
bool check)
{
Expand All @@ -132,7 +68,7 @@ resource::resource_partitioner &get_resource_partitioner(
}
else
{
rp.parse(desc_cmdline, argc, argv, std::move(ini_config), mode);
rp.parse(f, desc_cmdline, argc, argv, std::move(ini_config), mode);
}
return rp;
}
Expand Down Expand Up @@ -339,12 +275,6 @@ namespace resource {
return cores_needed_;
}

void resource_partitioner::set_hpx_init_options(util::function_nonser<int(
boost::program_options::variables_map &vm)> const &f)
{
cfg_.hpx_main_f_ = f;
}

int resource_partitioner::call_cmd_line_options(
boost::program_options::options_description const &desc_cmdline,
int argc, char **argv)
Expand Down Expand Up @@ -569,7 +499,7 @@ namespace resource {

for (std::size_t i = 0; i != num_thread_pools; i++)
{
if (initial_thread_pools_[i].assigned_pus_.size() == 0)
if (initial_thread_pools_[i].assigned_pus_.empty())
{
return false;
}
Expand Down Expand Up @@ -844,13 +774,17 @@ namespace resource {
}

int resource_partitioner::parse(
util::function_nonser<
int(boost::program_options::variables_map& vm)
> const& f,
boost::program_options::options_description desc_cmdline, int argc,
char **argv, std::vector<std::string> ini_config, runtime_mode mode,
bool fill_internal_topology)
{
// set internal parameters of runtime configuration
cfg_.rtcfg_ = util::runtime_configuration(argv[0], mode);
cfg_.ini_config_ = std::move(ini_config);
cfg_.hpx_main_f_ = f;

// parse command line and set options
// terminate set if program options contain --hpx:help or --hpx:version ...
Expand All @@ -861,7 +795,7 @@ namespace resource {

if (fill_internal_topology)
{
// set data describing internal topology backend
// set data describing internal topology back-end
fill_topology_vectors();
}

Expand Down

0 comments on commit f54f94c

Please sign in to comment.