Skip to content

Commit

Permalink
Fixed #973: Would like option to report hwloc bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
sithhell committed Oct 29, 2013
1 parent 2bbd6a5 commit 9a099e8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 93 deletions.
4 changes: 0 additions & 4 deletions hpx/runtime/threads/topology.hpp
Expand Up @@ -372,10 +372,6 @@ namespace hpx { namespace threads
std::vector<std::size_t> num_pus;
parse_affinity_options(spec, affinities, 1, 1, num_pus, ec);
}

HPX_API_EXPORT void print_affinity_options(std::ostream& s,
std::size_t num_threads, std::string const& affinity_options,
error_code& ec = throws);
#endif

/// \endcond
Expand Down
27 changes: 0 additions & 27 deletions src/runtime/threads/policies/parse_affinity_options.cpp
Expand Up @@ -770,33 +770,6 @@ namespace hpx { namespace threads
break;
}
}

///////////////////////////////////////////////////////////////////////////
void print_affinity_options(std::ostream& os, std::size_t num_threads,
std::string const& affinity_options, error_code& ec)
{
util::osstream strm; // make sure all ouput is kept together

strm << std::string(79, '*') << '\n';
strm << "locality: " << hpx::get_locality_id() << '\n';

std::vector<mask_type> affinities(num_threads);
std::vector<std::size_t> num_pus;
std::size_t used_cores = get_runtime().get_config().get_used_cores();
std::size_t max_cores = boost::lexical_cast<std::size_t>(get_runtime().get_config().get_entry("hpx.cores", used_cores));
parse_affinity_options(affinity_options, affinities, used_cores, max_cores, num_pus, ec);
if (ec) return;

threads::hwloc_topology& topo = threads::create_topology();

int i = 0;
BOOST_FOREACH(mask_type const& m, affinities)
{
topo.print_affinity_mask(strm, i++, m);
}

os << util::osstream_get_string(strm);
}
}}

#endif
73 changes: 11 additions & 62 deletions src/util/command_line_handling.cpp
Expand Up @@ -698,72 +698,21 @@ namespace hpx { namespace util
void handle_print_bind(boost::program_options::variables_map const& vm_,
std::size_t num_threads)
{
if (!vm_.count("hpx:bind")) {
std::size_t num_threads = 1;
if (vm_.count("hpx:threads")) {
std::string threads = vm_["hpx:threads"].as<std::string>();
if (threads == "all")
num_threads = threads::hardware_concurrency();
else
num_threads = boost::lexical_cast<std::size_t>(threads);
}

std::size_t pu_offset = 0;
if (vm_.count("hpx:pu-offset"))
pu_offset = vm_["hpx:pu-offset"].as<std::size_t>();

std::size_t pu_step = 1;
if (vm_.count("hpx:pu-step"))
pu_step = vm_["hpx:pu-step"].as<std::size_t>();

std::string affinity_domain;
if (vm_.count("hpx:affinity")) {
affinity_domain = vm_["hpx:affinity"].as<std::string>();
if (0 != std::string("pu").find(affinity_domain) &&
0 != std::string("core").find(affinity_domain) &&
0 != std::string("numa").find(affinity_domain) &&
0 != std::string("machine").find(affinity_domain))
{
throw std::logic_error("Invalid command line option "
"--hpx:affinity, value must be one of: pu, core, numa, "
"or machine.");
}
}

threads::policies::init_affinity_data init_data(pu_offset,
pu_step, affinity_domain);
init_data.used_cores_ = get_runtime().get_config().get_used_cores();
threads::policies::detail::affinity_data aff(num_threads);
threads::topology& top = threads::create_topology();
aff.init(init_data, top);

bool numa_sensitive = vm_.count("hpx:numa-sensitive") != 0;
{
util::osstream strm; // make sure all ouput is kept together

strm << std::string(79, '*') << '\n';
strm << "locality: " << hpx::get_locality_id() << '\n';
for (std::size_t i = 0; i != num_threads; ++i)
{
top.print_affinity_mask(strm, i, aff.get_pu_mask(top, i, numa_sensitive));
}
threads::topology& top = threads::create_topology();
runtime & rt = get_runtime();
{
util::osstream strm; // make sure all ouput is kept together

std::cout << util::osstream_get_string(strm);
}
}
else {
std::string affinity_desc;
std::vector<std::string> bind_affinity =
vm_["hpx:bind"].as<std::vector<std::string> >();
BOOST_FOREACH(std::string const& s, bind_affinity)
strm << std::string(79, '*') << '\n';
strm << "locality: " << hpx::get_locality_id() << '\n';
for (std::size_t i = 0; i != num_threads; ++i)
{
if (!affinity_desc.empty())
affinity_desc += ";";
affinity_desc += s;
top.print_affinity_mask(
strm, i, rt.get_thread_manager().get_pu_mask(top, i)
);
}

threads::print_affinity_options(std::cout, num_threads,
affinity_desc);
std::cout << util::osstream_get_string(strm);
}
}
#endif
Expand Down

0 comments on commit 9a099e8

Please sign in to comment.