Skip to content

Commit

Permalink
Refactoring resource partitioner code
Browse files Browse the repository at this point in the history
- Reduced exposed user interface, changed creation of RP in user-code
- shuffled things around, etc.
  • Loading branch information
hkaiser committed Aug 10, 2017
1 parent 466cc16 commit a5296f2
Show file tree
Hide file tree
Showing 34 changed files with 1,179 additions and 872 deletions.
Expand Up @@ -9,7 +9,7 @@
#include <hpx/parallel/algorithms/for_loop.hpp>
#include <hpx/parallel/executors.hpp>
//
#include <hpx/runtime/resource_partitioner.hpp>
#include <hpx/runtime/resource/partitioner.hpp>
#include <hpx/runtime/threads/cpu_mask.hpp>
#include <hpx/runtime/threads/executors/customized_pool_executors.hpp>
#include <hpx/runtime/threads/detail/scheduled_thread_pool_impl.hpp>
Expand Down Expand Up @@ -104,14 +104,10 @@ int hpx_main(boost::program_options::variables_map& vm)
mpi_executor = high_priority_executor;
}

// get a pointer to the resource_partitioner instance
hpx::resource::resource_partitioner& rpart =
hpx::get_resource_partitioner();

// print partition characteristics
std::cout << "\n\n[hpx_main] print resource_partitioner characteristics : "
<< "\n";
rpart.print_init_pool_data(std::cout);
hpx::resource::get_partitioner().print_init_pool_data(std::cout);

// print partition characteristics
std::cout << "\n\n[hpx_main] print thread-manager pools : "
Expand Down Expand Up @@ -267,7 +263,7 @@ int main(int argc, char* argv[])

pool_threads = vm["pool-threads"].as<int>();

auto& rp = hpx::get_resource_partitioner(desc_cmdline, argc, argv,
hpx::resource::partitioner rp(desc_cmdline, argc, argv,
hpx::resource::mode_allow_oversubscription);

// auto &topo = rp.get_topology();
Expand Down
15 changes: 6 additions & 9 deletions examples/resource_partitioner/simple_resource_partitioner.cpp
Expand Up @@ -9,10 +9,10 @@
#include <hpx/parallel/algorithms/for_loop.hpp>
#include <hpx/parallel/executors.hpp>
//
#include <hpx/runtime/resource_partitioner.hpp>
#include <hpx/runtime/resource/partitioner.hpp>
#include <hpx/runtime/threads/cpu_mask.hpp>
#include <hpx/runtime/threads/executors/customized_pool_executors.hpp>
#include <hpx/runtime/threads/detail/scheduled_thread_pool_impl.hpp>
#include <hpx/runtime/threads/executors/customized_pool_executors.hpp>
//
#include <hpx/include/iostreams.hpp>
#include <hpx/include/runtime.hpp>
Expand Down Expand Up @@ -104,14 +104,10 @@ int hpx_main(boost::program_options::variables_map& vm)
mpi_executor = high_priority_executor;
}

// get a pointer to the resource_partitioner instance
hpx::resource::resource_partitioner& rpart =
hpx::get_resource_partitioner();

// print partition characteristics
std::cout << "\n\n[hpx_main] print resource_partitioner characteristics : "
<< "\n";
rpart.print_init_pool_data(std::cout);
hpx::resource::get_partitioner().print_init_pool_data(std::cout);

// print partition characteristics
std::cout << "\n\n[hpx_main] print thread-manager pools : "
Expand Down Expand Up @@ -267,7 +263,8 @@ int main(int argc, char* argv[])

pool_threads = vm["pool-threads"].as<int>();

auto& rp = hpx::get_resource_partitioner(desc_cmdline, argc, argv);
// Create the resource partitioner
hpx::resource::partitioner rp(desc_cmdline, argc, argv);

