Skip to content
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

Making sure resource partitioner is not accessed if its not valid #3202

Merged
merged 1 commit into from Mar 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions hpx/runtime/resource/partitioner_fwd.hpp
Expand Up @@ -34,6 +34,7 @@ namespace hpx
// May be used anywhere in code and returns a reference to the single,
// global resource partitioner.
HPX_EXPORT detail::partitioner& get_partitioner();
HPX_EXPORT bool is_partitioner_valid();

// resource_partitioner mode
enum partitioner_mode
Expand Down
39 changes: 28 additions & 11 deletions src/runtime.cpp
Expand Up @@ -777,6 +777,10 @@ namespace hpx
{
return get_runtime().get_config().get_entry(key, dflt);
}
if (!resource::is_partitioner_valid())
{
return dflt;
}
return resource::get_partitioner()
.get_command_line_switches().rtcfg_.get_entry(key, dflt);
}
Expand All @@ -787,6 +791,10 @@ namespace hpx
{
return get_runtime().get_config().get_entry(key, dflt);
}
if (!resource::is_partitioner_valid())
{
return std::to_string(dflt);
}
return resource::get_partitioner()
.get_command_line_switches().rtcfg_.get_entry(key, dflt);
}
Expand All @@ -796,22 +804,28 @@ namespace hpx
{
if (get_runtime_ptr() != nullptr)
{
return get_runtime_ptr()->get_config().add_entry(key, value);
get_runtime_ptr()->get_config().add_entry(key, value);
}
if (resource::is_partitioner_valid())
{
resource::get_partitioner()
.get_command_line_switches().rtcfg_.add_entry(key, value);
}
return resource::get_partitioner()
.get_command_line_switches().rtcfg_.add_entry(key, value);
}

void set_config_entry(std::string const& key, std::size_t value)
{
if (get_runtime_ptr() != nullptr)
{
return get_runtime_ptr()->get_config().add_entry(
get_runtime_ptr()->get_config().add_entry(
key, std::to_string(value));
}
return resource::get_partitioner()
.get_command_line_switches().rtcfg_.
add_entry(key, std::to_string(value));
if (resource::is_partitioner_valid())
{
resource::get_partitioner()
.get_command_line_switches().rtcfg_.
add_entry(key, std::to_string(value));
}
}

void set_config_entry_callback(std::string const& key,
Expand All @@ -820,12 +834,15 @@ namespace hpx
{
if (get_runtime_ptr() != nullptr)
{
return get_runtime_ptr()->get_config().add_notification_callback(
get_runtime_ptr()->get_config().add_notification_callback(
key, callback);
}
return resource::get_partitioner()
.get_command_line_switches()
.rtcfg_.add_notification_callback(key, callback);
if (resource::is_partitioner_valid())
{
return resource::get_partitioner()
.get_command_line_switches()
.rtcfg_.add_notification_callback(key, callback);
}
}

///////////////////////////////////////////////////////////////////////////
Expand Down
15 changes: 15 additions & 0 deletions src/runtime/resource/partitioner.cpp
Expand Up @@ -154,6 +154,16 @@ namespace hpx { namespace resource
{
std::unique_ptr<detail::partitioner>& rp = detail::get_partitioner();

if (!rp)
{
// if the resource partitioner is not accessed for the first time
// if the command-line parsing has not yet been done
throw std::invalid_argument(
"hpx::resource::get_partitioner() can be called only after "
"the resource partitioner has been initialized and before it "
"has been deleted");
}

if (!rp->cmd_line_parsed())
{
if (get_runtime_ptr() != nullptr)
Expand All @@ -177,6 +187,11 @@ namespace hpx { namespace resource
return *rp;
}

bool is_partitioner_valid()
{
return bool(detail::get_partitioner());
}

namespace detail
{
detail::partitioner &create_partitioner(
Expand Down