Skip to content

Commit

Permalink
Merge pull request #3202 from STEllAR-GROUP/fixing_config_entry
Browse files Browse the repository at this point in the history
Making sure resource partitioner is not accessed if its not valid
  • Loading branch information
hkaiser committed Mar 7, 2018
2 parents b43ec23 + 549be5a commit 58d8a85
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 11 deletions.
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 @@ -789,6 +789,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 @@ -799,6 +803,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 @@ -808,22 +816,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);

This comment has been minimized.

Copy link
@msimberg

msimberg Mar 9, 2018

Contributor

Also missing a return?

}
if (resource::is_partitioner_valid())
{
resource::get_partitioner()

This comment has been minimized.

Copy link
@msimberg

msimberg Mar 9, 2018

Contributor

If there's no partitioner it will silently fail, no? Would it be better to actually let it fail in this case?

.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(

This comment has been minimized.

Copy link
@hkaiser

hkaiser Mar 8, 2018

Author Member

This return got lost as well... Doh!

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 @@ -832,12 +846,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(

This comment has been minimized.

Copy link
@msimberg

msimberg Mar 8, 2018

Contributor

@hkaiser It looks like this is caused by the callback being added twice. Is this wrong or the is the test now wrong?

This comment has been minimized.

Copy link
@hkaiser

hkaiser Mar 8, 2018

Author Member

You're right. Somehow the return got lost...

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 @@ -155,6 +155,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 @@ -178,6 +188,11 @@ namespace hpx { namespace resource
return *rp;
}

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

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

0 comments on commit 58d8a85

Please sign in to comment.