// auto &topo = rp.get_topology();
std::cout << "[main] obtained reference to the resource_partitioner\n";
Expand Down Expand Up @@ -350,5 +347,5 @@ int main(int argc, char* argv[])
std::cout << "[main] resources added to thread_pools \n";
}

return hpx::init(desc_cmdline, argc, argv);
return hpx::init();
}
4 changes: 0 additions & 4 deletions hpx/runtime.hpp
Expand Up @@ -23,7 +23,6 @@
#include <hpx/util/runtime_configuration.hpp>
#include <hpx/util/static_reinit.hpp>
#include <hpx/util/thread_specific_ptr.hpp>
#include <hpx/runtime/resource_partitioner.hpp>

#include <boost/atomic.hpp>
#include <boost/smart_ptr/scoped_ptr.hpp>
Expand Down Expand Up @@ -337,9 +336,6 @@ namespace hpx
// registered with the library
boost::scoped_ptr<util::thread_mapper> thread_support_;

// pointer to the resource_partitioner
resource::resource_partitioner* resource_partitioner_;

// topology and affinity data
threads::topology& topology_;

Expand Down
92 changes: 92 additions & 0 deletions hpx/runtime/resource/detail/create_partitioner.hpp
@@ -0,0 +1,92 @@
// Copyright (c) 2017 Shoshana Jakobovits
//
// 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_DETAIL_CREATE_PARTITIONER_AUG_10_2017_1116AM)
#define HPX_DETAIL_CREATE_PARTITIONER_AUG_10_2017_1116AM

#include <hpx/config.hpp>
#include <hpx/runtime/resource/partitioner_fwd.hpp>
#include <hpx/runtime/runtime_mode.hpp>

#include <boost/program_options.hpp>

#include <cstddef>
#include <string>
#include <vector>

#if !defined(HPX_EXPORTS)
// This function must be implemented by the application.
int hpx_main(boost::program_options::variables_map& vm);
typedef int (*hpx_main_type)(boost::program_options::variables_map&);
#endif

namespace hpx { namespace resource { namespace detail
{
// if the resource partitioner is accessed before the HPX runtime has started
// 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.
HPX_EXPORT partitioner& create_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,
resource::partitioner_mode rpmode = resource::mode_default,
runtime_mode mode = runtime_mode_default,
bool check = true);

#if !defined(HPX_EXPORTS)
inline partitioner& create_partitioner(
int argc, char** argv,
resource::partitioner_mode rpmode = resource::mode_default,
runtime_mode mode = runtime_mode_default, bool check = true)
{
boost::program_options::options_description desc_cmdline(
std::string("Usage: ") + HPX_APPLICATION_STRING + " [options]");

return create_partitioner(static_cast<hpx_main_type>(::hpx_main),
desc_cmdline, argc, argv, std::vector<std::string>(),
rpmode, mode, check);
}

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

return create_partitioner(static_cast<hpx_main_type>(::hpx_main),
desc_cmdline, argc, argv, std::move(ini_config),
rpmode, mode, check);
}

///////////////////////////////////////////////////////////////////////////////
inline partitioner &create_partitioner(
boost::program_options::options_description const& desc_cmdline,
int argc, char **argv,
resource::partitioner_mode rpmode = resource::mode_default,
runtime_mode mode = runtime_mode_default, bool check = true)
{
return create_partitioner(static_cast<hpx_main_type>(::hpx_main),
desc_cmdline, argc, argv, std::vector<std::string>(),
rpmode, mode, check);
}

inline partitioner &create_partitioner(
boost::program_options::options_description const& desc_cmdline,
int argc, char **argv, std::vector<std::string> ini_config,
resource::partitioner_mode rpmode = resource::mode_default,
runtime_mode mode = runtime_mode_default, bool check = true)
{
return create_partitioner(static_cast<hpx_main_type>(::hpx_main),
desc_cmdline, argc, argv, ini_config, rpmode, mode, check);
}
#endif
}}}

#endif

0 comments on commit a5296f2

Please sign in to comment.