Skip to content

Commit

Permalink
Merge pull request #2294 from STEllAR-GROUP/fixing_2282
Browse files Browse the repository at this point in the history
Throwing exceptions if the runtime is not up and running
  • Loading branch information
hkaiser committed Aug 19, 2016
2 parents 0aa4c49 + 30a111a commit e0581a5
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 5 deletions.
36 changes: 36 additions & 0 deletions src/runtime.cpp
Expand Up @@ -1130,15 +1130,27 @@ namespace hpx
{
runtime* rt = get_runtime_ptr();
if (nullptr == rt)
{
HPX_THROW_EXCEPTION(
invalid_status,
"hpx::get_os_thread_count()",
"the runtime system has not been initialized yet");
return std::size_t(0);
}
return rt->get_config().get_os_thread_count();
}

std::size_t get_os_thread_count(threads::executor const& exec)
{
runtime* rt = get_runtime_ptr();
if (nullptr == rt)
{
HPX_THROW_EXCEPTION(
invalid_status,
"hpx::get_os_thread_count(exec)",
"the runtime system has not been initialized yet");
return std::size_t(0);
}

if (!exec)
return rt->get_config().get_os_thread_count();
Expand All @@ -1152,15 +1164,28 @@ namespace hpx
{
runtime* rt = get_runtime_ptr();
if (nullptr == rt)
{
HPX_THROW_EXCEPTION(
invalid_status,
"hpx::get_worker_thread_num",
"the runtime system has not been initialized yet");
return std::size_t(-1);
}
return rt->get_thread_manager().get_worker_thread_num();
}

std::size_t get_num_worker_threads()
{
runtime* rt = get_runtime_ptr();
if (nullptr == rt)
{
HPX_THROW_EXCEPTION(
invalid_status,
"hpx::get_num_worker_threads",
"the runtime system has not been initialized yet");
return std::size_t(0);
}

error_code ec(lightweight);
return static_cast<std::size_t>(
rt->get_agas_client().get_num_overall_threads(ec));
Expand All @@ -1170,7 +1195,13 @@ namespace hpx
{
runtime* rt = get_runtime_ptr();
if (nullptr == rt)
{
HPX_THROW_EXCEPTION(
invalid_status,
"hpx::is_scheduler_numa_sensitive",
"the runtime system has not been initialized yet");
return false;
}

bool numa_sensitive = false;
if (std::size_t(-1) !=
Expand All @@ -1185,6 +1216,11 @@ namespace hpx
runtime* rt = get_runtime_ptr();
if (nullptr != rt)
return rt->keep_factory_alive(type);

HPX_THROW_EXCEPTION(
invalid_status,
"hpx::keep_factory_alive",
"the runtime system has not been initialized yet");
return false;
}

Expand Down
18 changes: 14 additions & 4 deletions src/version.cpp
@@ -1,6 +1,6 @@
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011 Bryce Lelbach
// Copyright (c) 2011-2014 Hartmut Kaiser
// Copyright (c) 2011-2016 Hartmut Kaiser
//
// 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)
Expand All @@ -15,6 +15,7 @@
#endif

#include <hpx/exception.hpp>
#include <hpx/runtime_fwd.hpp>
#include <hpx/util/command_line_handling.hpp>
#include <hpx/util/find_prefix.hpp>
#include <hpx/version.hpp>
Expand Down Expand Up @@ -246,11 +247,20 @@ namespace hpx
strm << " HPX_HAVE_MALLOC=" << HPX_HAVE_MALLOC << "\n";
#endif

strm << " HPX_PREFIX (configured)=" << util::hpx_prefix() << "\n";
if (get_runtime_ptr() == nullptr)
{
strm << " HPX_PREFIX (configured)=unknown\n";
#if !defined(__ANDROID__) && !defined(ANDROID) && !defined(__MIC)
strm << " HPX_PREFIX=" << util::find_prefix() << "\n";
strm << " HPX_PREFIX=unknown\n";
#endif

}
else
{
strm << " HPX_PREFIX (configured)=" << util::hpx_prefix() << "\n";
#if !defined(__ANDROID__) && !defined(ANDROID) && !defined(__MIC)
strm << " HPX_PREFIX=" << util::find_prefix() << "\n";
#endif
}
return strm.str();
}

Expand Down
3 changes: 2 additions & 1 deletion tests/regressions/parallel/CMakeLists.txt
@@ -1,4 +1,4 @@
# Copyright (c) 2014-2015 Hartmut Kaiser
# Copyright (c) 2014-2016 Hartmut Kaiser
#
# 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)
Expand All @@ -9,6 +9,7 @@ set(tests
scan_non_commutative
scan_shortlength
search_zerolength
static_chunker_2282
)

foreach(test ${tests})
Expand Down
33 changes: 33 additions & 0 deletions tests/regressions/parallel/static_chunker_2282.cpp
@@ -0,0 +1,33 @@
// Copyright (c) 2016 Marcin Copik
//
// 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)

#include <hpx/hpx_init.hpp>
#include <hpx/hpx.hpp>
#include <hpx/include/parallel_algorithm.hpp>
#include <hpx/util/lightweight_test.hpp>

int main()
{
const int size = 1000000;
float* a = new float[size];

bool caught_exception = false;
try {
// this should throw as the HPX runtime has not been initialized
hpx::parallel::fill(hpx::parallel::par, a, a + size, 1.0f);

// fill should have thrown
HPX_TEST(false);
}
catch (hpx::exception const&) {
caught_exception = true;
}

HPX_TEST(caught_exception);

delete[] a;

return 0;
}

0 comments on commit e0581a5

Please sign in to comment.