From a4c788655184044bbad39bc6d84e0e70bd66fae5 Mon Sep 17 00:00:00 2001 From: Hartmut Kaiser Date: Sat, 20 Apr 2019 20:31:00 -0500 Subject: [PATCH 1/9] Allow setting default scheduler mode via the configuration database --- hpx/runtime/threads/policies/scheduler_mode.hpp | 10 +++++++++- src/runtime/threads/policies/scheduler_base.cpp | 13 +++++++++++++ src/util/runtime_configuration.cpp | 1 + 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/hpx/runtime/threads/policies/scheduler_mode.hpp b/hpx/runtime/threads/policies/scheduler_mode.hpp index a533316fa4d5..2e9f5f0460b4 100644 --- a/hpx/runtime/threads/policies/scheduler_mode.hpp +++ b/hpx/runtime/threads/policies/scheduler_mode.hpp @@ -41,8 +41,16 @@ namespace hpx { namespace threads { namespace policies reduce_thread_priority | delay_exit | enable_stealing | - enable_idle_backoff + enable_idle_backoff, ///< This option represents the default mode. + all_flags = + do_background_work | + reduce_thread_priority | + delay_exit | + fast_idle_mode | + enable_elasticity | + enable_stealing | + enable_idle_backoff }; }}} diff --git a/src/runtime/threads/policies/scheduler_base.cpp b/src/runtime/threads/policies/scheduler_base.cpp index 3e7b2e793e35..76cd8a970100 100644 --- a/src/runtime/threads/policies/scheduler_base.cpp +++ b/src/runtime/threads/policies/scheduler_base.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -51,6 +52,18 @@ namespace hpx { namespace threads { namespace policies , parent_pool_(nullptr) , background_thread_count_(0) { + // if there is a cfg setting for the default_scheduler_mode, use that + // instead of the built-in default + std::string default_scheduler_mode = hpx::get_config_entry( + "hpx.default_scheduler_mode", ""); + + if (!default_scheduler_mode.empty()) + { + mode = scheduler_mode(hpx::util::safe_lexical_cast( + default_scheduler_mode)); + HPX_ASSERT((mode & ~scheduler_mode::all_flags) == 0); + } + set_scheduler_mode(mode); #if defined(HPX_HAVE_THREAD_MANAGER_IDLE_BACKOFF) diff --git a/src/util/runtime_configuration.cpp b/src/util/runtime_configuration.cpp index 5abbb64d87d1..b147237447f5 100644 --- a/src/util/runtime_configuration.cpp +++ b/src/util/runtime_configuration.cpp @@ -200,6 +200,7 @@ namespace hpx { namespace util "max_idle_backoff_time = ${HPX_MAX_IDLE_BACKOFF_TIME:" HPX_PP_STRINGIZE(HPX_PP_EXPAND(HPX_IDLE_BACKOFF_TIME_MAX)) "}", #endif + "default_scheduler_mode = ${HPX_DEFAULT_SCHEDULER_MODE}", /// If HPX_HAVE_ATTACH_DEBUGGER_ON_TEST_FAILURE is set, /// then apply the test-failure value as default. From 30a5c8dd80444b36950b8eb8b67d5d1c1f996e88 Mon Sep 17 00:00:00 2001 From: Hartmut Kaiser Date: Sun, 21 Apr 2019 10:41:11 -0500 Subject: [PATCH 2/9] Adding more error handling to failing example --- hpx/parallel/util/numa_allocator.hpp | 5 +++++ src/runtime/threads/policies/scheduler_base.cpp | 2 +- src/runtime/threads/topology.cpp | 10 ++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/hpx/parallel/util/numa_allocator.hpp b/hpx/parallel/util/numa_allocator.hpp index 4bbad59f25f1..b659b8cb09de 100644 --- a/hpx/parallel/util/numa_allocator.hpp +++ b/hpx/parallel/util/numa_allocator.hpp @@ -124,6 +124,11 @@ namespace hpx { namespace parallel { namespace util } hpx::wait_all(first_touch); + for (auto && f : first_touch) + { + f.get(); // rethrow exceptions + } + // return the overall memory block return p; } diff --git a/src/runtime/threads/policies/scheduler_base.cpp b/src/runtime/threads/policies/scheduler_base.cpp index 76cd8a970100..1ad8e09c3074 100644 --- a/src/runtime/threads/policies/scheduler_base.cpp +++ b/src/runtime/threads/policies/scheduler_base.cpp @@ -55,7 +55,7 @@ namespace hpx { namespace threads { namespace policies // if there is a cfg setting for the default_scheduler_mode, use that // instead of the built-in default std::string default_scheduler_mode = hpx::get_config_entry( - "hpx.default_scheduler_mode", ""); + "hpx.default_scheduler_mode", std::string()); if (!default_scheduler_mode.empty()) { diff --git a/src/runtime/threads/topology.cpp b/src/runtime/threads/topology.cpp index 06a3dc78f4cb..0859cc2c9c92 100644 --- a/src/runtime/threads/topology.cpp +++ b/src/runtime/threads/topology.cpp @@ -552,6 +552,16 @@ namespace hpx { namespace threads hwloc_bitmap_free(cpuset); return mask; } + else + { + std::string errstr = std::strerror(errno); + + lk.unlock(); + HPX_THROW_EXCEPTION(no_success, + "topology::get_thread_affinity_mask_from_lva", + "failed calling 'hwloc_get_area_membind_nodeset', " + "reported error: " + errstr); + } } hwloc_bitmap_free(nodeset); From 2de71eeb87c688991b36c5aaed28ec97b595ebd0 Mon Sep 17 00:00:00 2001 From: Mikael Simberg Date: Thu, 2 May 2019 08:40:18 +0200 Subject: [PATCH 3/9] Add message to default scheduler mode assertion --- src/runtime/threads/policies/scheduler_base.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/runtime/threads/policies/scheduler_base.cpp b/src/runtime/threads/policies/scheduler_base.cpp index 1ad8e09c3074..9455ddf50ede 100644 --- a/src/runtime/threads/policies/scheduler_base.cpp +++ b/src/runtime/threads/policies/scheduler_base.cpp @@ -61,7 +61,8 @@ namespace hpx { namespace threads { namespace policies { mode = scheduler_mode(hpx::util::safe_lexical_cast( default_scheduler_mode)); - HPX_ASSERT((mode & ~scheduler_mode::all_flags) == 0); + HPX_ASSERT_MSG((mode & ~scheduler_mode::all_flags) == 0, + "hpx.default_scheduler_mode contains unknown scheduler modes"); } set_scheduler_mode(mode); From 537a8ce833d01bf22e17a12497338aadf92b769e Mon Sep 17 00:00:00 2001 From: Alberto Invernizzi Date: Thu, 2 May 2019 08:51:54 +0200 Subject: [PATCH 4/9] minor fix: option HPX_WITH_TEST was not completely disabling specialized CMake test targets --- libs/_example/tests/CMakeLists.txt | 2 +- libs/create_library_skeleton.py | 2 +- libs/preprocessor/tests/CMakeLists.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/_example/tests/CMakeLists.txt b/libs/_example/tests/CMakeLists.txt index fadcb7e3d044..fd430c629248 100644 --- a/libs/_example/tests/CMakeLists.txt +++ b/libs/_example/tests/CMakeLists.txt @@ -3,7 +3,7 @@ # 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 (NOT HPX_WITH_TESTS AND HPX_TOP_LEVEL) +if (NOT HPX_WITH_TESTS) return() endif() if (NOT HPX__EXAMPLE_WITH_TESTS) diff --git a/libs/create_library_skeleton.py b/libs/create_library_skeleton.py index 519722e2b596..f96255d4cfc8 100755 --- a/libs/create_library_skeleton.py +++ b/libs/create_library_skeleton.py @@ -87,7 +87,7 @@ ''' tests_cmakelists_template = cmake_header + f''' -if (NOT HPX_WITH_TESTS AND HPX_TOP_LEVEL) +if (NOT HPX_WITH_TESTS) return() endif() if (NOT HPX_{lib_name_upper}_WITH_TESTS) diff --git a/libs/preprocessor/tests/CMakeLists.txt b/libs/preprocessor/tests/CMakeLists.txt index dddd703ef9fc..f6d1dd2c0ae9 100644 --- a/libs/preprocessor/tests/CMakeLists.txt +++ b/libs/preprocessor/tests/CMakeLists.txt @@ -3,7 +3,7 @@ # 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 (NOT HPX_WITH_TESTS AND HPX_TOP_LEVEL) +if (NOT HPX_WITH_TESTS) return() endif() if (NOT HPX_PREPROCESSOR_WITH_TESTS) From d391ccab432ac5747ec72ee1d04b029a46d8398a Mon Sep 17 00:00:00 2001 From: Mikael Simberg Date: Mon, 29 Apr 2019 16:11:36 +0300 Subject: [PATCH 5/9] Fix libs tests in CircleCI config --- .circleci/config.yml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 8af6b687c0fc..e461c896ef03 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -772,6 +772,31 @@ jobs: - store_artifacts: path: tests.unit.util + tests.unit.libs: + <<: *defaults + steps: + - attach_workspace: + at: /hpx + - run: + name: Building Unit Tests + command: | + ninja -j2 -k 0 tests.unit.preprocessor + - run: + name: Running Unit Tests + when: always + command: | + ulimit -c unlimited + ctest -T test --no-compress-output --output-on-failure -R tests.unit.preprocessor + - run: + <<: *convert_xml + - run: + <<: *move_core_dump + - run: + <<: *move_debug_log + - store_test_results: + path: tests.unit.libs + - store_artifacts: + path: tests.unit.libs tests.regressions: <<: *defaults steps: @@ -1179,6 +1204,8 @@ workflows: <<: *core_dependency - tests.unit.util: <<: *core_dependency + - tests.unit.libs: + <<: *core_dependency - tests.regressions: <<: *core_dependency - tests.performance: @@ -1207,6 +1234,8 @@ workflows: <<: *core_dependency - tests.headers.util: <<: *core_dependency + - tests.headers.libs: + <<: *core_dependency - examples: <<: *core_dependency - tests.unit.build: @@ -1241,6 +1270,7 @@ workflows: - tests.unit.threads - tests.unit.traits - tests.unit.util + - tests.unit.libs - tests.headers.compat - tests.headers.components - tests.headers.compute @@ -1253,6 +1283,7 @@ workflows: - tests.headers.runtime - tests.headers.traits - tests.headers.util + - tests.headers.libs - tests.performance - tests.regressions - examples From d0e06fa73ba4317ac17271dd17e8b84befdaf4e9 Mon Sep 17 00:00:00 2001 From: Mikael Simberg Date: Mon, 29 Apr 2019 16:14:04 +0300 Subject: [PATCH 6/9] Use hpx_option in preprocessor module --- libs/create_library_skeleton.py | 9 ++++++++- libs/preprocessor/CMakeLists.txt | 8 ++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/libs/create_library_skeleton.py b/libs/create_library_skeleton.py index f96255d4cfc8..0f311596c68f 100755 --- a/libs/create_library_skeleton.py +++ b/libs/create_library_skeleton.py @@ -67,7 +67,14 @@ list(APPEND CMAKE_MODULE_PATH "${{CMAKE_CURRENT_SOURCE_DIR}}/cmake") -option(HPX_{lib_name_upper}_WITH_TESTS "Include tests for {lib_name}" On) +include(HPX_AddDefinitions) +include(HPX_Option) + +hpx_option(HPX_{lib_name_upper}_WITH_TESTS + BOOL + "Build HPX {lib_name} module tests. (default: ON)" + ON ADVANCED + CATEGORY "Modules") message(STATUS "{lib_name}: Configuring") diff --git a/libs/preprocessor/CMakeLists.txt b/libs/preprocessor/CMakeLists.txt index c4b52be87568..4353bfbf76f0 100644 --- a/libs/preprocessor/CMakeLists.txt +++ b/libs/preprocessor/CMakeLists.txt @@ -9,11 +9,15 @@ project(HPX.preprocessor CXX) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") -option(HPX_PREPROCESSOR_WITH_TESTS "Include tests for preprocessor" On) - include(HPX_AddDefinitions) include(HPX_Option) +hpx_option(HPX_PREPROCESSOR_WITH_TESTS + BOOL + "Build HPX preprocessor module tests. (default: ON)" + ON ADVANCED + CATEGORY "Modules") + hpx_option(HPX_PREPROCESSOR_WITH_DEPRECATION_WARNINGS BOOL "Enable warnings for deprecated facilities. (default: ${HPX_WITH_DEPRECATION_WARNINGS})" From 8d75d810aeee97febeab5a7600297a4c9e9eda2e Mon Sep 17 00:00:00 2001 From: Mikael Simberg Date: Thu, 2 May 2019 15:05:55 +0200 Subject: [PATCH 7/9] Use HPX_LIBS variable in src/CMakeLists.txt --- src/CMakeLists.txt | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2ac79bb8e99f..f3832b232d60 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -300,15 +300,14 @@ foreach(_plugin ${HPX_STATIC_PARCELPORT_PLUGINS}) endforeach() # integrate the hpx modules with the main library -set(_modules hpx_preprocessor) -foreach(_module ${_modules}) +foreach(_module ${HPX_LIBS}) # add module binaries as PRIVATE dependencies to the core hpx library to # avoid dependent applicatons have to link against those - target_link_libraries(hpx ${HPX_TLL_PRIVATE} ${_module}) + target_link_libraries(hpx ${HPX_TLL_PRIVATE} hpx_${_module}) # add module include directories as PUBLIC to core hpx library to enable # compilation against indirectly included headers - get_target_property(_module_includes ${_module} INTERFACE_INCLUDE_DIRECTORIES) + get_target_property(_module_includes hpx_${_module} INTERFACE_INCLUDE_DIRECTORIES) target_include_directories(hpx PUBLIC ${_module_includes}) endforeach() @@ -355,10 +354,10 @@ if(NOT HPX_WITH_STATIC_LINKING) endif() target_include_directories(hpx_init PRIVATE $) - foreach(_module ${_modules}) + foreach(_module ${HPX_LIBS}) # add module include directories as PRIVATE to the hpx_init library to # enable its compilation against indirectly included headers - get_target_property(_module_includes ${_module} INTERFACE_INCLUDE_DIRECTORIES) + get_target_property(_module_includes hpx_${_module} INTERFACE_INCLUDE_DIRECTORIES) target_include_directories(hpx_init PRIVATE ${_module_includes}) endforeach() @@ -402,10 +401,10 @@ if(HPX_WITH_DYNAMIC_HPX_MAIN AND (("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") OR ( target_include_directories(hpx_wrap PRIVATE $) - foreach(_module ${_modules}) + foreach(_module ${HPX_LIBS}) # add module include directories as PRIVATE to the hpx_wrap library to # enable its compilation against indirectly included headers - get_target_property(_module_includes ${_module} INTERFACE_INCLUDE_DIRECTORIES) + get_target_property(_module_includes hpx_${_module} INTERFACE_INCLUDE_DIRECTORIES) target_include_directories(hpx_wrap PRIVATE ${_module_includes}) endforeach() From 9747f9bd7c865b3acf737bfd377b49d4bca2dad0 Mon Sep 17 00:00:00 2001 From: Mikael Simberg Date: Thu, 2 May 2019 16:19:02 +0200 Subject: [PATCH 8/9] Remove hpx_libs_link_mode --- CMakeLists.txt | 9 --------- 1 file changed, 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 613af207c67a..d3677d355675 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1855,15 +1855,6 @@ set(HPX_DEBUG_POSTFIX "d") ################################################################################ # Add libraries ################################################################################ -if(HPX_WITH_STATIC_LINKING) - if(MSVC) - # The MSVC linker can't handle a static library as large as we get when - # statically linking the main HPX library - set(hpx_libs_link_mode SHARED) - endif() -else() - set(hpx_libs_link_mode ${hpx_library_link_mode}) -endif() add_subdirectory(libs) ################################################################################ From 250a884b3272e8e9539a17ca63179ec9c89c5c12 Mon Sep 17 00:00:00 2001 From: tianyi93 Date: Thu, 2 May 2019 16:31:21 -0500 Subject: [PATCH 9/9] make latch counter_ protected for adapting latch to hpxmp --- hpx/lcos/local/latch.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hpx/lcos/local/latch.hpp b/hpx/lcos/local/latch.hpp index b719993d7055..77760026a7a2 100644 --- a/hpx/lcos/local/latch.hpp +++ b/hpx/lcos/local/latch.hpp @@ -55,7 +55,7 @@ namespace hpx { namespace lcos { namespace local /// Postconditions: counter_ == count. /// explicit latch(std::ptrdiff_t count) - : mtx_(), cond_(), counter_(count), notified_(count == 0) + : mtx_(), cond_(), notified_(count == 0), counter_(count) { } @@ -187,8 +187,9 @@ namespace hpx { namespace lcos { namespace local private: mutable util::cache_line_data mtx_; mutable util::cache_line_data cond_; - std::atomic counter_; bool notified_; + protected: + std::atomic counter_; }; }}}