From 39aea305eceec5d717d5f7d399d80bd663035ef7 Mon Sep 17 00:00:00 2001 From: dimitraka Date: Thu, 13 Jul 2023 22:58:32 +0200 Subject: [PATCH 01/25] Add MPI migration guide --- docs/sphinx/manual/migration_guide.rst | 122 +++++++++++++++++- .../include/hpx/parallel/algorithm.hpp | 1 + .../examples/channel_communicator.cpp | 5 +- 3 files changed, 125 insertions(+), 3 deletions(-) diff --git a/docs/sphinx/manual/migration_guide.rst b/docs/sphinx/manual/migration_guide.rst index 01a6099b4df3..72f46fb7f847 100644 --- a/docs/sphinx/manual/migration_guide.rst +++ b/docs/sphinx/manual/migration_guide.rst @@ -12,7 +12,7 @@ Migration guide =============== The Migration Guide serves as a valuable resource for developers seeking to transition their -parallel computing applications from different APIs (i.e. |openmp|, |tbb|) to |hpx|. |hpx|, an +parallel computing applications from different APIs (i.e. |openmp|, |tbb|, |mpi|) to |hpx|. |hpx|, an advanced C++ library, offers a versatile and high-performance platform for parallel and distributed computing, providing a wide range of features and capabilities. This guide aims to assist developers in understanding the key differences between different APIs and |hpx|, and it provides step-by-step @@ -1045,3 +1045,123 @@ task_group |hpx| drew inspiration from |tbb| to introduce the :cpp:func:`hpx::experimental::task_group` feature. Therefore, utilizing :cpp:func:`hpx::experimental::task_group` provides an equivalent functionality to `tbb::task_group`. + +|mpi| +===== + +|mpi| is a standardized communication protocol and library that allows multiple processes or +nodes in a parallel computing system to exchange data and coordinate their execution. + +MPI_send & MPI_recv +------------------- + +Let's assume we have the following simple message passing code where each process sends a +message to the next process in a circular manner. The exchanged message is modified and printed +to the console. + +|mpi| code: + +.. code-block:: c++ + + #include + #include + #include + #include + #include + + constexpr int times = 2; + + int main(int argc, char *argv[]) { + MPI_Init(&argc, &argv); + + int num_localities; + MPI_Comm_size(MPI_COMM_WORLD, &num_localities); + + int this_locality; + MPI_Comm_rank(MPI_COMM_WORLD, &this_locality); + + int next_locality = (this_locality + 1) % num_localities; + std::vector msg_vec = {0, 1}; + + int cnt = 0; + int msg = msg_vec[this_locality]; + + int recv_msg; + MPI_Request request_send, request_recv; + MPI_Status status; + + while (cnt < times) { + cnt += 1; + + MPI_Isend(&msg, 1, MPI_INT, next_locality, cnt, MPI_COMM_WORLD, + &request_send); + MPI_Irecv(&recv_msg, 1, MPI_INT, next_locality, cnt, MPI_COMM_WORLD, + &request_recv); + + MPI_Wait(&request_send, &status); + MPI_Wait(&request_recv, &status); + + std::cout << "Time: " << cnt << ", Locality " << this_locality + << " received msg: " << recv_msg << "\n"; + + recv_msg += 10; + msg = recv_msg; + } + + MPI_Finalize(); + return 0; + } + +|hpx| equivalent: + +.. literalinclude:: ../../libs/full/collectives/examples/channel_communicator.cpp + :start-after: //[doc + :end-before: //doc] + +To perform message passing between different processes in |hpx| we can use a channel communicator. +To understand this example, let's focus on the `hpx_main()` function: + +- `hpx::get_num_localities(hpx::launch::sync)` retrieves the number of localities, while + `hpx::get_locality_id()` returns the ID of the current locality. +- `create_channel_communicator` function is used to create a channel to serve the communication. + This function takes several arguments, including the launch policy (`hpx::launch::sync`), the + name of the communicator (`channel_communicator_name`), the number of localities, and the ID + of the current locality. +- The communication follows a ring pattern, where each process (or locality) sends a message to + its neighbor in a circular manner. This means that the messages circulate around the localities, + ensuring that the communication wraps around when reaching the end of the locality sequence. + To achieve this, the `next_locality` variable is calculated as the ID of the next locality in + the ring. +- The initial values for the communication are set (`msg_vec`, `cnt`, `msg`). +- The `set()` function is called to send the message to the next locality in the ring. The message + is sent asynchronously and is associated with a tag (`cnt`). +- The `get()` function is called to receive a message from the next locality. It is also associated + with the same tag as the `set()` operation. +- The `setf.get()` call blocks until the message sending operation is complete. +- A continuation is set up using the function `then()` to handle the received message. + Inside the continuation: + + - The received message value (`rec_msg`) is retrieved using `f.get()`. + + - The received message is printed to the console and then modified by adding 10. + + - The `set()` and `get()` operations are repeated to send and receive the modified message to + the next locality. + + - The `setf.get()` call blocks until the new message sending operation is complete. +- The `done_msg.get()` call blocks until the continuation is complete for the current loop iteration. + +Having said that, we conclude to the following table: + +.. table:: |hpx| equivalent functions of |mpi| + + ========================= ============================================================== + |openmpi| function |hpx| equivalent + ========================= ============================================================== + MPI_Comm_create `hpx::collectives::create_channel_communicator()` + MPI_Comm_size `hpx::get_num_localities` + MPI_Comm_rank `hpx::get_locality_id()` + MPI_Isend `hpx::collectives::set()` + MPI_Irecv `hpx::collectives::get()` + MPI_Wait `hpx::collectives::get()` used with a future i.e. `setf.get()` + ========================= ============================================================== diff --git a/libs/core/algorithms/include/hpx/parallel/algorithm.hpp b/libs/core/algorithms/include/hpx/parallel/algorithm.hpp index 127c3f8993b8..af8372c62ffc 100644 --- a/libs/core/algorithms/include/hpx/parallel/algorithm.hpp +++ b/libs/core/algorithms/include/hpx/parallel/algorithm.hpp @@ -51,6 +51,7 @@ #include #include #include +#include #include // Parallelism TS V2 diff --git a/libs/full/collectives/examples/channel_communicator.cpp b/libs/full/collectives/examples/channel_communicator.cpp index 841a896c5bd0..def6f0788a65 100644 --- a/libs/full/collectives/examples/channel_communicator.cpp +++ b/libs/full/collectives/examples/channel_communicator.cpp @@ -5,6 +5,8 @@ // 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) +/////////////////////////////////////////////////////////////////////////////// +//[doc #include #if !defined(HPX_COMPUTE_DEVICE_CODE) @@ -20,14 +22,12 @@ using namespace hpx::collectives; -/////////////////////////////////////////////////////////////////////////////// constexpr char const* channel_communicator_name = "/example/channel_communicator/"; // the number of times constexpr int times = 2; -//////////////////////////////////////////////////////////////////////// int hpx_main() { std::uint32_t num_localities = hpx::get_num_localities(hpx::launch::sync); @@ -89,3 +89,4 @@ int main(int argc, char* argv[]) return 0; #endif } +//doc] From 537bec8c93d1c5d7b86adbd170e645336e55cb9d Mon Sep 17 00:00:00 2001 From: dimitraka Date: Tue, 1 Aug 2023 18:53:49 +0200 Subject: [PATCH 02/25] Add MPI_Gather doc --- docs/sphinx/manual/migration_guide.rst | 103 ++++++++++++++++++++++++- 1 file changed, 102 insertions(+), 1 deletion(-) diff --git a/docs/sphinx/manual/migration_guide.rst b/docs/sphinx/manual/migration_guide.rst index 72f46fb7f847..5011307c16fc 100644 --- a/docs/sphinx/manual/migration_guide.rst +++ b/docs/sphinx/manual/migration_guide.rst @@ -1052,7 +1052,7 @@ equivalent functionality to `tbb::task_group`. |mpi| is a standardized communication protocol and library that allows multiple processes or nodes in a parallel computing system to exchange data and coordinate their execution. -MPI_send & MPI_recv +MPI_Send & MPI_Recv ------------------- Let's assume we have the following simple message passing code where each process sends a @@ -1165,3 +1165,104 @@ Having said that, we conclude to the following table: MPI_Irecv `hpx::collectives::get()` MPI_Wait `hpx::collectives::get()` used with a future i.e. `setf.get()` ========================= ============================================================== + +MPI_Gather +---------- + +The following code gathers data from all processes to the root process and verifies +the gathered data in the root process. + +|mpi| code: + +.. code-block:: c++ + + #include + + int main(int argc, char* argv[]) + { + int num_localities, this_locality; + int gather_data[10]; + + // Initialize MPI + MPI_Init(&argc, &argv); + MPI_Comm_size(MPI_COMM_WORLD, &num_localities); + MPI_Comm_rank(MPI_COMM_WORLD, &this_locality); + + // Test functionality based on immediate local result value + for (int i = 0; i < 10; ++i) + { + if (this_locality == 0) + { + int value = 42; + MPI_Gather(&value, 1, MPI_INT, gather_data, 1, MPI_INT, 0, MPI_COMM_WORLD); + + if (this_locality == 0) + { + for (int j = 0; j < num_localities; ++j) + { + // Verify gathered data + assert(j + 42 == gather_data[j]); + } + } + } + else + { + int value = this_locality + 42; + MPI_Gather(&value, 1, MPI_INT, nullptr, 0, MPI_INT, 0, MPI_COMM_WORLD); + } + } + + // Finalize MPI + MPI_Finalize(); + + return 0; + } + + +|hpx| equivalent: + +.. literalinclude:: ../../libs/full/collectives/tests/unit/gather.cpp + :start-after: //[doc + :end-before: //doc] + +|hpx| uses two functions to implement the functionality of `MPI_Gather`: `hpx::gather_here` and +`hpx::gather_there`. `hpx::gather_here` is gathering data from all localities to the locality +with ID 0 (root locality). `hpx::gather_there` allows non-root localities to participate in the +gather operation by sending data to the root locality. In more detail: + +- `hpx::get_num_localities(hpx::launch::sync)` retrieves the number of localities, while + `hpx::get_locality_id()` returns the ID of the current locality. + +- If the current locality is the root (its ID is equal to 0): + + - the `hpx::gather_here` function is used to perform the gather operation. It collects data from all + other localities into the `overall_result` future object. The function arguments provide the necessary + information, such as the base name for the gather operation (`gather_direct_basename`), the value + to be gathered (`value`), the number of localities (`num_localities`), the current locality ID + (`this_locality`), and the generation number (related to the gather operation). + + - The `get()` member function of the `overall_result` future is used to retrieve the gathered data. + + - The next `for` loop is used to verify the correctness of the gathered data (`sol`). `HPX_TEST` + is a macro provided by the |hpx| testing utilities to perform similar testing withthe Standard + C++ macro `assert`. + +- If the current locality is not the root: + + - The `hpx::gather_there` function is used to participate in the gather operation initiated by + the root locality. It sends the data (in this case, the value `this_locality + 42`) to the root + locality, indicating that it should be included in the gathering. + + - The `get()` member function of the `overall_result` future is used to wait for the gather operation + to complete for this locality. + + +.. table:: |hpx| equivalent functions of |mpi| + + ========================= ===================================================================== + |openmpi| function |hpx| equivalent + ========================= ===================================================================== + MPI_Comm_size `hpx::get_num_localities` + MPI_Comm_rank `hpx::get_locality_id()` + MPI_Gather `hpx::gather_here()` and `hpx::gather_there()` both used with `get()` + ========================= ===================================================================== From ac2831562ca3ff04ac484d1dfae9530a224e024b Mon Sep 17 00:00:00 2001 From: Panos Date: Fri, 11 Aug 2023 16:06:50 +0300 Subject: [PATCH 03/25] Ensure hpx_main is a proper thread_function --- libs/core/runtime_local/src/runtime_local.cpp | 12 +++++++----- .../runtime_distributed/src/runtime_distributed.cpp | 13 ++++++++----- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/libs/core/runtime_local/src/runtime_local.cpp b/libs/core/runtime_local/src/runtime_local.cpp index 2aa33b83e009..0bc3eb1e47b8 100644 --- a/libs/core/runtime_local/src/runtime_local.cpp +++ b/libs/core/runtime_local/src/runtime_local.cpp @@ -1460,11 +1460,13 @@ namespace hpx { lbt_ << "(1st stage) runtime::start: launching run_helper " "HPX thread"; - threads::thread_init_data data( - hpx::bind(&runtime::run_helper, this, func, std::ref(result_), true, - &detail::handle_print_bind), - "run_helper", threads::thread_priority::normal, - threads::thread_schedule_hint(0), threads::thread_stacksize::large); + threads::thread_function_type thread_func = + threads::make_thread_function(hpx::bind(&runtime::run_helper, this, + func, std::ref(result_), true, &detail::handle_print_bind)); + + threads::thread_init_data data(HPX_MOVE(thread_func), "run_helper", + threads::thread_priority::normal, threads::thread_schedule_hint(0), + threads::thread_stacksize::large); this->runtime::starting(); threads::thread_id_ref_type id = threads::invalid_thread_id; diff --git a/libs/full/runtime_distributed/src/runtime_distributed.cpp b/libs/full/runtime_distributed/src/runtime_distributed.cpp index 2f7731914334..4238b8d869f8 100644 --- a/libs/full/runtime_distributed/src/runtime_distributed.cpp +++ b/libs/full/runtime_distributed/src/runtime_distributed.cpp @@ -472,11 +472,14 @@ namespace hpx { lbt_ << "(1st stage) runtime_distributed::start: launching " "run_helper HPX thread"; - threads::thread_init_data data( - hpx::bind(&runtime_distributed::run_helper, this, func, - std::ref(result_)), - "run_helper", threads::thread_priority::normal, - threads::thread_schedule_hint(0), threads::thread_stacksize::large); + threads::thread_function_type thread_func = + threads::make_thread_function( + hpx::bind(&runtime_distributed::run_helper, this, func, + std::ref(result_))); + + threads::thread_init_data data(HPX_MOVE(thread_func), "run_helper", + threads::thread_priority::normal, threads::thread_schedule_hint(0), + threads::thread_stacksize::large); this->runtime::starting(); threads::thread_id_ref_type id = threads::invalid_thread_id; From 17ff8c78fd10dca3ac8233c5c4ce44b1a757cc2b Mon Sep 17 00:00:00 2001 From: Panos Date: Fri, 11 Aug 2023 22:23:28 +0300 Subject: [PATCH 04/25] Add regression test for hpx_main exit callbacks --- tests/regressions/threads/CMakeLists.txt | 1 + .../threads/main_thread_exit_callbacks.cpp | 55 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 tests/regressions/threads/main_thread_exit_callbacks.cpp diff --git a/tests/regressions/threads/CMakeLists.txt b/tests/regressions/threads/CMakeLists.txt index 4970747154ce..73920cd63342 100644 --- a/tests/regressions/threads/CMakeLists.txt +++ b/tests/regressions/threads/CMakeLists.txt @@ -7,6 +7,7 @@ set(tests block_os_threads_1036 + main_thread_exit_callbacks run_as_hpx_thread_exceptions_3304 run_as_os_thread_lockup_2991 stackless_self_4155 diff --git a/tests/regressions/threads/main_thread_exit_callbacks.cpp b/tests/regressions/threads/main_thread_exit_callbacks.cpp new file mode 100644 index 000000000000..4a6451236cd0 --- /dev/null +++ b/tests/regressions/threads/main_thread_exit_callbacks.cpp @@ -0,0 +1,55 @@ +// Copyright (c) 2023 Panos Syskakis +// +// SPDX-License-Identifier: BSL-1.0 +// 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 +#include +#include +#include + +#include +#include + +bool callback_called(false); + +int hpx_main() +{ + hpx::threads::thread_id_type id = hpx::threads::get_self_id(); + hpx::threads::add_thread_exit_callback(id, [id]() { + hpx::threads::thread_id_type id1 = hpx::threads::get_self_id(); + HPX_TEST_EQ(id1, id); + + callback_called = true; + }); + + return hpx::finalize(); +} + +int main(int argc, char* argv[]) +{ + // Test local runtime + { + hpx::init_params iparams; + iparams.mode = hpx::runtime_mode::local; + callback_called = false; + HPX_TEST_EQ_MSG(hpx::init(argc, argv, iparams), 0, + "HPX main exited with non-zero status"); + HPX_TEST(callback_called); + } + +#if defined(HPX_HAVE_DISTRIBUTED_RUNTIME) + // Test distributed runtime + { + hpx::init_params iparams; + iparams.mode = hpx::runtime_mode::console; + callback_called = false; + HPX_TEST_EQ_MSG(hpx::init(argc, argv, iparams), 0, + "HPX main exited with non-zero status"); + + HPX_TEST(callback_called); + } +#endif + return hpx::util::report_errors(); +} From 4f676fe799d1da1215866c4efcead74edde890d7 Mon Sep 17 00:00:00 2001 From: Hartmut Kaiser Date: Thu, 10 Aug 2023 19:35:12 -0500 Subject: [PATCH 05/25] Fixing cyclic dependencies - Fixing cyclic dependencies related to parcelport symbols - Fixing cyclic dependencies in naming and agas modules - Adding linux static github builder - flyby: fixing compression filter linking order --- .github/workflows/linux_release_static.yml | 47 ++++++++++++++ cmake/FindHwloc.cmake | 5 +- cmake/HPX_AddModule.cmake | 11 ++-- cmake/HPX_ParcelPorts.cmake | 26 +------- .../binary_filter/bzip2/CMakeLists.txt | 7 ++- .../binary_filter/snappy/CMakeLists.txt | 7 ++- .../binary_filter/zlib/CMakeLists.txt | 7 ++- libs/CMakeLists.txt | 13 ++-- libs/core/CMakeLists.txt | 5 ++ libs/core/include_local/CMakeLists.txt | 20 +++--- libs/core/init_runtime_local/CMakeLists.txt | 4 +- libs/create_module_skeleton.py | 11 ++-- libs/full/CMakeLists.txt | 12 +++- libs/full/agas/src/route.cpp | 28 ++++++--- libs/full/agas_base/CMakeLists.txt | 1 + .../agas_base/include/hpx/agas_base/route.hpp | 21 +++++++ .../agas_base/server/primary_namespace.hpp | 8 ++- .../src/server/primary_namespace_server.cpp | 14 +++++ libs/full/init_runtime/CMakeLists.txt | 4 +- libs/full/init_runtime/src/hpx_init.cpp | 9 +++ libs/full/modules.rst | 20 +++++- .../include/hpx/naming/credit_handling.hpp | 5 +- libs/full/naming/src/credit_handling.cpp | 62 +++++++++++-------- .../include/hpx/naming_base/id_type.hpp | 45 +++++++------- libs/full/naming_base/src/id_type.cpp | 26 ++++---- libs/full/parcelports/CMakeLists.txt | 58 +++++++++++++++++ .../templates/static_parcelports.hpp.in | 17 +++-- .../hpx/parcelports/init_all_parcelports.hpp | 19 ++++++ .../parcelports/src/static_parcelports.cpp | 35 +++++++++++ libs/full/parcelset/CMakeLists.txt | 1 + .../hpx/parcelset/init_parcelports.hpp | 22 +++++++ libs/full/parcelset/src/parcelhandler.cpp | 2 +- .../plugin_factories/parcelport_factory.hpp | 2 +- 33 files changed, 430 insertions(+), 144 deletions(-) create mode 100644 .github/workflows/linux_release_static.yml create mode 100644 libs/full/agas_base/include/hpx/agas_base/route.hpp create mode 100644 libs/full/parcelports/CMakeLists.txt rename {cmake => libs/full/parcelports/cmake}/templates/static_parcelports.hpp.in (62%) create mode 100644 libs/full/parcelports/include/hpx/parcelports/init_all_parcelports.hpp create mode 100644 libs/full/parcelports/src/static_parcelports.cpp create mode 100644 libs/full/parcelset/include/hpx/parcelset/init_parcelports.hpp diff --git a/.github/workflows/linux_release_static.yml b/.github/workflows/linux_release_static.yml new file mode 100644 index 000000000000..6ff33a5fb9d3 --- /dev/null +++ b/.github/workflows/linux_release_static.yml @@ -0,0 +1,47 @@ +# Copyright (c) 2020 ETH Zurich +# Copyright (c) 2023 The STE||AR Group +# +# SPDX-License-Identifier: BSL-1.0 +# 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) + +name: Linux CI (Release, Static) + +on: [pull_request] + +jobs: + build: + runs-on: ubuntu-latest + container: stellargroup/build_env:16 + + steps: + - uses: actions/checkout@v3 + - name: Configure + shell: bash + run: | + cmake \ + . \ + -Bbuild \ + -GNinja \ + -DCMAKE_BUILD_TYPE=Release \ + -DHPX_WITH_STATIC_LINKING=ON \ + -DHPX_WITH_MALLOC=system \ + -DHPX_WITH_FETCH_ASIO=ON \ + -DHPX_WITH_EXAMPLES=ON \ + -DHPX_WITH_TESTS=ON \ + -DHPX_WITH_TESTS_MAX_THREADS_PER_LOCALITY=2 \ + -DHPX_WITH_CHECK_MODULE_DEPENDENCIES=On + - name: Build + shell: bash + run: | + cmake --build build --target all + cmake --build build --target examples + - name: Test + shell: bash + run: | + cd build + ctest \ + --output-on-failure \ + --tests-regex tests.examples \ + --exclude-regex tests.examples.transpose.transpose_block_numa \ + --exclude-regex tests.examples.quickstart.distributed.tcp.custom_serialization diff --git a/cmake/FindHwloc.cmake b/cmake/FindHwloc.cmake index cdede78fb68b..89dadf132013 100644 --- a/cmake/FindHwloc.cmake +++ b/cmake/FindHwloc.cmake @@ -26,7 +26,7 @@ if(NOT TARGET Hwloc::hwloc) find_library( HWLOC_LIBRARY - NAMES hwloc libhwloc + NAMES libhwloc.so hwloc HINTS ${HWLOC_ROOT} ENV HWLOC_ROOT @@ -70,7 +70,8 @@ if(NOT TARGET Hwloc::hwloc) add_library(Hwloc::hwloc INTERFACE IMPORTED) target_include_directories(Hwloc::hwloc SYSTEM INTERFACE ${HWLOC_INCLUDE_DIR}) - target_link_libraries(Hwloc::hwloc INTERFACE ${HWLOC_LIBRARIES}) + target_link_libraries(Hwloc::hwloc INTERFACE ${HWLOC_LIBRARIES}) mark_as_advanced(HWLOC_ROOT HWLOC_LIBRARY HWLOC_INCLUDE_DIR) + endif() diff --git a/cmake/HPX_AddModule.cmake b/cmake/HPX_AddModule.cmake index 3efec41ec1f1..22510e5117be 100644 --- a/cmake/HPX_AddModule.cmake +++ b/cmake/HPX_AddModule.cmake @@ -176,10 +176,9 @@ function(add_hpx_module libname modulename) endforeach() else() foreach(file_to_generate ${${modulename}_GENERATED_HEADERS}) - if(EXISTS ${file_to_generate}) - hpx_warn("Removing zombie generated header: ${file_to_generate}") - file(REMOVE ${file_to_generate}) - endif() + set(generated_headers ${generated_headers} + ${generated_file_base}/${file_to_generate} + ) endforeach() endif() endif() @@ -284,8 +283,8 @@ function(add_hpx_module libname modulename) list(FIND _hpx_${libname}_modules ${dep} dep_index) if(${dep_index} EQUAL -1) hpx_error( - "The module ${dep} should not be be listed in MODULE_DEPENDENCIES " - "for module hpx_${modulename}" + "The module hpx_${dep} should not be be listed in MODULE_DEPENDENCIES " + "for '${libname}' module hpx_${modulename}" ) endif() endif() diff --git a/cmake/HPX_ParcelPorts.cmake b/cmake/HPX_ParcelPorts.cmake index 0c7aab45bb31..8dbcafc6df1c 100644 --- a/cmake/HPX_ParcelPorts.cmake +++ b/cmake/HPX_ParcelPorts.cmake @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Hartmut Kaiser +# Copyright (c) 2021-2023 Hartmut Kaiser # # SPDX-License-Identifier: BSL-1.0 # Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -9,26 +9,6 @@ if(HPX_WITH_DISTRIBUTED_RUNTIME) ${HPX_STATIC_PARCELPORT_PLUGINS} ) - # add_subdirectory is called before to insure HPX_STATIC_PARCELPORT_PLUGINS - # cache variable is filled - set(_parcelport_export) - set(_parcelport_init) - - foreach(parcelport ${HPX_STATIC_PARCELPORT_PLUGINS}) - set(_parcelport_export - "${_parcelport_export}HPX_EXPORT hpx::plugins::parcelport_factory_base *${parcelport}_factory_init(\n" - ) - set(_parcelport_export - "${_parcelport_export} std::vector& factories);\n" - ) - set(_parcelport_init - "${_parcelport_init} ${parcelport}_factory_init(factories);\n" - ) - endforeach() - - configure_file( - "${PROJECT_SOURCE_DIR}/cmake/templates/static_parcelports.hpp.in" - "${PROJECT_BINARY_DIR}/libs/full/parcelset/include/hpx/parcelset/static_parcelports.hpp" - @ONLY - ) + # handle parcelports module to create proper dependencies + add_subdirectory(libs/full/parcelports) endif() diff --git a/components/parcel_plugins/binary_filter/bzip2/CMakeLists.txt b/components/parcel_plugins/binary_filter/bzip2/CMakeLists.txt index cd0ed71697ec..33d173ab75af 100644 --- a/components/parcel_plugins/binary_filter/bzip2/CMakeLists.txt +++ b/components/parcel_plugins/binary_filter/bzip2/CMakeLists.txt @@ -30,14 +30,15 @@ add_hpx_library( "hpx/binary_filter/bzip2_serialization_filter.hpp" "hpx/binary_filter/bzip2_serialization_filter_registration.hpp" PREPEND_HEADER_ROOT INSTALL_HEADERS - FOLDER "Core/Plugins/Compression" - DEPENDENCIES ${BZIP2_LIBRARIES} ${HPX_WITH_UNITY_BUILD_OPTION} + FOLDER "Core/Plugins/Compression" ${HPX_WITH_UNITY_BUILD_OPTION} ) target_include_directories( compression_bzip2 SYSTEM PRIVATE ${BZIP2_INCLUDE_DIR} ) -target_link_libraries(compression_bzip2 PUBLIC Boost::iostreams) +target_link_libraries( + compression_bzip2 PUBLIC Boost::iostreams ${BZIP2_LIBRARIES} +) add_hpx_pseudo_dependencies( components.parcel_plugins.binary_filter.bzip2 compression_bzip2 diff --git a/components/parcel_plugins/binary_filter/snappy/CMakeLists.txt b/components/parcel_plugins/binary_filter/snappy/CMakeLists.txt index ebc41f37b119..6550e27e3ca1 100644 --- a/components/parcel_plugins/binary_filter/snappy/CMakeLists.txt +++ b/components/parcel_plugins/binary_filter/snappy/CMakeLists.txt @@ -30,8 +30,7 @@ add_hpx_library( "hpx/binary_filter/snappy_serialization_filter.hpp" "hpx/binary_filter/snappy_serialization_filter_registration.hpp" PREPEND_HEADER_ROOT INSTALL_HEADERS - FOLDER "Core/Plugins/Compression" - DEPENDENCIES ${SNAPPY_LIBRARY} ${HPX_WITH_UNITY_BUILD_OPTION} + FOLDER "Core/Plugins/Compression" ${HPX_WITH_UNITY_BUILD_OPTION} ) target_include_directories( @@ -39,7 +38,9 @@ target_include_directories( ) target_link_directories(compression_snappy PRIVATE ${SNAPPY_LIBRARY_DIR}) -target_link_libraries(compression_snappy PUBLIC Boost::iostreams) +target_link_libraries( + compression_snappy PUBLIC Boost::iostreams ${SNAPPY_LIBRARY} +) add_hpx_pseudo_dependencies( components.parcel_plugins.binary_filter.snappy compression_snappy diff --git a/components/parcel_plugins/binary_filter/zlib/CMakeLists.txt b/components/parcel_plugins/binary_filter/zlib/CMakeLists.txt index 1b324f17e1c7..6dba673e7225 100644 --- a/components/parcel_plugins/binary_filter/zlib/CMakeLists.txt +++ b/components/parcel_plugins/binary_filter/zlib/CMakeLists.txt @@ -30,12 +30,13 @@ add_hpx_library( "hpx/binary_filter/zlib_serialization_filter.hpp" "hpx/binary_filter/zlib_serialization_filter_registration.hpp" PREPEND_HEADER_ROOT INSTALL_HEADERS - FOLDER "Core/Plugins/Compression" - DEPENDENCIES ${ZLIB_LIBRARIES} ${HPX_WITH_UNITY_BUILD_OPTION} + FOLDER "Core/Plugins/Compression" ${HPX_WITH_UNITY_BUILD_OPTION} ) target_include_directories(compression_zlib SYSTEM PRIVATE ${ZLIB_INCLUDE_DIRS}) -target_link_libraries(compression_zlib PUBLIC Boost::iostreams) +target_link_libraries( + compression_zlib PUBLIC Boost::iostreams ${ZLIB_LIBRARIES} +) add_hpx_pseudo_dependencies( components.parcel_plugins.binary_filter.zlib compression_zlib diff --git a/libs/CMakeLists.txt b/libs/CMakeLists.txt index 1791882be2e0..974c7592f239 100644 --- a/libs/CMakeLists.txt +++ b/libs/CMakeLists.txt @@ -100,13 +100,7 @@ target_include_directories( ) target_link_libraries(hpx_full PUBLIC hpx_base_libraries) - -if((NOT HPX_WITH_STATIC_LINKING) AND (("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") - OR (APPLE)) -) - set_target_properties(hpx_full PROPERTIES POSITION_INDEPENDENT_CODE ON) -endif() - +set_target_properties(hpx_full PROPERTIES POSITION_INDEPENDENT_CODE ON) target_compile_definitions(hpx_full PRIVATE HPX_COMPONENT_NAME=hpx HPX_EXPORTS) # ############################################################################## @@ -340,6 +334,11 @@ foreach(lib ${HPX_LIBS}) endif() add_subdirectory(${lib}) + + set(_hpx_${lib}_modules + ${_hpx_${lib}_modules} + PARENT_SCOPE + ) endforeach() # add_hpx_module populates HPX_ENABLED_MODULES diff --git a/libs/core/CMakeLists.txt b/libs/core/CMakeLists.txt index ac374840ecfc..c7cb957f36e6 100644 --- a/libs/core/CMakeLists.txt +++ b/libs/core/CMakeLists.txt @@ -93,3 +93,8 @@ hpx_info(" Configuring libhpx_core modules:") foreach(module ${_hpx_core_modules}) add_subdirectory(${module}) endforeach() + +set(_hpx_core_modules + ${_hpx_core_modules} + PARENT_SCOPE +) diff --git a/libs/core/include_local/CMakeLists.txt b/libs/core/include_local/CMakeLists.txt index b95b536e1f4d..6bae183b3cfe 100644 --- a/libs/core/include_local/CMakeLists.txt +++ b/libs/core/include_local/CMakeLists.txt @@ -32,15 +32,17 @@ set(include_local_headers hpx/experimental/task_group.hpp ) -set(generated_include_local_headers - hpx/algorithm.hpp - hpx/barrier.hpp - hpx/channel.hpp - hpx/compute.hpp - hpx/future.hpp - hpx/latch.hpp - hpx/runtime.hpp -) +if(NOT HPX_WITH_DISTRIBUTED_RUNTIME) + set(generated_include_local_headers + hpx/algorithm.hpp + hpx/barrier.hpp + hpx/channel.hpp + hpx/compute.hpp + hpx/future.hpp + hpx/latch.hpp + hpx/runtime.hpp + ) +endif() # The headers in hpx/local/ were deprecated in HPX V1.9.1 # cmake-format: off diff --git a/libs/core/init_runtime_local/CMakeLists.txt b/libs/core/init_runtime_local/CMakeLists.txt index d2316469b18b..a122badfed8e 100644 --- a/libs/core/init_runtime_local/CMakeLists.txt +++ b/libs/core/init_runtime_local/CMakeLists.txt @@ -12,7 +12,9 @@ set(init_runtime_local_headers hpx/init_runtime_local/detail/init_logging.hpp hpx/init_runtime_local/init_runtime_local.hpp ) -set(generated_init_runtime_local_headers hpx/init.hpp) +if(NOT HPX_WITH_DISTRIBUTED_RUNTIME) + set(generated_init_runtime_local_headers hpx/init.hpp) +endif() set(init_runtime_local_sources init_logging.cpp init_runtime_local.cpp) diff --git a/libs/create_module_skeleton.py b/libs/create_module_skeleton.py index 9ca789c583f1..e254f101d4a1 100755 --- a/libs/create_module_skeleton.py +++ b/libs/create_module_skeleton.py @@ -2,6 +2,7 @@ ''' Copyright (c) 2019-2020 ETH Zurich Copyright (c) 2018 Thomas Heller +Copyright (c) 2022-2023 Hartmut Kaiser SPDX-License-Identifier: BSL-1.0 Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -24,14 +25,14 @@ header_str = '=' * len(module_name) -cmake_root_header = f'''# Copyright (c) 2019-2021 The STE||AR-Group +cmake_root_header = f'''# Copyright (c) 2019-2023 The STE||AR-Group # # SPDX-License-Identifier: BSL-1.0 # 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) ''' -cmake_header = f'''# Copyright (c) 2020-2021 The STE||AR-Group +cmake_header = f'''# Copyright (c) 2020-2023 The STE||AR-Group # # SPDX-License-Identifier: BSL-1.0 # Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -40,7 +41,7 @@ readme_template = f''' .. - Copyright (c) 2020-2021 The STE||AR-Group + Copyright (c) 2020-2023 The STE||AR-Group SPDX-License-Identifier: BSL-1.0 Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -57,7 +58,7 @@ ''' index_rst = f'''.. - Copyright (c) 2020-2021 The STE||AR-Group + Copyright (c) 2020-2023 The STE||AR-Group SPDX-License-Identifier: BSL-1.0 Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -255,7 +256,7 @@ def mkdir(path): header_underline_str = '=' * len(header_name_str) modules_rst = f'''.. - Copyright (c) 2018-2021 The STE||AR-Group + Copyright (c) 2018-2023 The STE||AR-Group SPDX-License-Identifier: BSL-1.0 Distributed under the Boost Software License, Version 1.0. (See accompanying diff --git a/libs/full/CMakeLists.txt b/libs/full/CMakeLists.txt index d491915e7ba1..40d254f0d17b 100644 --- a/libs/full/CMakeLists.txt +++ b/libs/full/CMakeLists.txt @@ -35,6 +35,7 @@ set(_hpx_full_modules parcelport_libfabric parcelport_mpi parcelport_tcp + parcelports parcelset parcelset_base performance_counters @@ -51,5 +52,14 @@ hpx_info("") hpx_info(" Configuring libhpx modules:") foreach(module ${_hpx_full_modules}) - add_subdirectory(${module}) + # the parcelports module is handled explicitly after all other modules have + # been processed (see HPX_ParcelPorts.cmake) + if(NOT (${module} STREQUAL "parcelports")) + add_subdirectory(${module}) + endif() endforeach() + +set(_hpx_full_modules + ${_hpx_full_modules} + PARENT_SCOPE +) diff --git a/libs/full/agas/src/route.cpp b/libs/full/agas/src/route.cpp index 3fde16520a9f..a9e237b7fab6 100644 --- a/libs/full/agas/src/route.cpp +++ b/libs/full/agas/src/route.cpp @@ -10,6 +10,7 @@ #if defined(HPX_HAVE_NETWORKING) #include #include +#include #include #include #include @@ -41,32 +42,28 @@ HPX_PLAIN_ACTION_ID(hpx::detail::update_agas_cache, update_agas_cache_action, namespace hpx::agas::server { - void primary_namespace::route(parcelset::parcel&& p) + void route_impl(primary_namespace& server, parcelset::parcel&& p) { - LPT_(debug).format("primary_namespace::route: {}", p.parcel_id()); - - util::scoped_timer> update( - counter_data_.route_.time_, counter_data_.route_.enabled_); - counter_data_.increment_route_count(); + LPT_(debug).format("agas::server::route_impl: {}", p.parcel_id()); naming::gid_type const& gid = p.destination(); naming::address& addr = p.addr(); - resolved_type cache_address; + primary_namespace::resolved_type cache_address; // resolve destination addresses, we should be able to resolve all of // them, otherwise it's an error { - std::unique_lock l(mutex_); + std::unique_lock l(server.mutex()); error_code& ec = throws; // wait for any migration to be completed if (naming::detail::is_migratable(gid)) { - wait_for_migration_locked(l, gid, ec); + server.wait_for_migration_locked(l, gid, ec); } - cache_address = resolve_gid_locked(l, gid, ec); + cache_address = server.resolve_gid_locked(l, gid, ec); if (ec || hpx::get<0>(cache_address) == naming::invalid_gid) { @@ -133,6 +130,17 @@ namespace hpx::agas::server { } } } + + /////////////////////////////////////////////////////////////////////////// + struct init_route_function + { + init_route_function() + { + server::route = &route_impl; + } + }; + + init_route_function init; } // namespace hpx::agas::server #endif diff --git a/libs/full/agas_base/CMakeLists.txt b/libs/full/agas_base/CMakeLists.txt index 76288c7dbbb6..8fb09230926a 100644 --- a/libs/full/agas_base/CMakeLists.txt +++ b/libs/full/agas_base/CMakeLists.txt @@ -20,6 +20,7 @@ set(agas_base_headers hpx/agas_base/gva.hpp hpx/agas_base/locality_namespace.hpp hpx/agas_base/primary_namespace.hpp + hpx/agas_base/route.hpp hpx/agas_base/server/component_namespace.hpp hpx/agas_base/server/locality_namespace.hpp hpx/agas_base/server/primary_namespace.hpp diff --git a/libs/full/agas_base/include/hpx/agas_base/route.hpp b/libs/full/agas_base/include/hpx/agas_base/route.hpp new file mode 100644 index 000000000000..ec3b75eb42d6 --- /dev/null +++ b/libs/full/agas_base/include/hpx/agas_base/route.hpp @@ -0,0 +1,21 @@ +// Copyright (c) 2007-2023 Hartmut Kaiser +// +// SPDX-License-Identifier: BSL-1.0 +// 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) + +#pragma once + +#include + +#if defined(HPX_HAVE_NETWORKING) +#include +#include + +namespace hpx::agas::server { + + extern HPX_EXPORT void (*route)( + primary_namespace& server, parcelset::parcel&& p); +} // namespace hpx::agas::server + +#endif diff --git a/libs/full/agas_base/include/hpx/agas_base/server/primary_namespace.hpp b/libs/full/agas_base/include/hpx/agas_base/server/primary_namespace.hpp index 0c39dc21db0b..8d0489e131a2 100644 --- a/libs/full/agas_base/include/hpx/agas_base/server/primary_namespace.hpp +++ b/libs/full/agas_base/include/hpx/agas_base/server/primary_namespace.hpp @@ -126,6 +126,11 @@ namespace hpx::agas::server { using resolved_type = hpx::tuple; + mutex_type& mutex() + { + return mutex_; + } + private: // REVIEW: Separate mutexes might reduce contention here. This has to be // investigated carefully. @@ -241,6 +246,7 @@ namespace hpx::agas::server { char const* func_name); #endif + public: // helper function void wait_for_migration_locked(std::unique_lock& l, naming::gid_type const& id, error_code& ec); @@ -295,10 +301,10 @@ namespace hpx::agas::server { std::pair allocate( std::uint64_t count); - private: resolved_type resolve_gid_locked(std::unique_lock& l, naming::gid_type const& gid, error_code& ec); + private: resolved_type resolve_gid_locked_non_local( std::unique_lock& l, naming::gid_type const& gid, error_code& ec); diff --git a/libs/full/agas_base/src/server/primary_namespace_server.cpp b/libs/full/agas_base/src/server/primary_namespace_server.cpp index f91819e3917e..a0a56c2f2e39 100644 --- a/libs/full/agas_base/src/server/primary_namespace_server.cpp +++ b/libs/full/agas_base/src/server/primary_namespace_server.cpp @@ -7,6 +7,7 @@ // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #include +#include #include #include #include @@ -1119,6 +1120,19 @@ namespace hpx::agas::server { return resolved_type(naming::invalid_gid, gva(), naming::invalid_gid); } +#if defined(HPX_HAVE_NETWORKING) + void (*route)(primary_namespace& server, parcelset::parcel&& p) = nullptr; + + void primary_namespace::route(parcelset::parcel&& p) + { + util::scoped_timer> update( + counter_data_.route_.time_, counter_data_.route_.enabled_); + counter_data_.increment_route_count(); + + (*server::route)(*this, HPX_MOVE(p)); + } +#endif + // access current counter values std::int64_t primary_namespace::counter_data::get_bind_gid_count(bool reset) { diff --git a/libs/full/init_runtime/CMakeLists.txt b/libs/full/init_runtime/CMakeLists.txt index 7b3edd57771c..71307fbbc85f 100644 --- a/libs/full/init_runtime/CMakeLists.txt +++ b/libs/full/init_runtime/CMakeLists.txt @@ -31,8 +31,8 @@ if(HPX_WITH_DISTRIBUTED_RUNTIME) set(init_runtime_sources ${init_runtime_sources} pre_main.cpp) set(init_runtime_optional_module_dependencies - hpx_async_distributed hpx_collectives hpx_naming hpx_performance_counters - hpx_runtime_distributed + hpx_async_distributed hpx_collectives hpx_naming hpx_parcelports + hpx_performance_counters hpx_runtime_distributed ) endif() diff --git a/libs/full/init_runtime/src/hpx_init.cpp b/libs/full/init_runtime/src/hpx_init.cpp index ef823d5e0a52..c1a54da0a3e2 100644 --- a/libs/full/init_runtime/src/hpx_init.cpp +++ b/libs/full/init_runtime/src/hpx_init.cpp @@ -67,6 +67,7 @@ #include #include #if defined(HPX_HAVE_NETWORKING) +#include #include #include #endif @@ -124,6 +125,10 @@ namespace hpx::detail { // application apex::version(); #endif +#endif +#if defined(HPX_HAVE_NETWORKING) + // force linking parcelports + hpx::parcelset::init_all_parcelports(); #endif util::set_hpx_prefix(hpx_prefix); #if defined(__FreeBSD__) @@ -157,6 +162,10 @@ namespace hpx::detail { // application apex::version(); #endif +#endif +#if defined(HPX_HAVE_NETWORKING) + // force linking parcelports + hpx::parcelset::init_all_parcelports(); #endif util::set_hpx_prefix(hpx_prefix); #if defined(__FreeBSD__) diff --git a/libs/full/modules.rst b/libs/full/modules.rst index 7d41a956c030..0f025215b8a5 100644 --- a/libs/full/modules.rst +++ b/libs/full/modules.rst @@ -14,20 +14,36 @@ Main |hpx| modules .. toctree:: :maxdepth: 2 + /libs/full/actions/docs/index.rst + /libs/full/actions_base/docs/index.rst + /libs/full/agas/docs/index.rst /libs/full/agas_base/docs/index.rst + /libs/full/async_colocated/docs/index.rst /libs/full/async_distributed/docs/index.rst /libs/full/checkpoint/docs/index.rst /libs/full/checkpoint_base/docs/index.rst /libs/full/collectives/docs/index.rst /libs/full/command_line_handling/docs/index.rst + /libs/full/components/docs/index.rst + /libs/full/components_base/docs/index.rst /libs/full/compute/docs/index.rst + /libs/full/distribution_policies/docs/index.rst /libs/full/executors_distributed/docs/index.rst /libs/full/include/docs/index.rst - /libs/full/lci_base/docs/index.rst + /libs/full/init_runtime/docs/index.rst /libs/full/lcos_distributed/docs/index.rst + /libs/full/naming/docs/index.rst /libs/full/naming_base/docs/index.rst + /libs/full/parcelport_lci/docs/index.rst + /libs/full/parcelport_libfabric/docs/index.rst + /libs/full/parcelport_mpi/docs/index.rst + /libs/full/parcelport_tcp/docs/index.rst + /libs/full/parcelset/docs/index.rst + /libs/full/parcelset_base/docs/index.rst /libs/full/performance_counters/docs/index.rst + /libs/full/plugin_factories/docs/index.rst /libs/full/resiliency_distributed/docs/index.rst + /libs/full/runtime_components/docs/index.rst + /libs/full/runtime_distributed/docs/index.rst /libs/full/segmented_algorithms/docs/index.rst /libs/full/statistics/docs/index.rst - /libs/full/version/docs/index.rst diff --git a/libs/full/naming/include/hpx/naming/credit_handling.hpp b/libs/full/naming/include/hpx/naming/credit_handling.hpp index 45750c60b92b..b083861e9ad4 100644 --- a/libs/full/naming/include/hpx/naming/credit_handling.hpp +++ b/libs/full/naming/include/hpx/naming/credit_handling.hpp @@ -39,7 +39,8 @@ namespace hpx::naming { gid_type& id, std::int64_t debit); HPX_EXPORT std::int64_t fill_credit_for_gid(gid_type& id, - std::int64_t credits = std::int64_t(HPX_GLOBALCREDIT_INITIAL)); + std::int64_t credits = static_cast( + HPX_GLOBALCREDIT_INITIAL)); /////////////////////////////////////////////////////////////////////// HPX_EXPORT gid_type move_gid(gid_type& id); @@ -58,7 +59,7 @@ namespace hpx::naming { std::unique_lock& l, gid_type& id); /////////////////////////////////////////////////////////////////////// - HPX_EXPORT void decrement_refcnt(id_type_impl* gid) noexcept; + HPX_EXPORT void decrement_refcnt(id_type_impl const* gid) noexcept; /////////////////////////////////////////////////////////////////////// // credit management (called during serialization), this function diff --git a/libs/full/naming/src/credit_handling.cpp b/libs/full/naming/src/credit_handling.cpp index cceb6175de92..230faac199e8 100644 --- a/libs/full/naming/src/credit_handling.cpp +++ b/libs/full/naming/src/credit_handling.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2007-2022 Hartmut Kaiser +// Copyright (c) 2007-2023 Hartmut Kaiser // Copyright (c) 2011 Bryce Lelbach // // SPDX-License-Identifier: BSL-1.0 @@ -114,7 +114,7 @@ namespace hpx::naming { /////////////////////////////////////////////////////////////////////////// namespace detail { - void decrement_refcnt(id_type_impl* p) noexcept + void decrement_refcnt(id_type_impl const* p) noexcept { // do nothing if it's too late in the game if (!get_runtime_ptr()) @@ -136,7 +136,7 @@ namespace hpx::naming { if (gid_was_split(*p) || !agas::resolve_cached(*p, addr)) { // decrement global reference count for the given gid, - std::int64_t credits = detail::get_credit_from_gid(*p); + std::int64_t const credits = get_credit_from_gid(*p); HPX_ASSERT(0 != credits); if (get_runtime_ptr()) // -V547 @@ -206,13 +206,13 @@ namespace hpx::naming { // Get the current credit for our gid. If no other concurrent // split has happened since we invoked incref below, the credit // of this gid is equal to 2, otherwise it is larger. - std::int64_t src_credit = get_credit_from_gid(gid); + std::int64_t const src_credit = get_credit_from_gid(gid); HPX_ASSERT(src_credit >= 2); - std::int64_t split_credit = + constexpr std::int64_t split_credit = static_cast(HPX_GLOBALCREDIT_INITIAL) - 2; std::int64_t new_credit = src_credit + split_credit; - std::int64_t overflow_credit = new_credit - + std::int64_t const overflow_credit = new_credit - static_cast(HPX_GLOBALCREDIT_INITIAL); HPX_ASSERT(overflow_credit >= 0); @@ -258,7 +258,8 @@ namespace hpx::naming { // credit is guaranteed to arrive only after we incremented the // credit successfully in agas. HPX_ASSERT(get_log2credit_from_gid(gid) > 0); - std::int16_t src_log2credits = get_log2credit_from_gid(gid); + std::int16_t const src_log2credits = + get_log2credit_from_gid(gid); // Credit exhaustion - we need to get more. if (src_log2credits == 1) @@ -279,11 +280,11 @@ namespace hpx::naming { // We add HPX_GLOBALCREDIT_INITIAL credits for the new gid // and HPX_GLOBALCREDIT_INITIAL - 2 for the old one. - std::int64_t new_credit = 2 * + constexpr std::int64_t new_credit = 2 * (static_cast(HPX_GLOBALCREDIT_INITIAL) - 1); - naming::gid_type new_gid = gid; // strips lock-bit + naming::gid_type const new_gid = gid; // strips lock-bit HPX_ASSERT(new_gid != invalid_gid); return agas::incref(new_gid, new_credit) .then(hpx::launch::sync, @@ -338,7 +339,7 @@ namespace hpx::naming { { HPX_ASSERT_OWNS_LOCK(l); - std::uint16_t log2credits = get_log2credit_from_gid(id); + std::int16_t const log2credits = get_log2credit_from_gid(id); HPX_ASSERT(log2credits > 0); gid_type newid = id; // strips lock-bit @@ -362,21 +363,19 @@ namespace hpx::naming { std::int64_t replenish_credits_locked( std::unique_lock& l, gid_type& gid) { - std::int64_t added_credit = 0; - HPX_ASSERT(0 == get_credit_from_gid(gid)); - added_credit = naming::detail::fill_credit_for_gid(gid); + std::int64_t const added_credit = + naming::detail::fill_credit_for_gid(gid); naming::detail::set_credit_split_mask_for_gid(gid); - gid_type unlocked_gid = gid; // strips lock-bit + gid_type const unlocked_gid = gid; // strips lock-bit - std::int64_t result = 0; + std::int64_t result; { hpx::unlock_guard> ul(l); result = agas::incref(launch::sync, unlocked_gid, added_credit); } - return result; } @@ -403,10 +402,10 @@ namespace hpx::naming { std::int64_t fill_credit_for_gid(gid_type& id, std::int64_t credits) { - std::int64_t c = get_credit_from_gid(id); + std::int64_t const c = get_credit_from_gid(id); HPX_ASSERT(c <= credits); - std::int64_t added = credits - c; + std::int64_t const added = credits - c; set_credit_for_gid(id, credits); return added; @@ -419,7 +418,7 @@ namespace hpx::naming { HPX_ASSERT(detail::gid_was_split(gid)); // decrement global reference count for the given gid, - std::int64_t credits = detail::get_credit_from_gid(gid); + std::int64_t const credits = detail::get_credit_from_gid(gid); HPX_ASSERT(0 != credits); // Fire-and-forget semantics. @@ -432,7 +431,7 @@ namespace hpx::naming { // custom deleter for managed gid_types, will be called when the last // copy of the corresponding hpx::id_type goes out of scope - void gid_managed_deleter(id_type_impl* p) noexcept + void gid_managed_deleter_impl(id_type_impl const* p) noexcept { // a credit of zero means the component is not (globally) reference // counted @@ -450,11 +449,23 @@ namespace hpx::naming { // custom deleter for unmanaged gid_types, will be called when the last // copy of the corresponding hpx::id_type goes out of scope - void gid_unmanaged_deleter(id_type_impl* p) noexcept + void gid_unmanaged_deleter_impl(id_type_impl const* p) noexcept { delete p; // delete local gid representation only } + // break cyclic dependency with naming_base + struct init_deleter_functions + { + init_deleter_functions() + { + gid_managed_deleter = &gid_managed_deleter_impl; + gid_unmanaged_deleter = &gid_unmanaged_deleter_impl; + } + }; + + init_deleter_functions init; + /////////////////////////////////////////////////////////////////////// // prepare the given id, note: this function modifies the passed id void handle_credit_splitting(serialization::output_archive& ar, @@ -551,7 +562,8 @@ namespace hpx::naming { { preprocess_gid(id_impl, ar); - gid_serialization_data data{id_impl, type}; + gid_serialization_data const data{ + static_cast(id_impl), type}; ar << data; return; } @@ -569,7 +581,7 @@ namespace hpx::naming { gid_type new_gid; if (hpx::id_type::management_type::unmanaged == type) { - new_gid = id_impl; + new_gid = static_cast(id_impl); } else if (hpx::id_type::management_type::managed_move_credit == type) { @@ -587,12 +599,12 @@ namespace hpx::naming { } #if defined(HPX_DEBUG) - auto* split_gids = ar.try_get_extra_data< + auto const* split_gids = ar.try_get_extra_data< serialization::detail::preprocess_gid_types>(); HPX_ASSERT(!split_gids || !split_gids->has_gid(id_impl)); #endif - gid_serialization_data data{new_gid, type}; + gid_serialization_data const data{new_gid, type}; ar << data; } diff --git a/libs/full/naming_base/include/hpx/naming_base/id_type.hpp b/libs/full/naming_base/include/hpx/naming_base/id_type.hpp index 08d956b5d087..cfeef69c6d83 100644 --- a/libs/full/naming_base/include/hpx/naming_base/id_type.hpp +++ b/libs/full/naming_base/include/hpx/naming_base/id_type.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2007-2022 Hartmut Kaiser +// Copyright (c) 2007-2023 Hartmut Kaiser // // SPDX-License-Identifier: BSL-1.0 // Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -32,8 +32,10 @@ namespace hpx { HPX_EXPORT void intrusive_ptr_add_ref(id_type_impl* p) noexcept; HPX_EXPORT void intrusive_ptr_release(id_type_impl* p) noexcept; - HPX_EXPORT void gid_managed_deleter(id_type_impl* p) noexcept; - HPX_EXPORT void gid_unmanaged_deleter(id_type_impl* p) noexcept; + extern HPX_EXPORT void (*gid_managed_deleter)( + id_type_impl const* p) noexcept; + extern HPX_EXPORT void (*gid_unmanaged_deleter)( + id_type_impl const* p) noexcept; } // namespace naming::detail /////////////////////////////////////////////////////////////////////////// @@ -96,6 +98,8 @@ namespace hpx { id_type& operator=(id_type const& o) = default; id_type& operator=(id_type&& o) noexcept = default; + ~id_type() = default; + naming::gid_type& get_gid(); naming::gid_type const& get_gid() const; @@ -104,7 +108,7 @@ namespace hpx { management_type get_management_type() const noexcept; id_type& operator++(); - id_type operator++(int); + id_type operator++(int) const; explicit operator bool() const noexcept; @@ -121,11 +125,11 @@ namespace hpx { // access the internal parts of the gid std::uint64_t get_msb() const; - void set_msb(std::uint64_t msb); + void set_msb(std::uint64_t msb) const; std::uint64_t get_lsb() const; - void set_lsb(std::uint64_t lsb); - void set_lsb(void* lsb); + void set_lsb(std::uint64_t lsb) const; + void set_lsb(void* lsb) const; // Convert this id into an unmanaged one (in-place) - Use with maximum // care, or better, don't use this at all. @@ -164,14 +168,14 @@ namespace hpx { inline id_type get_id_from_locality_id( std::uint32_t locality_id) noexcept { - return id_type((std::uint64_t(locality_id) + 1) + return {(static_cast(locality_id) + 1) << naming::gid_type::locality_id_shift, - 0, id_type::management_type::unmanaged); + 0, id_type::management_type::unmanaged}; } inline std::uint32_t get_locality_id_from_id(id_type const& id) noexcept { - return std::uint32_t( + return static_cast( id.get_msb() >> naming::gid_type::locality_id_shift) - 1; } @@ -200,10 +204,13 @@ namespace hpx { struct id_type_impl : gid_type { public: - HPX_NON_COPYABLE(id_type_impl); + id_type_impl(id_type_impl const&) = delete; + id_type_impl(id_type_impl&&) = delete; + id_type_impl& operator=(id_type_impl const&) = delete; + id_type_impl& operator=(id_type_impl&&) = delete; private: - using deleter_type = void (*)(detail::id_type_impl*) noexcept; + using deleter_type = void (*)(detail::id_type_impl const*) noexcept; static deleter_type get_deleter( id_type::management_type t) noexcept; @@ -245,6 +252,8 @@ namespace hpx { { } + ~id_type_impl() = default; + constexpr id_type::management_type get_management_type() const noexcept { @@ -282,12 +291,6 @@ namespace hpx { } private: - // custom deleter for id_type_impl - friend HPX_EXPORT void gid_managed_deleter( - id_type_impl* p) noexcept; - friend HPX_EXPORT void gid_unmanaged_deleter( - id_type_impl* p) noexcept; - // reference counting friend HPX_EXPORT void intrusive_ptr_add_ref( id_type_impl* p) noexcept; @@ -389,7 +392,7 @@ namespace hpx { { return gid_->get_msb(); } - inline void id_type::set_msb(std::uint64_t msb) + inline void id_type::set_msb(std::uint64_t msb) const { gid_->set_msb(msb); } @@ -398,11 +401,11 @@ namespace hpx { { return gid_->get_lsb(); } - inline void id_type::set_lsb(std::uint64_t lsb) + inline void id_type::set_lsb(std::uint64_t lsb) const { gid_->set_lsb(lsb); } - inline void id_type::set_lsb(void* lsb) + inline void id_type::set_lsb(void* lsb) const { gid_->set_lsb(lsb); } diff --git a/libs/full/naming_base/src/id_type.cpp b/libs/full/naming_base/src/id_type.cpp index fa270c9428f8..94ef2ff94fa3 100644 --- a/libs/full/naming_base/src/id_type.cpp +++ b/libs/full/naming_base/src/id_type.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2007-2022 Hartmut Kaiser +// Copyright (c) 2007-2023 Hartmut Kaiser // // SPDX-License-Identifier: BSL-1.0 // Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -18,6 +18,9 @@ namespace hpx { /////////////////////////////////////////////////////////////////////////// namespace naming::detail { + void (*gid_managed_deleter)(id_type_impl const* p) noexcept = nullptr; + void (*gid_unmanaged_deleter)(id_type_impl const* p) noexcept = nullptr; + util::internal_allocator id_type_impl::alloc_; id_type_impl::deleter_type id_type_impl::get_deleter( @@ -26,18 +29,18 @@ namespace hpx { switch (t) { case hpx::id_type::management_type::unmanaged: - return &detail::gid_unmanaged_deleter; + return gid_unmanaged_deleter; case hpx::id_type::management_type::managed: [[fallthrough]]; case hpx::id_type::management_type::managed_move_credit: - return &detail::gid_managed_deleter; + return gid_managed_deleter; default: HPX_ASSERT(false); // invalid management type - return &detail::gid_unmanaged_deleter; + break; } - return nullptr; + return gid_unmanaged_deleter; } // support functions for hpx::intrusive_ptr @@ -62,9 +65,10 @@ namespace hpx { return *this; } - id_type id_type::operator++(int) // post-increment + id_type id_type::operator++(int) const + // post-increment { - return id_type((*gid_)++, management_type::unmanaged); + return {(*gid_)++, management_type::unmanaged}; } // comparison is required as well @@ -138,10 +142,10 @@ namespace hpx::traits { hpx::id_type get_remote_result::call( naming::gid_type const& rhs) { - bool has_credits = naming::detail::has_credits(rhs); - return hpx::id_type(rhs, + bool const has_credits = naming::detail::has_credits(rhs); + return {rhs, has_credits ? hpx::id_type::management_type::managed : - hpx::id_type::management_type::unmanaged); + hpx::id_type::management_type::unmanaged}; } // we need to specialize this template to allow for automatic conversion of @@ -154,7 +158,7 @@ namespace hpx::traits { result.reserve(rhs.size()); for (naming::gid_type const& r : rhs) { - bool has_credits = naming::detail::has_credits(r); + bool const has_credits = naming::detail::has_credits(r); result.emplace_back(r, has_credits ? hpx::id_type::management_type::managed : hpx::id_type::management_type::unmanaged); diff --git a/libs/full/parcelports/CMakeLists.txt b/libs/full/parcelports/CMakeLists.txt new file mode 100644 index 000000000000..c775de66a0af --- /dev/null +++ b/libs/full/parcelports/CMakeLists.txt @@ -0,0 +1,58 @@ +# Copyright (c) 2019-2023 The STE||AR-Group +# +# SPDX-License-Identifier: BSL-1.0 +# 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_DISTRIBUTED_RUNTIME) + return() +endif() + +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") + +set(parcelports_headers hpx/parcelports/init_all_parcelports.hpp) + +set(parcelports_sources static_parcelports.cpp) + +set(parcelports_generated_headers hpx/parcelports/static_parcelports.hpp) + +set(parcelport_module_dependencies) +set(parcelport_export_declarations) +set(parcelport_init_definitions) + +foreach(parcelport ${HPX_STATIC_PARCELPORT_PLUGINS}) + set(parcelport_module_dependencies ${parcelport_module_dependencies} + hpx_${parcelport} + ) + + # generate header defining initialization functions for parcelports + set(parcelport_export_declarations + "${parcelport_export_declarations}HPX_EXPORT hpx::plugins::parcelport_factory_base *\n" + ) + set(parcelport_export_declarations + "${parcelport_export_declarations} ${parcelport}_factory_init(\n" + ) + set(parcelport_export_declarations + "${parcelport_export_declarations} std::vector& factories);\n" + ) + set(parcelport_init_definitions + "${parcelport_init_definitions} ${parcelport}_factory_init(factories);\n" + ) +endforeach() + +configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/static_parcelports.hpp.in" + "${CMAKE_CURRENT_BINARY_DIR}/include/hpx/parcelports/static_parcelports.hpp" + @ONLY +) + +include(HPX_AddModule) +add_hpx_module( + full parcelports + GLOBAL_HEADER_GEN OFF + GENERATED_HEADERS ${parcelports_generated_headers} + SOURCES ${parcelports_sources} + HEADERS ${parcelports_headers} + DEPENDENCIES hpx_core + MODULE_DEPENDENCIES hpx_parcelset ${parcelport_module_dependencies} +) diff --git a/cmake/templates/static_parcelports.hpp.in b/libs/full/parcelports/cmake/templates/static_parcelports.hpp.in similarity index 62% rename from cmake/templates/static_parcelports.hpp.in rename to libs/full/parcelports/cmake/templates/static_parcelports.hpp.in index 4f068f446455..92c74024334b 100644 --- a/cmake/templates/static_parcelports.hpp.in +++ b/libs/full/parcelports/cmake/templates/static_parcelports.hpp.in @@ -1,5 +1,5 @@ // Copyright (c) 2012-2015 Thomas Heller -// Copyright (c) 2007-2021 Hartmut Kaiser +// Copyright (c) 2007-2023 Hartmut Kaiser // // SPDX-License-Identifier: BSL-1.0 // Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -9,16 +9,23 @@ #pragma once -#include +#include + +#if defined(HPX_HAVE_NETWORKING) #include #include -@_parcelport_export@ +@parcelport_export_declarations@ namespace hpx::parcelset { - void init_static_parcelport_factories( + // force linking with this module + HPX_EXPORT void init_parcel_ports(); + + inline void init_static_parcelport_factories_impl( std::vector& factories) { -@_parcelport_init@ } +@parcelport_init_definitions@ } } + +#endif diff --git a/libs/full/parcelports/include/hpx/parcelports/init_all_parcelports.hpp b/libs/full/parcelports/include/hpx/parcelports/init_all_parcelports.hpp new file mode 100644 index 000000000000..554173676522 --- /dev/null +++ b/libs/full/parcelports/include/hpx/parcelports/init_all_parcelports.hpp @@ -0,0 +1,19 @@ +// Copyright (c) 2023 Hartmut Kaiser +// +// SPDX-License-Identifier: BSL-1.0 +// 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) + +#pragma once + +#include + +#if defined(HPX_HAVE_NETWORKING) + +namespace hpx::parcelset +{ + // force linking with this module + HPX_EXPORT void init_all_parcelports(); +} + +#endif diff --git a/libs/full/parcelports/src/static_parcelports.cpp b/libs/full/parcelports/src/static_parcelports.cpp new file mode 100644 index 000000000000..7258b6171cd9 --- /dev/null +++ b/libs/full/parcelports/src/static_parcelports.cpp @@ -0,0 +1,35 @@ +// Copyright (c) 2023 Hartmut Kaiser +// +// SPDX-License-Identifier: BSL-1.0 +// 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 + +#if defined(HPX_HAVE_NETWORKING) +#include +#include +#include +#include + +#include + +namespace hpx::parcelset { + + void (*init_static_parcelport_factories)( + std::vector& factories) = nullptr; + + struct HPX_EXPORT init_parcelports + { + init_parcelports() + { + init_static_parcelport_factories = + init_static_parcelport_factories_impl; + } + } init; + + // force linking with this module + void init_all_parcelports() {} +} // namespace hpx::parcelset + +#endif diff --git a/libs/full/parcelset/CMakeLists.txt b/libs/full/parcelset/CMakeLists.txt index 3b331756c5a8..cc49c3f793aa 100644 --- a/libs/full/parcelset/CMakeLists.txt +++ b/libs/full/parcelset/CMakeLists.txt @@ -14,6 +14,7 @@ set(parcelset_headers hpx/parcelset/detail/parcel_await.hpp hpx/parcelset/detail/message_handler_interface_functions.hpp hpx/parcelset/encode_parcels.hpp + hpx/parcelset/init_parcelports.hpp hpx/parcelset/message_handler_fwd.hpp hpx/parcelset/parcel.hpp hpx/parcelset/parcelhandler.hpp diff --git a/libs/full/parcelset/include/hpx/parcelset/init_parcelports.hpp b/libs/full/parcelset/include/hpx/parcelset/init_parcelports.hpp new file mode 100644 index 000000000000..02420f7fe211 --- /dev/null +++ b/libs/full/parcelset/include/hpx/parcelset/init_parcelports.hpp @@ -0,0 +1,22 @@ +// Copyright (c) 2023 Hartmut Kaiser +// +// SPDX-License-Identifier: BSL-1.0 +// 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) + +#pragma once + +#include + +#if defined(HPX_HAVE_NETWORKING) +#include + +#include + +namespace hpx::parcelset { + + extern HPX_EXPORT void (*init_static_parcelport_factories)( + std::vector& factories); +} + +#endif diff --git a/libs/full/parcelset/src/parcelhandler.cpp b/libs/full/parcelset/src/parcelhandler.cpp index 8e073b362af6..216bca8e52c4 100644 --- a/libs/full/parcelset/src/parcelhandler.cpp +++ b/libs/full/parcelset/src/parcelhandler.cpp @@ -33,9 +33,9 @@ #include #include +#include #include #include -#include #include #include #include diff --git a/libs/full/plugin_factories/include/hpx/plugin_factories/parcelport_factory.hpp b/libs/full/plugin_factories/include/hpx/plugin_factories/parcelport_factory.hpp index 763aab44c689..3e9922a46a2d 100644 --- a/libs/full/plugin_factories/include/hpx/plugin_factories/parcelport_factory.hpp +++ b/libs/full/plugin_factories/include/hpx/plugin_factories/parcelport_factory.hpp @@ -1,5 +1,5 @@ // Copyright (c) 2014 Thomas Heller -// Copyright (c) 2007-2022 Hartmut Kaiser +// Copyright (c) 2007-2023 Hartmut Kaiser // Copyright (c) 2020 Google // // SPDX-License-Identifier: BSL-1.0 From 268b225a52930885ef801940ef16dc8ca610d81e Mon Sep 17 00:00:00 2001 From: Hartmut Kaiser Date: Fri, 18 Aug 2023 15:18:07 -0500 Subject: [PATCH 06/25] Fixing test failure - flyby: remove stubs from example --- .../cancelable_action/cancelable_action.cpp | 10 ++--- .../cancelable_action/cancelable_action.hpp | 22 +++++----- .../server/cancelable_action.hpp | 37 ++++++++++------ .../stubs/cancelable_action.hpp | 43 ------------------- .../cancelable_action_client.cpp | 5 ++- .../hpx/parcelports/init_all_parcelports.hpp | 6 +-- 6 files changed, 47 insertions(+), 76 deletions(-) delete mode 100644 examples/cancelable_action/cancelable_action/stubs/cancelable_action.hpp diff --git a/examples/cancelable_action/cancelable_action/cancelable_action.cpp b/examples/cancelable_action/cancelable_action/cancelable_action.cpp index 189b352e556c..8c176f414cc2 100644 --- a/examples/cancelable_action/cancelable_action/cancelable_action.cpp +++ b/examples/cancelable_action/cancelable_action/cancelable_action.cpp @@ -1,14 +1,14 @@ -// Copyright (c) 2007-2012 Hartmut Kaiser +// Copyright (c) 2007-2023 Hartmut Kaiser // // SPDX-License-Identifier: BSL-1.0 // 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 + #if !defined(HPX_COMPUTE_DEVICE_CODE) -#include #include -#include +#include #include "server/cancelable_action.hpp" @@ -17,8 +17,8 @@ HPX_REGISTER_COMPONENT_MODULE() /////////////////////////////////////////////////////////////////////////////// -typedef hpx::components::component - cancelable_action_component_type; +using cancelable_action_component_type = + hpx::components::component; HPX_REGISTER_COMPONENT(cancelable_action_component_type, cancelable_action) diff --git a/examples/cancelable_action/cancelable_action/cancelable_action.hpp b/examples/cancelable_action/cancelable_action/cancelable_action.hpp index cd660ff0e4ab..372ac05e1ebd 100644 --- a/examples/cancelable_action/cancelable_action/cancelable_action.hpp +++ b/examples/cancelable_action/cancelable_action/cancelable_action.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2007-2011 Hartmut Kaiser +// Copyright (c) 2007-2023 Hartmut Kaiser // // SPDX-License-Identifier: BSL-1.0 // Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -11,21 +11,21 @@ #include #include -#include "stubs/cancelable_action.hpp" +#include "server/cancelable_action.hpp" #include namespace examples { + /////////////////////////////////////////////////////////////////////////// // Client side representation for for the \a server::cancelable_action // component. class cancelable_action : public hpx::components::client_base + server::cancelable_action> { - typedef hpx::components::client_base - base_type; + using base_type = hpx::components::client_base; public: // Default construct an empty client side representation (not @@ -45,16 +45,18 @@ namespace examples { } /////////////////////////////////////////////////////////////////////// - void do_it(hpx::error_code& ec = hpx::throws) + void do_it(hpx::error_code& ec = hpx::throws) const { + using action_type = server::cancelable_action::do_it_action; HPX_ASSERT(this->get_id()); - this->base_type::do_it(this->get_id(), ec); + hpx::async(this->get_id()).get(ec); } - void cancel_it() + void cancel_it() const { + using action_type = server::cancelable_action::cancel_it_action; HPX_ASSERT(this->get_id()); - this->base_type::cancel_it(this->get_id()); + hpx::post(this->get_id()); } }; } // namespace examples diff --git a/examples/cancelable_action/cancelable_action/server/cancelable_action.hpp b/examples/cancelable_action/cancelable_action/server/cancelable_action.hpp index b3b9de3e62f7..9c131d256650 100644 --- a/examples/cancelable_action/cancelable_action/server/cancelable_action.hpp +++ b/examples/cancelable_action/cancelable_action/server/cancelable_action.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2007-2022 Hartmut Kaiser +// Copyright (c) 2007-2023 Hartmut Kaiser // // SPDX-License-Identifier: BSL-1.0 // Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -7,18 +7,22 @@ #pragma once #include + #if !defined(HPX_COMPUTE_DEVICE_CODE) -#include +#include + #include #include #include #include #include +#include #include /////////////////////////////////////////////////////////////////////////////// -namespace examples { namespace server { +namespace examples::server { + /////////////////////////////////////////////////////////////////////////// inline void delay(int c) { @@ -50,24 +54,29 @@ namespace examples { namespace server { explicit reset_id(cancelable_action& this_) : outer_(this_) { - std::lock_guard l(outer_.mtx_); - hpx::thread::id old_value = outer_.id_; + auto const mtx = outer_.mtx_; + std::lock_guard l(*mtx); + + [[maybe_unused]] hpx::thread::id const old_value = outer_.id_; outer_.id_ = hpx::this_thread::get_id(); HPX_ASSERT(old_value == hpx::thread::id()); - HPX_UNUSED(old_value); } ~reset_id() { - hpx::thread::id old_value = outer_.id_; + [[maybe_unused]] hpx::thread::id const old_value = outer_.id_; outer_.id_ = hpx::thread::id(); HPX_ASSERT(old_value != hpx::thread::id()); - HPX_UNUSED(old_value); } cancelable_action& outer_; }; public: + cancelable_action() + : mtx_(std::make_shared()) + { + } + // Do some lengthy work void do_it() { @@ -85,15 +94,17 @@ namespace examples { namespace server { } // Cancel the lengthy action above - void cancel_it() + void cancel_it() const { // Make sure id_ has been set hpx::util::yield_while([this]() { - std::lock_guard l(mtx_); + auto const mtx = mtx_; + std::lock_guard l(*mtx); return id_ == hpx::thread::id(); }); - std::lock_guard l(mtx_); + auto const mtx = mtx_; + std::lock_guard l(*mtx); HPX_ASSERT(id_ != hpx::thread::id()); hpx::thread::interrupt(id_); } @@ -103,10 +114,10 @@ namespace examples { namespace server { cancelable_action, cancel_it, cancel_it_action) private: - hpx::mutex mtx_; + std::shared_ptr mtx_; hpx::thread::id id_; }; -}} // namespace examples::server +} // namespace examples::server /////////////////////////////////////////////////////////////////////////////// HPX_REGISTER_ACTION_DECLARATION( diff --git a/examples/cancelable_action/cancelable_action/stubs/cancelable_action.hpp b/examples/cancelable_action/cancelable_action/stubs/cancelable_action.hpp deleted file mode 100644 index e7253a683c72..000000000000 --- a/examples/cancelable_action/cancelable_action/stubs/cancelable_action.hpp +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (c) 2007-2012 Hartmut Kaiser -// -// SPDX-License-Identifier: BSL-1.0 -// 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) - -#pragma once - -#include -#if !defined(HPX_COMPUTE_DEVICE_CODE) -#include - -#include "../server/cancelable_action.hpp" - -/////////////////////////////////////////////////////////////////////////////// -namespace examples { namespace stubs { - /////////////////////////////////////////////////////////////////////////// - struct cancelable_action - : hpx::components::stub_base - { - // Do some lengthy work - static hpx::future do_it_async(hpx::id_type const& gid) - { - typedef server::cancelable_action::do_it_action action_type; - return hpx::async(gid); - } - - static void do_it( - hpx::id_type const& gid, hpx::error_code& ec = hpx::throws) - { - do_it_async(gid).get(ec); - } - - // Cancel the lengthy action above - static void cancel_it(hpx::id_type const& gid) - { - typedef server::cancelable_action::cancel_it_action action_type; - hpx::post(gid); - } - }; -}} // namespace examples::stubs - -#endif diff --git a/examples/cancelable_action/cancelable_action_client.cpp b/examples/cancelable_action/cancelable_action_client.cpp index 5d025fa10e2b..11e166230083 100644 --- a/examples/cancelable_action/cancelable_action_client.cpp +++ b/examples/cancelable_action/cancelable_action_client.cpp @@ -1,10 +1,11 @@ -// Copyright (c) 2007-2012 Hartmut Kaiser +// Copyright (c) 2007-2023 Hartmut Kaiser // // SPDX-License-Identifier: BSL-1.0 // 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 + #if !defined(HPX_COMPUTE_DEVICE_CODE) #include #include @@ -12,7 +13,7 @@ #include "cancelable_action/cancelable_action.hpp" /////////////////////////////////////////////////////////////////////////////// -void interrupt_do_it(examples::cancelable_action ca) +void interrupt_do_it(examples::cancelable_action const& ca) { // wait for one second before interrupting the (possibly remote) operation hpx::this_thread::sleep_for(std::chrono::seconds(1)); diff --git a/libs/full/parcelports/include/hpx/parcelports/init_all_parcelports.hpp b/libs/full/parcelports/include/hpx/parcelports/init_all_parcelports.hpp index 554173676522..2c4c2eb190db 100644 --- a/libs/full/parcelports/include/hpx/parcelports/init_all_parcelports.hpp +++ b/libs/full/parcelports/include/hpx/parcelports/init_all_parcelports.hpp @@ -10,10 +10,10 @@ #if defined(HPX_HAVE_NETWORKING) -namespace hpx::parcelset -{ +namespace hpx::parcelset { + // force linking with this module HPX_EXPORT void init_all_parcelports(); -} +} // namespace hpx::parcelset #endif From 57170177fdc89b5a8300139d47fa2e6f159b641e Mon Sep 17 00:00:00 2001 From: Hartmut Kaiser Date: Fri, 18 Aug 2023 17:49:26 -0500 Subject: [PATCH 07/25] Don't register components if in local mode --- libs/full/init_runtime/src/hpx_init.cpp | 62 ++++++++++++++----------- 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/libs/full/init_runtime/src/hpx_init.cpp b/libs/full/init_runtime/src/hpx_init.cpp index 67222404d61e..5351ef014e4d 100644 --- a/libs/full/init_runtime/src/hpx_init.cpp +++ b/libs/full/init_runtime/src/hpx_init.cpp @@ -130,11 +130,17 @@ namespace hpx::detail { freebsd_environ = environ; #endif // set a handler for std::abort, std::at_quick_exit, and std::atexit - std::signal(SIGABRT, detail::on_abort); - std::atexit(detail::on_exit); + [[maybe_unused]] auto const prev_signal = + std::signal(SIGABRT, detail::on_abort); + HPX_ASSERT(prev_signal != SIG_ERR); + + [[maybe_unused]] auto const ret_at_exit = std::atexit(detail::on_exit); + HPX_ASSERT(ret_at_exit == 0); + #if defined(HPX_HAVE_CXX11_STD_QUICK_EXIT) - [[maybe_unused]] int const ret = std::at_quick_exit(detail::on_exit); - HPX_ASSERT(ret == 0); + [[maybe_unused]] auto const ret_at_quick_exit = + std::at_quick_exit(detail::on_exit); + HPX_ASSERT(ret_at_quick_exit == 0); #endif return detail::run_or_start(f, argc, argv, params, true); } @@ -163,11 +169,17 @@ namespace hpx::detail { freebsd_environ = environ; #endif // set a handler for std::abort, std::at_quick_exit, and std::atexit - std::signal(SIGABRT, detail::on_abort); - std::atexit(detail::on_exit); + [[maybe_unused]] auto const prev_signal = + std::signal(SIGABRT, detail::on_abort); + HPX_ASSERT(prev_signal != SIG_ERR); + + [[maybe_unused]] auto const ret_atexit = std::atexit(detail::on_exit); + HPX_ASSERT(ret_atexit == 0); + #if defined(HPX_HAVE_CXX11_STD_QUICK_EXIT) - [[maybe_unused]] int const ret = std::at_quick_exit(detail::on_exit); - HPX_ASSERT(ret == 0); + [[maybe_unused]] auto const ret_at_quick_exit = + std::at_quick_exit(detail::on_exit); + HPX_ASSERT(ret_at_quick_exit == 0); #endif return 0 == detail::run_or_start(f, argc, argv, params, false); } @@ -870,15 +882,15 @@ namespace hpx { hpx_startup::user_main_config(params.cfg), f}; #endif + std::vector< + std::shared_ptr> + component_registries; + // scope exception handling to resource partitioner initialization // any exception thrown during run_or_start below are handled // separately try { - std::vector< - std::shared_ptr> - component_registries; - result = cmdline.call( params.desc_cmdline, argc, argv, component_registries); @@ -903,13 +915,6 @@ namespace hpx { hpx::resource::detail::make_partitioner( params.rp_mode, cmdline.rtcfg_, affinity_data); - for (auto& registry : component_registries) - { - hpx::register_startup_function([registry]() { - registry->register_component_type(); - }); - } - activate_global_options(cmdline, argc, argv); // check whether HPX should be exited at this point @@ -964,6 +969,13 @@ namespace hpx { default: { #if defined(HPX_HAVE_DISTRIBUTED_RUNTIME) + for (auto const& registry : component_registries) + { + hpx::register_startup_function([registry]() { + registry->register_component_type(); + }); + } + LPROGRESS_ << "creating distributed runtime"; rt.reset(new hpx::runtime_distributed(cmdline.rtcfg_, &hpx::detail::pre_main, &hpx::detail::post_main)); @@ -1011,7 +1023,7 @@ namespace hpx { } catch (hpx::util::bad_lexical_cast const&) { - ; // do nothing + // do nothing } } return default_; @@ -1112,9 +1124,8 @@ namespace hpx { if (std::abs(shutdown_timeout + 1.0) < 1e-16) shutdown_timeout = detail::get_option("hpx.shutdown_timeout", -1.0); - components::server::runtime_support* p = - static_cast( - get_runtime_distributed().get_runtime_support_lva()); + auto* p = static_cast( + get_runtime_distributed().get_runtime_support_lva()); if (nullptr == p) { @@ -1147,9 +1158,8 @@ namespace hpx { } #if defined(HPX_HAVE_DISTRIBUTED_RUNTIME) - components::server::runtime_support* p = - static_cast( - get_runtime_distributed().get_runtime_support_lva()); + auto* p = static_cast( + get_runtime_distributed().get_runtime_support_lva()); if (nullptr == p) { From d992fa072abcfb3a88efc4c1fd2076dd7e1f0d75 Mon Sep 17 00:00:00 2001 From: Hartmut Kaiser Date: Sat, 19 Aug 2023 09:59:19 -0500 Subject: [PATCH 08/25] Adding POSITION_INDEPENDENT_CODE=ON to all HPX targets --- cmake/HPX_SetupTarget.cmake | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmake/HPX_SetupTarget.cmake b/cmake/HPX_SetupTarget.cmake index aec75f68959e..5b3f8c61950b 100644 --- a/cmake/HPX_SetupTarget.cmake +++ b/cmake/HPX_SetupTarget.cmake @@ -216,6 +216,8 @@ function(hpx_setup_target target) hpx_debug("setup_target.${target} UNITY_BUILD: OFF") endif() + set_target_properties(${target} PROPERTIES POSITION_INDEPENDENT_CODE ON) + get_target_property(target_EXCLUDE_FROM_ALL ${target} EXCLUDE_FROM_ALL) if(target_EXPORT AND NOT target_EXCLUDE_FROM_ALL) From d17c9c5e1e8d83f6b4710c9f2bde47734f709bc2 Mon Sep 17 00:00:00 2001 From: Hartmut Kaiser Date: Wed, 19 Jul 2023 17:49:57 -0500 Subject: [PATCH 09/25] Adapting build system for CMake V3.27 --- CMakeLists.txt | 33 ++++--- cmake/FindAmplifier.cmake | 53 ++++++----- cmake/FindAsio.cmake | 46 +++++---- cmake/FindBreathe.cmake | 17 +++- cmake/FindHwloc.cmake | 67 +++++++------ cmake/FindJemalloc.cmake | 95 ++++++++++--------- cmake/FindLibSigSegv.cmake | 64 +++++++------ cmake/FindLibfabric.cmake | 39 +++++--- cmake/FindMSR.cmake | 43 +++++---- cmake/FindOrangeFS.cmake | 45 +++++---- cmake/FindPAPI.cmake | 71 -------------- cmake/FindPWR.cmake | 73 +++++++------- cmake/FindPapi.cmake | 88 +++++++++++++++++ cmake/FindQThreads.cmake | 45 +++++---- cmake/FindRDMA_CM.cmake | 30 ++++-- cmake/FindRdmacm.cmake | 37 +++++--- cmake/FindSnappy.cmake | 49 ++++++---- cmake/FindSphinx.cmake | 17 +++- cmake/FindTBB.cmake | 41 ++++---- cmake/FindTBBmalloc.cmake | 69 ++++++++------ cmake/FindTCMalloc.cmake | 61 +++++++----- cmake/FindValgrind.cmake | 27 ++++-- cmake/HPX_AddTest.cmake | 6 +- cmake/HPX_Documentation.cmake | 8 +- cmake/HPX_SetupAllocator.cmake | 22 ++--- cmake/HPX_SetupApex.cmake | 51 +++++++--- cmake/HPX_SetupAsio.cmake | 20 +++- cmake/HPX_SetupBoost.cmake | 21 ++-- cmake/HPX_SetupBoostFilesystem.cmake | 7 +- cmake/HPX_SetupBoostIostreams.cmake | 6 +- cmake/HPX_SetupBoostRegex.cmake | 6 +- cmake/HPX_SetupEve.cmake | 24 +++-- cmake/HPX_SetupHIP.cmake | 2 +- cmake/HPX_SetupHwloc.cmake | 4 +- cmake/HPX_SetupLCI.cmake | 16 +++- cmake/HPX_SetupPapi.cmake | 6 +- cmake/HPX_SetupSVE.cmake | 24 +++-- cmake/HPX_SetupValgrind.cmake | 4 +- cmake/installed_hpx.cmake | 19 +++- cmake/templates/HPXConfig.cmake.in | 46 ++++----- cmake/templates/HPXMacros.cmake.in | 8 +- cmake/templates/cmake_variables.rst.in | 12 +-- cmake/templates/hpxcxx.in | 2 +- cmake/templates/hpxrun.py.in | 2 +- cmake/toolchains/BGION-gcc.cmake | 4 +- .../binary_filter/snappy/CMakeLists.txt | 11 ++- docs/CMakeLists.txt | 4 +- docs/sphinx/contributing/documentation.rst | 6 +- docs/sphinx/manual/building_hpx.rst | 30 +++--- docs/sphinx/manual/creating_hpx_projects.rst | 20 ++-- .../manual/optimizing_hpx_applications.rst | 2 +- docs/sphinx/manual/troubleshooting.rst | 4 +- docs/sphinx/releases/whats_new_1_10_0.rst | 4 + examples/1d_stencil/README.APEX | 2 +- libs/CMakeLists.txt | 2 +- .../cmake/HPX_SetupJSON.cmake | 19 +++- .../parcelport_libfabric/cmake/FindPMI.cmake | 66 +++++++------ tests/performance/local/CMakeLists.txt | 10 +- .../performance/local/htts_v2/CMakeLists.txt | 8 +- tools/build_boost.sh | 4 +- 60 files changed, 971 insertions(+), 651 deletions(-) delete mode 100644 cmake/FindPAPI.cmake create mode 100644 cmake/FindPapi.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 49196caf2f18..dbac004e39f4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1265,7 +1265,7 @@ hpx_option( ) if(HPX_WITH_EXAMPLES_TBB) find_package(TBB) - if(NOT TBB_FOUND) + if(NOT Tbb_FOUND) set(HPX_WITH_EXAMPLES_TBB OFF) endif() endif() @@ -1277,7 +1277,7 @@ hpx_option( ) if(HPX_WITH_EXAMPLES_QTHREADS) find_package(QThreads) - if(NOT QTHREADS_FOUND) + if(NOT Qthreads_FOUND) set(HPX_WITH_EXAMPLES_QTHREADS OFF) endif() endif() @@ -1290,7 +1290,7 @@ hpx_option( ) if(HPX_WITH_EXAMPLES_HDF5) find_package(HDF5 COMPONENTS CXX) - if(NOT HDF5_FOUND) + if(NOT Hdf5_FOUND) set(HPX_WITH_EXAMPLES_HDF5 OFF) endif() endif() @@ -1305,7 +1305,7 @@ if(NOT "${HPX_PLATFORM_UC}" STREQUAL "BLUEGENEQ") ) if(HPX_WITH_EXAMPLES_QT4) find_package(Qt4) - if(NOT QT4_FOUND) + if(NOT Qt4_FOUND) set(HPX_WITH_EXAMPLES_QT4 OFF) endif() endif() @@ -2310,12 +2310,23 @@ add_subdirectory(components) # ############################################################################## # Tests # ############################################################################## -find_package(PythonInterp) +if(POLICY CMP0148) + find_package(Python COMPONENTS Interpreter) + if(NOT Python_FOUND) + hpx_warn( + "A python interpreter could not be found. The test suite can not be run automatically." + ) + endif() -if(NOT PYTHONINTERP_FOUND) - hpx_warn( - "A python interpreter could not be found. The test suite can not be run automatically." - ) +else() + find_package(PythonInterp) + if(NOT PYTHONINTERP_FOUND) + hpx_warn( + "A python interpreter could not be found. The test suite can not be run automatically." + ) + else() + set(Python_EXECUTABLE ${PYTHON_EXECUTABLE}) + endif() endif() if(HPX_WITH_TESTS) @@ -2341,7 +2352,7 @@ if(HPX_WITH_TOOLS OR HPX_WITH_TESTS_BENCHMARKS) endif() # Configure hpxrun.py -if(PYTHONINTERP_FOUND) +if(PYTHONINTERP_FOUND OR Python_FOUND) configure_file( "${PROJECT_SOURCE_DIR}/cmake/templates/hpxrun.py.in" "${PROJECT_BINARY_DIR}/bin/hpxrun.py" @ONLY @@ -2466,7 +2477,7 @@ endif() # ############################################################################## # installation instructions # ############################################################################## -if(PYTHONINTERP_FOUND) +if(PYTHONINTERP_FOUND OR Python_FOUND) install( FILES "${PROJECT_BINARY_DIR}/bin/hpxrun.py" DESTINATION ${CMAKE_INSTALL_BINDIR} diff --git a/cmake/FindAmplifier.cmake b/cmake/FindAmplifier.cmake index abdacd13ac93..41ffbf74434e 100644 --- a/cmake/FindAmplifier.cmake +++ b/cmake/FindAmplifier.cmake @@ -1,64 +1,73 @@ # Copyright (c) 2014 Thomas Heller -# Copyright (c) 2012 Hartmut Kaiser +# Copyright (c) 2012-2023 Hartmut Kaiser # # SPDX-License-Identifier: BSL-1.0 # 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 TARGET Amplifier::amplifier) + # compatibility with older CMake versions + if(AMPLIFIER_ROOT AND NOT Amplifier_ROOT) + set(Amplifier_ROOT + ${AMPLIFIER_ROOT} + CACHE PATH "Amplifier base directory" + ) + unset(AMPLIFIER_ROOT CACHE) + endif() + find_package(PkgConfig QUIET) pkg_check_modules(PC_AMPLIFIER QUIET amplifier) find_path( - AMPLIFIER_INCLUDE_DIR ittnotify.h - HINTS ${AMPLIFIER_ROOT} ENV AMPLIFIER_ROOT ${PC_AMPLIFIER_INCLUDEDIR} - ${PC_AMPLIFIER_INCLUDE_DIRS} + Amplifier_INCLUDE_DIR ittnotify.h + HINTS ${Amplifier_ROOT} ENV AMPLIFIER_ROOT ${PC_Amplifier_INCLUDEDIR} + ${PC_Amplifier_INCLUDE_DIRS} PATH_SUFFIXES include ) find_library( - AMPLIFIER_LIBRARY + Amplifier_LIBRARY NAMES ittnotify libittnotify - HINTS ${AMPLIFIER_ROOT} ENV AMPLIFIER_ROOT ${PC_AMPLIFIER_LIBDIR} - ${PC_AMPLIFIER_LIBRARY_DIRS} + HINTS ${Amplifier_ROOT} ENV AMPLIFIER_ROOT ${PC_Amplifier_LIBDIR} + ${PC_Amplifier_LIBRARY_DIRS} PATH_SUFFIXES lib lib64 ) - # Set AMPLIFIER_ROOT in case the other hints are used - if(AMPLIFIER_ROOT) + # Set Amplifier_ROOT in case the other hints are used + if(Amplifier_ROOT) # The call to file is for compatibility for windows paths - file(TO_CMAKE_PATH ${AMPLIFIER_ROOT} AMPLIFIER_ROOT) + file(TO_CMAKE_PATH ${Amplifier_ROOT} Amplifier_ROOT) elseif("$ENV{AMPLIFIER_ROOT}") - file(TO_CMAKE_PATH $ENV{AMPLIFIER_ROOT} AMPLIFIER_ROOT) + file(TO_CMAKE_PATH $ENV{AMPLIFIER_ROOT} Amplifier_ROOT) else() - file(TO_CMAKE_PATH "${AMPLIFIER_INCLUDE_DIR}" AMPLIFIER_INCLUDE_DIR) - string(REPLACE "/include" "" AMPLIFIER_ROOT "${AMPLIFIER_INCLUDE_DIR}") + file(TO_CMAKE_PATH "${Amplifier_INCLUDE_DIR}" Amplifier_INCLUDE_DIR) + string(REPLACE "/include" "" Amplifier_ROOT "${Amplifier_INCLUDE_DIR}") endif() - set(AMPLIFIER_LIBRARIES ${AMPLIFIER_LIBRARY}) - set(AMPLIFIER_INCLUDE_DIRS ${AMPLIFIER_INCLUDE_DIR}) + set(Amplifier_LIBRARIES ${Amplifier_LIBRARY}) + set(Amplifier_INCLUDE_DIRS ${Amplifier_INCLUDE_DIR}) find_package_handle_standard_args( - Amplifier DEFAULT_MSG AMPLIFIER_LIBRARY AMPLIFIER_INCLUDE_DIR + Amplifier DEFAULT_MSG Amplifier_LIBRARY Amplifier_INCLUDE_DIR ) get_property( _type - CACHE AMPLIFIER_ROOT + CACHE Amplifier_ROOT PROPERTY TYPE ) if(_type) - set_property(CACHE AMPLIFIER_ROOT PROPERTY ADVANCED 1) + set_property(CACHE Amplifier_ROOT PROPERTY ADVANCED 1) if("x${_type}" STREQUAL "xUNINITIALIZED") - set_property(CACHE AMPLIFIER_ROOT PROPERTY TYPE PATH) + set_property(CACHE Amplifier_ROOT PROPERTY TYPE PATH) endif() endif() - mark_as_advanced(AMPLIFIER_ROOT AMPLIFIER_LIBRARY AMPLIFIER_INCLUDE_DIR) + mark_as_advanced(Amplifier_ROOT Amplifier_LIBRARY Amplifier_INCLUDE_DIR) add_library(Amplifier::amplifier INTERFACE IMPORTED) target_include_directories( - Amplifier::amplifier SYSTEM INTERFACE ${AMPLIFIER_INCLUDE_DIR} + Amplifier::amplifier SYSTEM INTERFACE ${Amplifier_INCLUDE_DIR} ) - target_link_libraries(Amplifier::amplifier INTERFACE ${AMPLIFIER_LIBRARIES}) + target_link_libraries(Amplifier::amplifier INTERFACE ${Amplifier_LIBRARIES}) endif() diff --git a/cmake/FindAsio.cmake b/cmake/FindAsio.cmake index d66bcff352e5..76fea2033ddd 100644 --- a/cmake/FindAsio.cmake +++ b/cmake/FindAsio.cmake @@ -8,57 +8,67 @@ # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) if(NOT TARGET Asio::asio) + # compatibility with older CMake versions + if(ASIO_ROOT AND NOT Asio_ROOT) + set(Asio_ROOT + ${ASIO_ROOT} + CACHE PATH "Asio base directory" + ) + unset(ASIO_ROOT CACHE) + endif() + find_path( - ASIO_INCLUDE_DIR asio.hpp - HINTS "${ASIO_ROOT}" ENV ASIO_ROOT "${HPX_ASIO_ROOT}" + Asio_INCLUDE_DIR asio.hpp + HINTS "${Asio_ROOT}" ENV ASIO_ROOT "${HPX_ASIO_ROOT}" PATH_SUFFIXES include ) - if(NOT ASIO_INCLUDE_DIR) + if(NOT Asio_INCLUDE_DIR) hpx_error( - "Could not find Asio. Set ASIO_ROOT as a CMake or environment variable to point to the Asio root install directory. Alternatively, set HPX_WITH_FETCH_ASIO=ON to fetch Asio using CMake's FetchContent (when using this option Asio will be installed together with HPX, be careful about conflicts with separately installed versions of Asio)." + "Could not find Asio. Set Asio_ROOT as a CMake or environment variable to point to the Asio root install directory. Alternatively, set HPX_WITH_FETCH_ASIO=ON to fetch Asio using CMake's FetchContent (when using this option Asio will be installed together with HPX, be careful about conflicts with separately installed versions of Asio)." ) endif() - # Set ASIO_ROOT in case the other hints are used - if(ASIO_ROOT) + # Set Asio_ROOT in case the other hints are used + if(Asio_ROOT) # The call to file is for compatibility with windows paths - file(TO_CMAKE_PATH ${ASIO_ROOT} ASIO_ROOT) + file(TO_CMAKE_PATH ${Asio_ROOT} Asio_ROOT) elseif("$ENV{ASIO_ROOT}") - file(TO_CMAKE_PATH $ENV{ASIO_ROOT} ASIO_ROOT) + file(TO_CMAKE_PATH $ENV{ASIO_ROOT} Asio_ROOT) else() - file(TO_CMAKE_PATH "${ASIO_INCLUDE_DIR}" ASIO_INCLUDE_DIR) - string(REPLACE "/include" "" ASIO_ROOT "${ASIO_INCLUDE_DIR}") + file(TO_CMAKE_PATH "${Asio_INCLUDE_DIR}" Asio_INCLUDE_DIR) + string(REPLACE "/include" "" Asio_ROOT "${Asio_INCLUDE_DIR}") endif() - if(ASIO_INCLUDE_DIR AND EXISTS "${ASIO_INCLUDE_DIR}/asio/version.hpp") + if(Asio_INCLUDE_DIR AND EXISTS "${Asio_INCLUDE_DIR}/asio/version.hpp") # Matches a line of the form: # # #define ASIO_VERSION XXYYZZ // XX.YY.ZZ # # with arbitrary whitespace between the tokens file( - STRINGS "${ASIO_INCLUDE_DIR}/asio/version.hpp" ASIO_VERSION_DEFINE_LINE + STRINGS "${Asio_INCLUDE_DIR}/asio/version.hpp" Asio_VERSION_DEFINE_LINE REGEX "#define[ \t]+ASIO_VERSION[ \t]+[0-9]+[ \t]+//[ \t]+[0-9]+\.[0-9]+\.[0-9]+[ \t]*" ) # Extracts the dotted version number after the comment as - # ASIO_VERSION_STRING + # Asio_VERSION_STRING string(REGEX REPLACE "#define ASIO_VERSION [0-9]+ // ([0-9]+\.[0-9]+\.[0-9]+)" - "\\1" ASIO_VERSION_STRING "${ASIO_VERSION_DEFINE_LINE}" + "\\1" Asio_VERSION_STRING "${Asio_VERSION_DEFINE_LINE}" ) endif() include(FindPackageHandleStandardArgs) find_package_handle_standard_args( Asio - REQUIRED_VARS ASIO_INCLUDE_DIR - VERSION_VAR ASIO_VERSION_STRING + REQUIRED_VARS Asio_INCLUDE_DIR + VERSION_VAR Asio_VERSION_STRING + FOUND_VAR Asio_FOUND ) add_library(Asio::asio INTERFACE IMPORTED) - target_include_directories(Asio::asio SYSTEM INTERFACE ${ASIO_INCLUDE_DIR}) + target_include_directories(Asio::asio SYSTEM INTERFACE ${Asio_INCLUDE_DIR}) - mark_as_advanced(ASIO_ROOT ASIO_INCLUDE_DIR ASIO_VERSION_STRING) + mark_as_advanced(Asio_ROOT Asio_INCLUDE_DIR Asio_VERSION_STRING) endif() diff --git a/cmake/FindBreathe.cmake b/cmake/FindBreathe.cmake index f8fc8bc14d74..a43963c2bba5 100644 --- a/cmake/FindBreathe.cmake +++ b/cmake/FindBreathe.cmake @@ -4,16 +4,25 @@ # 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) +# compatibility with older CMake versions +if(BREATHE_APIDOC_ROOT AND NOT Breathe_APIDOC_ROOT) + set(Breathe_APIDOC_ROOT + ${BREATHE_APIDOC_ROOT} + CACHE PATH "Breathe base directory" + ) + unset(BREATHE_ROOT CACHE) +endif() + find_program( - BREATHE_APIDOC_EXECUTABLE + Breathe_APIDOC_EXECUTABLE NAMES breathe-apidoc - PATHS ${BREATHE_APIDOC_ROOT} ENV BREATHE_APIDOC_ROOT + PATHS ${Breathe_APIDOC_ROOT} ENV Breathe_APIDOC_ROOT DOC "Path to breathe-apidoc executable" ) -if(BREATHE_APIDOC_EXECUTABLE) +if(Breathe_APIDOC_EXECUTABLE) include(FindPackageHandleStandardArgs) find_package_handle_standard_args( - Breathe DEFAULT_MESSAGE BREATHE_APIDOC_EXECUTABLE + Breathe DEFAULT_MESSAGE Breathe_APIDOC_EXECUTABLE ) endif() diff --git a/cmake/FindHwloc.cmake b/cmake/FindHwloc.cmake index 89dadf132013..7760048c948f 100644 --- a/cmake/FindHwloc.cmake +++ b/cmake/FindHwloc.cmake @@ -1,5 +1,5 @@ # Copyright (c) 2014 Thomas Heller -# Copyright (c) 2007-2012 Hartmut Kaiser +# Copyright (c) 2007-2023 Hartmut Kaiser # Copyright (c) 2010-2011 Matt Anderson # Copyright (c) 2011 Bryce Lelbach # @@ -8,70 +8,79 @@ # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) if(NOT TARGET Hwloc::hwloc) + # compatibility with older CMake versions + if(HWLOC_ROOT AND NOT Hwloc_ROOT) + set(Hwloc_ROOT + ${HWLOC_ROOT} + CACHE PATH "Hwloc base directory" + ) + unset(HWLOC_ROOT CACHE) + endif() + find_package(PkgConfig QUIET) pkg_check_modules(PC_HWLOC QUIET hwloc) find_path( - HWLOC_INCLUDE_DIR hwloc.h - HINTS ${HWLOC_ROOT} + Hwloc_INCLUDE_DIR hwloc.h + HINTS ${Hwloc_ROOT} ENV HWLOC_ROOT ${HPX_HWLOC_ROOT} - ${PC_HWLOC_MINIMAL_INCLUDEDIR} - ${PC_HWLOC_MINIMAL_INCLUDE_DIRS} - ${PC_HWLOC_INCLUDEDIR} - ${PC_HWLOC_INCLUDE_DIRS} + ${PC_Hwloc_MINIMAL_INCLUDEDIR} + ${PC_Hwloc_MINIMAL_INCLUDE_DIRS} + ${PC_Hwloc_INCLUDEDIR} + ${PC_Hwloc_INCLUDE_DIRS} PATH_SUFFIXES include ) find_library( - HWLOC_LIBRARY + Hwloc_LIBRARY NAMES libhwloc.so hwloc - HINTS ${HWLOC_ROOT} + HINTS ${Hwloc_ROOT} ENV HWLOC_ROOT - ${HPX_HWLOC_ROOT} - ${PC_HWLOC_MINIMAL_LIBDIR} - ${PC_HWLOC_MINIMAL_LIBRARY_DIRS} - ${PC_HWLOC_LIBDIR} - ${PC_HWLOC_LIBRARY_DIRS} + ${HPX_Hwloc_ROOT} + ${PC_Hwloc_MINIMAL_LIBDIR} + ${PC_Hwloc_MINIMAL_LIBRARY_DIRS} + ${PC_Hwloc_LIBDIR} + ${PC_Hwloc_LIBRARY_DIRS} PATH_SUFFIXES lib lib64 ) - # Set HWLOC_ROOT in case the other hints are used - if(HWLOC_ROOT) + # Set Hwloc_ROOT in case the other hints are used + if(Hwloc_ROOT) # The call to file is for compatibility with windows paths - file(TO_CMAKE_PATH ${HWLOC_ROOT} HWLOC_ROOT) + file(TO_CMAKE_PATH ${Hwloc_ROOT} Hwloc_ROOT) elseif("$ENV{HWLOC_ROOT}") - file(TO_CMAKE_PATH $ENV{HWLOC_ROOT} HWLOC_ROOT) + file(TO_CMAKE_PATH $ENV{HWLOC_ROOT} Hwloc_ROOT) else() - file(TO_CMAKE_PATH "${HWLOC_INCLUDE_DIR}" HWLOC_INCLUDE_DIR) - string(REPLACE "/include" "" HWLOC_ROOT "${HWLOC_INCLUDE_DIR}") + file(TO_CMAKE_PATH "${Hwloc_INCLUDE_DIR}" Hwloc_INCLUDE_DIR) + string(REPLACE "/include" "" Hwloc_ROOT "${Hwloc_INCLUDE_DIR}") endif() - set(HWLOC_LIBRARIES ${HWLOC_LIBRARY}) - set(HWLOC_INCLUDE_DIRS ${HWLOC_INCLUDE_DIR}) + set(Hwloc_LIBRARIES ${Hwloc_LIBRARY}) + set(Hwloc_INCLUDE_DIRS ${Hwloc_INCLUDE_DIR}) find_package_handle_standard_args( - Hwloc DEFAULT_MSG HWLOC_LIBRARY HWLOC_INCLUDE_DIR + Hwloc DEFAULT_MSG Hwloc_LIBRARY Hwloc_INCLUDE_DIR ) get_property( _type - CACHE HWLOC_ROOT + CACHE Hwloc_ROOT PROPERTY TYPE ) if(_type) - set_property(CACHE HWLOC_ROOT PROPERTY ADVANCED 1) + set_property(CACHE Hwloc_ROOT PROPERTY ADVANCED 1) if("x${_type}" STREQUAL "xUNINITIALIZED") - set_property(CACHE HWLOC_ROOT PROPERTY TYPE PATH) + set_property(CACHE Hwloc_ROOT PROPERTY TYPE PATH) endif() endif() add_library(Hwloc::hwloc INTERFACE IMPORTED) - target_include_directories(Hwloc::hwloc SYSTEM INTERFACE ${HWLOC_INCLUDE_DIR}) - - target_link_libraries(Hwloc::hwloc INTERFACE ${HWLOC_LIBRARIES}) + target_include_directories(Hwloc::hwloc SYSTEM INTERFACE ${Hwloc_INCLUDE_DIR}) + target_link_libraries(Hwloc::hwloc INTERFACE ${Hwloc_LIBRARIES}) mark_as_advanced(HWLOC_ROOT HWLOC_LIBRARY HWLOC_INCLUDE_DIR) + mark_as_advanced(Hwloc_ROOT Hwloc_LIBRARY Hwloc_INCLUDE_DIR) endif() diff --git a/cmake/FindJemalloc.cmake b/cmake/FindJemalloc.cmake index facccbbb7ca5..e828a39b5170 100644 --- a/cmake/FindJemalloc.cmake +++ b/cmake/FindJemalloc.cmake @@ -1,5 +1,5 @@ # Copyright (c) 2014 Thomas Heller -# Copyright (c) 2007-2012 Hartmut Kaiser +# Copyright (c) 2007-2023 Hartmut Kaiser # Copyright (c) 2010-2011 Matt Anderson # Copyright (c) 2011 Bryce Lelbach # @@ -7,19 +7,28 @@ # 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) +# compatibility with older CMake versions +if(JEMALLOC_ROOT AND NOT Jemalloc_ROOT) + set(Jemalloc_ROOT + ${JEMALLOC_ROOT} + CACHE PATH "Jemalloc base directory" + ) + unset(JEMALLOC_ROOT CACHE) +endif() + find_package(PkgConfig QUIET) pkg_check_modules(PC_JEMALLOC QUIET jemalloc) find_path( - JEMALLOC_INCLUDE_DIR jemalloc/jemalloc.h - HINTS ${JEMALLOC_ROOT} + Jemalloc_INCLUDE_DIR jemalloc/jemalloc.h + HINTS ${Jemalloc_ROOT} ENV - JEMALLOC_ROOT - ${HPX_JEMALLOC_ROOT} - ${PC_JEMALLOC_MINIMAL_INCLUDEDIR} - ${PC_JEMALLOC_MINIMAL_INCLUDE_DIRS} - ${PC_JEMALLOC_INCLUDEDIR} - ${PC_JEMALLOC_INCLUDE_DIRS} + Jemalloc_ROOT + ${HPX_Jemalloc_ROOT} + ${PC_Jemalloc_MINIMAL_INCLUDEDIR} + ${PC_Jemalloc_MINIMAL_INCLUDE_DIRS} + ${PC_Jemalloc_INCLUDEDIR} + ${PC_Jemalloc_INCLUDE_DIRS} PATH_SUFFIXES include ) @@ -27,68 +36,68 @@ if(MSVC) # MSVC needs additional header files provided by jemalloc to compensate for # missing posix headers find_path( - JEMALLOC_ADDITIONAL_INCLUDE_DIR msvc_compat/strings.h - HINTS ${JEMALLOC_ROOT} + Jemalloc_ADDITIONAL_INCLUDE_DIR msvc_compat/strings.h + HINTS ${Jemalloc_ROOT} ENV - JEMALLOC_ROOT - ${HPX_JEMALLOC_ROOT} - ${PC_JEMALLOC_MINIMAL_INCLUDEDIR} - ${PC_JEMALLOC_MINIMAL_INCLUDE_DIRS} - ${PC_JEMALLOC_INCLUDEDIR} - ${PC_JEMALLOC_INCLUDE_DIRS} + Jemalloc_ROOT + ${HPX_Jemalloc_ROOT} + ${PC_Jemalloc_MINIMAL_INCLUDEDIR} + ${PC_Jemalloc_MINIMAL_INCLUDE_DIRS} + ${PC_Jemalloc_INCLUDEDIR} + ${PC_Jemalloc_INCLUDE_DIRS} PATH_SUFFIXES include ) endif() -# Set JEMALLOC_ROOT in case the other hints are used -if(JEMALLOC_ROOT) +# Set Jemalloc_ROOT in case the other hints are used +if(Jemalloc_ROOT) # The call to file is for compatibility with windows paths - file(TO_CMAKE_PATH ${JEMALLOC_ROOT} JEMALLOC_ROOT) + file(TO_CMAKE_PATH ${Jemalloc_ROOT} Jemalloc_ROOT) elseif("$ENV{JEMALLOC_ROOT}") - file(TO_CMAKE_PATH $ENV{JEMALLOC_ROOT} JEMALLOC_ROOT) + file(TO_CMAKE_PATH $ENV{JEMALLOC_ROOT} Jemalloc_ROOT) else() - file(TO_CMAKE_PATH "${JEMALLOC_INCLUDE_DIR}" JEMALLOC_INCLUDE_DIR) - string(REPLACE "/include" "" JEMALLOC_ROOT "${JEMALLOC_INCLUDE_DIR}") + file(TO_CMAKE_PATH "${Jemalloc_INCLUDE_DIR}" Jemalloc_INCLUDE_DIR) + string(REPLACE "/include" "" Jemalloc_ROOT "${Jemalloc_INCLUDE_DIR}") endif() find_library( - JEMALLOC_LIBRARY + Jemalloc_LIBRARY NAMES jemalloc libjemalloc - HINTS ${JEMALLOC_ROOT} + HINTS ${Jemalloc_ROOT} ENV - JEMALLOC_ROOT - ${HPX_JEMALLOC_ROOT} - ${PC_JEMALLOC_MINIMAL_LIBDIR} - ${PC_JEMALLOC_MINIMAL_LIBRARY_DIRS} - ${PC_JEMALLOC_LIBDIR} - ${PC_JEMALLOC_LIBRARY_DIRS} + Jemalloc_ROOT + ${HPX_Jemalloc_ROOT} + ${PC_Jemalloc_MINIMAL_LIBDIR} + ${PC_Jemalloc_MINIMAL_LIBRARY_DIRS} + ${PC_Jemalloc_LIBDIR} + ${PC_Jemalloc_LIBRARY_DIRS} PATH_SUFFIXES lib lib64 ) -# Set JEMALLOC_ROOT in case the other hints are used -if(NOT JEMALLOC_ROOT AND "$ENV{JEMALLOC_ROOT}") - set(JEMALLOC_ROOT $ENV{JEMALLOC_ROOT}) -elseif(NOT JEMALLOC_ROOT) - string(REPLACE "/include" "" JEMALLOC_ROOT "${JEMALLOC_INCLUDE_DIR}") +# Set Jemalloc_ROOT in case the other hints are used +if(NOT Jemalloc_ROOT AND "$ENV{JEMALLOC_ROOT}") + set(Jemalloc_ROOT $ENV{JEMALLOC_ROOT}) +elseif(NOT Jemalloc_ROOT) + string(REPLACE "/include" "" Jemalloc_ROOT "${Jemalloc_INCLUDE_DIR}") endif() -set(JEMALLOC_LIBRARIES ${JEMALLOC_LIBRARY}) -set(JEMALLOC_INCLUDE_DIRS ${JEMALLOC_INCLUDE_DIR}) +set(Jemalloc_LIBRARIES ${Jemalloc_LIBRARY}) +set(Jemalloc_INCLUDE_DIRS ${Jemalloc_INCLUDE_DIR}) find_package_handle_standard_args( - Jemalloc DEFAULT_MSG JEMALLOC_LIBRARY JEMALLOC_INCLUDE_DIR + Jemalloc DEFAULT_MSG Jemalloc_LIBRARY Jemalloc_INCLUDE_DIR ) get_property( _type - CACHE JEMALLOC_ROOT + CACHE Jemalloc_ROOT PROPERTY TYPE ) if(_type) - set_property(CACHE JEMALLOC_ROOT PROPERTY ADVANCED 1) + set_property(CACHE Jemalloc_ROOT PROPERTY ADVANCED 1) if("x${_type}" STREQUAL "xUNINITIALIZED") - set_property(CACHE JEMALLOC_ROOT PROPERTY TYPE PATH) + set_property(CACHE Jemalloc_ROOT PROPERTY TYPE PATH) endif() endif() -mark_as_advanced(JEMALLOC_ROOT JEMALLOC_LIBRARY JEMALLOC_INCLUDE_DIR) +mark_as_advanced(Jemalloc_ROOT Jemalloc_LIBRARY Jemalloc_INCLUDE_DIR) diff --git a/cmake/FindLibSigSegv.cmake b/cmake/FindLibSigSegv.cmake index 150c31965660..e37bac02a0b6 100644 --- a/cmake/FindLibSigSegv.cmake +++ b/cmake/FindLibSigSegv.cmake @@ -1,64 +1,74 @@ # Copyright (c) 2017 Abhimanyu Rawat +# # SPDX-License-Identifier: BSL-1.0 # 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) +# compatibility with older CMake versions +if(LIBSIGSEGV_ROOT AND NOT Libsigsegv_ROOT) + set(Libsigsegv_ROOT + ${LIBSIGSEGV_ROOT} + CACHE PATH "Libsigsegv base directory" + ) + unset(LIBSIGSEGV_ROOT CACHE) +endif() + find_package(PkgConfig QUIET) pkg_check_modules(PC_LIBSIGSEGV QUIET libsigsegv) find_path( - LIBSIGSEGV_INCLUDE_DIR sigsegv.h - HINTS ${LIBSIGSEGV_ROOT} + Libsigsegv_INCLUDE_DIR sigsegv.h + HINTS ${Libsigsegv_ROOT} ENV - LIBSIGSEGV_ROOT - ${PC_LIBSIGSEGV_MINIMAL_INCLUDEDIR} - ${PC_LIBSIGSEGV_MINIMAL_INCLUDE_DIRS} - ${PC_LIBSIGSEGV_INCLUDEDIR} - ${PC_LIBSIGSEGV_INCLUDE_DIRS} + Libsigsegv_ROOT + ${PC_Libsigsegv_MINIMAL_INCLUDEDIR} + ${PC_Libsigsegv_MINIMAL_INCLUDE_DIRS} + ${PC_Libsigsegv_INCLUDEDIR} + ${PC_Libsigsegv_INCLUDE_DIRS} PATH_SUFFIXES include ) find_library( - LIBSIGSEGV_LIBRARY + Libsigsegv_LIBRARY NAMES sigsegv libsigsegv - HINTS ${LIBSIGSEGV_ROOT} + HINTS ${Libsigsegv_ROOT} ENV - LIBSIGSEGV_ROOT - ${PC_LIBSIGSEGV_MINIMAL_LIBDIR} - ${PC_LIBSIGSEGV_MINIMAL_LIBRARY_DIRS} - ${PC_LIBSIGSEGV_LIBDIR} - ${PC_LIBSIGSEGV_LIBRARY_DIRS} + Libsigsegv_ROOT + ${PC_Libsigsegv_MINIMAL_LIBDIR} + ${PC_Libsigsegv_MINIMAL_LIBRARY_DIRS} + ${PC_Libsigsegv_LIBDIR} + ${PC_Libsigsegv_LIBRARY_DIRS} PATH_SUFFIXES lib lib64 ) -# Set LIBSIGSEGV_ROOT in case the other hints are used -if(LIBSIGSEGV_ROOT) +# Set Libsigsegv_ROOT in case the other hints are used +if(Libsigsegv_ROOT) # The call to file is for compatibility with windows paths - file(TO_CMAKE_PATH ${LIBSIGSEGV_ROOT} LIBSIGSEGV_ROOT) + file(TO_CMAKE_PATH ${Libsigsegv_ROOT} Libsigsegv_ROOT) elseif("$ENV{LIBSIGSEGV_ROOT}") - file(TO_CMAKE_PATH $ENV{LIBSIGSEGV_ROOT} LIBSIGSEGV_ROOT) + file(TO_CMAKE_PATH $ENV{LIBSIGSEGV_ROOT} Libsigsegv_ROOT) else() - file(TO_CMAKE_PATH "${LIBSIGSEGV_INCLUDE_DIR}" LIBSIGSEGV_INCLUDE_DIR) - string(REPLACE "/include" "" LIBSIGSEGV_ROOT "${LIBSIGSEGV_INCLUDE_DIR}") + file(TO_CMAKE_PATH "${Libsigsegv_INCLUDE_DIR}" Libsigsegv_INCLUDE_DIR) + string(REPLACE "/include" "" Libsigsegv_ROOT "${Libsigsegv_INCLUDE_DIR}") endif() -set(LIBSIGSEGV_LIBRARIES ${LIBSIGSEGV_LIBRARY}) -set(LIBSIGSEGV_INCLUDE_DIRS ${LIBSIGSEGV_INCLUDE_DIR}) +set(Libsigsegv_LIBRARIES ${Libsigsegv_LIBRARY}) +set(Libsigsegv_INCLUDE_DIRS ${Libsigsegv_INCLUDE_DIR}) find_package_handle_standard_args( - LibSigSegv DEFAULT_MSG LIBSIGSEGV_LIBRARY LIBSIGSEGV_INCLUDE_DIR + LibSigSegv DEFAULT_MSG Libsigsegv_LIBRARY Libsigsegv_INCLUDE_DIR ) get_property( _type - CACHE LIBSIGSEGV_ROOT + CACHE Libsigsegv_ROOT PROPERTY TYPE ) if(_type) - set_property(CACHE LIBSIGSEGV_ROOT PROPERTY ADVANCED 1) + set_property(CACHE Libsigsegv_ROOT PROPERTY ADVANCED 1) if("x${_type}" STREQUAL "xUNINITIALIZED") - set_property(CACHE LIBSIGSEGV_ROOT PROPERTY TYPE PATH) + set_property(CACHE Libsigsegv_ROOT PROPERTY TYPE PATH) endif() endif() -mark_as_advanced(LIBSIGSEGV_ROOT LIBSIGSEGV_LIBRARY LIBSIGSEGV_INCLUDE_DIR) +mark_as_advanced(Libsigsegv_ROOT Libsigsegv_LIBRARY Libsigsegv_INCLUDE_DIR) diff --git a/cmake/FindLibfabric.cmake b/cmake/FindLibfabric.cmake index d5a9ae06408a..ce6a3a247835 100644 --- a/cmake/FindLibfabric.cmake +++ b/cmake/FindLibfabric.cmake @@ -4,42 +4,51 @@ # 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) +# compatibility with older CMake versions +if(LIBFABRIC_ROOT AND NOT Libfabric_ROOT) + set(Libfabric_ROOT + ${LIBFABRIC_ROOT} + CACHE PATH "Libfabric base directory" + ) + unset(LIBFABRIC_ROOT CACHE) +endif() + find_package(PkgConfig QUIET) pkg_check_modules(PC_LIBFABRIC QUIET libfabric) find_path( - LIBFABRIC_INCLUDE_DIR rdma/fabric.h - HINTS ${LIBFABRIC_ROOT} ENV LIBFABRIC_ROOT ${LIBFABRIC_DIR} ENV LIBFABRIC_DIR + Libfabric_INCLUDE_DIR rdma/fabric.h + HINTS ${Libfabric_ROOT} ENV LIBFABRIC_ROOT ${Libfabric_DIR} ENV LIBFABRIC_DIR PATH_SUFFIXES include ) find_library( - LIBFABRIC_LIBRARY + Libfabric_LIBRARY NAMES fabric - HINTS ${LIBFABRIC_ROOT} ENV LIBFABRIC_ROOT + HINTS ${Libfabric_ROOT} ENV LIBFABRIC_ROOT PATH_SUFFIXES lib lib64 ) -# Set LIBFABRIC_ROOT in case the other hints are used -if(LIBFABRIC_ROOT) +# Set Libfabric_ROOT in case the other hints are used +if(Libfabric_ROOT) # The call to file is for compatibility with windows paths - file(TO_CMAKE_PATH ${LIBFABRIC_ROOT} LIBFABRIC_ROOT) + file(TO_CMAKE_PATH ${Libfabric_ROOT} Libfabric_ROOT) elseif("$ENV{LIBFABRIC_ROOT}") - file(TO_CMAKE_PATH $ENV{LIBFABRIC_ROOT} LIBFABRIC_ROOT) + file(TO_CMAKE_PATH $ENV{LIBFABRIC_ROOT} Libfabric_ROOT) else() - file(TO_CMAKE_PATH "${LIBFABRIC_INCLUDE_DIR}" LIBFABRIC_INCLUDE_DIR) - string(REPLACE "/include" "" LIBFABRIC_ROOT "${LIBFABRIC_INCLUDE_DIR}") + file(TO_CMAKE_PATH "${Libfabric_INCLUDE_DIR}" Libfabric_INCLUDE_DIR) + string(REPLACE "/include" "" Libfabric_ROOT "${Libfabric_INCLUDE_DIR}") endif() -if(NOT LIBFABRIC_INCLUDE_DIR OR NOT LIBFABRIC_LIBRARY) - hpx_error("Could not find LIBFABRIC_INCLUDE_DIR or LIBFABRIC_LIBRARY please \ - set the LIBFABRIC_ROOT environment variable" +if(NOT Libfabric_INCLUDE_DIR OR NOT Libfabric_LIBRARY) + hpx_error("Could not find Libfabric_INCLUDE_DIR or Libfabric_LIBRARY please \ + set the Libfabric_ROOT environment variable" ) endif() include(FindPackageHandleStandardArgs) find_package_handle_standard_args( - Libfabric DEFAULT_MSG LIBFABRIC_LIBRARY LIBFABRIC_INCLUDE_DIR + Libfabric DEFAULT_MSG Libfabric_LIBRARY Libfabric_INCLUDE_DIR ) -mark_as_advanced(LIBFABRIC_ROOT) +mark_as_advanced(Libfabric_ROOT) diff --git a/cmake/FindMSR.cmake b/cmake/FindMSR.cmake index 13edbd17aa0e..fb7c2a41526c 100644 --- a/cmake/FindMSR.cmake +++ b/cmake/FindMSR.cmake @@ -8,48 +8,57 @@ # 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) +# compatibility with older CMake versions +if(MSR_ROOT AND NOT Msr_ROOT) + set(Msr_ROOT + ${MSR_ROOT} + CACHE PATH "Msr base directory" + ) + unset(MSR_ROOT CACHE) +endif() + find_package(PkgConfig QUIET) pkg_check_modules(PC_MSR QUIET libmsr) find_path( - MSR_INCLUDE_DIR msr_core.h - HINTS ${MSR_ROOT} ENV MSR_ROOT ${PC_MSR_INCLUDEDIR} ${PC_MSR_INCLUDE_DIRS} + Msr_INCLUDE_DIR msr_core.h + HINTS ${Msr_ROOT} ENV MSR_ROOT ${PC_Msr_INCLUDEDIR} ${PC_Msr_INCLUDE_DIRS} PATH_SUFFIXES include ) find_library( - MSR_LIBRARY + Msr_LIBRARY NAMES msr libmsr - HINTS ${MSR_ROOT} ENV MSR_ROOT ${PC_MSR_LIBDIR} ${PC_MSR_LIBRARY_DIRS} + HINTS ${Msr_ROOT} ENV MSR_ROOT ${PC_Msr_LIBDIR} ${PC_Msr_LIBRARY_DIRS} PATH_SUFFIXES lib lib64 ) -# Set MSR_ROOT in case the other hints are used -if(MSR_ROOT) +# Set Msr_ROOT in case the other hints are used +if(Msr_ROOT) # The call to file is for compatibility with windows paths - file(TO_CMAKE_PATH ${MSR_ROOT} MSR_ROOT) + file(TO_CMAKE_PATH ${Msr_ROOT} Msr_ROOT) elseif("$ENV{MSR_ROOT}") - file(TO_CMAKE_PATH $ENV{MSR_ROOT} MSR_ROOT) + file(TO_CMAKE_PATH $ENV{MSR_ROOT} Msr_ROOT) else() - file(TO_CMAKE_PATH "${MSR_INCLUDE_DIR}" MSR_INCLUDE_DIR) - string(REPLACE "/include" "" MSR_ROOT "${MSR_INCLUDE_DIR}") + file(TO_CMAKE_PATH "${Msr_INCLUDE_DIR}" Msr_INCLUDE_DIR) + string(REPLACE "/include" "" Msr_ROOT "${Msr_INCLUDE_DIR}") endif() -set(MSR_LIBRARIES ${MSR_LIBRARY}) -set(MSR_INCLUDE_DIRS ${MSR_INCLUDE_DIR}) +set(Msr_LIBRARIES ${Msr_LIBRARY}) +set(Msr_INCLUDE_DIRS ${Msr_INCLUDE_DIR}) -find_package_handle_standard_args(MSR DEFAULT_MSG MSR_LIBRARY MSR_INCLUDE_DIR) +find_package_handle_standard_args(MSR DEFAULT_MSG Msr_LIBRARY Msr_INCLUDE_DIR) get_property( _type - CACHE MSR_ROOT + CACHE Msr_ROOT PROPERTY TYPE ) if(_type) - set_property(CACHE MSR_ROOT PROPERTY ADVANCED 1) + set_property(CACHE Msr_ROOT PROPERTY ADVANCED 1) if("x${_type}" STREQUAL "xUNINITIALIZED") - set_property(CACHE MSR_ROOT PROPERTY TYPE PATH) + set_property(CACHE Msr_ROOT PROPERTY TYPE PATH) endif() endif() -mark_as_advanced(MSR_ROOT MSR_LIBRARY MSR_INCLUDE_DIR) +mark_as_advanced(Msr_ROOT Msr_LIBRARY Msr_INCLUDE_DIR) diff --git a/cmake/FindOrangeFS.cmake b/cmake/FindOrangeFS.cmake index df968570217d..36caaaaa0f26 100644 --- a/cmake/FindOrangeFS.cmake +++ b/cmake/FindOrangeFS.cmake @@ -5,44 +5,53 @@ # 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) +# compatibility with older CMake versions +if(ORANGEFS_ROOT AND NOT Orangefs_ROOT) + set(Orangefs_ROOT + ${ORANGEFS_ROOT} + CACHE PATH "OrangeFS base directory" + ) + unset(ORANGEFS_ROOT CACHE) +endif() + find_package(PkgConfig QUIET) -pkg_check_modules(PC_ORANGEFS QUIET orangefs) +pkg_check_modules(PC_Orangefs QUIET orangefs) find_path( - ORANGEFS_INCLUDE_DIR + Orangefs_INCLUDE_DIR NAMES pxfs.h orange.h - HINTS ${ORANGEFS_ROOT} ENV ORANGEFS_ROOT ${PC_ORANGEFS_INCLUDEDIR} - ${PC_ORANGEFS_INCLUDE_DIRS} + HINTS ${Orangefs_ROOT} ENV Orangefs_ROOT ${PC_Orangefs_INCLUDEDIR} + ${PC_Orangefs_INCLUDE_DIRS} PATH_SUFFIXES include ) find_library( - ORANGEFS_LIBRARY + Orangefs_LIBRARY NAMES pvfs2 # orangefs pvfs2 orangefsposix - HINTS ${ORANGEFS_ROOT} ENV ORANGEFS_ROOT ${PC_ORANGEFS_LIBDIR} - ${PC_ORANGEFS_LIBRARY_DIRS} + HINTS ${Orangefs_ROOT} ENV ORANGEFS_ROOT ${PC_Orangefs_LIBDIR} + ${PC_Orangefs_LIBRARY_DIRS} PATH_SUFFIXES lib lib64 ) -# Set ORANGEFS_ROOT in case the other hints are used -if(ORANGEFS_ROOT) +# Set Orangefs_ROOT in case the other hints are used +if(Orangefs_ROOT) # The call to file is for compatibility with windows paths - file(TO_CMAKE_PATH ${ORANGEFS_ROOT} ORANGEFS_ROOT) + file(TO_CMAKE_PATH ${Orangefs_ROOT} Orangefs_ROOT) elseif("$ENV{ORANGEFS_ROOT}") - file(TO_CMAKE_PATH $ENV{ORANGEFS_ROOT} ORANGEFS_ROOT) + file(TO_CMAKE_PATH $ENV{ORANGEFS_ROOT} Orangefs_ROOT) else() - file(TO_CMAKE_PATH "${ORANGEFS_INCLUDE_DIR}" ORANGEFS_INCLUDE_DIR) - string(REPLACE "/include" "" ORANGEFS_ROOT "${ORANGEFS_INCLUDE_DIR}") + file(TO_CMAKE_PATH "${Orangefs_INCLUDE_DIR}" Orangefs_INCLUDE_DIR) + string(REPLACE "/include" "" Orangefs_ROOT "${Orangefs_INCLUDE_DIR}") endif() -set(ORANGEFS_LIBRARIES ${ORANGEFS_LIBRARY}) -set(ORANGEFS_INCLUDE_DIRS ${ORANGEFS_INCLUDE_DIR}) +set(Orangefs_LIBRARIES ${Orangefs_LIBRARY}) +set(Orangefs_INCLUDE_DIRS ${Orangefs_INCLUDE_DIR}) find_package_handle_standard_args( - OrangeFS DEFAULT_MSG ORANGEFS_LIBRARY ORANGEFS_INCLUDE_DIR + OrangeFS DEFAULT_MSG Orangefs_LIBRARY Orangefs_INCLUDE_DIR ) -foreach(v ORANGEFS_ROOT) +foreach(v Orangefs_ROOT) get_property( _type CACHE ${v} @@ -56,4 +65,4 @@ foreach(v ORANGEFS_ROOT) endif() endforeach() -mark_as_advanced(ORANGEFS_ROOT ORANGEFS_LIBRARY ORANGEFS_INCLUDE_DIR) +mark_as_advanced(Orangefs_ROOT Orangefs_LIBRARY Orangefs_INCLUDE_DIR) diff --git a/cmake/FindPAPI.cmake b/cmake/FindPAPI.cmake deleted file mode 100644 index 9f6d906b023e..000000000000 --- a/cmake/FindPAPI.cmake +++ /dev/null @@ -1,71 +0,0 @@ -# Copyright (c) 2014 Thomas Heller -# Copyright (c) 2007-2011 Hartmut Kaiser -# Copyright (c) 2011 Bryce Lelbach -# Copyright (c) 2011 Maciej Brodowicz -# -# SPDX-License-Identifier: BSL-1.0 -# 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 TARGET Papi::papi) - find_package(PkgConfig QUIET) - pkg_check_modules(PC_PAPI QUIET papi) - - find_path( - PAPI_INCLUDE_DIR papi.h - HINTS ${PAPI_ROOT} ENV PAPI_ROOT ${HPX_PAPI_ROOT} ${PC_PAPI_INCLUDEDIR} - ${PC_PAPI_INCLUDE_DIRS} - PATH_SUFFIXES include - ) - - find_library( - PAPI_LIBRARY - NAMES papi libpapi - HINTS ${PAPI_ROOT} ENV PAPI_ROOT ${HPX_PAPI_ROOT} ${PC_PAPI_LIBDIR} - ${PC_PAPI_LIBRARY_DIRS} - PATH_SUFFIXES lib lib64 - ) - - # Set PAPI_ROOT in case the other hints are used - if(NOT PAPI_ROOT AND "$ENV{PAPI_ROOT}") - set(PAPI_ROOT $ENV{PAPI_ROOT}) - elseif(NOT PAPI_ROOT) - string(REPLACE "/include" "" PAPI_ROOT "${PAPI_INCLUDE_DIR}") - endif() - - # Set PAPI_ROOT in case the other hints are used - if(PAPI_ROOT) - # The call to file is for compatibility with windows paths - file(TO_CMAKE_PATH ${PAPI_ROOT} PAPI_ROOT) - elseif("$ENV{PAPI_ROOT}") - file(TO_CMAKE_PATH $ENV{PAPI_ROOT} PAPI_ROOT) - else() - file(TO_CMAKE_PATH "${PAPI_INCLUDE_DIR}" PAPI_INCLUDE_DIR) - string(REPLACE "/include" "" PAPI_ROOT "${PAPI_INCLUDE_DIR}") - endif() - - set(PAPI_LIBRARIES ${PAPI_LIBRARY}) - set(PAPI_INCLUDE_DIRS ${PAPI_INCLUDE_DIR}) - - find_package_handle_standard_args( - PAPI DEFAULT_MSG PAPI_LIBRARY PAPI_INCLUDE_DIR - ) - - get_property( - _type - CACHE PAPI_ROOT - PROPERTY TYPE - ) - if(_type) - set_property(CACHE PAPI_ROOT PROPERTY ADVANCED 1) - if("x${_type}" STREQUAL "xUNINITIALIZED") - set_property(CACHE PAPI_ROOT PROPERTY TYPE PATH) - endif() - endif() - - mark_as_advanced(PAPI_ROOT PAPI_LIBRARY PAPI_INCLUDE_DIR) - - add_library(Papi::papi INTERFACE IMPORTED) - target_include_directories(Papi::papi SYSTEM INTERFACE ${PAPI_INCLUDE_DIR}) - target_link_libraries(Papi::papi INTERFACE ${PAPI_LIBRARY}) -endif() diff --git a/cmake/FindPWR.cmake b/cmake/FindPWR.cmake index edcadc73cf79..0007fa6008dc 100644 --- a/cmake/FindPWR.cmake +++ b/cmake/FindPWR.cmake @@ -8,70 +8,79 @@ # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) if(NOT TARGET PWR::pwr) + # compatibility with older CMake versions + if(PWR_ROOT AND NOT Pwr_ROOT) + set(Pwr_ROOT + ${PWR_ROOT} + CACHE PATH "PWR base directory" + ) + unset(PWR_ROOT CACHE) + endif() + find_package(PkgConfig QUIET) - pkg_check_modules(PC_PWR QUIET pwr) - if(NOT PC_PWR_FOUND) - pkg_check_modules(PC_PWR pwrapi QUIET) + pkg_check_modules(PC_Pwr QUIET pwr) + if(NOT PC_Pwr_FOUND) + pkg_check_modules(PC_Pwr pwrapi QUIET) endif() find_path( - PWR_INCLUDE_DIR pwr.h - HINTS ${PWR_ROOT} + Pwr_INCLUDE_DIR pwr.h + HINTS ${Pwr_ROOT} ENV PWR_ROOT - ${HPX_PWR_ROOT} - ${PC_PWR_MINIMAL_INCLUDEDIR} - ${PC_PWR_MINIMAL_INCLUDE_DIRS} - ${PC_PWR_INCLUDEDIR} - ${PC_PWR_INCLUDE_DIRS} + ${HPX_Pwr_ROOT} + ${PC_Pwr_MINIMAL_INCLUDEDIR} + ${PC_Pwr_MINIMAL_INCLUDE_DIRS} + ${PC_Pwr_INCLUDEDIR} + ${PC_Pwr_INCLUDE_DIRS} PATH_SUFFIXES include ) find_library( - PWR_LIBRARY + Pwr_LIBRARY NAMES pwr libpwr - HINTS ${PWR_ROOT} + HINTS ${Pwr_ROOT} ENV PWR_ROOT - ${HPX_PWR_ROOT} - ${PC_PWR_MINIMAL_LIBDIR} - ${PC_PWR_MINIMAL_LIBRARY_DIRS} - ${PC_PWR_LIBDIR} - ${PC_PWR_LIBRARY_DIRS} + ${HPX_Pwr_ROOT} + ${PC_Pwr_MINIMAL_LIBDIR} + ${PC_Pwr_MINIMAL_LIBRARY_DIRS} + ${PC_Pwr_LIBDIR} + ${PC_Pwr_LIBRARY_DIRS} PATH_SUFFIXES lib lib64 ) - # Set PWR_ROOT in case the other hints are used - if(PWR_ROOT) + # Set Pwr_ROOT in case the other hints are used + if(Pwr_ROOT) # The call to file is for compatibility with windows paths - file(TO_CMAKE_PATH ${PWR_ROOT} PWR_ROOT) + file(TO_CMAKE_PATH ${Pwr_ROOT} Pwr_ROOT) elseif("$ENV{PWR_ROOT}") - file(TO_CMAKE_PATH $ENV{PWR_ROOT} PWR_ROOT) + file(TO_CMAKE_PATH $ENV{PWR_ROOT} Pwr_ROOT) else() - file(TO_CMAKE_PATH "${PWR_INCLUDE_DIR}" PWR_INCLUDE_DIR) - string(REPLACE "/include" "" PWR_ROOT "${PWR_INCLUDE_DIR}") + file(TO_CMAKE_PATH "${Pwr_INCLUDE_DIR}" Pwr_INCLUDE_DIR) + string(REPLACE "/include" "" Pwr_ROOT "${Pwr_INCLUDE_DIR}") endif() - set(PWR_LIBRARIES ${PWR_LIBRARY}) - set(PWR_INCLUDE_DIRS ${PWR_INCLUDE_DIR}) + set(Pwr_LIBRARIES ${Pwr_LIBRARY}) + set(Pwr_INCLUDE_DIRS ${Pwr_INCLUDE_DIR}) - find_package_handle_standard_args(PWR DEFAULT_MSG PWR_LIBRARY PWR_INCLUDE_DIR) + find_package_handle_standard_args(PWR DEFAULT_MSG Pwr_LIBRARY Pwr_INCLUDE_DIR) get_property( _type - CACHE PWR_ROOT + CACHE Pwr_ROOT PROPERTY TYPE ) if(_type) - set_property(CACHE PWR_ROOT PROPERTY ADVANCED 1) + set_property(CACHE Pwr_ROOT PROPERTY ADVANCED 1) if("x${_type}" STREQUAL "xUNINITIALIZED") - set_property(CACHE PWR_ROOT PROPERTY TYPE PATH) + set_property(CACHE Pwr_ROOT PROPERTY TYPE PATH) endif() endif() add_library(PWR::pwr INTERFACE IMPORTED) - target_include_directories(PWR::pwr SYSTEM INTERFACE ${PWR_INCLUDE_DIR}) - target_link_libraries(PWR::pwr INTERFACE ${PWR_LIBRARIES}) + target_include_directories(PWR::pwr SYSTEM INTERFACE ${Pwr_INCLUDE_DIR}) + target_link_libraries(PWR::pwr INTERFACE ${Pwr_LIBRARIES}) - mark_as_advanced(PWR_ROOT PWR_LIBRARY PWR_INCLUDE_DIR) + mark_as_advanced(Pwr_ROOT Pwr_LIBRARY Pwr_INCLUDE_DIR) endif() diff --git a/cmake/FindPapi.cmake b/cmake/FindPapi.cmake new file mode 100644 index 000000000000..b0a4dbf4cf2e --- /dev/null +++ b/cmake/FindPapi.cmake @@ -0,0 +1,88 @@ +# Copyright (c) 2014 Thomas Heller +# Copyright (c) 2007-2023 Hartmut Kaiser +# Copyright (c) 2011 Bryce Lelbach +# Copyright (c) 2011 Maciej Brodowicz +# +# SPDX-License-Identifier: BSL-1.0 +# 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 TARGET Papi::papi) + # compatibility with older CMake versions + if(PAPI_ROOT AND NOT Papi_ROOT) + set(Papi_ROOT + ${PAPI_ROOT} + CACHE PATH "PAPI base directory" + ) + unset(PAPI_ROOT CACHE) + endif() + + find_package(PkgConfig QUIET) + pkg_check_modules(PC_Papi QUIET papi) + + find_path( + Papi_INCLUDE_DIR papi.h + HINTS ${Papi_ROOT} ENV PAPI_ROOT ${HPX_PAPI_ROOT} ${PC_Papi_INCLUDEDIR} + ${PC_Papi_INCLUDE_DIRS} + PATH_SUFFIXES include + ) + + find_library( + Papi_LIBRARY + NAMES papi libpapi + HINTS ${Papi_ROOT} ENV PAPI_ROOT ${HPX_PAPI_ROOT} ${PC_Papi_LIBDIR} + ${PC_Papi_LIBRARY_DIRS} + PATH_SUFFIXES lib lib64 + ) + + # Set Papi_ROOT in case the other hints are used + if(NOT Papi_ROOT AND "$ENV{PAPI_ROOT}") + set(Papi_ROOT $ENV{PAPI_ROOT}) + elseif(NOT Papi_ROOT) + string(REPLACE "/include" "" Papi_ROOT "${Papi_INCLUDE_DIR}") + endif() + + # Set Papi_ROOT in case the other hints are used + if(Papi_ROOT) + # The call to file is for compatibility with windows paths + file(TO_CMAKE_PATH ${Papi_ROOT} Papi_ROOT) + elseif("$ENV{PAPI_ROOT}") + file(TO_CMAKE_PATH $ENV{PAPI_ROOT} Papi_ROOT) + else() + file(TO_CMAKE_PATH "${Papi_INCLUDE_DIR}" Papi_INCLUDE_DIR) + string(REPLACE "/include" "" Papi_ROOT "${Papi_INCLUDE_DIR}") + endif() + + set(Papi_LIBRARIES ${Papi_LIBRARY}) + set(Papi_INCLUDE_DIRS ${Papi_INCLUDE_DIR}) + + find_package_handle_standard_args( + Papi + REQUIRED_VARS Papi_LIBRARY Papi_INCLUDE_DIR + FOUND_VAR Papi_FOUND + ) + + if(NOT Papi_FOUND) + message(FATAL "The PAPI library could not be found using Papi_LIBRARY: " + ${Papi_LIBRARY} "and Papi_INCLUDE_DIR: " ${Papi_INCLUDE_DIR} + ) + endif() + + get_property( + _type + CACHE Papi_ROOT + PROPERTY TYPE + ) + if(_type) + set_property(CACHE Papi_ROOT PROPERTY ADVANCED 1) + if("x${_type}" STREQUAL "xUNINITIALIZED") + set_property(CACHE Papi_ROOT PROPERTY TYPE PATH) + endif() + endif() + + mark_as_advanced(Papi_ROOT Papi_LIBRARY Papi_INCLUDE_DIR) + + add_library(Papi::papi INTERFACE IMPORTED) + target_include_directories(Papi::papi SYSTEM INTERFACE ${Papi_INCLUDE_DIR}) + target_link_libraries(Papi::papi INTERFACE ${Papi_LIBRARY}) +endif() diff --git a/cmake/FindQThreads.cmake b/cmake/FindQThreads.cmake index d731aab6b8ba..08e2342521fb 100644 --- a/cmake/FindQThreads.cmake +++ b/cmake/FindQThreads.cmake @@ -5,43 +5,52 @@ # 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) +# compatibility with older CMake versions +if(QTHREADS_ROOT AND NOT Qthreads_ROOT) + set(Qthreads_ROOT + ${QTHREADS_ROOT} + CACHE PATH "QThreads base directory" + ) + unset(QTHREADS_ROOT CACHE) +endif() + find_package(PkgConfig QUIET) -pkg_check_modules(PC_QTHREADS QUIET swarm) +pkg_check_modules(PC_Qthreads QUIET swarm) find_path( - QTHREADS_INCLUDE_DIR qthread/qthread.h - HINTS ${QTHREADS_ROOT} ENV QTHREADS_ROOT ${PC_QTHREADS_INCLUDEDIR} - ${PC_QTHREADS_INCLUDE_DIRS} + Qthreads_INCLUDE_DIR qthread/qthread.h + HINTS ${Qthreads_ROOT} ENV QTHREADS_ROOT ${PC_Qthreads_INCLUDEDIR} + ${PC_Qthreads_INCLUDE_DIRS} PATH_SUFFIXES include ) find_library( - QTHREADS_LIBRARY + Qthreads_LIBRARY NAMES qthread libqthread - HINTS ${QTHREADS_ROOT} ENV QTHREADS_ROOT ${PC_QTHREADS_LIBDIR} - ${PC_QTHREADS_LIBRARY_DIRS} + HINTS ${Qthreads_ROOT} ENV QTHREADS_ROOT ${PC_Qthreads_LIBDIR} + ${PC_Qthreads_LIBRARY_DIRS} PATH_SUFFIXES lib lib64 ) -# Set QTHREADS_ROOT in case the other hints are used -if(QTHREADS_ROOT) +# Set Qthreads_ROOT in case the other hints are used +if(Qthreads_ROOT) # The call to file is for compatibility with windows paths - file(TO_CMAKE_PATH ${QTHREADS_ROOT} QTHREADS_ROOT) + file(TO_CMAKE_PATH ${Qthreads_ROOT} Qthreads_ROOT) elseif("$ENV{QTHREADS_ROOT}") - file(TO_CMAKE_PATH $ENV{QTHREADS_ROOT} QTHREADS_ROOT) + file(TO_CMAKE_PATH $ENV{QTHREADS_ROOT} Qthreads_ROOT) else() - file(TO_CMAKE_PATH "${QTHREADS_INCLUDE_DIR}" QTHREADS_INCLUDE_DIR) - string(REPLACE "/include" "" QTHREADS_ROOT "${QTHREADS_INCLUDE_DIR}") + file(TO_CMAKE_PATH "${Qthreads_INCLUDE_DIR}" Qthreads_INCLUDE_DIR) + string(REPLACE "/include" "" Qthreads_ROOT "${Qthreads_INCLUDE_DIR}") endif() -set(QTHREADS_LIBRARIES ${QTHREADS_LIBRARY}) -set(QTHREADS_INCLUDE_DIRS ${QTHREADS_INCLUDE_DIR}) +set(Qthreads_LIBRARIES ${Qthreads_LIBRARY}) +set(Qthreads_INCLUDE_DIRS ${Qthreads_INCLUDE_DIR}) find_package_handle_standard_args( - QThreads DEFAULT_MSG QTHREADS_LIBRARY QTHREADS_INCLUDE_DIR + QThreads DEFAULT_MSG Qthreads_LIBRARY Qthreads_INCLUDE_DIR ) -foreach(v QTHREADS_ROOT) +foreach(v Qthreads_ROOT) get_property( _type CACHE ${v} @@ -55,4 +64,4 @@ foreach(v QTHREADS_ROOT) endif() endforeach() -mark_as_advanced(QTHREADS_ROOT QTHREADS_LIBRARY QTHREADS_INCLUDE_DIR) +mark_as_advanced(Qthreads_ROOT Qthreads_LIBRARY Qthreads_INCLUDE_DIR) diff --git a/cmake/FindRDMA_CM.cmake b/cmake/FindRDMA_CM.cmake index 1a33f36e5db3..3f0d210a4213 100644 --- a/cmake/FindRDMA_CM.cmake +++ b/cmake/FindRDMA_CM.cmake @@ -6,28 +6,38 @@ # # - Try to find RDMA CM # Once done this will define -# RDMA_CM_FOUND - System has RDMA CM -# RDMA_CM_INCLUDE_DIRS - The RDMA CM include directories -# RDMA_CM_LIBRARIES - The libraries needed to use RDMA CM +# Rdma_CM_FOUND - System has RDMA CM +# Rdma_CM_INCLUDE_DIRS - The RDMA CM include directories +# Rdma_CM_LIBRARIES - The libraries needed to use RDMA CM -find_path(RDMA_CM_INCLUDE_DIR rdma_cma.h HINTS /usr/local/include +# compatibility with older CMake versions +if(RDMA_ROOT AND NOT Rdma_ROOT) + set(Rdma_ROOT + ${RDMA_ROOT} + CACHE PATH "RDMA base directory" + ) + unset(RDMA_ROOT CACHE) +endif() + +find_path(Rdma_CM_INCLUDE_DIR rdma_cma.h HINTS /usr/local/include /usr/include/rdma ) find_library( - RDMA_CM_LIBRARY + Rdma_CM_LIBRARY NAMES rdmacm PATHS /usr/local/lib /usr/lib ) -set(RDMA_CM_INCLUDE_DIRS ${RDMA_CM_INCLUDE_DIR}) -set(RDMA_CM_LIBRARIES ${RDMA_CM_LIBRARY}) +set(Rdma_CM_INCLUDE_DIRS ${Rdma_CM_INCLUDE_DIR}) +set(Rdma_CM_LIBRARIES ${Rdma_CM_LIBRARY}) include(FindPackageHandleStandardArgs) -# handle the QUIETLY and REQUIRED arguments and set RDMA_CM_FOUND to TRUE if all + +# handle the QUIETLY and REQUIRED arguments and set Rdma_CM_FOUND to TRUE if all # listed variables are TRUE find_package_handle_standard_args( - RDMA_CM DEFAULT_MSG RDMA_CM_INCLUDE_DIR RDMA_CM_LIBRARY + Rdma_CM DEFAULT_MSG Rdma_CM_INCLUDE_DIR Rdma_CM_LIBRARY ) -mark_as_advanced(RDMA_CM_INCLUDE_DIR RDMA_CM_LIBRARY) +mark_as_advanced(Rdma_CM_INCLUDE_DIR Rdma_CM_LIBRARY) diff --git a/cmake/FindRdmacm.cmake b/cmake/FindRdmacm.cmake index 2eb9896125e6..5513ea4bd646 100644 --- a/cmake/FindRdmacm.cmake +++ b/cmake/FindRdmacm.cmake @@ -7,38 +7,47 @@ # 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) +# compatibility with older CMake versions +if(RDMACM_ROOT AND NOT Rdmacm_ROOT) + set(Rdmacm_ROOT + ${RDMACM_ROOT} + CACHE PATH "RDMACM base directory" + ) + unset(RDMACM_ROOT CACHE) +endif() + find_package(PkgConfig QUIET) -pkg_check_modules(PC_RDMACM QUIET libibverbs) +pkg_check_modules(PC_Rdmacm QUIET libibverbs) find_path( - RDMACM_INCLUDE_DIR rdma/rdma_cma.h - HINTS ${RDMACM_ROOT} ENV RDMACM_ROOT ${PC_RDMACM_INCLUDEDIR} - ${PC_RDMACM_INCLUDE_DIRS} + Rdmacm_INCLUDE_DIR rdma/rdma_cma.h + HINTS ${Rdmacm_ROOT} ENV RDMACM_ROOT ${PC_Rdmacm_INCLUDEDIR} + ${PC_Rdmacm_INCLUDE_DIRS} PATH_SUFFIXES include ) find_library( - RDMACM_LIBRARY + Rdmacm_LIBRARY NAMES rdmacm librdmacm - HINTS ${RDMACM_ROOT} ENV RDMACM_ROOT ${PC_RDMACM_LIBDIR} - ${PC_RDMACM_LIBRARY_DIRS} + HINTS ${Rdmacm_ROOT} ENV RDMACM_ROOT ${PC_Rdmacm_LIBDIR} + ${PC_Rdmacm_LIBRARY_DIRS} PATH_SUFFIXES lib lib64 ) -set(RDMACM_LIBRARIES - ${RDMACM_LIBRARY} +set(Rdmacm_LIBRARIES + ${Rdmacm_LIBRARY} CACHE INTERNAL "" ) -set(RDMACM_INCLUDE_DIRS - ${RDMACM_INCLUDE_DIR} +set(Rdmacm_INCLUDE_DIRS + ${Rdmacm_INCLUDE_DIR} CACHE INTERNAL "" ) find_package_handle_standard_args( - Rdmacm DEFAULT_MSG RDMACM_LIBRARY RDMACM_INCLUDE_DIR + Rdmacm DEFAULT_MSG Rdmacm_LIBRARY Rdmacm_INCLUDE_DIR ) -foreach(v RDMACM_ROOT) +foreach(v Rdmacm_ROOT) get_property( _type CACHE ${v} @@ -52,4 +61,4 @@ foreach(v RDMACM_ROOT) endif() endforeach() -mark_as_advanced(RDMACM_ROOT RDMACM_LIBRARY RDMACM_INCLUDE_DIR) +mark_as_advanced(Rdmacm_ROOT Rdmacm_LIBRARY Rdmacm_INCLUDE_DIR) diff --git a/cmake/FindSnappy.cmake b/cmake/FindSnappy.cmake index 58cee9ca47e0..0374be7dff41 100644 --- a/cmake/FindSnappy.cmake +++ b/cmake/FindSnappy.cmake @@ -1,55 +1,64 @@ # Copyright (c) 2014 Thomas Heller -# Copyright (c) 2013 Hartmut Kaiser +# Copyright (c) 2013-2023 Hartmut Kaiser # # SPDX-License-Identifier: BSL-1.0 # 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) +# compatibility with older CMake versions +if(SNAPPY_ROOT AND NOT Snappy_ROOT) + set(Snappy_ROOT + ${SNAPPY_ROOT} + CACHE PATH "Snappy base directory" + ) + unset(SNAPPY_ROOT CACHE) +endif() + find_package(PkgConfig QUIET) pkg_check_modules(PC_SNAPPY QUIET snappy) find_path( - SNAPPY_INCLUDE_DIR snappy.h - HINTS ${SNAPPY_ROOT} + Snappy_INCLUDE_DIR snappy.h + HINTS ${Snappy_ROOT} ENV SNAPPY_ROOT - ${PC_SNAPPY_MINIMAL_INCLUDEDIR} - ${PC_SNAPPY_MINIMAL_INCLUDE_DIRS} - ${PC_SNAPPY_INCLUDEDIR} - ${PC_SNAPPY_INCLUDE_DIRS} + ${PC_Snappy_MINIMAL_INCLUDEDIR} + ${PC_Snappy_MINIMAL_INCLUDE_DIRS} + ${PC_Snappy_INCLUDEDIR} + ${PC_Snappy_INCLUDE_DIRS} PATH_SUFFIXES include ) find_library( - SNAPPY_LIBRARY + Snappy_LIBRARY NAMES snappy libsnappy - HINTS ${SNAPPY_ROOT} + HINTS ${Snappy_ROOT} ENV SNAPPY_ROOT - ${PC_SNAPPY_MINIMAL_LIBDIR} - ${PC_SNAPPY_MINIMAL_LIBRARY_DIRS} - ${PC_SNAPPY_LIBDIR} - ${PC_SNAPPY_LIBRARY_DIRS} + ${PC_Snappy_MINIMAL_LIBDIR} + ${PC_Snappy_MINIMAL_LIBRARY_DIRS} + ${PC_Snappy_LIBDIR} + ${PC_Snappy_LIBRARY_DIRS} PATH_SUFFIXES lib lib64 ) -set(SNAPPY_LIBRARIES ${SNAPPY_LIBRARY}) -set(SNAPPY_INCLUDE_DIRS ${SNAPPY_INCLUDE_DIR}) +set(Snappy_LIBRARIES ${Snappy_LIBRARY}) +set(Snappy_INCLUDE_DIRS ${Snappy_INCLUDE_DIR}) find_package_handle_standard_args( - Snappy DEFAULT_MSG SNAPPY_LIBRARY SNAPPY_INCLUDE_DIR + Snappy DEFAULT_MSG Snappy_LIBRARY Snappy_INCLUDE_DIR ) get_property( _type - CACHE SNAPPY_ROOT + CACHE Snappy_ROOT PROPERTY TYPE ) if(_type) - set_property(CACHE SNAPPY_ROOT PROPERTY ADVANCED 1) + set_property(CACHE Snappy_ROOT PROPERTY ADVANCED 1) if("x${_type}" STREQUAL "xUNINITIALIZED") - set_property(CACHE SNAPPY_ROOT PROPERTY TYPE PATH) + set_property(CACHE Snappy_ROOT PROPERTY TYPE PATH) endif() endif() -mark_as_advanced(SNAPPY_ROOT SNAPPY_LIBRARY SNAPPY_INCLUDE_DIR) +mark_as_advanced(Snappy_ROOT Snappy_LIBRARY Snappy_INCLUDE_DIR) diff --git a/cmake/FindSphinx.cmake b/cmake/FindSphinx.cmake index 9c5f66180e97..9b9e58ec6edd 100644 --- a/cmake/FindSphinx.cmake +++ b/cmake/FindSphinx.cmake @@ -4,14 +4,23 @@ # 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) +# compatibility with older CMake versions +if(SPHINX_ROOT AND NOT Sphinx_ROOT) + set(Sphinx_ROOT + ${SPHINX_ROOT} + CACHE PATH "Sphinx base directory" + ) + unset(SPHINX_ROOT CACHE) +endif() + find_program( - SPHINX_EXECUTABLE + Sphinx_EXECUTABLE NAMES sphinx-build sphinx-build2 - PATHS ${SPHINX_ROOT} ENV SPHINX_ROOT + PATHS ${Sphinx_ROOT} ENV SPHINX_ROOT DOC "Path to sphinx-build executable" ) -if(SPHINX_EXECUTABLE) +if(Sphinx_EXECUTABLE) include(FindPackageHandleStandardArgs) - find_package_handle_standard_args(Sphinx DEFAULT_MESSAGE SPHINX_EXECUTABLE) + find_package_handle_standard_args(Sphinx DEFAULT_MESSAGE Sphinx_EXECUTABLE) endif() diff --git a/cmake/FindTBB.cmake b/cmake/FindTBB.cmake index 648e9587f43b..821117c52aba 100644 --- a/cmake/FindTBB.cmake +++ b/cmake/FindTBB.cmake @@ -5,38 +5,47 @@ # 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) +# compatibility with older CMake versions +if(TBB_ROOT AND NOT Tbb_ROOT) + set(Tbb_ROOT + ${TBB_ROOT} + CACHE PATH "TBB base directory" + ) + unset(TBB_ROOT CACHE) +endif() + find_package(PkgConfig QUIET) -pkg_check_modules(PC_TBB QUIET libtbb) +pkg_check_modules(PC_Tbb QUIET libtbb) find_path( - TBB_INCLUDE_DIR tbb/tbb.h - HINTS ${TBB_ROOT} ENV TBB_ROOT ${PC_TBB_INCLUDEDIR} ${PC_TBB_INCLUDE_DIRS} + Tbb_INCLUDE_DIR tbb/tbb.h + HINTS ${Tbb_ROOT} ENV TBB_ROOT ${PC_Tbb_INCLUDEDIR} ${PC_Tbb_INCLUDE_DIRS} PATH_SUFFIXES include ) -set(TBB_PATH_SUFFIX "lib/intel64" "lib/intel64/gcc4.4") -if(TBB_PLATFORM STREQUAL "mic") - set(TBB_PATH_SUFFIX "lib/mic") +set(Tbb_PATH_SUFFIX "lib/intel64" "lib/intel64/gcc4.4") +if(Tbb_PLATFORM STREQUAL "mic") + set(Tbb_PATH_SUFFIX "lib/mic") endif() -if(TBB_PLATFORM STREQUAL "mic-knl") - set(TBB_PATH_SUFFIX "lib/intel64_lin_mic") +if(Tbb_PLATFORM STREQUAL "mic-knl") + set(Tbb_PATH_SUFFIX "lib/intel64_lin_mic") endif() find_library( - TBB_PROXY_LIBRARY + Tbb_PROXY_LIBRARY NAMES tbb libtbb - HINTS ${TBB_ROOT} ENV TBB_ROOT ${PC_TBB_LIBDIR} ${PC_TBB_LIBRARY_DIRS} - PATH_SUFFIXES ${TBB_PATH_SUFFIX} lib lib64 + HINTS ${Tbb_ROOT} ENV TBB_ROOT ${PC_Tbb_LIBDIR} ${PC_Tbb_LIBRARY_DIRS} + PATH_SUFFIXES ${Tbb_PATH_SUFFIX} lib lib64 ) -set(TBB_LIBRARIES ${TBB_LIBRARY} ${TBB_PROXY_LIBRARY}) -set(TBB_INCLUDE_DIRS ${TBB_INCLUDE_DIR}) +set(Tbb_LIBRARIES ${Tbb_LIBRARY} ${Tbb_PROXY_LIBRARY}) +set(Tbb_INCLUDE_DIRS ${Tbb_INCLUDE_DIR}) find_package_handle_standard_args( - TBBmalloc DEFAULT_MSG TBB_LIBRARY TBB_PROXY_LIBRARY TBB_INCLUDE_DIR + TBBmalloc DEFAULT_MSG Tbb_LIBRARY Tbb_PROXY_LIBRARY Tbb_INCLUDE_DIR ) -foreach(v TBB_ROOT TBB_PLATFORM) +foreach(v Tbb_ROOT Tbb_PLATFORM) get_property( _type CACHE ${v} @@ -50,4 +59,4 @@ foreach(v TBB_ROOT TBB_PLATFORM) endif() endforeach() -mark_as_advanced(TBB_ROOT TBB_LIBRARY TBB_PROXY_LIBRARY TBB_INCLUDE_DIR) +mark_as_advanced(Tbb_ROOT Tbb_LIBRARY Tbb_PROXY_LIBRARY Tbb_INCLUDE_DIR) diff --git a/cmake/FindTBBmalloc.cmake b/cmake/FindTBBmalloc.cmake index 1329597fba40..9b029ac51068 100644 --- a/cmake/FindTBBmalloc.cmake +++ b/cmake/FindTBBmalloc.cmake @@ -7,58 +7,67 @@ # 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) +# compatibility with older CMake versions +if(TBBMALLOC_ROOT AND NOT Tbbmalloc_ROOT) + set(Tbbmalloc_ROOT + ${TBBMALLOC_ROOT} + CACHE PATH "TBBMalloc base directory" + ) + unset(TBBMALLOC_ROOT CACHE) +endif() + find_package(PkgConfig QUIET) -pkg_check_modules(PC_TBBMALLOC QUIET libtbbmalloc) +pkg_check_modules(PC_Tbbmalloc QUIET libtbbmalloc) find_path( - TBBMALLOC_INCLUDE_DIR tbb/scalable_allocator.h - HINTS ${TBBMALLOC_ROOT} ENV TBBMALLOC_ROOT ${HPX_TBBMALLOC_ROOT} - ${PC_TBBMALLOC_INCLUDEDIR} ${PC_TBBMALLOC_INCLUDE_DIRS} + Tbbmalloc_INCLUDE_DIR tbb/scalable_allocator.h + HINTS ${Tbbmalloc_ROOT} ENV TBBMALLOC_ROOT ${HPX_TBBMALLOC_ROOT} + ${PC_Tbbmalloc_INCLUDEDIR} ${PC_Tbbmalloc_INCLUDE_DIRS} PATH_SUFFIXES include ) -set(TBBMALLOC_PATH_SUFFIX "lib/intel64" "lib/intel64/gcc4.4") -if(TBBMALLOC_PLATFORM STREQUAL "mic") - set(TBBMALLOC_PATH_SUFFIX "lib/mic") +set(Tbbmalloc_PATH_SUFFIX "lib/intel64" "lib/intel64/gcc4.4") +if(Tbbmalloc_PLATFORM STREQUAL "mic") + set(Tbbmalloc_PATH_SUFFIX "lib/mic") endif() -if(TBBMALLOC_PLATFORM STREQUAL "mic-knl") - set(TBBMALLOC_PATH_SUFFIX "lib/intel64_lin_mic") +if(Tbbmalloc_PLATFORM STREQUAL "mic-knl") + set(Tbbmalloc_PATH_SUFFIX "lib/intel64_lin_mic") endif() -message("${TBBMALLOC_ROOT} ${TBBMALLOC_PATH_SUFFIX} ${TBBMALLOC_PLATFORM}") +message("${Tbbmalloc_ROOT} ${Tbbmalloc_PATH_SUFFIX} ${Tbbmalloc_PLATFORM}") find_library( - TBBMALLOC_LIBRARY + Tbbmalloc_LIBRARY NAMES tbbmalloc libtbbmalloc - HINTS ${TBBMALLOC_ROOT} ENV TBBMALLOC_ROOT ${HPX_TBBMALLOC_ROOT} - ${PC_TBBMALLOC_LIBDIR} ${PC_TBBMALLOC_LIBRARY_DIRS} - PATH_SUFFIXES ${TBBMALLOC_PATH_SUFFIX} lib lib64 + HINTS ${Tbbmalloc_ROOT} ENV TBBMALLOC_ROOT ${HPX_TBBMALLOC_ROOT} + ${PC_Tbbmalloc_LIBDIR} ${PC_Tbbmalloc_LIBRARY_DIRS} + PATH_SUFFIXES ${Tbbmalloc_PATH_SUFFIX} lib lib64 ) find_library( - TBBMALLOC_PROXY_LIBRARY + Tbbmalloc_PROXY_LIBRARY NAMES tbbmalloc_proxy libtbbmalloc_proxy - HINTS ${TBBMALLOC_ROOT} ENV TBBMALLOC_ROOT ${HPX_TBBMALLOC_ROOT} - ${PC_TBBMALLOC_LIBDIR} ${PC_TBBMALLOC_LIBRARY_DIRS} - PATH_SUFFIXES ${TBBMALLOC_PATH_SUFFIX} lib lib64 + HINTS ${Tbbmalloc_ROOT} ENV TBBMALLOC_ROOT ${HPX_TBBMALLOC_ROOT} + ${PC_Tbbmalloc_LIBDIR} ${PC_Tbbmalloc_LIBRARY_DIRS} + PATH_SUFFIXES ${Tbbmalloc_PATH_SUFFIX} lib lib64 ) -# Set TBBMALLOC_ROOT in case the other hints are used -if(NOT TBBMALLOC_ROOT AND "$ENV{TBBMALLOC_ROOT}") - set(TBBMALLOC_ROOT $ENV{TBBMALLOC_ROOT}) -elseif(NOT TBBMALLOC_ROOT) - string(REPLACE "/include" "" TBBMALLOC_ROOT "${TBBMALLOC_INCLUDE_DIR}") +# Set Tbbmalloc_ROOT in case the other hints are used +if(NOT Tbbmalloc_ROOT AND "$ENV{TBBMALLOC_ROOT}") + set(Tbbmalloc_ROOT $ENV{TBBMALLOC_ROOT}) +elseif(NOT Tbbmalloc_ROOT) + string(REPLACE "/include" "" Tbbmalloc_ROOT "${Tbbmalloc_INCLUDE_DIR}") endif() -set(TBBMALLOC_LIBRARIES ${TBBMALLOC_LIBRARY} ${TBBMALLOC_PROXY_LIBRARY}) -set(TBBMALLOC_INCLUDE_DIRS ${TBBMALLOC_INCLUDE_DIR}) +set(Tbbmalloc_LIBRARIES ${Tbbmalloc_LIBRARY} ${Tbbmalloc_PROXY_LIBRARY}) +set(Tbbmalloc_INCLUDE_DIRS ${Tbbmalloc_INCLUDE_DIR}) find_package_handle_standard_args( - TBBmalloc DEFAULT_MSG TBBMALLOC_LIBRARY TBBMALLOC_PROXY_LIBRARY - TBBMALLOC_INCLUDE_DIR + TBBmalloc DEFAULT_MSG Tbbmalloc_LIBRARY Tbbmalloc_PROXY_LIBRARY + Tbbmalloc_INCLUDE_DIR ) -foreach(v TBBMALLOC_ROOT TBBMALLOC_PLATFORM) +foreach(v Tbbmalloc_ROOT Tbbmalloc_PLATFORM) get_property( _type CACHE ${v} @@ -73,6 +82,6 @@ foreach(v TBBMALLOC_ROOT TBBMALLOC_PLATFORM) endforeach() mark_as_advanced( - TBBMALLOC_ROOT TBBMALLOC_LIBRARY TBBMALLOC_PROXY_LIBRARY - TBBMALLOC_INCLUDE_DIR + Tbbmalloc_ROOT Tbbmalloc_LIBRARY Tbbmalloc_PROXY_LIBRARY + Tbbmalloc_INCLUDE_DIR ) diff --git a/cmake/FindTCMalloc.cmake b/cmake/FindTCMalloc.cmake index 9d33a5559150..8503410b8d94 100644 --- a/cmake/FindTCMalloc.cmake +++ b/cmake/FindTCMalloc.cmake @@ -7,61 +7,70 @@ # 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) +# compatibility with older CMake versions +if(TCMALLOC_ROOT AND NOT Tcmalloc_ROOT) + set(Tcmalloc_ROOT + ${TCMALLOC_ROOT} + CACHE PATH "TcMalloc base directory" + ) + unset(TCMALLOC_ROOT CACHE) +endif() + find_package(PkgConfig QUIET) -pkg_check_modules(PC_TCMALLOC_MINIMAL QUIET libtcmalloc_minimal) -pkg_check_modules(PC_TCMALLOC QUIET libtcmalloc) +pkg_check_modules(PC_Tcmalloc_MINIMAL QUIET libtcmalloc_minimal) +pkg_check_modules(PC_Tcmalloc QUIET libtcmalloc) find_path( - TCMALLOC_INCLUDE_DIR google/tcmalloc.h - HINTS ${TCMALLOC_ROOT} + Tcmalloc_INCLUDE_DIR google/tcmalloc.h + HINTS ${Tcmalloc_ROOT} ENV TCMALLOC_ROOT ${HPX_TCMALLOC_ROOT} - ${PC_TCMALLOC_MINIMAL_INCLUDEDIR} - ${PC_TCMALLOC_MINIMAL_INCLUDE_DIRS} - ${PC_TCMALLOC_INCLUDEDIR} - ${PC_TCMALLOC_INCLUDE_DIRS} + ${PC_Tcmalloc_MINIMAL_INCLUDEDIR} + ${PC_Tcmalloc_MINIMAL_INCLUDE_DIRS} + ${PC_Tcmalloc_INCLUDEDIR} + ${PC_Tcmalloc_INCLUDE_DIRS} PATH_SUFFIXES include ) find_library( - TCMALLOC_LIBRARY + Tcmalloc_LIBRARY NAMES tcmalloc_minimal libtcmalloc_minimal tcmalloc libtcmalloc - HINTS ${TCMALLOC_ROOT} + HINTS ${Tcmalloc_ROOT} ENV TCMALLOC_ROOT ${HPX_TCMALLOC_ROOT} - ${PC_TCMALLOC_MINIMAL_LIBDIR} - ${PC_TCMALLOC_MINIMAL_LIBRARY_DIRS} - ${PC_TCMALLOC_LIBDIR} - ${PC_TCMALLOC_LIBRARY_DIRS} + ${PC_Tcmalloc_MINIMAL_LIBDIR} + ${PC_Tcmalloc_MINIMAL_LIBRARY_DIRS} + ${PC_Tcmalloc_LIBDIR} + ${PC_Tcmalloc_LIBRARY_DIRS} PATH_SUFFIXES lib lib64 ) -# Set TCMALLOC_ROOT in case the other hints are used -if(NOT TCMALLOC_ROOT AND "$ENV{TCMALLOC_ROOT}") - set(TCMALLOC_ROOT $ENV{TCMALLOC_ROOT}) -elseif(NOT TCMALLOC_ROOT) - string(REPLACE "/include" "" TCMALLOC_ROOT "${TCMALLOC_INCLUDE_DIR}") +# Set Tcmalloc_ROOT in case the other hints are used +if(NOT Tcmalloc_ROOT AND "$ENV{TCMALLOC_ROOT}") + set(Tcmalloc_ROOT $ENV{TCMALLOC_ROOT}) +elseif(NOT Tcmalloc_ROOT) + string(REPLACE "/include" "" Tcmalloc_ROOT "${Tcmalloc_INCLUDE_DIR}") endif() -set(TCMALLOC_LIBRARIES ${TCMALLOC_LIBRARY}) -set(TCMALLOC_INCLUDE_DIRS ${TCMALLOC_INCLUDE_DIR}) +set(Tcmalloc_LIBRARIES ${Tcmalloc_LIBRARY}) +set(Tcmalloc_INCLUDE_DIRS ${Tcmalloc_INCLUDE_DIR}) find_package_handle_standard_args( - TCMalloc DEFAULT_MSG TCMALLOC_LIBRARY TCMALLOC_INCLUDE_DIR + TCMalloc DEFAULT_MSG Tcmalloc_LIBRARY Tcmalloc_INCLUDE_DIR ) get_property( _type - CACHE TCMALLOC_ROOT + CACHE Tcmalloc_ROOT PROPERTY TYPE ) if(_type) - set_property(CACHE TCMALLOC_ROOT PROPERTY ADVANCED 1) + set_property(CACHE Tcmalloc_ROOT PROPERTY ADVANCED 1) if("x${_type}" STREQUAL "xUNINITIALIZED") - set_property(CACHE TCMALLOC_ROOT PROPERTY TYPE PATH) + set_property(CACHE Tcmalloc_ROOT PROPERTY TYPE PATH) endif() endif() -mark_as_advanced(TCMALLOC_ROOT TCMALLOC_LIBRARY TCMALLOC_INCLUDE_DIR) +mark_as_advanced(Tcmalloc_ROOT Tcmalloc_LIBRARY Tcmalloc_INCLUDE_DIR) diff --git a/cmake/FindValgrind.cmake b/cmake/FindValgrind.cmake index 862901014333..f473ac321bc9 100644 --- a/cmake/FindValgrind.cmake +++ b/cmake/FindValgrind.cmake @@ -7,30 +7,39 @@ # 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) +# compatibility with older CMake versions +if(VALGRIND_ROOT AND NOT Valgrind_ROOT) + set(Valgrind_ROOT + ${VALGRIND_ROOT} + CACHE PATH "Valgrind base directory" + ) + unset(VALGRIND_ROOT CACHE) +endif() + find_package(PkgConfig QUIET) pkg_check_modules(PC_VALGRIND QUIET valgrind) find_path( - VALGRIND_INCLUDE_DIR valgrind/valgrind.h - HINTS ${VALGRIND_ROOT} ENV VALGRIND_ROOT ${PC_VALGRIND_INCLUDEDIR} - ${PC_VALGRIND_INCLUDE_DIRS} + Valgrind_INCLUDE_DIR valgrind/valgrind.h + HINTS ${Valgrind_ROOT} ENV VALGRIND_ROOT ${PC_Valgrind_INCLUDEDIR} + ${PC_Valgrind_INCLUDE_DIRS} PATH_SUFFIXES include ) -set(VALGRIND_INCLUDE_DIRS ${VALGRIND_INCLUDE_DIR}) +set(Valgrind_INCLUDE_DIRS ${Valgrind_INCLUDE_DIR}) -find_package_handle_standard_args(Valgrind DEFAULT_MSG VALGRIND_INCLUDE_DIR) +find_package_handle_standard_args(Valgrind DEFAULT_MSG Valgrind_INCLUDE_DIR) get_property( _type - CACHE VALGRIND_ROOT + CACHE Valgrind_ROOT PROPERTY TYPE ) if(_type) - set_property(CACHE VALGRIND_ROOT PROPERTY ADVANCED 1) + set_property(CACHE Valgrind_ROOT PROPERTY ADVANCED 1) if("x${_type}" STREQUAL "xUNINITIALIZED") - set_property(CACHE VALGRIND_ROOT PROPERTY TYPE PATH) + set_property(CACHE Valgrind_ROOT PROPERTY TYPE PATH) endif() endif() -mark_as_advanced(VALGRIND_ROOT VALGRIND_INCLUDE_DIR) +mark_as_advanced(Valgrind_ROOT Valgrind_INCLUDE_DIR) diff --git a/cmake/HPX_AddTest.cmake b/cmake/HPX_AddTest.cmake index 738b529ccfe5..d416d99fe3ce 100644 --- a/cmake/HPX_AddTest.cmake +++ b/cmake/HPX_AddTest.cmake @@ -82,9 +82,13 @@ function(add_hpx_test category name) set(_script_location ${PROJECT_BINARY_DIR}) endif() + if(PYTHON_EXECUTABLE AND NOT Python_EXECUTABLE) + set(Python_EXECUTABLE ${PYTHON_EXECUTABLE}) + endif() + # cmake-format: off set(cmd - "${PYTHON_EXECUTABLE}" + "${Python_EXECUTABLE}" "${_script_location}/bin/hpxrun.py" ${CMAKE_CROSSCOMPILING_EMULATOR} ${_exe} diff --git a/cmake/HPX_Documentation.cmake b/cmake/HPX_Documentation.cmake index fe9b38887fcb..c6530c04207b 100644 --- a/cmake/HPX_Documentation.cmake +++ b/cmake/HPX_Documentation.cmake @@ -11,14 +11,14 @@ if(HPX_WITH_DOCUMENTATION) find_package(Sphinx) find_package(Breathe) - if(NOT SPHINX_FOUND) + if(NOT Sphinx_FOUND) hpx_error( - "Sphinx is unavailable, sphinx documentation generation disabled. Set SPHINX_ROOT to your sphinx-build installation directory." + "Sphinx is unavailable, sphinx documentation generation disabled. Set Sphinx_ROOT to your sphinx-build installation directory." ) set(HPX_WITH_DOCUMENTATION OFF) - elseif(NOT BREATHE_FOUND) + elseif(NOT Breathe_FOUND) hpx_error( - "Breathe is unavailable, sphinx documentation generation disabled. Set BREATHE_APIDOC_ROOT to your breathe-apidoc installation directory." + "Breathe is unavailable, sphinx documentation generation disabled. Set Breathe_APIDOC_ROOT to your breathe-apidoc installation directory." ) set(HPX_WITH_DOCUMENTATION OFF) elseif(NOT DOXYGEN_FOUND) diff --git a/cmake/HPX_SetupAllocator.cmake b/cmake/HPX_SetupAllocator.cmake index 2e9d760a7781..4770573eef5a 100644 --- a/cmake/HPX_SetupAllocator.cmake +++ b/cmake/HPX_SetupAllocator.cmake @@ -43,12 +43,12 @@ if(NOT TARGET hpx_dependencies_allocator) # TCMALLOC if("${HPX_WITH_MALLOC_UPPER}" STREQUAL "TCMALLOC") find_package(TCMalloc) - if(NOT TCMALLOC_LIBRARIES) + if(NOT Tcmalloc_LIBRARIES) hpx_error(${allocator_error}) endif() target_link_libraries( - hpx_dependencies_allocator INTERFACE ${TCMALLOC_LIBRARIES} + hpx_dependencies_allocator INTERFACE ${Tcmalloc_LIBRARIES} ) if(MSVC) @@ -63,15 +63,15 @@ if(NOT TARGET hpx_dependencies_allocator) # JEMALLOC if("${HPX_WITH_MALLOC_UPPER}" STREQUAL "JEMALLOC") find_package(Jemalloc) - if(NOT JEMALLOC_LIBRARIES) + if(NOT Jemalloc_LIBRARIES) hpx_error(${allocator_error}) endif() target_include_directories( - hpx_dependencies_allocator INTERFACE ${JEMALLOC_INCLUDE_DIR} - ${JEMALLOC_ADDITIONAL_INCLUDE_DIR} + hpx_dependencies_allocator INTERFACE ${Jemalloc_INCLUDE_DIR} + ${Jemalloc_ADDITIONAL_INCLUDE_DIR} ) target_link_libraries( - hpx_dependencies_allocator INTERFACE ${JEMALLOC_LIBRARIES} + hpx_dependencies_allocator INTERFACE ${Jemalloc_LIBRARIES} ) endif() @@ -96,7 +96,7 @@ if(NOT TARGET hpx_dependencies_allocator) # TBBMALLOC if("${HPX_WITH_MALLOC_UPPER}" STREQUAL "TBBMALLOC") find_package(TBBmalloc) - if(NOT TBBMALLOC_LIBRARY AND NOT TBBMALLOC_PROXY_LIBRARY) + if(NOT Tbbmalloc_LIBRARY AND NOT Tbbmalloc_PROXY_LIBRARY) hpx_error(${allocator_error}) endif() if(MSVC) @@ -105,8 +105,8 @@ if(NOT TARGET hpx_dependencies_allocator) ) endif() target_link_libraries( - hpx_dependencies_allocator INTERFACE ${TBBMALLOC_LIBRARY} - ${TBBMALLOC_PROXY_LIBRARY} + hpx_dependencies_allocator INTERFACE ${Tbbmalloc_LIBRARY} + ${Tbbmalloc_PROXY_LIBRARY} ) endif() @@ -135,9 +135,9 @@ if(NOT TARGET hpx_dependencies_allocator) if((NOT HPX_WITH_APEX) AND HPX_WITH_ITTNOTIFY) find_package(Amplifier) - if(NOT AMPLIFIER_FOUND) + if(NOT Amplifier_FOUND) hpx_error( - "Intel Amplifier could not be found and HPX_WITH_ITTNOTIFY=On, please specify AMPLIFIER_ROOT to point to the root of your Amplifier installation" + "Intel Amplifier could not be found and HPX_WITH_ITTNOTIFY=On, please specify Amplifier_ROOT to point to the root of your Amplifier installation" ) endif() diff --git a/cmake/HPX_SetupApex.cmake b/cmake/HPX_SetupApex.cmake index 39cb573f3ad4..01d9b96a844c 100644 --- a/cmake/HPX_SetupApex.cmake +++ b/cmake/HPX_SetupApex.cmake @@ -15,20 +15,43 @@ # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) if(HPX_WITH_APEX AND NOT TARGET APEX::apex) + # compatibility with older CMake versions + if(APEX_ROOT AND NOT Apex_ROOT) + set(Apex_ROOT + ${APEX_ROOT} + CACHE PATH "Apex base directory" + ) + unset(APEX_ROOT CACHE) + endif() + if(MSR_ROOT AND NOT Msr_ROOT) + set(Msr_ROOT + ${MSR_ROOT} + CACHE PATH "MSR base directory" + ) + unset(MSR_ROOT CACHE) + endif() + if(OTF2_ROOT AND NOT Otf2_ROOT) + set(Otf2_ROOT + ${OTF2_ROOT} + CACHE PATH "OTF2 base directory" + ) + unset(OTF2_ROOT CACHE) + endif() + if(NOT HPX_FIND_PACKAGE) - if(NOT "${APEX_ROOT}" AND "$ENV{APEX_ROOT}") - set(APEX_ROOT "$ENV{APEX_ROOT}") + if(NOT "${Apex_ROOT}" AND "$ENV{APEX_ROOT}") + set(Apex_ROOT "$ENV{APEX_ROOT}") endif() # We want to track parent dependencies hpx_add_config_define(HPX_HAVE_THREAD_PARENT_REFERENCE) - if(APEX_ROOT) + if(Apex_ROOT) # Use given (external) APEX - set(HPX_APEX_ROOT ${APEX_ROOT}) + set(HPX_APEX_ROOT ${Apex_ROOT}) else() - # If APEX_ROOT not specified, local clone into hpx source dir + # If Apex_ROOT not specified, local clone into hpx source dir include(FetchContent) fetchcontent_declare( apex @@ -50,15 +73,15 @@ if(HPX_WITH_APEX AND NOT TARGET APEX::apex) if(NOT apex_POPULATED) hpx_error("APEX could not be populated with HPX_WITH_APEX=On") endif() - set(APEX_ROOT ${apex_SOURCE_DIR}) + set(Apex_ROOT ${apex_SOURCE_DIR}) - hpx_info("APEX_ROOT is not set. Cloning APEX into ${apex_SOURCE_DIR}.") + hpx_info("Apex_ROOT is not set. Cloning APEX into ${apex_SOURCE_DIR}.") endif() - list(APPEND CMAKE_MODULE_PATH "${APEX_ROOT}/cmake/Modules") - add_subdirectory(${APEX_ROOT}/src/apex ${CMAKE_BINARY_DIR}/apex/src/apex) - if(AMPLIFIER_FOUND) - hpx_error("AMPLIFIER_FOUND has been set. Please disable the use of the \ + list(APPEND CMAKE_MODULE_PATH "${Apex_ROOT}/cmake/Modules") + add_subdirectory(${Apex_ROOT}/src/apex ${CMAKE_BINARY_DIR}/apex/src/apex) + if(Amplifier_FOUND) + hpx_error("Amplifier_FOUND has been set. Please disable the use of the \ Intel Amplifier (WITH_AMPLIFIER=Off) in order to use APEX" ) endif() @@ -86,14 +109,14 @@ if(HPX_WITH_APEX AND NOT TARGET APEX::apex) # handle optional ITTNotify library (private dependency, skip when called in # find_package(HPX)) if(HPX_WITH_ITTNOTIFY AND NOT HPX_FIND_PACKAGE) - add_subdirectory(${APEX_ROOT}/src/ITTNotify) - if(NOT ITTNOTIFY_FOUND) + add_subdirectory(${Apex_ROOT}/src/ITTNotify) + if(NOT Ittnotify_FOUND) hpx_error("ITTNotify could not be found and HPX_WITH_ITTNOTIFY=On") endif() add_library(ITTNotify::ittnotify INTERFACE IMPORTED) target_include_directories( - ITTNotify::ittnotify SYSTEM INTERFACE ${ITTNOTIFY_SOURCE_DIR} + ITTNotify::ittnotify SYSTEM INTERFACE ${Ittnotify_SOURCE_DIR} ) target_link_libraries(APEX::apex INTERFACE ITTNotify::ittnotify) hpx_add_config_define(HPX_HAVE_ITTNOTIFY 1) diff --git a/cmake/HPX_SetupAsio.cmake b/cmake/HPX_SetupAsio.cmake index 1dfbdd9416d6..86a33a635f08 100644 --- a/cmake/HPX_SetupAsio.cmake +++ b/cmake/HPX_SetupAsio.cmake @@ -4,6 +4,15 @@ # 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) +# compatibility with older CMake versions +if(ASIO_ROOT AND NOT Asio_ROOT) + set(Asio_ROOT + ${ASIO_ROOT} + CACHE PATH "ASIO base directory" + ) + unset(ASIO_ROOT CACHE) +endif() + if(NOT HPX_WITH_FETCH_ASIO) find_package(Asio 1.12.0 REQUIRED) elseif(NOT TARGET Asio::asio AND NOT HPX_FIND_PACKAGE) @@ -27,11 +36,11 @@ elseif(NOT TARGET Asio::asio AND NOT HPX_FIND_PACKAGE) if(NOT asio_POPULATED) fetchcontent_populate(asio) endif() - set(ASIO_ROOT ${asio_SOURCE_DIR}) + set(Asio_ROOT ${asio_SOURCE_DIR}) add_library(asio INTERFACE) target_include_directories( - asio SYSTEM INTERFACE $ + asio SYSTEM INTERFACE $ $ ) @@ -42,7 +51,7 @@ elseif(NOT TARGET Asio::asio AND NOT HPX_FIND_PACKAGE) ) install( - DIRECTORY ${ASIO_ROOT}/asio/include/ + DIRECTORY ${Asio_ROOT}/asio/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT core FILES_MATCHING @@ -72,17 +81,22 @@ if(NOT HPX_FIND_PACKAGE) if(NOT HPX_WITH_CXX17_ALIGNED_NEW) hpx_add_config_cond_define(ASIO_DISABLE_STD_ALIGNED_ALLOC) endif() + # Asio does not detect that invoke_result is available, but we assume it # always is since we require C++17. hpx_add_config_cond_define(ASIO_HAS_STD_INVOKE_RESULT 1) + # Asio should not use Boost exceptions hpx_add_config_cond_define(ASIO_HAS_BOOST_THROW_EXCEPTION 0) + # Disable concepts support in Asio as a workaround to # https://github.com/boostorg/asio/issues/312 hpx_add_config_cond_define(ASIO_DISABLE_CONCEPTS) + # Disable experimental std::string_view support as a workaround to # https://github.com/chriskohlhoff/asio/issues/597 hpx_add_config_cond_define(ASIO_DISABLE_STD_EXPERIMENTAL_STRING_VIEW) + # Disable Asio's definition of NOMINMAX hpx_add_config_cond_define(ASIO_NO_NOMINMAX) endif() diff --git a/cmake/HPX_SetupBoost.cmake b/cmake/HPX_SetupBoost.cmake index 39b754606a05..873d7724a714 100644 --- a/cmake/HPX_SetupBoost.cmake +++ b/cmake/HPX_SetupBoost.cmake @@ -58,22 +58,31 @@ if(NOT TARGET hpx_dependencies_boost) list(REMOVE_DUPLICATES __boost_libraries) + # compatibility with older CMake versions + if(BOOST_ROOT AND NOT Boost_ROOT) + set(Boost_ROOT + ${BOOST_ROOT} + CACHE PATH "Boost base directory" + ) + unset(BOOST_ROOT CACHE) + endif() + find_package( - Boost ${Boost_MINIMUM_VERSION} MODULE REQUIRED + Boost ${Boost_MINIMUM_VERSION} NO_POLICY_SCOPE MODULE REQUIRED COMPONENTS ${__boost_libraries} ) if(NOT Boost_FOUND) hpx_error( - "Could not find Boost. Please set BOOST_ROOT to point to your Boost installation." + "Could not find Boost. Please set Boost_ROOT to point to your Boost installation." ) endif() # We are assuming that there is only one Boost Root - if(NOT BOOST_ROOT AND "$ENV{BOOST_ROOT}") - set(BOOST_ROOT $ENV{BOOST_ROOT}) - elseif(NOT BOOST_ROOT) - string(REPLACE "/include" "" BOOST_ROOT "${Boost_INCLUDE_DIRS}") + if(NOT Boost_ROOT AND "$ENV{BOOST_ROOT}") + set(Boost_ROOT $ENV{BOOST_ROOT}) + elseif(NOT Boost_ROOT) + string(REPLACE "/include" "" Boost_ROOT "${Boost_INCLUDE_DIRS}") endif() add_library(hpx_dependencies_boost INTERFACE IMPORTED) diff --git a/cmake/HPX_SetupBoostFilesystem.cmake b/cmake/HPX_SetupBoostFilesystem.cmake index 661099bbd949..44cc5f4531a3 100644 --- a/cmake/HPX_SetupBoostFilesystem.cmake +++ b/cmake/HPX_SetupBoostFilesystem.cmake @@ -1,4 +1,4 @@ -# Copyright (c) 2019 The STE||AR-Group +# Copyright (c) 2019-2023 The STE||AR-Group # # SPDX-License-Identifier: BSL-1.0 # Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -7,7 +7,10 @@ if(HPX_FILESYSTEM_WITH_BOOST_FILESYSTEM_COMPATIBILITY) # In case find_package(HPX) is called multiple times if(NOT TARGET Boost::filesystem) - find_package(Boost ${Boost_MINIMUM_VERSION} MODULE COMPONENTS filesystem) + find_package( + Boost ${Boost_MINIMUM_VERSION} NO_POLICY_SCOPE MODULE + COMPONENTS filesystem + ) if(NOT Boost_FILESYSTEM_FOUND) hpx_error( diff --git a/cmake/HPX_SetupBoostIostreams.cmake b/cmake/HPX_SetupBoostIostreams.cmake index 033c4f15e807..77784cd073c0 100644 --- a/cmake/HPX_SetupBoostIostreams.cmake +++ b/cmake/HPX_SetupBoostIostreams.cmake @@ -1,4 +1,4 @@ -# Copyright (c) 2019 The STE||AR-Group +# Copyright (c) 2019-2023 The STE||AR-Group # # SPDX-License-Identifier: BSL-1.0 # Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -9,7 +9,9 @@ if((HPX_WITH_COMPRESSION_BZIP2 OR HPX_WITH_COMPRESSION_ZLIB) AND NOT TARGET Boost::iostreams ) - find_package(Boost ${Boost_MINIMUM_VERSION} MODULE COMPONENTS iostreams) + find_package( + Boost ${Boost_MINIMUM_VERSION} NO_POLICY_SCOPE MODULE COMPONENTS iostreams + ) if(Boost_IOSTREAMS_FOUND) hpx_info(" iostreams") diff --git a/cmake/HPX_SetupBoostRegex.cmake b/cmake/HPX_SetupBoostRegex.cmake index 903810bc57e9..5ea12927da37 100644 --- a/cmake/HPX_SetupBoostRegex.cmake +++ b/cmake/HPX_SetupBoostRegex.cmake @@ -1,11 +1,13 @@ -# Copyright (c) 2019 The STE||AR-Group +# Copyright (c) 2019-2023 The STE||AR-Group # # SPDX-License-Identifier: BSL-1.0 # 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 TARGET Boost::regex) - find_package(Boost ${Boost_MINIMUM_VERSION} MODULE COMPONENTS regex) + find_package( + Boost ${Boost_MINIMUM_VERSION} NO_POLICY_SCOPE MODULE COMPONENTS regex + ) if(Boost_REGEX_FOUND) hpx_info(" regex") diff --git a/cmake/HPX_SetupEve.cmake b/cmake/HPX_SetupEve.cmake index 9dff0f454a4d..884ef9b6793e 100644 --- a/cmake/HPX_SetupEve.cmake +++ b/cmake/HPX_SetupEve.cmake @@ -5,6 +5,16 @@ # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) if(("${HPX_WITH_DATAPAR_BACKEND}" STREQUAL "EVE") AND NOT TARGET eve::eve) + + # compatibility with older CMake versions + if(EVE_ROOT AND NOT Eve_ROOT) + set(Eve_ROOT + ${EVE_ROOT} + CACHE PATH "Eve base directory" + ) + unset(EVE_ROOT CACHE) + endif() + if(HPX_WITH_FETCH_EVE) if(FETCHCONTENT_SOURCE_DIR_EVE) hpx_info( @@ -12,7 +22,7 @@ if(("${HPX_WITH_DATAPAR_BACKEND}" STREQUAL "EVE") AND NOT TARGET eve::eve) ) else() hpx_info( - "HPX_WITH_FETCH_EVE=${HPX_WITH_FETCH_EVE}, EVE will be fetched using CMake's FetchContent and installed alongside HPX (HPX_WITH_EVE_TAG=${HPX_WITH_EVE_TAG})" + "HPX_WITH_FETCH_EVE=${HPX_WITH_FETCH_EVE}, EVE will be fetched using CMake's FetchContent and installed alongside HPX (HPX_WITH_Eve_TAG=${HPX_WITH_Eve_TAG})" ) endif() include(FetchContent) @@ -26,11 +36,11 @@ if(("${HPX_WITH_DATAPAR_BACKEND}" STREQUAL "EVE") AND NOT TARGET eve::eve) if(NOT eve_POPULATED) fetchcontent_populate(eve) endif() - set(EVE_ROOT ${eve_SOURCE_DIR}) + set(Eve_ROOT ${eve_SOURCE_DIR}) add_library(eve INTERFACE) target_include_directories( - eve SYSTEM INTERFACE $ + eve SYSTEM INTERFACE $ $ ) @@ -41,7 +51,7 @@ if(("${HPX_WITH_DATAPAR_BACKEND}" STREQUAL "EVE") AND NOT TARGET eve::eve) ) install( - DIRECTORY ${EVE_ROOT}/include/ + DIRECTORY ${Eve_ROOT}/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT core FILES_MATCHING @@ -66,10 +76,10 @@ if(("${HPX_WITH_DATAPAR_BACKEND}" STREQUAL "EVE") AND NOT TARGET eve::eve) add_library(eve::eve ALIAS eve) else() - if(EVE_ROOT) - find_package(eve REQUIRED PATHS ${EVE_ROOT}) + if(Eve_ROOT) + find_package(eve REQUIRED PATHS ${Eve_ROOT}) else() - hpx_error("EVE_ROOT not set") + hpx_error("Eve_ROOT not set") endif() endif() endif() diff --git a/cmake/HPX_SetupHIP.cmake b/cmake/HPX_SetupHIP.cmake index e19b78c7e271..2b2a42ae346f 100644 --- a/cmake/HPX_SetupHIP.cmake +++ b/cmake/HPX_SetupHIP.cmake @@ -23,7 +23,7 @@ if(HPX_WITH_HIP AND NOT TARGET roc::hipblas) if(NOT hipblas_FOUND) hpx_warn( "Hipblas could not be found, the blas parts will therefore be disabled.\n\ - You can reconfigure specifying HIPBLAS_ROOT to enable hipblas" + You can reconfigure specifying HIPBLAS_ROOT environment variable to enable hipblas" ) set(HPX_WITH_GPUBLAS OFF) else() diff --git a/cmake/HPX_SetupHwloc.cmake b/cmake/HPX_SetupHwloc.cmake index edbf001a8cfc..12ce52247a36 100644 --- a/cmake/HPX_SetupHwloc.cmake +++ b/cmake/HPX_SetupHwloc.cmake @@ -14,8 +14,8 @@ # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) find_package(Hwloc) -if(NOT HWLOC_FOUND) +if(NOT Hwloc_FOUND) hpx_error( - "Hwloc could not be found, please specify HWLOC_ROOT to point to the correct location" + "Hwloc could not be found, please specify Hwloc_ROOT to point to the correct location" ) endif() diff --git a/cmake/HPX_SetupLCI.cmake b/cmake/HPX_SetupLCI.cmake index 98a01ea68205..26b1ecd18076 100644 --- a/cmake/HPX_SetupLCI.cmake +++ b/cmake/HPX_SetupLCI.cmake @@ -9,13 +9,23 @@ macro(hpx_setup_lci) if(NOT TARGET LCI::LCI) + + # compatibility with older CMake versions + if(LCI_ROOT AND NOT Lci_ROOT) + set(Lci_ROOT + ${LCI_ROOT} + CACHE PATH "LCI base directory" + ) + unset(LCI_ROOT CACHE) + endif() + if(NOT HPX_WITH_FETCH_LCI) find_package( LCI CONFIG REQUIRED HINTS - ${LCI_ROOT} + ${Lci_ROOT} $ENV{LCI_ROOT} PATH_SUFFIXES lib/cmake @@ -28,14 +38,14 @@ macro(hpx_setup_lci) ) else() hpx_info( - "HPX_WITH_FETCH_LCI=${HPX_WITH_FETCH_LCI}, LCI will be fetched using CMake's FetchContent and installed alongside HPX (HPX_WITH_LCI_TAG=${HPX_WITH_LCI_TAG})" + "HPX_WITH_FETCH_LCI=${HPX_WITH_FETCH_LCI}, LCI will be fetched using CMake's FetchContent and installed alongside HPX (HPX_WITH_Lci_TAG=${HPX_WITH_Lci_TAG})" ) endif() include(FetchContent) fetchcontent_declare( lci GIT_REPOSITORY https://github.com/uiuc-hpc/LC.git - GIT_TAG ${HPX_WITH_LCI_TAG} + GIT_TAG ${HPX_WITH_Lci_TAG} ) fetchcontent_getproperties(lci) diff --git a/cmake/HPX_SetupPapi.cmake b/cmake/HPX_SetupPapi.cmake index 300c41507d65..a091be1cb110 100644 --- a/cmake/HPX_SetupPapi.cmake +++ b/cmake/HPX_SetupPapi.cmake @@ -14,10 +14,10 @@ # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) if(HPX_WITH_PAPI) - find_package(PAPI) - if(NOT PAPI_FOUND) + find_package(Papi) + if(NOT Papi_FOUND) hpx_error("PAPI could not be found and HPX_WITH_PAPI=On, please specify \ - PAPI_ROOT to point to the root of your PAPI installation" + Papi_ROOT to point to the root of your PAPI installation" ) endif() endif() diff --git a/cmake/HPX_SetupSVE.cmake b/cmake/HPX_SetupSVE.cmake index c85b69c51104..467a6b048f6e 100644 --- a/cmake/HPX_SetupSVE.cmake +++ b/cmake/HPX_SetupSVE.cmake @@ -5,6 +5,16 @@ # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) if(("${HPX_WITH_DATAPAR_BACKEND}" STREQUAL "SVE") AND NOT TARGET SVE::sve) + + # compatibility with older CMake versions + if(SVE_ROOT AND NOT Sve_ROOT) + set(Sve_ROOT + ${SVE_ROOT} + CACHE PATH "SVE base directory" + ) + unset(SVE_ROOT CACHE) + endif() + if(HPX_WITH_FETCH_SVE) if(FETCHCONTENT_SOURCE_DIR_SVE) hpx_info( @@ -12,7 +22,7 @@ if(("${HPX_WITH_DATAPAR_BACKEND}" STREQUAL "SVE") AND NOT TARGET SVE::sve) ) else() hpx_info( - "HPX_WITH_FETCH_SVE=${HPX_WITH_FETCH_SVE}, SVE will be fetched using CMake's FetchContent and installed alongside HPX (HPX_WITH_SVE_TAG=${HPX_WITH_SVE_TAG})" + "HPX_WITH_FETCH_SVE=${HPX_WITH_FETCH_SVE}, SVE will be fetched using CMake's FetchContent and installed alongside HPX (HPX_WITH_Sve_TAG=${HPX_WITH_Sve_TAG})" ) endif() @@ -22,7 +32,7 @@ if(("${HPX_WITH_DATAPAR_BACKEND}" STREQUAL "SVE") AND NOT TARGET SVE::sve) ) endif() - set(SVE_LENGTH "${HPX_WITH_SVE_LENGTH}") + set(Sve_LENGTH "${HPX_WITH_SVE_LENGTH}") include(FetchContent) fetchcontent_declare( @@ -33,7 +43,7 @@ if(("${HPX_WITH_DATAPAR_BACKEND}" STREQUAL "SVE") AND NOT TARGET SVE::sve) fetchcontent_makeavailable(sve) - set(SVE_ROOT ${sve_SOURCE_DIR}) + set(Sve_ROOT ${sve_SOURCE_DIR}) install( TARGETS sve @@ -42,7 +52,7 @@ if(("${HPX_WITH_DATAPAR_BACKEND}" STREQUAL "SVE") AND NOT TARGET SVE::sve) ) install( - DIRECTORY ${SVE_ROOT}/include/ + DIRECTORY ${Sve_ROOT}/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT core FILES_MATCHING @@ -65,10 +75,10 @@ if(("${HPX_WITH_DATAPAR_BACKEND}" STREQUAL "SVE") AND NOT TARGET SVE::sve) ) else() - if(SVE_ROOT) - find_package(SVE REQUIRED PATHS ${SVE_ROOT}) + if(Sve_ROOT) + find_package(SVE REQUIRED PATHS ${Sve_ROOT}) else() - hpx_error("SVE_ROOT not set") + hpx_error("Sve_ROOT not set") endif() endif() endif() diff --git a/cmake/HPX_SetupValgrind.cmake b/cmake/HPX_SetupValgrind.cmake index f858a9186350..6c5295082610 100644 --- a/cmake/HPX_SetupValgrind.cmake +++ b/cmake/HPX_SetupValgrind.cmake @@ -16,9 +16,9 @@ if(HPX_WITH_VALGRIND AND NOT TARGET Valgrind::valgrind) find_package(Valgrind) - if(NOT VALGRIND_FOUND) + if(NOT Valgrind_FOUND) hpx_error("Valgrind could not be found and HPX_WITH_VALGRIND=On, please \ - specify VALGRIND_ROOT to point to the root of your Valgrind installation" + specify Valgrind_ROOT to point to the root of your Valgrind installation" ) endif() diff --git a/cmake/installed_hpx.cmake b/cmake/installed_hpx.cmake index 506fe121f0b8..5f079d802114 100644 --- a/cmake/installed_hpx.cmake +++ b/cmake/installed_hpx.cmake @@ -127,11 +127,20 @@ if(HPX_WITH_TESTS) include(CTest) # find Python interpreter (needed to run tests) - find_package(PythonInterp) - if(NOT PYTHONINTERP_FOUND) - hpx_warn( - "A python interpreter could not be found. The test suite can not be run automatically." - ) + if(POLICY CMP0148) + find_package(Python COMPONENTS Interpreter) + if(NOT Python_FOUND) + hpx_warn( + "A python interpreter could not be found. The test suite can not be run automatically." + ) + endif() + else() + find_package(PythonInterp) + if(NOT PYTHONINTERP_FOUND) + hpx_warn( + "A python interpreter could not be found. The test suite can not be run automatically." + ) + endif() endif() # add actual tests, first iterate through all modules diff --git a/cmake/templates/HPXConfig.cmake.in b/cmake/templates/HPXConfig.cmake.in index 0996804504b9..257e52a1415f 100644 --- a/cmake/templates/HPXConfig.cmake.in +++ b/cmake/templates/HPXConfig.cmake.in @@ -23,7 +23,7 @@ include("${CMAKE_CURRENT_LIST_DIR}/HPXMacros.cmake") if(HPX_WITH_FETCH_ASIO) include("${CMAKE_CURRENT_LIST_DIR}/HPXAsioTarget.cmake") else() - set(HPX_ASIO_ROOT "@ASIO_ROOT@") + set(HPX_ASIO_ROOT "@Asio_ROOT@") include(HPX_SetupAsio) endif() @@ -34,7 +34,7 @@ if(HPX_COMMAND_LINE_HANDLING_WITH_JSON_CONFIGURATION_FILES) if(HPX_WITH_FETCH_JSON) include("${CMAKE_CURRENT_LIST_DIR}/HPXJSONTarget.cmake") else() - set(HPX_JSON_ROOT "@JSON_ROOT@") + set(HPX_JSON_ROOT "@Json_ROOT@") include(HPX_SetupJSON) endif() endif() @@ -46,7 +46,7 @@ if(HPX_WITH_NETWORKING AND HPX_WITH_PARCELPORT_LCI) find_dependency(@LCI_FABRIC@) include("${CMAKE_CURRENT_LIST_DIR}/HPXLCITarget.cmake") else() - set(LCI_ROOT "@LCI_ROOT@") + set(Lci_ROOT "@Lci_ROOT@") include(HPX_SetupLCI) hpx_setup_lci() endif() @@ -58,7 +58,7 @@ if("${HPX_WITH_DATAPAR_BACKEND}" STREQUAL "EVE") if(HPX_WITH_FETCH_EVE) include("${CMAKE_CURRENT_LIST_DIR}/HPXEveTarget.cmake") else() - set(EVE_ROOT "@EVE_ROOT@") + set(Eve_ROOT "@Eve_ROOT@") include(HPX_SetupEve) endif() endif() @@ -67,7 +67,7 @@ if("${HPX_WITH_DATAPAR_BACKEND}" STREQUAL "SVE") if(HPX_WITH_FETCH_SVE) include("${CMAKE_CURRENT_LIST_DIR}/HPXSVETarget.cmake") else() - set(SVE_ROOT "@SVE_ROOT@") + set(Sve_ROOT "@Sve_ROOT@") include(HPX_SetupSVE) endif() endif() @@ -118,31 +118,31 @@ set(HPX_CXX_COMPILER_VERSION # Propagate Amplifier settings, if needed if(HPX_WITH_ITTNOTIFY) - set(AMPLIFIER_INCLUDE_DIR "@AMPLIFIER_INCLUDE_DIR@") - set(AMPLIFIER_LIBRARY "@AMPLIFIER_LIBRARY@") - set(AMPLIFIER_ROOT "@AMPLIFIER_ROOT@") + set(Amplifier_INCLUDE_DIR "@Amplifier_INCLUDE_DIR@") + set(Amplifier_LIBRARY "@Amplifier_LIBRARY@") + set(Amplifier_ROOT "@Amplifier_ROOT@") endif() # Allocator -set(HPX_JEMALLOC_ROOT "@JEMALLOC_ROOT@") -set(HPX_TCMALLOC_ROOT "@TCMALLOC_ROOT@") -set(HPX_TBBMALLOC_ROOT "@TBBMALLOC_ROOT@") +set(HPX_JEMALLOC_ROOT "@Jemalloc_ROOT@") +set(HPX_TCMALLOC_ROOT "@Tcmalloc_ROOT@") +set(HPX_TBBMALLOC_ROOT "@Tbbmalloc_ROOT@") # Special handle for mimalloc cause we can't specify HPX_MIMALLOC_ROOT as a HINT # to find_package -set(HPX_MIMALLOC_ROOT "@MIMALLOC_ROOT@") -if(NOT MIMALLOC_ROOT AND NOT "$ENV{MIMALLOC_ROOT}") - set(MIMALLOC_ROOT ${HPX_MIMALLOC_ROOT}) +set(HPX_MIMALLOC_ROOT "@Mimalloc_ROOT@") +if(NOT Mimalloc_ROOT AND NOT "$ENV{MIMALLOC_ROOT}") + set(Mimalloc_ROOT ${HPX_MIMALLOC_ROOT}) endif() include(HPX_SetupAllocator) include(HPX_SetupThreads) # Boost Separate boost targets to be unarily linked to some modules -set(HPX_BOOST_ROOT "@BOOST_ROOT@") -# By default BOOST_ROOT is set to HPX_BOOST_ROOT (not necessary for PAPI or +set(HPX_BOOST_ROOT "@Boost_ROOT@") +# By default Boost_ROOT is set to HPX_BOOST_ROOT (not necessary for PAPI or # HWLOC cause we are specifying HPX__ROOT as an HINT to find_package) -if(NOT BOOST_ROOT AND NOT "$ENV{BOOST_ROOT}") - set(BOOST_ROOT ${HPX_BOOST_ROOT}) +if(NOT Boost_ROOT AND NOT "$ENV{BOOST_ROOT}") + set(Boost_ROOT ${HPX_BOOST_ROOT}) endif() include(HPX_SetupBoost) include(HPX_SetupBoostFilesystem) @@ -152,11 +152,11 @@ include(HPX_SetupBoostIostreams) include(HPX_SetupHIP) # Hwloc -set(HPX_HWLOC_ROOT "@HWLOC_ROOT@") +set(HPX_HWLOC_ROOT "@Hwloc_ROOT@") include(HPX_SetupHwloc) # Papi -set(HPX_PAPI_ROOT "@PAPI_ROOT@") +set(HPX_PAPI_ROOT "@Papi_ROOT@") include(HPX_SetupPapi) # CUDA @@ -169,11 +169,11 @@ endif() # APEX set(APEX_WITH_MSR "@APEX_WITH_MSR@") -set(MSR_ROOT "@MSR_ROOT@") +set(Msr_ROOT "@Msr_ROOT@") set(APEX_WITH_ACTIVEHARMONY "@APEX_WITH_ACTIVEHARMONY@") -set(ACTIVEHARMONY_ROOT "@ACTIVEHARMONY_ROOT@") +set(Activeharmony_ROOT "@Activeharmony_ROOT@") set(APEX_WITH_OTF2 "@APEX_WITH_OTF2@") -set(OTF2_ROOT "@OTF2_ROOT@") +set(Otf2_ROOT "@Otf2_ROOT@") include(HPX_SetupApex) # ############################################################################## diff --git a/cmake/templates/HPXMacros.cmake.in b/cmake/templates/HPXMacros.cmake.in index 3315902d6e58..bd2f1dd6bb82 100644 --- a/cmake/templates/HPXMacros.cmake.in +++ b/cmake/templates/HPXMacros.cmake.in @@ -68,18 +68,18 @@ function(hpx_check_boost_compatibility) if(HPX_IGNORE_BOOST_COMPATIBILITY) return() endif() - if(NOT DEFINED BOOST_ROOT) + if(NOT DEFINED Boost_ROOT) return() endif() # make sure paths are tested even if not string identical get_filename_component(PATH1 "${HPX_BOOST_ROOT}" ABSOLUTE) - get_filename_component(PATH2 "${BOOST_ROOT}" ABSOLUTE) + get_filename_component(PATH2 "${Boost_ROOT}" ABSOLUTE) if(NOT PATH1 STREQUAL PATH2) - hpx_error("The specified BOOST_ROOT differs from what has been used when" + hpx_error("The specified Boost_ROOT differs from what has been used when" " configuring and building HPX. Please use the same Boost " - "versions. HPX boost is ${HPX_BOOST_ROOT} and users is ${BOOST_ROOT}. " + "versions. HPX boost is ${HPX_BOOST_ROOT} and users is ${Boost_ROOT}. " "To disable this message set HPX_IGNORE_BOOST_COMPATIBILITY On." ) endif() diff --git a/cmake/templates/cmake_variables.rst.in b/cmake/templates/cmake_variables.rst.in index 931d0de07d10..2a6752e668e9 100644 --- a/cmake/templates/cmake_variables.rst.in +++ b/cmake/templates/cmake_variables.rst.in @@ -42,9 +42,9 @@ Each of the tools or libraries listed here will be automatically detected if they are installed in some standard location. If a tool or library is installed in a different location, you can specify its base directory by appending ``_ROOT`` to the variable name as listed below. For instance, to configure a -custom directory for ``BOOST``, specify ``BOOST_ROOT=/custom/boost/root``. +custom directory for ``Boost``, specify ``Boost_ROOT=/custom/boost/root``. -.. option:: BOOST_ROOT:PATH +.. option:: Boost_ROOT:PATH Specifies where to look for the Boost installation to be used for compiling |hpx|. Set this if CMake is not able to locate a suitable version of @@ -52,7 +52,7 @@ custom directory for ``BOOST``, specify ``BOOST_ROOT=/custom/boost/root``. Boost distribution or the directory where you unpacked and built Boost without installing it (with staged libraries). -.. option:: HWLOC_ROOT:PATH +.. option:: Hwloc_ROOT:PATH Specifies where to look for the hwloc library. Set this if CMake is not able to locate a suitable version of hwloc. Hwloc provides platform- @@ -60,14 +60,14 @@ custom directory for ``BOOST``, specify ``BOOST_ROOT=/custom/boost/root``. architecture (number of cores, number of NUMA domains, hyperthreading, etc.). |hpx| utilizes this information if available. -.. option:: PAPI_ROOT:PATH +.. option:: Papi_ROOT:PATH Specifies where to look for the PAPI library. The PAPI library is needed to compile a special component exposing PAPI hardware events and counters as |hpx| performance counters. This is not available on the Windows platform. -.. option:: AMPLIFIER_ROOT:PATH +.. option:: Amplifier_ROOT:PATH Specifies where to look for one of the tools of the Intel Parallel Studio product, either Intel Amplifier or Intel Inspector. This should be @@ -78,6 +78,6 @@ custom directory for ``BOOST``, specify ``BOOST_ROOT=/custom/boost/root``. In addition, some of the examples may need the following variables: -.. option:: HDF5_ROOT:PATH +.. option:: Hdf5_ROOT:PATH Specifies where to look for the |hdf5| include files and libraries. diff --git a/cmake/templates/hpxcxx.in b/cmake/templates/hpxcxx.in index 8e2385265784..a6d091c8fe01 100755 --- a/cmake/templates/hpxcxx.in +++ b/cmake/templates/hpxcxx.in @@ -1,4 +1,4 @@ -#! @PYTHON_EXECUTABLE@ +#! @Python_EXECUTABLE@ # # Copyright (c) 2014 Steven R. Brandt # diff --git a/cmake/templates/hpxrun.py.in b/cmake/templates/hpxrun.py.in index 70a5991e22f0..1accb6d010dc 100755 --- a/cmake/templates/hpxrun.py.in +++ b/cmake/templates/hpxrun.py.in @@ -1,4 +1,4 @@ -#! @PYTHON_EXECUTABLE@ +#! @Python_EXECUTABLE@ # # Copyright (c) 2014 Thomas Heller # diff --git a/cmake/toolchains/BGION-gcc.cmake b/cmake/toolchains/BGION-gcc.cmake index fb100952552b..b0447328a573 100644 --- a/cmake/toolchains/BGION-gcc.cmake +++ b/cmake/toolchains/BGION-gcc.cmake @@ -85,8 +85,8 @@ set(HPX_HIDDEN_VISIBILITY # # Convenience setup for jb @ bbpbg2.cscs.ch # -set(BOOST_ROOT "/gpfs/bbp.cscs.ch/home/biddisco/apps/gcc-4.8.2/boost_1_56_0") -set(HWLOC_ROOT "/gpfs/bbp.cscs.ch/home/biddisco/apps/gcc-4.8.2/hwloc-1.8.1") +set(Boost_ROOT "/gpfs/bbp.cscs.ch/home/biddisco/apps/gcc-4.8.2/boost_1_56_0") +set(Hwloc_ROOT "/gpfs/bbp.cscs.ch/home/biddisco/apps/gcc-4.8.2/hwloc-1.8.1") set(CMAKE_BUILD_TYPE "Debug" diff --git a/components/parcel_plugins/binary_filter/snappy/CMakeLists.txt b/components/parcel_plugins/binary_filter/snappy/CMakeLists.txt index 6550e27e3ca1..4fcdaccbf0de 100644 --- a/components/parcel_plugins/binary_filter/snappy/CMakeLists.txt +++ b/components/parcel_plugins/binary_filter/snappy/CMakeLists.txt @@ -11,14 +11,14 @@ endif() include(HPX_AddLibrary) find_package(Snappy) -if(NOT SNAPPY_FOUND) +if(NOT Snappy_FOUND) hpx_error("Snappy could not be found and HPX_WITH_COMPRESSION_SNAPPY=ON, \ please specify SNAPPY_ROOT to point to the correct location or set \ HPX_WITH_COMPRESSION_SNAPPY to OFF" ) endif() -hpx_debug("add_snappy_module" "SNAPPY_FOUND: ${SNAPPY_FOUND}") +hpx_debug("add_snappy_module" "SNAPPY_FOUND: ${Snappy_FOUND}") add_hpx_library( compression_snappy INTERNAL_FLAGS PLUGIN @@ -30,13 +30,14 @@ add_hpx_library( "hpx/binary_filter/snappy_serialization_filter.hpp" "hpx/binary_filter/snappy_serialization_filter_registration.hpp" PREPEND_HEADER_ROOT INSTALL_HEADERS - FOLDER "Core/Plugins/Compression" ${HPX_WITH_UNITY_BUILD_OPTION} + FOLDER "Core/Plugins/Compression" + DEPENDENCIES ${Snappy_LIBRARY} ${HPX_WITH_UNITY_BUILD_OPTION} ) target_include_directories( - compression_snappy SYSTEM PRIVATE ${SNAPPY_INCLUDE_DIR} + compression_snappy SYSTEM PRIVATE ${Snappy_INCLUDE_DIR} ) -target_link_directories(compression_snappy PRIVATE ${SNAPPY_LIBRARY_DIR}) +target_link_directories(compression_snappy PRIVATE ${Snappy_LIBRARY_DIR}) target_link_libraries( compression_snappy PUBLIC Boost::iostreams ${SNAPPY_LIBRARY} diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt index 437aa6671b00..bc2c88e473a7 100644 --- a/docs/CMakeLists.txt +++ b/docs/CMakeLists.txt @@ -221,14 +221,14 @@ foreach(output_format ${HPX_WITH_DOCUMENTATION_OUTPUT_FORMATS}) # the moment not worth the effort. if(${output_format} STREQUAL "latexpdf") set(SPHINX_DOCS_BUILD_COMMAND - ${SPHINX_EXECUTABLE} -M ${output_format} + ${Sphinx_EXECUTABLE} -M ${output_format} "${CMAKE_CURRENT_BINARY_DIR}/sphinx" "${SPHINX_DOCS_OUTPUT_DIR}" || ( exit 0) ) else() set(SPHINX_DOCS_BUILD_COMMAND - ${SPHINX_EXECUTABLE} -b ${output_format} -n -d + ${Sphinx_EXECUTABLE} -b ${output_format} -n -d "${CMAKE_CURRENT_BINARY_DIR}/doctree" "${CMAKE_CURRENT_BINARY_DIR}/sphinx" "${SPHINX_DOCS_OUTPUT_DIR}" ) diff --git a/docs/sphinx/contributing/documentation.rst b/docs/sphinx/contributing/documentation.rst index 99b577c696eb..79edaf15b5dc 100644 --- a/docs/sphinx/contributing/documentation.rst +++ b/docs/sphinx/contributing/documentation.rst @@ -41,15 +41,15 @@ manager, you can install them using the Python package manager ``pip``: You may need to set the following CMake variables to make sure CMake can find the required dependencies. -.. option:: DOXYGEN_ROOT:PATH +.. option:: Doxygen_ROOT:PATH Specifies where to look for the installation of the |doxygen|_ tool. -.. option:: SPHINX_ROOT:PATH +.. option:: Sphinx_ROOT:PATH Specifies where to look for the installation of the |sphinx|_ tool. -.. option:: BREATHE_APIDOC_ROOT:PATH +.. option:: Breathe_APIDOC_ROOT:PATH Specifies where to look for the installation of the |breathe|_ tool. diff --git a/docs/sphinx/manual/building_hpx.rst b/docs/sphinx/manual/building_hpx.rst index cc5343eb854d..3e974517ddfa 100644 --- a/docs/sphinx/manual/building_hpx.rst +++ b/docs/sphinx/manual/building_hpx.rst @@ -196,10 +196,10 @@ known to |cmake|, the following gets you started: .. code-block:: shell-session - $ cmake -DBOOST_ROOT=/path/to/boost - -DHWLOC_ROOT=/path/to/hwloc - -DTCMALLOC_ROOT=/path/to/tcmalloc - -DJEMALLOC_ROOT=/path/to/jemalloc + $ cmake -DBoost_ROOT=/path/to/boost + -DHwloc_ROOT=/path/to/hwloc + -DTcmalloc_ROOT=/path/to/tcmalloc + -DJemalloc_ROOT=/path/to/jemalloc [other CMake variable definitions] /path/to/source/tree @@ -207,7 +207,7 @@ known to |cmake|, the following gets you started: .. code-block:: shell-session - $ cmake -DBOOST_ROOT=~/packages/boost -DHWLOC_ROOT=/packages/hwloc -DCMAKE_INSTALL_PREFIX=~/packages/hpx ~/downloads/hpx_1.5.1 + $ cmake -DBoost_ROOT=~/packages/boost -DHwloc_ROOT=/packages/hwloc -DCMAKE_INSTALL_PREFIX=~/packages/hpx ~/downloads/hpx_1.5.1 * If you want to try |hpx| without using a custom allocator pass ``-DHPX_WITH_MALLOC=system`` to |cmake|: @@ -290,14 +290,14 @@ To build |hpx| under Windows 10 x64 with Visual Studio 2015: in any way. Instead, it will generate Visual Studio Solution Files, which will build |hpx| packages out of the |hpx| source tree. -* Set three new environment variables (in CMake, not in Windows environment): - ``BOOST_ROOT``, ``HWLOC_ROOT``, ``ASIO_ROOT``, ``CMAKE_INSTALL_PREFIX``. The meaning of +* Set new configuration variables (in CMake, not in Windows environment): + ``Boost_ROOT``, ``Hwloc_ROOT``, ``Asio_ROOT``, ``CMAKE_INSTALL_PREFIX``. The meaning of these variables is as follows: - * ``BOOST_ROOT`` the |hpx| root directory of the unpacked Boost headers/cpp files. - * ``HWLOC_ROOT`` the |hpx| root directory of the unpacked Portable Hardware Locality + * ``Boost_ROOT`` the |hpx| root directory of the unpacked Boost headers/cpp files. + * ``Hwloc_ROOT`` the |hpx| root directory of the unpacked Portable Hardware Locality files. - * ``ASIO_ROOT`` the |hpx| root directory of the unpacked ASIO files. Alternatively use + * ``Asio_ROOT`` the |hpx| root directory of the unpacked ASIO files. Alternatively use ``HPX_WITH_FETCH_ASIO`` with value ``True``. * ``CMAKE_INSTALL_PREFIX`` the |hpx| root directory where the future builds of |hpx| should be installed. @@ -320,13 +320,13 @@ To build |hpx| under Windows 10 x64 with Visual Studio 2015: Example CMake adding entry. - Alternatively, users could provide ``BOOST_LIBRARYDIR`` instead of - ``BOOST_ROOT``; the difference is that ``BOOST_LIBRARYDIR`` should point to + Alternatively, users could provide ``Boost_LIBRARYDIR`` instead of + ``Boost_ROOT``; the difference is that ``Boost_LIBRARYDIR`` should point to the subdirectory inside Boost root where all the compiled DLLs/LIBs are. For - example, ``BOOST_LIBRARYDIR`` may point to the ``bin.v2`` subdirectory under + example, ``Boost_LIBRARYDIR`` may point to the ``bin.v2`` subdirectory under the Boost rootdir. It is important to keep the meanings of these two variables - separated from each other: ``BOOST_DIR`` points to the ROOT folder of the - Boost library. ``BOOST_LIBRARYDIR`` points to the subdir inside the Boost root + separated from each other: ``Boost_DIR`` points to the ROOT folder of the + Boost library. ``Boost_LIBRARYDIR`` points to the subdir inside the Boost root folder where the compiled binaries are. * Click the 'Configure' button of CMake-GUI. You will be immediately presented with a diff --git a/docs/sphinx/manual/creating_hpx_projects.rst b/docs/sphinx/manual/creating_hpx_projects.rst index e4b9fb06b1b7..102f118f879a 100644 --- a/docs/sphinx/manual/creating_hpx_projects.rst +++ b/docs/sphinx/manual/creating_hpx_projects.rst @@ -476,14 +476,14 @@ Add the following code: CXXFLAGS=-O3 -std=c++17 - BOOST_ROOT=/path/to/boost - HWLOC_ROOT=/path/to/hwloc - TCMALLOC_ROOT=/path/to/tcmalloc + Boost_ROOT=/path/to/boost + Hwloc_ROOT=/path/to/hwloc + Tcmalloc_ROOT=/path/to/tcmalloc HPX_ROOT=/path/to/hpx - INCLUDE_DIRECTIVES=$(HPX_ROOT)/include $(BOOST_ROOT)/include $(HWLOC_ROOT)/include + INCLUDE_DIRECTIVES=$(HPX_ROOT)/include $(Boost_ROOT)/include $(Hwloc_ROOT)/include - LIBRARY_DIRECTIVES=-L$(HPX_ROOT)/lib $(HPX_ROOT)/lib/libhpx_init.a $(HPX_ROOT)/lib/libhpx.so $(BOOST_ROOT)/lib/libboost_atomic-mt.so $(BOOST_ROOT)/lib/libboost_filesystem-mt.so $(BOOST_ROOT)/lib/libboost_program_options-mt.so $(BOOST_ROOT)/lib/libboost_regex-mt.so $(BOOST_ROOT)/lib/libboost_system-mt.so -lpthread $(TCMALLOC_ROOT)/libtcmalloc_minimal.so $(HWLOC_ROOT)/libhwloc.so -ldl -lrt + LIBRARY_DIRECTIVES=-L$(HPX_ROOT)/lib $(HPX_ROOT)/lib/libhpx_init.a $(HPX_ROOT)/lib/libhpx.so $(Boost_ROOT)/lib/libboost_atomic-mt.so $(Boost_ROOT)/lib/libboost_filesystem-mt.so $(Boost_ROOT)/lib/libboost_program_options-mt.so $(Boost_ROOT)/lib/libboost_regex-mt.so $(Boost_ROOT)/lib/libboost_system-mt.so -lpthread $(Tcmalloc_ROOT)/libtcmalloc_minimal.so $(Hwloc_ROOT)/libhwloc.so -ldl -lrt LINK_FLAGS=$(HPX_ROOT)/lib/libhpx_wrap.a -Wl,-wrap=main # should be left empty for HPX_WITH_HPX_MAIN=OFF @@ -548,14 +548,14 @@ Now, in the directory, create a Makefile. Add the following code: CXXFLAGS=-O3 -std=c++17 - BOOST_ROOT=/path/to/boost - HWLOC_ROOT=/path/to/hwloc - TCMALLOC_ROOT=/path/to/tcmalloc + Boost_ROOT=/path/to/boost + Hwloc_ROOT=/path/to/hwloc + Tcmalloc_ROOT=/path/to/tcmalloc HPX_ROOT=/path/to/hpx - INCLUDE_DIRECTIVES=$(HPX_ROOT)/include $(BOOST_ROOT)/include $(HWLOC_ROOT)/include + INCLUDE_DIRECTIVES=$(HPX_ROOT)/include $(Boost_ROOT)/include $(Hwloc_ROOT)/include - LIBRARY_DIRECTIVES=-L$(HPX_ROOT)/lib $(HPX_ROOT)/lib/libhpx_init.a $(HPX_ROOT)/lib/libhpx.so $(BOOST_ROOT)/lib/libboost_atomic-mt.so $(BOOST_ROOT)/lib/libboost_filesystem-mt.so $(BOOST_ROOT)/lib/libboost_program_options-mt.so $(BOOST_ROOT)/lib/libboost_regex-mt.so $(BOOST_ROOT)/lib/libboost_system-mt.so -lpthread $(TCMALLOC_ROOT)/libtcmalloc_minimal.so $(HWLOC_ROOT)/libhwloc.so -ldl -lrt + LIBRARY_DIRECTIVES=-L$(HPX_ROOT)/lib $(HPX_ROOT)/lib/libhpx_init.a $(HPX_ROOT)/lib/libhpx.so $(Boost_ROOT)/lib/libboost_atomic-mt.so $(Boost_ROOT)/lib/libboost_filesystem-mt.so $(Boost_ROOT)/lib/libboost_program_options-mt.so $(Boost_ROOT)/lib/libboost_regex-mt.so $(Boost_ROOT)/lib/libboost_system-mt.so -lpthread $(Tcmalloc_ROOT)/libtcmalloc_minimal.so $(Hwloc_ROOT)/libhwloc.so -ldl -lrt LINK_FLAGS=$(HPX_ROOT)/lib/libhpx_wrap.a -Wl,-wrap=main # should be left empty for HPX_WITH_HPX_MAIN=OFF diff --git a/docs/sphinx/manual/optimizing_hpx_applications.rst b/docs/sphinx/manual/optimizing_hpx_applications.rst index f3ec0d4c2a27..90d956441728 100644 --- a/docs/sphinx/manual/optimizing_hpx_applications.rst +++ b/docs/sphinx/manual/optimizing_hpx_applications.rst @@ -3407,7 +3407,7 @@ It can be added as a ``git`` submodule by turning on the option :option:`HPX_WIT during |cmake| configuration. |tau|_ is an optional dependency when using |apex|. To build |hpx| with |apex|, add :option:`HPX_WITH_APEX`\ ``=ON``, and, -optionally, ``TAU_ROOT=$PATH_TO_TAU`` to your |cmake| configuration. In +optionally, ``Tau_ROOT=$PATH_TO_TAU`` to your |cmake| configuration. In addition, you can override the tag used for |apex| with the :option:`HPX_WITH_APEX_TAG` option. Please see the |apex_hpx_doc|_ for detailed instructions on using |apex| with |hpx|. diff --git a/docs/sphinx/manual/troubleshooting.rst b/docs/sphinx/manual/troubleshooting.rst index 8a693d30c6af..800e35f9e67b 100644 --- a/docs/sphinx/manual/troubleshooting.rst +++ b/docs/sphinx/manual/troubleshooting.rst @@ -74,7 +74,7 @@ You may see an error message that looks a bit like this: .. code-block:: text - Could NOT find TCMalloc (missing: TCMALLOC_LIBRARY TCMALLOC_INCLUDE_DIR) + Could NOT find TCMalloc (missing: Tcmalloc_LIBRARY Tcmalloc_INCLUDE_DIR) ERROR: HPX_WITH_MALLOC was set to tcmalloc, but tcmalloc could not be found. Valid options for HPX_WITH_MALLOC are: system, tcmalloc, jemalloc, mimalloc, tbbmalloc, and custom @@ -117,7 +117,7 @@ following flag on your |hpx| application CMake configuration: |hpx|-application build type conformance ---------------------------------------- -Your application’s build type should align with the HPX build type. For example, if you specified +Your application's build type should align with the HPX build type. For example, if you specified ``-DCMAKE_BUILD_TYPE=Debug`` during the |hpx| compilation, then your application needs to be compiled with the same flag. We recommend keeping a separate build folder for different build types and just point accordingly to the type you want by using ``-DHPX_DIR=/lib/cmake/HPX``. diff --git a/docs/sphinx/releases/whats_new_1_10_0.rst b/docs/sphinx/releases/whats_new_1_10_0.rst index 747a33e79230..c8e5d6dad820 100644 --- a/docs/sphinx/releases/whats_new_1_10_0.rst +++ b/docs/sphinx/releases/whats_new_1_10_0.rst @@ -17,6 +17,10 @@ General changes Breaking changes ================ +- The CMake configuration keys ``SOMELIB_ROOT`` (e.g., ``BOOST_ROOT``) has been + renamed to ``Somelib_ROOT`` (e.g., ``Boost_ROOT``) to avoid warnings when using + newer versions of CMake. Please update your scripts accordingly. + Closed issues ============= diff --git a/examples/1d_stencil/README.APEX b/examples/1d_stencil/README.APEX index 52eb26a83fa5..a17aa4badf8f 100644 --- a/examples/1d_stencil/README.APEX +++ b/examples/1d_stencil/README.APEX @@ -7,7 +7,7 @@ configure HPX with APEX: cmake ... \ -DHPX_WITH_APEX=TRUE \ -DAPEX_WITH_ACTIVEHARMONY=TRUE \ --DACTIVEHARMONY_ROOT= \ +-DActiveharmony_ROOT= \ ... Then to execute the example: diff --git a/libs/CMakeLists.txt b/libs/CMakeLists.txt index 974c7592f239..229b1b51d47d 100644 --- a/libs/CMakeLists.txt +++ b/libs/CMakeLists.txt @@ -32,7 +32,7 @@ endif() set(hpx_external_SOURCES) if("${HPX_PLATFORM_UC}" STREQUAL "ANDROID") list(APPEND hpx_external_SOURCES ${hpx_external_objects_SOURCES} - "${ANDROID_NDK_ROOT}/sources/android/cpufeatures/cpu-features.c" + "${Android_NDK_ROOT}/sources/android/cpufeatures/cpu-features.c" ) endif() diff --git a/libs/core/command_line_handling_local/cmake/HPX_SetupJSON.cmake b/libs/core/command_line_handling_local/cmake/HPX_SetupJSON.cmake index f0e5bca5653c..119cb8eb07e3 100644 --- a/libs/core/command_line_handling_local/cmake/HPX_SetupJSON.cmake +++ b/libs/core/command_line_handling_local/cmake/HPX_SetupJSON.cmake @@ -4,6 +4,15 @@ # 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) +# compatibility with older CMake versions +if(JSON_ROOT AND NOT Json_ROOT) + set(Json_ROOT + ${JSON_ROOT} + CACHE PATH "Json base directory" + ) + unset(JSON_ROOT CACHE) +endif() + if(NOT HPX_WITH_FETCH_JSON) find_package(nlohmann_json 3.2.0 REQUIRED) elseif(NOT TARGET JSON::json) @@ -17,7 +26,7 @@ elseif(NOT TARGET JSON::json) ) else() hpx_info( - "HPX_WITH_FETCH_JSON=${HPX_WITH_FETCH_JSON}, JSON will be fetched using CMake's FetchContent and installed alongside HPX (HPX_WITH_JSON_TAG=${HPX_WITH_JSON_TAG})" + "HPX_WITH_FETCH_JSON=${HPX_WITH_FETCH_JSON}, JSON will be fetched using CMake's FetchContent and installed alongside HPX (HPX_WITH_Json_TAG=${HPX_WITH_Json_TAG})" ) endif() @@ -29,14 +38,14 @@ elseif(NOT TARGET JSON::json) ) fetchcontent_makeavailable(nlohmann_json) - set(JSON_ROOT ${nlohmann_json_SOURCE_DIR}) + set(Json_ROOT ${nlohmann_json_SOURCE_DIR}) add_library(json INTERFACE) target_include_directories( - json SYSTEM INTERFACE $ + json SYSTEM INTERFACE $ $ ) - target_compile_definitions(json INTERFACE JSON_HAS_CPP_17) + target_compile_definitions(json INTERFACE Json_HAS_CPP_17) install( TARGETS json @@ -45,7 +54,7 @@ elseif(NOT TARGET JSON::json) ) install( - DIRECTORY ${JSON_ROOT}/include/ + DIRECTORY ${Json_ROOT}/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT core FILES_MATCHING diff --git a/libs/full/parcelport_libfabric/cmake/FindPMI.cmake b/libs/full/parcelport_libfabric/cmake/FindPMI.cmake index 20426147c638..ef7073ab1262 100644 --- a/libs/full/parcelport_libfabric/cmake/FindPMI.cmake +++ b/libs/full/parcelport_libfabric/cmake/FindPMI.cmake @@ -4,62 +4,70 @@ # 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) +# compatibility with older CMake versions +if(PMI_ROOT AND NOT Pmi_ROOT) + set(Pmi_ROOT + ${PMI_ROOT} + CACHE PATH "PMI base directory" + ) + unset(PMI_ROOT CACHE) +endif() + find_package(PkgConfig QUIET) + # look for cray pmi... -pkg_check_modules(PC_PMI_CRAY QUIET cray-pmi) +pkg_check_modules(PC_Pmi_CRAY QUIET cray-pmi) + # look for the rest if we couldn't find the cray package -if(NOT PC_PMI_CRAY_FOUND) - pkg_check_modules(PC_PMI QUIET pmi) +if(NOT PC_Pmi_CRAY_FOUND) + pkg_check_modules(PC_Pmi QUIET pmi) endif() find_path( - PMI_INCLUDE_DIR pmi2.h - HINTS ${PMI_ROOT} + Pmi_INCLUDE_DIR pmi2.h + HINTS ${Pmi_ROOT} ENV PMI_ROOT - ${PMI_DIR} + ${Pmi_DIR} ENV PMI_DIR - ${PC_PMI_CRAY_INCLUDEDIR} - ${PC_PMI_CRAY_INCLUDE_DIRS} - ${PC_PMI_INCLUDEDIR} - ${PC_PMI_INCLUDE_DIRS} + ${PC_Pmi_CRAY_INCLUDEDIR} + ${PC_Pmi_CRAY_INCLUDE_DIRS} + ${PC_Pmi_INCLUDEDIR} + ${PC_Pmi_INCLUDE_DIRS} PATH_SUFFIXES include ) find_library( - PMI_LIBRARY + Pmi_LIBRARY NAMES pmi - HINTS ${PMI_ROOT} + HINTS ${Pmi_ROOT} ENV PMI_ROOT - ${PC_PMI_CRAY_LIBDIR} - ${PC_PMI_CRAY_LIBRARY_DIRS} - ${PC_PMI_LIBDIR} - ${PC_PMI_LIBRARY_DIRS} + ${PC_Pmi_CRAY_LIBDIR} + ${PC_Pmi_CRAY_LIBRARY_DIRS} + ${PC_Pmi_LIBDIR} + ${PC_Pmi_LIBRARY_DIRS} PATH_SUFFIXES lib lib64 ) -# Set PMI_ROOT in case the other hints are used -if(PMI_ROOT) +# Set Pmi_ROOT in case the other hints are used +if(Pmi_ROOT) # The call to file is for compatibility with windows paths - file(TO_CMAKE_PATH ${PMI_ROOT} PMI_ROOT) + file(TO_CMAKE_PATH ${Pmi_ROOT} Pmi_ROOT) elseif("$ENV{PMI_ROOT}") - file(TO_CMAKE_PATH $ENV{PMI_ROOT} PMI_ROOT) + file(TO_CMAKE_PATH $ENV{PMI_ROOT} Pmi_ROOT) else() - file(TO_CMAKE_PATH "${PMI_INCLUDE_DIR}" PMI_INCLUDE_DIR) - string(REPLACE "/include" "" PMI_ROOT "${PMI_INCLUDE_DIR}") + file(TO_CMAKE_PATH "${Pmi_INCLUDE_DIR}" Pmi_INCLUDE_DIR) + string(REPLACE "/include" "" Pmi_ROOT "${Pmi_INCLUDE_DIR}") endif() -if(NOT PMI_LIBRARY OR NOT PMI_INCLUDE_DIR) - set(PMI_FOUND=OFF) +if(NOT Pmi_LIBRARY OR NOT Pmi_INCLUDE_DIR) + set(Pmi_FOUND=OFF) return() endif() -# hpx_error( "PMI_LIBRARY OR PMI_INCLUDE_DIR not found, please install PMI or -# set \ the right PMI_ROOT path" ) - include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(PMI DEFAULT_MSG PMI_LIBRARY PMI_INCLUDE_DIR) +find_package_handle_standard_args(PMI DEFAULT_MSG Pmi_LIBRARY Pmi_INCLUDE_DIR) -mark_as_advanced(PMI_ROOT PMI_LIBRARY PMI_INCLUDE_DIR) +mark_as_advanced(Pmi_ROOT Pmi_LIBRARY Pmi_INCLUDE_DIR) diff --git a/tests/performance/local/CMakeLists.txt b/tests/performance/local/CMakeLists.txt index 9566be850d4f..4d537abdf382 100644 --- a/tests/performance/local/CMakeLists.txt +++ b/tests/performance/local/CMakeLists.txt @@ -65,17 +65,17 @@ if(HPX_WITH_EXAMPLES_QTHREADS) ) set(qthreads_homogeneous_timed_task_spawn_FLAGS - NOLIBS DEPENDENCIES ${boost_library_dependencies} ${QTHREADS_LIBRARIES} + NOLIBS DEPENDENCIES ${boost_library_dependencies} ${Qthreads_LIBRARIES} hpx_core ) set(qthreads_heterogeneous_timed_task_spawn_FLAGS - NOLIBS DEPENDENCIES ${boost_library_dependencies} ${QTHREADS_LIBRARIES} + NOLIBS DEPENDENCIES ${boost_library_dependencies} ${Qthreads_LIBRARIES} hpx_core ) set(qthreads_heterogeneous_timed_task_spawn_INCLUDE_DIRECTORIES - ${QTHREADS_INCLUDE_DIR} + ${Qthreads_INCLUDE_DIR} ) endif() @@ -83,11 +83,11 @@ if(HPX_WITH_EXAMPLES_TBB) list(APPEND benchmarks tbb_homogeneous_timed_task_spawn) set(tbb_homogeneous_timed_task_spawn_FLAGS - NOLIBS DEPENDENCIES ${boost_library_dependencies} ${TBB_LIBRARIES} + NOLIBS DEPENDENCIES ${boost_library_dependencies} ${Tbb_LIBRARIES} hpx_core ) - set(tbb_homogeneous_timed_task_spawn_INCLUDE_DIRECTORIES ${TBB_INCLUDE_DIR}) + set(tbb_homogeneous_timed_task_spawn_INCLUDE_DIRECTORIES ${Tbb_INCLUDE_DIR}) endif() if(HPX_WITH_DISTRIBUTED_RUNTIME) diff --git a/tests/performance/local/htts_v2/CMakeLists.txt b/tests/performance/local/htts_v2/CMakeLists.txt index 05647b2fd811..86bf74b2a5ba 100644 --- a/tests/performance/local/htts_v2/CMakeLists.txt +++ b/tests/performance/local/htts_v2/CMakeLists.txt @@ -12,14 +12,14 @@ endif() if(HPX_WITH_EXAMPLES_QTHREADS) set(benchmarks ${benchmarks} htts2_qthreads) - set(htts2_qthreads_LIBRARIES ${QTHREADS_LIBRARY}) - set(htts2_qthreads_INCLUDE_DIRECTORIES ${QTHREADS_INCLUDE_DIR}) + set(htts2_qthreads_LIBRARIES ${Qthreads_LIBRARY}) + set(htts2_qthreads_INCLUDE_DIRECTORIES ${Qthreads_INCLUDE_DIR}) endif() if(HPX_WITH_EXAMPLES_TBB) set(benchmarks ${benchmarks} htts2_tbb) - set(htts2_tbb_LIBRARIES ${TBB_LIBRARY}) - set(htts2_tbb_INCLUDE_DIRECTORIES ${TBB_INCLUDE_DIR}) + set(htts2_tbb_LIBRARIES ${Tbb_LIBRARY}) + set(htts2_tbb_INCLUDE_DIRECTORIES ${Tbb_INCLUDE_DIR}) endif() foreach(benchmark ${benchmarks}) diff --git a/tools/build_boost.sh b/tools/build_boost.sh index 9573ebe0b58b..e821eaf24c5b 100755 --- a/tools/build_boost.sh +++ b/tools/build_boost.sh @@ -198,10 +198,10 @@ echo echo "Successfully built Boost ${DOT_VERSION}" echo echo "Debug root:" -echo " BOOST_ROOT=$DIRECTORY/debug" +echo " Boost_ROOT=$DIRECTORY/debug" echo echo "Release root:" -echo " BOOST_ROOT=$DIRECTORY/release" +echo " Boost_ROOT=$DIRECTORY/release" From c94605093f28e6c22b3477fdb672c135255d958c Mon Sep 17 00:00:00 2001 From: Hartmut Kaiser Date: Sat, 19 Aug 2023 10:14:33 -0500 Subject: [PATCH 10/25] Fixing HIP builder --- .../include/hpx/parallel/util/loop.hpp | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/libs/core/algorithms/include/hpx/parallel/util/loop.hpp b/libs/core/algorithms/include/hpx/parallel/util/loop.hpp index dfa67230e5d6..b3207bc980e7 100644 --- a/libs/core/algorithms/include/hpx/parallel/util/loop.hpp +++ b/libs/core/algorithms/include/hpx/parallel/util/loop.hpp @@ -130,7 +130,7 @@ namespace hpx::parallel::util { inline constexpr loop_t loop = loop_t{}; #else template - HPX_HOST_DEVICE HPX_FORCEINLINE constexpr Begin loop( + HPX_HOST_DEVICE HPX_FORCEINLINE constexpr decltype(auto) loop( ExPolicy&& policy, Begin begin, End end, F&& f) { return hpx::parallel::util::loop_t{}( @@ -139,7 +139,7 @@ namespace hpx::parallel::util { template - HPX_HOST_DEVICE HPX_FORCEINLINE constexpr Begin loop( + HPX_HOST_DEVICE HPX_FORCEINLINE constexpr decltype(auto) loop( ExPolicy&& policy, Begin begin, End end, CancelToken& tok, F&& f) { return hpx::parallel::util::loop_t{}( @@ -190,7 +190,7 @@ namespace hpx::parallel::util { inline constexpr loop_pred_t loop_pred = loop_pred_t{}; #else template - HPX_HOST_DEVICE HPX_FORCEINLINE constexpr Begin loop_pred( + HPX_HOST_DEVICE HPX_FORCEINLINE constexpr decltype(auto) loop_pred( Begin begin, End end, Pred&& pred) { return hpx::parallel::util::loop_pred_t{}( @@ -262,7 +262,7 @@ namespace hpx::parallel::util { inline constexpr loop_ind_t loop_ind = loop_ind_t{}; #else template - HPX_HOST_DEVICE HPX_FORCEINLINE constexpr Begin loop_ind( + HPX_HOST_DEVICE HPX_FORCEINLINE constexpr decltype(auto) loop_ind( Begin begin, End end, F&& f) { return hpx::parallel::util::loop_ind_t{}( @@ -326,7 +326,7 @@ namespace hpx::parallel::util { #else template - HPX_HOST_DEVICE HPX_FORCEINLINE constexpr std::pair loop2( + HPX_HOST_DEVICE HPX_FORCEINLINE constexpr decltype(auto) loop2( Begin1 begin1, End1 end1, Begin2 begin2, F&& f) { return hpx::parallel::util::loop2_t{}( @@ -454,7 +454,7 @@ namespace hpx::parallel::util { inline constexpr loop_n_t loop_n = loop_n_t{}; #else template - HPX_HOST_DEVICE HPX_FORCEINLINE constexpr Iter loop_n( + HPX_HOST_DEVICE HPX_FORCEINLINE constexpr decltype(auto) loop_n( Iter it, std::size_t count, F&& f) { return hpx::parallel::util::loop_n_t{}( @@ -463,7 +463,7 @@ namespace hpx::parallel::util { template - HPX_HOST_DEVICE HPX_FORCEINLINE constexpr Iter loop_n( + HPX_HOST_DEVICE HPX_FORCEINLINE constexpr decltype(auto) loop_n( Iter it, std::size_t count, CancelToken& tok, F&& f) { return hpx::parallel::util::loop_n_t{}( @@ -593,7 +593,7 @@ namespace hpx::parallel::util { loop_n_ind_t{}; #else template - HPX_HOST_DEVICE HPX_FORCEINLINE constexpr Iter loop_n_ind( + HPX_HOST_DEVICE HPX_FORCEINLINE constexpr decltype(auto) loop_n_ind( Iter it, std::size_t count, F&& f) { return hpx::parallel::util::loop_n_ind_t{}( @@ -602,7 +602,7 @@ namespace hpx::parallel::util { template - HPX_HOST_DEVICE HPX_FORCEINLINE constexpr Iter loop_n_ind( + HPX_HOST_DEVICE HPX_FORCEINLINE constexpr decltype(auto) loop_n_ind( Iter it, std::size_t count, CancelToken& tok, F&& f) { return hpx::parallel::util::loop_n_ind_t{}( @@ -745,7 +745,7 @@ namespace hpx::parallel::util { #else template - HPX_HOST_DEVICE HPX_FORCEINLINE constexpr Begin loop_with_cleanup( + HPX_HOST_DEVICE HPX_FORCEINLINE constexpr decltype(auto) loop_with_cleanup( ExPolicy&& policy, Begin begin, Sent end, F&& f, Cleanup&& cleanup) { return hpx::parallel::util::detail::loop_with_cleanup{}( @@ -755,7 +755,7 @@ namespace hpx::parallel::util { template - HPX_HOST_DEVICE HPX_FORCEINLINE constexpr Begin loop_with_cleanup( + HPX_HOST_DEVICE HPX_FORCEINLINE constexpr decltype(auto) loop_with_cleanup( ExPolicy&& policy, Begin begin, Sent end, Begin2 dest, F&& f, Cleanup&& cleanup) { @@ -1010,7 +1010,8 @@ namespace hpx::parallel::util { detail::loop_with_cleanup_n{}; #else template - HPX_HOST_DEVICE HPX_FORCEINLINE constexpr Begin loop_with_cleanup_n( + HPX_HOST_DEVICE HPX_FORCEINLINE constexpr decltype(auto) + loop_with_cleanup_n( ExPolicy&& policy, Begin begin, std::size_t n, F&& f, Cleanup&& cleanup) { return hpx::parallel::util::detail::loop_with_cleanup_n{}( @@ -1020,9 +1021,9 @@ namespace hpx::parallel::util { template - HPX_HOST_DEVICE HPX_FORCEINLINE constexpr Begin loop_with_cleanup_n( - ExPolicy&& policy, Begin begin, std::size_t n, Begin2 dest, F&& f, - Cleanup&& cleanup) + HPX_HOST_DEVICE HPX_FORCEINLINE constexpr decltype(auto) + loop_with_cleanup_n(ExPolicy&& policy, Begin begin, std::size_t n, + Begin2 dest, F&& f, Cleanup&& cleanup) { return hpx::parallel::util::detail::loop_with_cleanup_n{}( HPX_FORWARD(ExPolicy, policy), begin, n, dest, HPX_FORWARD(F, f), @@ -1254,7 +1255,7 @@ namespace hpx::parallel::util { loop_idx_n_t{}; #else template - HPX_HOST_DEVICE HPX_FORCEINLINE constexpr Iter loop_idx_n( + HPX_HOST_DEVICE HPX_FORCEINLINE constexpr decltype(auto) loop_idx_n( std::size_t base_idx, Iter it, std::size_t count, F&& f) { return hpx::parallel::util::loop_idx_n_t{}( @@ -1263,7 +1264,7 @@ namespace hpx::parallel::util { template - HPX_HOST_DEVICE HPX_FORCEINLINE constexpr Iter loop_idx_n( + HPX_HOST_DEVICE HPX_FORCEINLINE constexpr decltype(auto) loop_idx_n( std::size_t base_idx, Iter it, std::size_t count, CancelToken& tok, F&& f) { From 1e319be223d70f9f120eb55eead122167a1affe5 Mon Sep 17 00:00:00 2001 From: Hartmut Kaiser Date: Sat, 19 Aug 2023 10:16:43 -0500 Subject: [PATCH 11/25] Remove obsolete and broken Daint builders --- .jenkins/cscs/Jenkinsfile | 2 +- .jenkins/cscs/env-clang-12.sh | 41 ----------------- .jenkins/cscs/env-clang-cuda.sh | 46 ------------------- .jenkins/cscs/env-gcc-10.sh | 34 -------------- .jenkins/cscs/env-gcc-cuda.sh | 28 ----------- .jenkins/cscs/slurm-constraint-clang-12.sh | 7 --- .jenkins/cscs/slurm-constraint-clang-9.sh | 7 --- .jenkins/cscs/slurm-constraint-clang-cuda.sh | 7 --- .jenkins/cscs/slurm-constraint-gcc-10.sh | 7 --- .jenkins/cscs/slurm-constraint-gcc-8.sh | 7 --- .jenkins/cscs/slurm-constraint-gcc-cuda.sh | 7 --- .jenkins/cscs/slurm-constraint-icc.sh | 7 --- .../tests/regressions/barrier_3792.cpp | 15 +++--- 13 files changed, 10 insertions(+), 205 deletions(-) delete mode 100644 .jenkins/cscs/env-clang-12.sh delete mode 100644 .jenkins/cscs/env-clang-cuda.sh delete mode 100644 .jenkins/cscs/env-gcc-10.sh delete mode 100644 .jenkins/cscs/env-gcc-cuda.sh delete mode 100644 .jenkins/cscs/slurm-constraint-clang-12.sh delete mode 100644 .jenkins/cscs/slurm-constraint-clang-9.sh delete mode 100644 .jenkins/cscs/slurm-constraint-clang-cuda.sh delete mode 100644 .jenkins/cscs/slurm-constraint-gcc-10.sh delete mode 100644 .jenkins/cscs/slurm-constraint-gcc-8.sh delete mode 100644 .jenkins/cscs/slurm-constraint-gcc-cuda.sh delete mode 100644 .jenkins/cscs/slurm-constraint-icc.sh diff --git a/.jenkins/cscs/Jenkinsfile b/.jenkins/cscs/Jenkinsfile index 817f2610cfb1..32c63feb7a8c 100644 --- a/.jenkins/cscs/Jenkinsfile +++ b/.jenkins/cscs/Jenkinsfile @@ -42,7 +42,7 @@ pipeline { // number of node-hours consumed axis { name 'configuration_name' - values 'gcc-11', 'gcc-cuda', 'clang-10', 'clang-13', 'clang-cuda', 'clang-apex' + values 'gcc-11', 'clang-10', 'clang-13', 'clang-apex' } axis { name 'build_type' diff --git a/.jenkins/cscs/env-clang-12.sh b/.jenkins/cscs/env-clang-12.sh deleted file mode 100644 index 402bfed89ab0..000000000000 --- a/.jenkins/cscs/env-clang-12.sh +++ /dev/null @@ -1,41 +0,0 @@ -# Copyright (c) 2020 ETH Zurich -# -# SPDX-License-Identifier: BSL-1.0 -# 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) - -export CRAYPE_LINK_TYPE=dynamic -export APPS_ROOT="/apps/daint/SSL/HPX/packages" -export CLANG_VER="12.0.0" -export CXX_STD="20" -export BOOST_VER="1.77.0" -export HWLOC_VER="2.2.0" -export CLANG_ROOT="${APPS_ROOT}/llvm-${CLANG_VER}" -export BOOST_ROOT="${APPS_ROOT}/boost-${BOOST_VER}-clang-${CLANG_VER}-c++20-release" -export HWLOC_ROOT="${APPS_ROOT}/hwloc-${HWLOC_VER}-gcc-10.2.0" -export CXXFLAGS="-Wno-unused-command-line-argument -stdlib=libc++ -nostdinc++ -isystem${CLANG_ROOT}/include/c++/v1 -L${CLANG_ROOT}/lib -Wl,-rpath,${CLANG_ROOT}/lib,-lsupc++" -export LDCXXFLAGS="-stdlib=libc++ -L${CLANG_ROOT}/lib -Wl,-rpath,${CLANG_ROOT}/lib,-lsupc++" -export CXX="${CLANG_ROOT}/bin/clang++" -export CC="${CLANG_ROOT}/bin/clang" -export CPP="${CLANG_ROOT}/bin/clang -E" - -module load daint-mc -spack load cmake@3.18.6 -spack load ninja@1.10.0 - -configure_extra_options+=" -DHPX_WITH_MALLOC=system" -configure_extra_options+=" -DHPX_WITH_FETCH_ASIO=ON" -configure_extra_options+=" -DHPX_WITH_CXX_STANDARD=${CXX_STD}" -configure_extra_options+=" -DHPX_WITH_COMPILER_WARNINGS=ON" -configure_extra_options+=" -DHPX_WITH_COMPILER_WARNINGS_AS_ERRORS=ON" -configure_extra_options+=" -DHPX_WITH_DYNAMIC_HPX_MAIN=OFF" -configure_extra_options+=" -DHPX_WITH_SPINLOCK_DEADLOCK_DETECTION=ON" -configure_extra_options+=" -DHPX_WITH_UNITY_BUILD=ON" - -# enable extra counters to verify everything compiles -configure_extra_options+=" -DHPX_WITH_PARCELPORT_ACTION_COUNTERS=ON" -configure_extra_options+=" -DHPX_WITH_THREAD_IDLE_RATES=ON" -configure_extra_options+=" -DHPX_WITH_THREAD_CREATION_AND_CLEANUP_RATES=ON" -configure_extra_options+=" -DHPX_WITH_THREAD_CUMULATIVE_COUNTS=ON" -configure_extra_options+=" -DHPX_WITH_THREAD_QUEUE_WAITTIME=ON" -configure_extra_options+=" -DHPX_WITH_THREAD_STEALING_COUNTS=ON" diff --git a/.jenkins/cscs/env-clang-cuda.sh b/.jenkins/cscs/env-clang-cuda.sh deleted file mode 100644 index ce5150aa40d6..000000000000 --- a/.jenkins/cscs/env-clang-cuda.sh +++ /dev/null @@ -1,46 +0,0 @@ -# Copyright (c) 2020 ETH Zurich -# -# SPDX-License-Identifier: BSL-1.0 -# 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) - -export CRAYPE_LINK_TYPE=dynamic -export APPS_ROOT="/apps/daint/SSL/HPX/packages" -export CXX_STD="17" -export HWLOC_ROOT="${APPS_ROOT}/hwloc-2.0.3-gcc-8.3.0" -export BOOST_ROOT="${APPS_ROOT}/boost-1.75.0-gcc-10.1.0-c++17-debug/" - -module load daint-gpu -module load cudatoolkit/11.0.2_3.38-8.1__g5b73779 -spack load cmake@3.18.6 -spack load ninja@1.10.0 - -export CXX=`which CC` -export CC=`which cc` - -configure_extra_options+=" -DHPX_WITH_MAX_CPU_COUNT=64" -configure_extra_options+=" -DHPX_WITH_CUDA=ON" -configure_extra_options+=" -DHPX_WITH_MALLOC=system" -configure_extra_options+=" -DHPX_WITH_FETCH_ASIO=ON" -configure_extra_options+=" -DHPX_WITH_CXX_STANDARD=${CXX_STD}" -configure_extra_options+=" -DHPX_WITH_COMPILER_WARNINGS=ON" -configure_extra_options+=" -DHPX_WITH_COMPILER_WARNINGS_AS_ERRORS=ON" -configure_extra_options+=" -DHPX_WITH_SPINLOCK_DEADLOCK_DETECTION=ON" -configure_extra_options+=" -DCMAKE_CUDA_COMPILER=$(which $CXX)" -configure_extra_options+=" -DCMAKE_CUDA_ARCHITECTURES=60" - -# The build unit test with HPX in Debug and the hello_world project in Debug -# mode hangs on this configuration Release-Debug, Debug-Release, and -# Release-Release do not hang. -configure_extra_options+=" -DHPX_WITH_TESTS_EXTERNAL_BUILD=OFF" - -# This is a workaround for a bug in the Cray clang compiler and/or Boost. When -# compiling in device mode, Boost detects that float128 is available, but -# compilation later fails with an error message saying float128 is not -# available for the target. -# -# This sets a custom Boost user configuration, which is a concatenation of the -# clang and nvcc compiler configurations, with the exception that -# BOOST_HAS_FLOAT128 is unconditionally disabled. -configure_extra_options+=" \"-DCMAKE_CXX_FLAGS=-I${src_dir}/.jenkins/cscs/ -DBOOST_USER_CONFIG=''\"" -configure_extra_options+=" \"-DCMAKE_CUDA_FLAGS=--cuda-gpu-arch=sm_60 -I${src_dir}/.jenkins/cscs/ -DBOOST_USER_CONFIG=''\"" diff --git a/.jenkins/cscs/env-gcc-10.sh b/.jenkins/cscs/env-gcc-10.sh deleted file mode 100644 index c1189ca53667..000000000000 --- a/.jenkins/cscs/env-gcc-10.sh +++ /dev/null @@ -1,34 +0,0 @@ -# Copyright (c) 2020 ETH Zurich -# -# SPDX-License-Identifier: BSL-1.0 -# 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) - -export CRAYPE_LINK_TYPE=dynamic -export APPS_ROOT="/apps/daint/SSL/HPX/packages" -export GCC_VER="10.1.0" -export CXX_STD="17" -export BOOST_VER="1.75.0" -export HWLOC_VER="2.2.0" -export GCC_ROOT="${APPS_ROOT}/gcc-${GCC_VER}" -export BOOST_ROOT="${APPS_ROOT}/boost-${BOOST_VER}-gcc-${GCC_VER}-c++${CXX_STD}-debug" -export HWLOC_ROOT="${APPS_ROOT}/hwloc-${HWLOC_VER}-gcc-${GCC_VER}" -export CXXFLAGS="-nostdinc++ -I${GCC_ROOT}/include/c++/${GCC_VER} -I${GCC_ROOT}/include/c++/${GCC_VER}/x86_64-unknown-linux-gnu -I${GCC_ROOT}/include/c++/${GCC_VER}/x86_64-pc-linux-gnu -L${GCC_ROOT}/lib64 -Wl,-rpath,${GCC_ROOT}/lib64" -export LDFLAGS="-L${GCC_ROOT}/lib64" -export CXX=${GCC_ROOT}/bin/g++ -export CC=${GCC_ROOT}/bin/gcc - -module load daint-mc -spack load cmake@3.18.6 -spack load ninja@1.10.0 - -configure_extra_options+=" -DHPX_WITH_MAX_CPU_COUNT=128" -configure_extra_options+=" -DHPX_WITH_MALLOC=system" -configure_extra_options+=" -DHPX_WITH_FETCH_ASIO=ON" -configure_extra_options+=" -DHPX_WITH_CXX_STANDARD=${CXX_STD}" -configure_extra_options+=" -DHPX_WITH_NETWORKING=OFF" -configure_extra_options+=" -DHPX_WITH_DISTRIBUTED_RUNTIME=OFF" -configure_extra_options+=" -DHPX_WITH_COMPILER_WARNINGS=ON" -configure_extra_options+=" -DHPX_WITH_COMPILER_WARNINGS_AS_ERRORS=ON" -configure_extra_options+=" -DHPX_WITH_SPINLOCK_DEADLOCK_DETECTION=ON" - diff --git a/.jenkins/cscs/env-gcc-cuda.sh b/.jenkins/cscs/env-gcc-cuda.sh deleted file mode 100644 index dd0b0b11f6b0..000000000000 --- a/.jenkins/cscs/env-gcc-cuda.sh +++ /dev/null @@ -1,28 +0,0 @@ -# Copyright (c) 2020 ETH Zurich -# -# SPDX-License-Identifier: BSL-1.0 -# 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) - -export CRAYPE_LINK_TYPE=dynamic -export CXX_STD="17" - -module load daint-gpu -module switch PrgEnv-cray PrgEnv-gnu -module load cudatoolkit -module load Boost/1.78.0-CrayGNU-21.09 -module load hwloc/2.4.1 -spack load cmake@3.18.6 -spack load ninja@1.10.0 - -export CXX=`which CC` -export CC=`which cc` - -configure_extra_options+=" -DHPX_WITH_MALLOC=system" -configure_extra_options+=" -DHPX_WITH_FETCH_ASIO=ON" -configure_extra_options+=" -DHPX_WITH_CXX_STANDARD=${CXX_STD}" -configure_extra_options+=" -DHPX_WITH_CUDA=ON" -configure_extra_options+=" -DHPX_WITH_EXAMPLES_OPENMP=ON" -configure_extra_options+=" -DHPX_WITH_COMPILER_WARNINGS=ON" -configure_extra_options+=" -DHPX_WITH_COMPILER_WARNINGS_AS_ERRORS=ON" -configure_extra_options+=" -DHWLOC_ROOT=${EBROOTHWLOC}" diff --git a/.jenkins/cscs/slurm-constraint-clang-12.sh b/.jenkins/cscs/slurm-constraint-clang-12.sh deleted file mode 100644 index 1f9f300cc8fd..000000000000 --- a/.jenkins/cscs/slurm-constraint-clang-12.sh +++ /dev/null @@ -1,7 +0,0 @@ -# Copyright (c) 2020 ETH Zurich -# -# SPDX-License-Identifier: BSL-1.0 -# 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) - -configuration_slurm_constraint="mc" diff --git a/.jenkins/cscs/slurm-constraint-clang-9.sh b/.jenkins/cscs/slurm-constraint-clang-9.sh deleted file mode 100644 index 1f9f300cc8fd..000000000000 --- a/.jenkins/cscs/slurm-constraint-clang-9.sh +++ /dev/null @@ -1,7 +0,0 @@ -# Copyright (c) 2020 ETH Zurich -# -# SPDX-License-Identifier: BSL-1.0 -# 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) - -configuration_slurm_constraint="mc" diff --git a/.jenkins/cscs/slurm-constraint-clang-cuda.sh b/.jenkins/cscs/slurm-constraint-clang-cuda.sh deleted file mode 100644 index 87293c78712d..000000000000 --- a/.jenkins/cscs/slurm-constraint-clang-cuda.sh +++ /dev/null @@ -1,7 +0,0 @@ -# Copyright (c) 2020 ETH Zurich -# -# SPDX-License-Identifier: BSL-1.0 -# 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) - -configuration_slurm_constraint="gpu" diff --git a/.jenkins/cscs/slurm-constraint-gcc-10.sh b/.jenkins/cscs/slurm-constraint-gcc-10.sh deleted file mode 100644 index 1f9f300cc8fd..000000000000 --- a/.jenkins/cscs/slurm-constraint-gcc-10.sh +++ /dev/null @@ -1,7 +0,0 @@ -# Copyright (c) 2020 ETH Zurich -# -# SPDX-License-Identifier: BSL-1.0 -# 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) - -configuration_slurm_constraint="mc" diff --git a/.jenkins/cscs/slurm-constraint-gcc-8.sh b/.jenkins/cscs/slurm-constraint-gcc-8.sh deleted file mode 100644 index 1f9f300cc8fd..000000000000 --- a/.jenkins/cscs/slurm-constraint-gcc-8.sh +++ /dev/null @@ -1,7 +0,0 @@ -# Copyright (c) 2020 ETH Zurich -# -# SPDX-License-Identifier: BSL-1.0 -# 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) - -configuration_slurm_constraint="mc" diff --git a/.jenkins/cscs/slurm-constraint-gcc-cuda.sh b/.jenkins/cscs/slurm-constraint-gcc-cuda.sh deleted file mode 100644 index 87293c78712d..000000000000 --- a/.jenkins/cscs/slurm-constraint-gcc-cuda.sh +++ /dev/null @@ -1,7 +0,0 @@ -# Copyright (c) 2020 ETH Zurich -# -# SPDX-License-Identifier: BSL-1.0 -# 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) - -configuration_slurm_constraint="gpu" diff --git a/.jenkins/cscs/slurm-constraint-icc.sh b/.jenkins/cscs/slurm-constraint-icc.sh deleted file mode 100644 index 1f9f300cc8fd..000000000000 --- a/.jenkins/cscs/slurm-constraint-icc.sh +++ /dev/null @@ -1,7 +0,0 @@ -# Copyright (c) 2020 ETH Zurich -# -# SPDX-License-Identifier: BSL-1.0 -# 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) - -configuration_slurm_constraint="mc" diff --git a/libs/full/collectives/tests/regressions/barrier_3792.cpp b/libs/full/collectives/tests/regressions/barrier_3792.cpp index a24dd0509e3d..519a3d081f99 100644 --- a/libs/full/collectives/tests/regressions/barrier_3792.cpp +++ b/libs/full/collectives/tests/regressions/barrier_3792.cpp @@ -20,7 +20,7 @@ #include /////////////////////////////////////////////////////////////////////////////// -void run_barrier_test1(std::vector locs) +void run_barrier_test1(std::vector const& locs) { auto loc_it = std::find(locs.begin(), locs.end(), hpx::get_locality_id()); if (loc_it == locs.end()) @@ -28,20 +28,20 @@ void run_barrier_test1(std::vector locs) std::size_t barrier_rank = std::distance(locs.begin(), loc_it); - std::string barrier_name = - "/loc_list/barrier" + std::to_string(locs[0]) + std::to_string(locs[1]); + std::string barrier_name = "/loc_list/barrier1" + std::to_string(locs[0]) + + std::to_string(locs[1]); hpx::distributed::barrier b(barrier_name, locs.size(), barrier_rank); b.wait(); } -void run_barrier_test2(std::vector locs) +void run_barrier_test2(std::vector const& locs) { auto loc_it = std::find(locs.begin(), locs.end(), hpx::get_locality_id()); if (loc_it == locs.end()) return; - std::string barrier_name = - "/loc_list/barrier" + std::to_string(locs[0]) + std::to_string(locs[1]); + std::string barrier_name = "/loc_list/barrier2" + std::to_string(locs[0]) + + std::to_string(locs[1]); hpx::distributed::barrier b(barrier_name, locs, hpx::get_locality_id()); b.wait(); } @@ -53,12 +53,15 @@ int hpx_main() std::vector locs_0{0, 1}; run_barrier_test1(locs_0); run_barrier_test2(locs_0); + std::vector locs_1{0, 2}; run_barrier_test1(locs_1); run_barrier_test2(locs_1); + std::vector locs_2{1, 2}; run_barrier_test1(locs_2); run_barrier_test2(locs_2); + return hpx::finalize(); } From 6b4ae353a6068e36a7197f67c937d1fa7d911d5a Mon Sep 17 00:00:00 2001 From: Hartmut Kaiser Date: Sun, 20 Aug 2023 09:52:20 -0500 Subject: [PATCH 12/25] Cleanup previous patch adapting to CMake V3.27 --- cmake/templates/HPXConfig.cmake.in | 2 +- docs/sphinx/releases/whats_new_1_10_0.rst | 8 +++++--- .../CMakeLists.txt | 2 +- .../cmake/HPX_SetupJSON.cmake | 20 +++++++++---------- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/cmake/templates/HPXConfig.cmake.in b/cmake/templates/HPXConfig.cmake.in index 257e52a1415f..5c2b68ba7052 100644 --- a/cmake/templates/HPXConfig.cmake.in +++ b/cmake/templates/HPXConfig.cmake.in @@ -32,7 +32,7 @@ endif() # find_package. if(HPX_COMMAND_LINE_HANDLING_WITH_JSON_CONFIGURATION_FILES) if(HPX_WITH_FETCH_JSON) - include("${CMAKE_CURRENT_LIST_DIR}/HPXJSONTarget.cmake") + include("${CMAKE_CURRENT_LIST_DIR}/HPXJsonTarget.cmake") else() set(HPX_JSON_ROOT "@Json_ROOT@") include(HPX_SetupJSON) diff --git a/docs/sphinx/releases/whats_new_1_10_0.rst b/docs/sphinx/releases/whats_new_1_10_0.rst index c8e5d6dad820..38ed581aa559 100644 --- a/docs/sphinx/releases/whats_new_1_10_0.rst +++ b/docs/sphinx/releases/whats_new_1_10_0.rst @@ -1,4 +1,4 @@ -.. +.. Copyright (C) 2007-2023 Hartmut Kaiser SPDX-License-Identifier: BSL-1.0 @@ -17,9 +17,11 @@ General changes Breaking changes ================ -- The CMake configuration keys ``SOMELIB_ROOT`` (e.g., ``BOOST_ROOT``) has been +- The |cmake| configuration keys ``SOMELIB_ROOT`` (e.g., ``BOOST_ROOT``) have been renamed to ``Somelib_ROOT`` (e.g., ``Boost_ROOT``) to avoid warnings when using - newer versions of CMake. Please update your scripts accordingly. + newer versions of |cmake|. Please update your scripts accordingly. For now, the + old variable names are re-assigned to the new names and unset in the |cmake| + cache. Closed issues ============= diff --git a/libs/core/command_line_handling_local/CMakeLists.txt b/libs/core/command_line_handling_local/CMakeLists.txt index b46c96205e01..51d744771110 100644 --- a/libs/core/command_line_handling_local/CMakeLists.txt +++ b/libs/core/command_line_handling_local/CMakeLists.txt @@ -39,7 +39,7 @@ set(command_line_handling_local_sources if(HPX_COMMAND_LINE_HANDLING_WITH_JSON_CONFIGURATION_FILES) include(HPX_SetupJSON) - set(command_line_handling_local_dependencies JSON::json) + set(command_line_handling_local_dependencies Json::json) set(command_line_handling_local_headers ${command_line_handling_local_headers} diff --git a/libs/core/command_line_handling_local/cmake/HPX_SetupJSON.cmake b/libs/core/command_line_handling_local/cmake/HPX_SetupJSON.cmake index 119cb8eb07e3..faf92256426e 100644 --- a/libs/core/command_line_handling_local/cmake/HPX_SetupJSON.cmake +++ b/libs/core/command_line_handling_local/cmake/HPX_SetupJSON.cmake @@ -15,7 +15,7 @@ endif() if(NOT HPX_WITH_FETCH_JSON) find_package(nlohmann_json 3.2.0 REQUIRED) -elseif(NOT TARGET JSON::json) +elseif(NOT TARGET Json::json) if(NOT HPX_WITH_JSON_TAG) set(HPX_WITH_JSON_TAG "v3.11.2") endif() @@ -26,7 +26,7 @@ elseif(NOT TARGET JSON::json) ) else() hpx_info( - "HPX_WITH_FETCH_JSON=${HPX_WITH_FETCH_JSON}, JSON will be fetched using CMake's FetchContent and installed alongside HPX (HPX_WITH_Json_TAG=${HPX_WITH_Json_TAG})" + "HPX_WITH_FETCH_JSON=${HPX_WITH_FETCH_JSON}, JSON will be fetched using CMake's FetchContent and installed alongside HPX (HPX_WITH_JSON_TAG=${HPX_WITH_JSON_TAG})" ) endif() @@ -45,11 +45,11 @@ elseif(NOT TARGET JSON::json) json SYSTEM INTERFACE $ $ ) - target_compile_definitions(json INTERFACE Json_HAS_CPP_17) + target_compile_definitions(json INTERFACE JSON_HAS_CPP_17) install( TARGETS json - EXPORT HPXJSONTarget + EXPORT HPXJsonTarget COMPONENT core ) @@ -63,17 +63,17 @@ elseif(NOT TARGET JSON::json) export( TARGETS json - NAMESPACE JSON:: - FILE "${CMAKE_BINARY_DIR}/lib/cmake/${HPX_PACKAGE_NAME}/HPXJSONTarget.cmake" + NAMESPACE Json:: + FILE "${CMAKE_BINARY_DIR}/lib/cmake/${HPX_PACKAGE_NAME}/HPXJsonTarget.cmake" ) install( - EXPORT HPXJSONTarget - NAMESPACE JSON:: - FILE HPXJSONTarget.cmake + EXPORT HPXJsonTarget + NAMESPACE Json:: + FILE HPXJsonTarget.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${HPX_PACKAGE_NAME} COMPONENT cmake ) - add_library(JSON::json ALIAS json) + add_library(Json::json ALIAS json) endif() From ca5e2d0bb4e0546007dd2d21acbe302fd5d6a2cd Mon Sep 17 00:00:00 2001 From: Hartmut Kaiser Date: Tue, 25 Jul 2023 15:15:44 -0500 Subject: [PATCH 13/25] Making sure changed number of counts is propagated to executor --- .../container_algorithms/is_sorted.hpp | 2 +- .../hpx/parallel/util/detail/chunk_size.hpp | 56 +++- .../hpx/parallel/util/foreach_partitioner.hpp | 10 +- .../include/hpx/parallel/util/partitioner.hpp | 21 +- .../tests/regressions/CMakeLists.txt | 1 + .../tests/regressions/num_cores.cpp | 41 +++ .../tests/unit/algorithms/rotate_sender.cpp | 8 +- .../is_sorted_until_range.cpp | 43 +-- .../executors/execution_parameters_fwd.hpp | 23 +- .../hpx/execution/executors/num_cores.hpp | 9 + .../tests/regressions/is_executor_1691.cpp | 1 + .../unit/executor_parameters_dispatching.cpp | 280 ++++++++---------- .../disable_thread_stealing_executor.cpp | 32 ++ .../examples/executor_with_thread_hooks.cpp | 6 + .../hpx/executors/annotating_executor.hpp | 10 +- .../executors/datapar/execution_policy.hpp | 114 ++++++- .../datapar/execution_policy_fwd.hpp | 8 +- .../hpx/executors/execution_policy.hpp | 241 ++++++++++++++- .../hpx/executors/execution_policy_fwd.hpp | 16 +- .../executors/execution_policy_mappings.hpp | 2 +- .../executors/explicit_scheduler_executor.hpp | 18 +- .../hpx/executors/parallel_executor.hpp | 62 +++- .../restricted_thread_pool_executor.hpp | 15 +- .../hpx/executors/scheduler_executor.hpp | 18 +- .../hpx/executors/sequenced_executor.hpp | 29 +- .../hpx/executors/thread_pool_scheduler.hpp | 53 +++- .../executors/thread_pool_scheduler_bulk.hpp | 8 +- .../tests/regressions/pu_count_6184.cpp | 2 +- .../hpx/resiliency/replay_executor.hpp | 56 +++- .../hpx/resiliency/replicate_executor.hpp | 63 +++- .../functional/detail/tag_fallback_invoke.hpp | 4 +- .../functional/detail/tag_priority_invoke.hpp | 6 +- .../include/hpx/functional/tag_invoke.hpp | 2 +- .../examples/1d_stencil_4_checkpoint.cpp | 88 +++--- 34 files changed, 984 insertions(+), 364 deletions(-) create mode 100644 libs/core/algorithms/tests/regressions/num_cores.cpp diff --git a/libs/core/algorithms/include/hpx/parallel/container_algorithms/is_sorted.hpp b/libs/core/algorithms/include/hpx/parallel/container_algorithms/is_sorted.hpp index beed8d6b620f..f72353ebd092 100644 --- a/libs/core/algorithms/include/hpx/parallel/container_algorithms/is_sorted.hpp +++ b/libs/core/algorithms/include/hpx/parallel/container_algorithms/is_sorted.hpp @@ -508,7 +508,7 @@ namespace hpx { namespace ranges { namespace hpx::ranges { - inline constexpr struct is_sorted_t final + inline constexpr struct is_sorted_t : hpx::detail::tag_parallel_algorithm { private: diff --git a/libs/core/algorithms/include/hpx/parallel/util/detail/chunk_size.hpp b/libs/core/algorithms/include/hpx/parallel/util/detail/chunk_size.hpp index 22836ce2de03..691c399c5744 100644 --- a/libs/core/algorithms/include/hpx/parallel/util/detail/chunk_size.hpp +++ b/libs/core/algorithms/include/hpx/parallel/util/detail/chunk_size.hpp @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -16,6 +17,7 @@ #include #include #include +#include #include #include @@ -132,7 +134,7 @@ namespace hpx::parallel::util::detail { template hpx::util::iterator_range> - get_bulk_iteration_shape(ExPolicy&& policy, IterOrR& it_or_r, + get_bulk_iteration_shape(ExPolicy& policy, IterOrR& it_or_r, std::size_t& count, Stride s = Stride(1)) { if (count == 0) @@ -166,6 +168,10 @@ namespace hpx::parallel::util::detail { // clang-format on } + // update executor with new values + policy = hpx::experimental::prefer( + execution::with_processing_units_count, policy, cores); + auto shape_begin = chunk_size_iterator(it_or_r, chunk_size, count); auto shape_end = chunk_size_iterator(last, chunk_size, count, count); @@ -175,7 +181,7 @@ namespace hpx::parallel::util::detail { template hpx::util::iterator_range> - get_bulk_iteration_shape(ExPolicy&& policy, std::vector& workitems, + get_bulk_iteration_shape(ExPolicy& policy, std::vector& workitems, F1&& f1, IterOrR& it_or_r, std::size_t& count, Stride s = Stride(1)) { if (count == 0) @@ -241,6 +247,10 @@ namespace hpx::parallel::util::detail { // clang-format on } + // update executor with new values + policy = hpx::experimental::prefer( + execution::with_processing_units_count, policy, cores); + auto shape_begin = chunk_size_iterator(it_or_r, chunk_size, count); auto shape_end = chunk_size_iterator(last, chunk_size, count, count); @@ -250,7 +260,7 @@ namespace hpx::parallel::util::detail { template std::vector> - get_bulk_iteration_shape_variable(ExPolicy&& policy, IterOrR& it_or_r, + get_bulk_iteration_shape_variable(ExPolicy& policy, IterOrR& it_or_r, std::size_t& count, Stride s = Stride(1)) { using tuple_type = hpx::tuple; @@ -308,27 +318,31 @@ namespace hpx::parallel::util::detail { } // clang-format on + // update executor with new values + policy = hpx::experimental::prefer( + execution::with_processing_units_count, policy, cores); + return shape; } template - decltype(auto) get_bulk_iteration_shape(std::false_type, ExPolicy&& policy, + decltype(auto) get_bulk_iteration_shape(std::false_type, ExPolicy& policy, std::vector& workitems, F1&& f1, FwdIter& begin, std::size_t& count, Stride s = Stride(1)) { - return get_bulk_iteration_shape(HPX_FORWARD(ExPolicy, policy), - workitems, HPX_FORWARD(F1, f1), begin, count, s); + return get_bulk_iteration_shape( + policy, workitems, HPX_FORWARD(F1, f1), begin, count, s); } template - decltype(auto) get_bulk_iteration_shape(std::true_type, ExPolicy&& policy, + decltype(auto) get_bulk_iteration_shape(std::true_type, ExPolicy& policy, std::vector& workitems, F1&& f1, FwdIter& begin, std::size_t& count, Stride s = Stride(1)) { - return get_bulk_iteration_shape_variable(HPX_FORWARD(ExPolicy, policy), - workitems, HPX_FORWARD(F1, f1), begin, count, s); + return get_bulk_iteration_shape_variable( + policy, workitems, HPX_FORWARD(F1, f1), begin, count, s); } /////////////////////////////////////////////////////////////////////////// @@ -360,7 +374,7 @@ namespace hpx::parallel::util::detail { typename Stride = std::size_t> hpx::util::iterator_range< parallel::util::detail::chunk_size_idx_iterator> - get_bulk_iteration_shape_idx(ExPolicy&& policy, FwdIter begin, + get_bulk_iteration_shape_idx(ExPolicy& policy, FwdIter begin, std::size_t count, Stride s = Stride(1)) { using iterator = @@ -397,6 +411,13 @@ namespace hpx::parallel::util::detail { // clang-format on } + // update executor with new values + policy = hpx::experimental::prefer( + execution::with_processing_units_count, policy, cores); + + using iterator = + parallel::util::detail::chunk_size_idx_iterator; + iterator shape_begin(begin, chunk_size, count, 0, 0); iterator shape_end(last, chunk_size, count, count, 0); @@ -407,7 +428,7 @@ namespace hpx::parallel::util::detail { typename Stride = std::size_t> hpx::util::iterator_range< parallel::util::detail::chunk_size_idx_iterator> - get_bulk_iteration_shape_idx(ExPolicy&& policy, + get_bulk_iteration_shape_idx(ExPolicy& policy, std::vector& workitems, F1&& f1, FwdIter begin, std::size_t count, Stride s = Stride(1)) { @@ -475,6 +496,13 @@ namespace hpx::parallel::util::detail { // clang-format on } + // update executor with new values + policy = hpx::experimental::prefer( + execution::with_processing_units_count, policy, cores); + + using iterator = + parallel::util::detail::chunk_size_idx_iterator; + iterator shape_begin(begin, chunk_size, count, 0, base_idx); iterator shape_end(last, chunk_size, count, count, base_idx); @@ -484,7 +512,7 @@ namespace hpx::parallel::util::detail { template std::vector> - get_bulk_iteration_shape_idx_variable(ExPolicy&& policy, FwdIter first, + get_bulk_iteration_shape_idx_variable(ExPolicy& policy, FwdIter first, std::size_t count, Stride s = Stride(1)) { using tuple_type = hpx::tuple; @@ -543,6 +571,10 @@ namespace hpx::parallel::util::detail { } // clang-format on + // update executor with new values + policy = hpx::experimental::prefer( + execution::with_processing_units_count, policy, cores); + return shape; } } // namespace hpx::parallel::util::detail diff --git a/libs/core/algorithms/include/hpx/parallel/util/foreach_partitioner.hpp b/libs/core/algorithms/include/hpx/parallel/util/foreach_partitioner.hpp index fccac47d871c..a47090890fc9 100644 --- a/libs/core/algorithms/include/hpx/parallel/util/foreach_partitioner.hpp +++ b/libs/core/algorithms/include/hpx/parallel/util/foreach_partitioner.hpp @@ -36,7 +36,7 @@ namespace hpx::parallel::util::detail { template auto foreach_partition( - ExPolicy&& policy, FwdIter first, std::size_t count, F&& f) + ExPolicy policy, FwdIter first, std::size_t count, F&& f) { // estimate a chunk size based on number of cores used using parameters_type = @@ -53,7 +53,7 @@ namespace hpx::parallel::util::detail { "has_variable_chunk_size and invokes_testing_function"); auto&& shape = detail::get_bulk_iteration_shape_idx_variable( - HPX_FORWARD(ExPolicy, policy), first, count); + policy, first, count); return execution::bulk_async_execute(policy.executor(), partitioner_iteration{HPX_FORWARD(F, f)}, @@ -61,8 +61,8 @@ namespace hpx::parallel::util::detail { } else if constexpr (!invokes_testing_function) { - auto&& shape = detail::get_bulk_iteration_shape_idx( - HPX_FORWARD(ExPolicy, policy), first, count); + auto&& shape = + detail::get_bulk_iteration_shape_idx(policy, first, count); return execution::bulk_async_execute(policy.executor(), partitioner_iteration{HPX_FORWARD(F, f)}, @@ -72,7 +72,7 @@ namespace hpx::parallel::util::detail { { std::vector> inititems; auto&& shape = detail::get_bulk_iteration_shape_idx( - HPX_FORWARD(ExPolicy, policy), inititems, f, first, count); + policy, inititems, f, first, count); auto&& workitems = execution::bulk_async_execute(policy.executor(), partitioner_iteration{HPX_FORWARD(F, f)}, diff --git a/libs/core/algorithms/include/hpx/parallel/util/partitioner.hpp b/libs/core/algorithms/include/hpx/parallel/util/partitioner.hpp index 2decc47e4f19..d458e422a6e5 100644 --- a/libs/core/algorithms/include/hpx/parallel/util/partitioner.hpp +++ b/libs/core/algorithms/include/hpx/parallel/util/partitioner.hpp @@ -40,7 +40,7 @@ namespace hpx::parallel::util::detail { template - auto partition(ExPolicy&& policy, IterOrR it_or_r, std::size_t count, F&& f) + auto partition(ExPolicy policy, IterOrR it_or_r, std::size_t count, F&& f) { // estimate a chunk size based on number of cores used using parameters_type = @@ -57,7 +57,7 @@ namespace hpx::parallel::util::detail { "has_variable_chunk_size and invokes_testing_function"); auto&& shape = detail::get_bulk_iteration_shape_variable( - HPX_FORWARD(ExPolicy, policy), it_or_r, count); + policy, it_or_r, count); return execution::bulk_async_execute(policy.executor(), partitioner_iteration{HPX_FORWARD(F, f)}, @@ -65,8 +65,8 @@ namespace hpx::parallel::util::detail { } else if constexpr (!invokes_testing_function) { - auto&& shape = detail::get_bulk_iteration_shape( - HPX_FORWARD(ExPolicy, policy), it_or_r, count); + auto&& shape = + detail::get_bulk_iteration_shape(policy, it_or_r, count); return execution::bulk_async_execute(policy.executor(), partitioner_iteration{HPX_FORWARD(F, f)}, @@ -76,7 +76,7 @@ namespace hpx::parallel::util::detail { { std::vector> inititems; auto&& shape = detail::get_bulk_iteration_shape( - HPX_FORWARD(ExPolicy, policy), inititems, f, it_or_r, count); + policy, inititems, f, it_or_r, count); auto&& workitems = execution::bulk_async_execute(policy.executor(), partitioner_iteration{HPX_FORWARD(F, f)}, @@ -88,8 +88,8 @@ namespace hpx::parallel::util::detail { template - auto partition_with_index(ExPolicy&& policy, FwdIter first, - std::size_t count, Stride stride, F&& f) + auto partition_with_index( + ExPolicy policy, FwdIter first, std::size_t count, Stride stride, F&& f) { // estimate a chunk size based on number of cores used using parameters_type = @@ -106,7 +106,7 @@ namespace hpx::parallel::util::detail { "has_variable_chunk_size and invokes_testing_function"); auto&& shape = detail::get_bulk_iteration_shape_idx_variable( - HPX_FORWARD(ExPolicy, policy), first, count, stride); + policy, first, count, stride); return execution::bulk_async_execute(policy.executor(), partitioner_iteration{HPX_FORWARD(F, f)}, @@ -115,7 +115,7 @@ namespace hpx::parallel::util::detail { else if constexpr (!invokes_testing_function) { auto&& shape = detail::get_bulk_iteration_shape_idx( - HPX_FORWARD(ExPolicy, policy), first, count, stride); + policy, first, count, stride); return execution::bulk_async_execute(policy.executor(), partitioner_iteration{HPX_FORWARD(F, f)}, @@ -125,8 +125,7 @@ namespace hpx::parallel::util::detail { { std::vector> inititems; auto&& shape = detail::get_bulk_iteration_shape_idx( - HPX_FORWARD(ExPolicy, policy), inititems, f, first, count, - stride); + policy, inititems, f, first, count, stride); auto&& workitems = execution::bulk_async_execute(policy.executor(), partitioner_iteration{HPX_FORWARD(F, f)}, diff --git a/libs/core/algorithms/tests/regressions/CMakeLists.txt b/libs/core/algorithms/tests/regressions/CMakeLists.txt index e4a023dad590..9c132a490c22 100644 --- a/libs/core/algorithms/tests/regressions/CMakeLists.txt +++ b/libs/core/algorithms/tests/regressions/CMakeLists.txt @@ -12,6 +12,7 @@ set(tests for_loop_5735 for_loop_with_auto_chunk_size minimal_findend + num_cores reduce_3641 scan_different_inits scan_non_commutative diff --git a/libs/core/algorithms/tests/regressions/num_cores.cpp b/libs/core/algorithms/tests/regressions/num_cores.cpp new file mode 100644 index 000000000000..de0287bd02cb --- /dev/null +++ b/libs/core/algorithms/tests/regressions/num_cores.cpp @@ -0,0 +1,41 @@ +// Copyright (c) 2023 Hartmut Kaiser +// +// SPDX-License-Identifier: BSL-1.0 +// 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 +#include +#include +#include +#include + +#include + +int hpx_main() +{ + hpx::execution::experimental::num_cores nc(2); + auto policy = hpx::execution::par.with(nc); + + HPX_TEST_EQ( + hpx::parallel::execution::processing_units_count(policy.parameters(), + policy.executor(), hpx::chrono::null_duration, 0), + static_cast(2)); + + auto policy2 = + hpx::parallel::execution::with_processing_units_count(policy, 2); + HPX_TEST_EQ(hpx::parallel::execution::processing_units_count( + hpx::execution::par.parameters(), policy2.executor(), + hpx::chrono::null_duration, 0), + static_cast(2)); + + return hpx::local::finalize(); +} + +int main(int argc, char* argv[]) +{ + HPX_TEST_EQ_MSG(hpx::local::init(hpx_main, argc, argv), 0, + "HPX main exited with non-zero status"); + + return hpx::util::report_errors(); +} diff --git a/libs/core/algorithms/tests/unit/algorithms/rotate_sender.cpp b/libs/core/algorithms/tests/unit/algorithms/rotate_sender.cpp index 3c52d08828a2..44dda8249d61 100644 --- a/libs/core/algorithms/tests/unit/algorithms/rotate_sender.cpp +++ b/libs/core/algorithms/tests/unit/algorithms/rotate_sender.cpp @@ -46,7 +46,7 @@ void test_rotate_direct(Policy l, ExPolicy&& policy, IteratorTag) std::iota(std::begin(c), std::end(c), std::rand()); std::copy(std::begin(c), std::end(c), std::back_inserter(d1)); - std::size_t mid_pos = std::rand() % c.size(); //-V104 + std::size_t const mid_pos = std::rand() % c.size(); //-V104 base_iterator mid = std::begin(c); std::advance(mid, mid_pos); @@ -88,7 +88,7 @@ void test_rotate(Policy l, ExPolicy&& policy, IteratorTag) std::iota(std::begin(c), std::end(c), std::rand()); std::copy(std::begin(c), std::end(c), std::back_inserter(d1)); - std::size_t mid_pos = std::rand() % c.size(); //-V104 + std::size_t const mid_pos = std::rand() % c.size(); //-V104 base_iterator mid = std::begin(c); std::advance(mid, mid_pos); @@ -127,7 +127,7 @@ void test_rotate_async_direct(Policy l, ExPolicy&& p, IteratorTag) std::iota(std::begin(c), std::end(c), std::rand()); std::copy(std::begin(c), std::end(c), std::back_inserter(d1)); - std::size_t mid_pos = std::rand() % c.size(); //-V104 + std::size_t const mid_pos = std::rand() % c.size(); //-V104 base_iterator mid = std::begin(c); std::advance(mid, mid_pos); @@ -191,7 +191,7 @@ void rotate_test() int hpx_main(hpx::program_options::variables_map& vm) { - unsigned int seed = (unsigned int) std::time(nullptr); + unsigned int seed = static_cast(std::time(nullptr)); if (vm.count("seed")) seed = vm["seed"].as(); diff --git a/libs/core/algorithms/tests/unit/container_algorithms/is_sorted_until_range.cpp b/libs/core/algorithms/tests/unit/container_algorithms/is_sorted_until_range.cpp index bb40a007a334..f60e99669ff0 100644 --- a/libs/core/algorithms/tests/unit/container_algorithms/is_sorted_until_range.cpp +++ b/libs/core/algorithms/tests/unit/container_algorithms/is_sorted_until_range.cpp @@ -5,6 +5,7 @@ // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #include +#include #include #include @@ -1214,7 +1215,7 @@ void test_sorted_until_bad_alloc(ExPolicy policy, IteratorTag) decorated_iterator( std::end(c), []() { throw std::runtime_error("test"); })); } - catch (hpx::exception_list const& e) + catch (hpx::exception_list const&) { caught_bad_alloc = true; } @@ -1232,7 +1233,7 @@ void test_sorted_until_bad_alloc(ExPolicy policy, IteratorTag) iterator(std::end(c)), [](int, int) -> bool { throw std::runtime_error("test"); }); } - catch (hpx::exception_list const& e) + catch (hpx::exception_list const&) { caught_bad_alloc = true; } @@ -1250,7 +1251,7 @@ void test_sorted_until_bad_alloc(ExPolicy policy, IteratorTag) iterator(std::end(c)), std::less(), [](int) -> int { throw std::runtime_error("test"); }); } - catch (hpx::exception_list const& e) + catch (hpx::exception_list const&) { caught_bad_alloc = true; } @@ -1285,7 +1286,7 @@ void test_sorted_until_async_bad_alloc(ExPolicy p, IteratorTag) HPX_TEST(false); } - catch (hpx::exception_list const& e) + catch (hpx::exception_list const&) { caught_bad_alloc = true; } @@ -1306,7 +1307,7 @@ void test_sorted_until_async_bad_alloc(ExPolicy p, IteratorTag) HPX_TEST(false); } - catch (hpx::exception_list const& e) + catch (hpx::exception_list const&) { caught_bad_alloc = true; } @@ -1327,7 +1328,7 @@ void test_sorted_until_async_bad_alloc(ExPolicy p, IteratorTag) HPX_TEST(false); } - catch (hpx::exception_list const& e) + catch (hpx::exception_list const&) { caught_bad_alloc = true; } @@ -1361,7 +1362,7 @@ void test_sorted_until_seq_bad_alloc(IteratorTag) decorated_iterator( std::end(c), []() { throw std::runtime_error("test"); })); } - catch (hpx::exception_list const& e) + catch (hpx::exception_list const&) { caught_bad_alloc = true; } @@ -1379,7 +1380,7 @@ void test_sorted_until_seq_bad_alloc(IteratorTag) iterator(std::end(c)), [](int, int) -> int { throw std::runtime_error("test"); }); } - catch (hpx::exception_list const& e) + catch (hpx::exception_list const&) { caught_bad_alloc = true; } @@ -1397,7 +1398,7 @@ void test_sorted_until_seq_bad_alloc(IteratorTag) iterator(std::end(c)), std::less(), [](int) -> int { throw std::runtime_error("test"); }); } - catch (hpx::exception_list const& e) + catch (hpx::exception_list const&) { caught_bad_alloc = true; } @@ -1426,7 +1427,7 @@ void test_sorted_until_bad_alloc(ExPolicy policy) hpx::ranges::is_sorted_until(policy, c, [](int, int) -> bool { throw std::runtime_error("test"); }); } - catch (hpx::exception_list const& e) + catch (hpx::exception_list const&) { caught_bad_alloc = true; } @@ -1443,7 +1444,7 @@ void test_sorted_until_bad_alloc(ExPolicy policy) hpx::ranges::is_sorted_until(policy, c, std::less(), [](int) -> int { throw std::runtime_error("test"); }); } - catch (hpx::exception_list const& e) + catch (hpx::exception_list const&) { caught_bad_alloc = true; } @@ -1470,7 +1471,7 @@ void test_sorted_until_async_bad_alloc(ExPolicy p) HPX_TEST(false); } - catch (hpx::exception_list const& e) + catch (hpx::exception_list const&) { caught_bad_alloc = true; } @@ -1490,7 +1491,7 @@ void test_sorted_until_async_bad_alloc(ExPolicy p) HPX_TEST(false); } - catch (hpx::exception_list const& e) + catch (hpx::exception_list const&) { caught_bad_alloc = true; } @@ -1515,7 +1516,7 @@ void test_sorted_until_seq_bad_alloc() hpx::ranges::is_sorted_until( c, [](int, int) -> int { throw std::runtime_error("test"); }); } - catch (hpx::exception_list const& e) + catch (hpx::exception_list const&) { caught_bad_alloc = true; } @@ -1532,7 +1533,7 @@ void test_sorted_until_seq_bad_alloc() hpx::ranges::is_sorted_until(c, std::less(), [](int) -> int { throw std::runtime_error("test"); }); } - catch (hpx::exception_list const& e) + catch (hpx::exception_list const&) { caught_bad_alloc = true; } @@ -1585,12 +1586,12 @@ int hpx_main() sorted_until_exception_test(); sorted_until_bad_alloc_test(); - std::vector c(100); - hpx::future f = - hpx::dataflow(hpx::ranges::is_sorted, hpx::execution::par, c); - f = hpx::dataflow( - hpx::unwrapping(hpx::ranges::is_sorted), hpx::execution::par, c, f); - f.get(); + // std::vector c(100); + // hpx::future f = + // hpx::dataflow(hpx::ranges::is_sorted, hpx::execution::par, c); + // f = hpx::dataflow( + // hpx::unwrapping(hpx::ranges::is_sorted), hpx::execution::par, c, f); + // f.get(); return hpx::local::finalize(); } diff --git a/libs/core/execution/include/hpx/execution/executors/execution_parameters_fwd.hpp b/libs/core/execution/include/hpx/execution/executors/execution_parameters_fwd.hpp index ba4b834d6d89..856e389abf6e 100644 --- a/libs/core/execution/include/hpx/execution/executors/execution_parameters_fwd.hpp +++ b/libs/core/execution/include/hpx/execution/executors/execution_parameters_fwd.hpp @@ -64,6 +64,16 @@ namespace hpx::parallel::execution { /////////////////////////////////////////////////////////////////////////// // define customization points + inline constexpr struct null_parameters_t + { + } null_parameters{}; + + /// \cond NOINTERNAL + template <> + struct is_executor_parameters : std::true_type + { + }; + /// \endcond /// Return the number of invocations of the given function \a f which should /// be combined into a single task @@ -287,7 +297,7 @@ namespace hpx::parallel::execution { // clang-format off template ::value + hpx::traits::is_executor_any_v )> // clang-format on friend HPX_FORCEINLINE decltype(auto) tag_fallback_invoke( @@ -295,22 +305,23 @@ namespace hpx::parallel::execution { hpx::chrono::steady_duration const& iteration_duration, std::size_t num_tasks) { - return detail::processing_units_count_fn_helper>::call(HPX_FORWARD(Executor, exec), - iteration_duration, num_tasks); + return detail::processing_units_count_fn_helper>::call(null_parameters, + HPX_FORWARD(Executor, exec), iteration_duration, num_tasks); } // clang-format off template ::value + hpx::traits::is_executor_any_v )> // clang-format on friend HPX_FORCEINLINE decltype(auto) tag_fallback_invoke( processing_units_count_t tag, Executor&& exec, std::size_t num_tasks = 0) { - return tag(HPX_FORWARD(Executor, exec), hpx::chrono::null_duration, + return tag(hpx::parallel::execution::null_parameters, + HPX_FORWARD(Executor, exec), hpx::chrono::null_duration, num_tasks); } } processing_units_count{}; diff --git a/libs/core/execution/include/hpx/execution/executors/num_cores.hpp b/libs/core/execution/include/hpx/execution/executors/num_cores.hpp index eb3a0e128d73..ab02e9b4f2c9 100644 --- a/libs/core/execution/include/hpx/execution/executors/num_cores.hpp +++ b/libs/core/execution/include/hpx/execution/executors/num_cores.hpp @@ -35,6 +35,15 @@ namespace hpx::execution::experimental { /// \cond NOINTERNAL // discover the number of cores to use for parallelization + template + friend std::size_t tag_invoke( + hpx::parallel::execution::processing_units_count_t, + num_cores params, Executor&&, hpx::chrono::steady_duration const&, + std::size_t) noexcept + { + return params.num_cores_; + } + template constexpr std::size_t processing_units_count(Executor&&, hpx::chrono::steady_duration const&, std::size_t) const noexcept diff --git a/libs/core/execution/tests/regressions/is_executor_1691.cpp b/libs/core/execution/tests/regressions/is_executor_1691.cpp index 3184f83b7721..33e4902cd9e3 100644 --- a/libs/core/execution/tests/regressions/is_executor_1691.cpp +++ b/libs/core/execution/tests/regressions/is_executor_1691.cpp @@ -17,6 +17,7 @@ struct my_executor : hpx::execution::parallel_executor }; namespace hpx::parallel::execution { + template <> struct is_one_way_executor : std::true_type { diff --git a/libs/core/execution/tests/unit/executor_parameters_dispatching.cpp b/libs/core/execution/tests/unit/executor_parameters_dispatching.cpp index 0947189d345f..83296b9bb67a 100644 --- a/libs/core/execution/tests/unit/executor_parameters_dispatching.cpp +++ b/libs/core/execution/tests/unit/executor_parameters_dispatching.cpp @@ -27,10 +27,7 @@ std::atomic exec_count(0); struct test_executor_get_chunk_size : hpx::execution::parallel_executor { - test_executor_get_chunk_size() - : hpx::execution::parallel_executor() - { - } + test_executor_get_chunk_size() = default; template static std::size_t get_chunk_size(Parameters&& /* params */, @@ -42,12 +39,11 @@ struct test_executor_get_chunk_size : hpx::execution::parallel_executor } }; -namespace hpx::parallel::execution { - template <> - struct is_two_way_executor : std::true_type - { - }; -} // namespace hpx::parallel::execution +template <> +struct hpx::parallel::execution::is_two_way_executor< + test_executor_get_chunk_size> : std::true_type +{ +}; struct test_chunk_size { @@ -61,14 +57,11 @@ struct test_chunk_size } }; -namespace hpx::parallel::execution { - /// \cond NOINTERNAL - template <> - struct is_executor_parameters : std::true_type - { - }; - /// \endcond -} // namespace hpx::parallel::execution +template <> +struct hpx::parallel::execution::is_executor_parameters + : std::true_type +{ +}; /////////////////////////////////////////////////////////////////////////////// void test_get_chunk_size() @@ -80,8 +73,8 @@ void test_get_chunk_size() hpx::parallel::execution::get_chunk_size( test_chunk_size{}, hpx::execution::par.executor(), 1, 1); - HPX_TEST_EQ(params_count, std::size_t(1)); - HPX_TEST_EQ(exec_count, std::size_t(0)); + HPX_TEST_EQ(params_count, static_cast(1)); + HPX_TEST_EQ(exec_count, static_cast(0)); } { @@ -91,8 +84,8 @@ void test_get_chunk_size() hpx::parallel::execution::get_chunk_size(test_chunk_size{}, hpx::execution::par.executor(), hpx::chrono::null_duration, 1, 1); - HPX_TEST_EQ(params_count, std::size_t(1)); - HPX_TEST_EQ(exec_count, std::size_t(0)); + HPX_TEST_EQ(params_count, static_cast(1)); + HPX_TEST_EQ(exec_count, static_cast(0)); } { @@ -102,8 +95,8 @@ void test_get_chunk_size() hpx::parallel::execution::get_chunk_size( test_chunk_size{}, test_executor_get_chunk_size{}, 1, 1); - HPX_TEST_EQ(params_count, std::size_t(0)); - HPX_TEST_EQ(exec_count, std::size_t(1)); + HPX_TEST_EQ(params_count, static_cast(0)); + HPX_TEST_EQ(exec_count, static_cast(1)); } { @@ -113,8 +106,8 @@ void test_get_chunk_size() hpx::parallel::execution::get_chunk_size(test_chunk_size{}, test_executor_get_chunk_size{}, hpx::chrono::null_duration, 1, 1); - HPX_TEST_EQ(params_count, std::size_t(0)); - HPX_TEST_EQ(exec_count, std::size_t(1)); + HPX_TEST_EQ(params_count, static_cast(0)); + HPX_TEST_EQ(exec_count, static_cast(1)); } } @@ -123,10 +116,7 @@ void test_get_chunk_size() struct test_executor_measure_iteration : hpx::execution::parallel_executor { - test_executor_measure_iteration() - : hpx::execution::parallel_executor() - { - } + test_executor_measure_iteration() = default; template static auto measure_iteration(Parameters&&, F&&, std::size_t) @@ -136,12 +126,11 @@ struct test_executor_measure_iteration : hpx::execution::parallel_executor } }; -namespace hpx::parallel::execution { - template <> - struct is_two_way_executor : std::true_type - { - }; -} // namespace hpx::parallel::execution +template <> +struct hpx::parallel::execution::is_two_way_executor< + test_executor_measure_iteration> : std::true_type +{ +}; struct test_measure_iteration { @@ -153,14 +142,11 @@ struct test_measure_iteration } }; -namespace hpx::parallel::execution { - /// \cond NOINTERNAL - template <> - struct is_executor_parameters : std::true_type - { - }; - /// \endcond -} // namespace hpx::parallel::execution +template <> +struct hpx::parallel::execution::is_executor_parameters + : std::true_type +{ +}; /////////////////////////////////////////////////////////////////////////////// void test_get_measure_iteration() @@ -173,8 +159,8 @@ void test_get_measure_iteration() test_measure_iteration{}, hpx::execution::par.executor(), [](std::size_t) { return 0; }, 1); - HPX_TEST_EQ(params_count, std::size_t(1)); - HPX_TEST_EQ(exec_count, std::size_t(0)); + HPX_TEST_EQ(params_count, static_cast(1)); + HPX_TEST_EQ(exec_count, static_cast(0)); } { @@ -185,8 +171,8 @@ void test_get_measure_iteration() test_measure_iteration{}, test_executor_measure_iteration{}, [](std::size_t) { return 0; }, 1); - HPX_TEST_EQ(params_count, std::size_t(0)); - HPX_TEST_EQ(exec_count, std::size_t(1)); + HPX_TEST_EQ(params_count, static_cast(0)); + HPX_TEST_EQ(exec_count, static_cast(1)); } } @@ -196,10 +182,7 @@ void test_get_measure_iteration() struct test_executor_maximal_number_of_chunks : hpx::execution::parallel_executor { - test_executor_maximal_number_of_chunks() - : hpx::execution::parallel_executor() - { - } + test_executor_maximal_number_of_chunks() = default; template static std::size_t maximal_number_of_chunks( @@ -210,18 +193,16 @@ struct test_executor_maximal_number_of_chunks } }; -namespace hpx::parallel::execution { - template <> - struct is_two_way_executor - : std::true_type - { - }; -} // namespace hpx::parallel::execution +template <> +struct hpx::parallel::execution::is_two_way_executor< + test_executor_maximal_number_of_chunks> : std::true_type +{ +}; struct test_number_of_chunks { template - std::size_t maximal_number_of_chunks( + static std::size_t maximal_number_of_chunks( Executor&&, std::size_t, std::size_t num_tasks) { ++params_count; @@ -229,12 +210,11 @@ struct test_number_of_chunks } }; -namespace hpx::parallel::execution { - template <> - struct is_executor_parameters : std::true_type - { - }; -} // namespace hpx::parallel::execution +template <> +struct hpx::parallel::execution::is_executor_parameters + : std::true_type +{ +}; /////////////////////////////////////////////////////////////////////////////// void test_maximal_number_of_chunks() @@ -246,8 +226,8 @@ void test_maximal_number_of_chunks() hpx::parallel::execution::maximal_number_of_chunks( test_number_of_chunks{}, hpx::execution::par.executor(), 1, 1); - HPX_TEST_EQ(params_count, std::size_t(1)); - HPX_TEST_EQ(exec_count, std::size_t(0)); + HPX_TEST_EQ(params_count, static_cast(1)); + HPX_TEST_EQ(exec_count, static_cast(0)); } { @@ -258,8 +238,8 @@ void test_maximal_number_of_chunks() test_number_of_chunks{}, test_executor_maximal_number_of_chunks{}, 1, 1); - HPX_TEST_EQ(params_count, std::size_t(0)); - HPX_TEST_EQ(exec_count, std::size_t(1)); + HPX_TEST_EQ(params_count, static_cast(0)); + HPX_TEST_EQ(exec_count, static_cast(1)); } } @@ -269,10 +249,7 @@ void test_maximal_number_of_chunks() struct test_executor_reset_thread_distribution : hpx::execution::parallel_executor { - test_executor_reset_thread_distribution() - : hpx::execution::parallel_executor() - { - } + test_executor_reset_thread_distribution() = default; template static void reset_thread_distribution(Parameters&&) @@ -281,29 +258,26 @@ struct test_executor_reset_thread_distribution } }; -namespace hpx::parallel::execution { - template <> - struct is_two_way_executor - : std::true_type - { - }; -} // namespace hpx::parallel::execution +template <> +struct hpx::parallel::execution::is_two_way_executor< + test_executor_reset_thread_distribution> : std::true_type +{ +}; struct test_thread_distribution { template - void reset_thread_distribution(Executor&&) + static void reset_thread_distribution(Executor&&) { ++params_count; } }; -namespace hpx::parallel::execution { - template <> - struct is_executor_parameters : std::true_type - { - }; -} // namespace hpx::parallel::execution +template <> +struct hpx::parallel::execution::is_executor_parameters< + test_thread_distribution> : std::true_type +{ +}; /////////////////////////////////////////////////////////////////////////////// void test_reset_thread_distribution() @@ -315,8 +289,8 @@ void test_reset_thread_distribution() hpx::parallel::execution::reset_thread_distribution( test_thread_distribution{}, hpx::execution::par.executor()); - HPX_TEST_EQ(params_count, std::size_t(1)); - HPX_TEST_EQ(exec_count, std::size_t(0)); + HPX_TEST_EQ(params_count, static_cast(1)); + HPX_TEST_EQ(exec_count, static_cast(0)); } { @@ -327,8 +301,8 @@ void test_reset_thread_distribution() test_thread_distribution{}, test_executor_reset_thread_distribution{}); - HPX_TEST_EQ(params_count, std::size_t(0)); - HPX_TEST_EQ(exec_count, std::size_t(1)); + HPX_TEST_EQ(params_count, static_cast(0)); + HPX_TEST_EQ(exec_count, static_cast(1)); } } @@ -337,10 +311,7 @@ void test_reset_thread_distribution() struct test_executor_processing_units_count : hpx::execution::parallel_executor { - test_executor_processing_units_count() - : hpx::execution::parallel_executor() - { - } + test_executor_processing_units_count() = default; template static std::size_t processing_units_count( @@ -351,31 +322,30 @@ struct test_executor_processing_units_count : hpx::execution::parallel_executor } }; -namespace hpx::parallel::execution { - template <> - struct is_two_way_executor - : std::true_type - { - }; -} // namespace hpx::parallel::execution +template <> +struct hpx::parallel::execution::is_two_way_executor< + test_executor_processing_units_count> : std::true_type +{ +}; struct test_processing_units { template - static std::size_t processing_units_count( - Executor&&, hpx::chrono::steady_duration const&, std::size_t) + friend std::size_t tag_invoke( + hpx::parallel::execution::processing_units_count_t, + test_processing_units, Executor&&, hpx::chrono::steady_duration const&, + std::size_t) { ++params_count; return 1; } }; -namespace hpx::parallel::execution { - template <> - struct is_executor_parameters : std::true_type - { - }; -} // namespace hpx::parallel::execution +template <> +struct hpx::parallel::execution::is_executor_parameters + : std::true_type +{ +}; /////////////////////////////////////////////////////////////////////////////// void test_processing_units_count() @@ -386,7 +356,7 @@ void test_processing_units_count() hpx::parallel::execution::processing_units_count( test_processing_units{}, hpx::execution::parallel_executor()); - HPX_TEST_EQ(params_count, std::size_t(0)); + HPX_TEST_EQ(params_count, static_cast(0)); } { @@ -397,8 +367,8 @@ void test_processing_units_count() test_processing_units{}, test_executor_processing_units_count{}, hpx::chrono::null_duration, 0); - HPX_TEST_EQ(params_count, std::size_t(0)); - HPX_TEST_EQ(exec_count, std::size_t(1)); + HPX_TEST_EQ(params_count, static_cast(1)); + HPX_TEST_EQ(exec_count, static_cast(0)); } { @@ -407,38 +377,35 @@ void test_processing_units_count() auto p = hpx::parallel::execution::with_processing_units_count( hpx::execution::par, 2); - std::size_t num_cores = + std::size_t const num_cores = hpx::parallel::execution::processing_units_count( test_processing_units{}, p.executor()); - HPX_TEST_EQ(num_cores, std::size_t(2)); - HPX_TEST_EQ(params_count, std::size_t(0)); + HPX_TEST_EQ(num_cores, static_cast(2)); + HPX_TEST_EQ(params_count, static_cast(0)); } { - params_count = 0; - hpx::execution::experimental::num_cores nc(2); auto p = hpx::parallel::execution::with_processing_units_count( hpx::execution::par, nc); - std::size_t num_cores = + std::size_t const num_cores = hpx::parallel::execution::processing_units_count( - test_processing_units{}, p.executor(), + hpx::parallel::execution::null_parameters, p.executor(), hpx::chrono::null_duration, 0); - HPX_TEST_EQ(num_cores, std::size_t(2)); - HPX_TEST_EQ(params_count, std::size_t(0)); + HPX_TEST_EQ(num_cores, static_cast(2)); } { auto p = hpx::parallel::execution::with_processing_units_count( hpx::execution::par, 2); - std::size_t num_cores = + std::size_t const num_cores = hpx::parallel::execution::processing_units_count(p); - HPX_TEST_EQ(num_cores, std::size_t(2)); + HPX_TEST_EQ(num_cores, static_cast(2)); } } @@ -447,64 +414,59 @@ void test_processing_units_count() struct test_executor_begin_end : hpx::execution::parallel_executor { - test_executor_begin_end() - : hpx::execution::parallel_executor() - { - } + test_executor_begin_end() = default; template - void mark_begin_execution(Parameters&&) + static void mark_begin_execution(Parameters&&) { ++exec_count; } template - void mark_end_of_scheduling(Parameters&&) + static void mark_end_of_scheduling(Parameters&&) { ++exec_count; } template - void mark_end_execution(Parameters&&) + static void mark_end_execution(Parameters&&) { ++exec_count; } }; -namespace hpx::parallel::execution { - template <> - struct is_two_way_executor : std::true_type - { - }; -} // namespace hpx::parallel::execution +template <> +struct hpx::parallel::execution::is_two_way_executor + : std::true_type +{ +}; struct test_begin_end { template - void mark_begin_execution(Executor&&) + static void mark_begin_execution(Executor&&) { ++params_count; } template - void mark_end_of_scheduling(Executor&&) + static void mark_end_of_scheduling(Executor&&) { ++params_count; } template - void mark_end_execution(Executor&&) + static void mark_end_execution(Executor&&) { ++params_count; } }; -namespace hpx::parallel::execution { - template <> - struct is_executor_parameters : std::true_type - { - }; -} // namespace hpx::parallel::execution +template <> +struct hpx::parallel::execution::is_executor_parameters + : std::true_type +{ +}; /////////////////////////////////////////////////////////////////////////////// void test_mark_begin_execution() @@ -516,8 +478,8 @@ void test_mark_begin_execution() hpx::parallel::execution::mark_begin_execution( test_begin_end{}, hpx::execution::par.executor()); - HPX_TEST_EQ(params_count, std::size_t(1)); - HPX_TEST_EQ(exec_count, std::size_t(0)); + HPX_TEST_EQ(params_count, static_cast(1)); + HPX_TEST_EQ(exec_count, static_cast(0)); } { @@ -527,8 +489,8 @@ void test_mark_begin_execution() hpx::parallel::execution::mark_begin_execution( test_begin_end{}, test_executor_begin_end{}); - HPX_TEST_EQ(params_count, std::size_t(0)); - HPX_TEST_EQ(exec_count, std::size_t(1)); + HPX_TEST_EQ(params_count, static_cast(0)); + HPX_TEST_EQ(exec_count, static_cast(1)); } } @@ -541,8 +503,8 @@ void test_mark_end_of_scheduling() hpx::parallel::execution::mark_end_of_scheduling( test_begin_end{}, hpx::execution::par.executor()); - HPX_TEST_EQ(params_count, std::size_t(1)); - HPX_TEST_EQ(exec_count, std::size_t(0)); + HPX_TEST_EQ(params_count, static_cast(1)); + HPX_TEST_EQ(exec_count, static_cast(0)); } { @@ -552,8 +514,8 @@ void test_mark_end_of_scheduling() hpx::parallel::execution::mark_end_of_scheduling( test_begin_end{}, test_executor_begin_end{}); - HPX_TEST_EQ(params_count, std::size_t(0)); - HPX_TEST_EQ(exec_count, std::size_t(1)); + HPX_TEST_EQ(params_count, static_cast(0)); + HPX_TEST_EQ(exec_count, static_cast(1)); } } @@ -566,8 +528,8 @@ void test_mark_end_execution() hpx::parallel::execution::mark_end_execution( test_begin_end{}, hpx::execution::par.executor()); - HPX_TEST_EQ(params_count, std::size_t(1)); - HPX_TEST_EQ(exec_count, std::size_t(0)); + HPX_TEST_EQ(params_count, static_cast(1)); + HPX_TEST_EQ(exec_count, static_cast(0)); } { @@ -577,8 +539,8 @@ void test_mark_end_execution() hpx::parallel::execution::mark_end_execution( test_begin_end{}, test_executor_begin_end{}); - HPX_TEST_EQ(params_count, std::size_t(0)); - HPX_TEST_EQ(exec_count, std::size_t(1)); + HPX_TEST_EQ(params_count, static_cast(0)); + HPX_TEST_EQ(exec_count, static_cast(1)); } } diff --git a/libs/core/executors/examples/disable_thread_stealing_executor.cpp b/libs/core/executors/examples/disable_thread_stealing_executor.cpp index 4a3e952a40df..721b1064ec64 100644 --- a/libs/core/executors/examples/disable_thread_stealing_executor.cpp +++ b/libs/core/executors/examples/disable_thread_stealing_executor.cpp @@ -66,6 +66,38 @@ namespace executor_example { } }; + // support all properties exposed by the wrapped executor + // clang-format off + template + )> + auto tag_invoke(Tag tag, + disable_thread_stealing_executor const& exec, + Property&& prop) + -> decltype(disable_thread_stealing_executor( + std::declval()( + std::declval(), std::declval()))) + // clang-format on + { + return disable_thread_stealing_executor( + tag(static_cast(exec), + HPX_FORWARD(Property, prop))); + } + + // clang-format off + template + )> + // clang-format on + auto tag_invoke( + Tag tag, disable_thread_stealing_executor const& exec) + -> decltype(std::declval()(std::declval())) + { + return tag(static_cast(exec)); + } + template auto make_disable_thread_stealing_executor(BaseExecutor&& exec) { diff --git a/libs/core/executors/examples/executor_with_thread_hooks.cpp b/libs/core/executors/examples/executor_with_thread_hooks.cpp index 19a5db048b82..5dc5bd7b113e 100644 --- a/libs/core/executors/examples/executor_with_thread_hooks.cpp +++ b/libs/core/executors/examples/executor_with_thread_hooks.cpp @@ -168,6 +168,12 @@ namespace executor_example { std::forward(predecessor), std::forward(ts)...); } + [[nodiscard]] constexpr std::decay_t const& get_executor() + const noexcept + { + return exec_; + } + private: using thread_hook = hpx::function; diff --git a/libs/core/executors/include/hpx/executors/annotating_executor.hpp b/libs/core/executors/include/hpx/executors/annotating_executor.hpp index 2f34179b140b..6f9a750fa6d2 100644 --- a/libs/core/executors/include/hpx/executors/annotating_executor.hpp +++ b/libs/core/executors/include/hpx/executors/annotating_executor.hpp @@ -203,7 +203,7 @@ namespace hpx::execution::experimental { } std::decay_t exec_; - char const* const annotation_ = nullptr; + char const* annotation_ = nullptr; /// \endcond }; @@ -212,7 +212,7 @@ namespace hpx::execution::experimental { template - )> + )> // clang-format on auto tag_invoke( Tag tag, annotating_executor const& exec, Property&& prop) @@ -227,7 +227,7 @@ namespace hpx::execution::experimental { template - )> + )> // clang-format on auto tag_invoke(Tag tag, annotating_executor const& exec) -> decltype(std::declval()(std::declval())) @@ -259,7 +259,7 @@ namespace hpx::execution::experimental { template - )> + )> // clang-format on constexpr auto tag_fallback_invoke( with_annotation_t, Executor&& exec, char const* annotation) @@ -272,7 +272,7 @@ namespace hpx::execution::experimental { template - )> + )> // clang-format on auto tag_fallback_invoke( with_annotation_t, Executor&& exec, std::string annotation) diff --git a/libs/core/executors/include/hpx/executors/datapar/execution_policy.hpp b/libs/core/executors/include/hpx/executors/datapar/execution_policy.hpp index dd46113d68ed..6ade940bab80 100644 --- a/libs/core/executors/include/hpx/executors/datapar/execution_policy.hpp +++ b/libs/core/executors/include/hpx/executors/datapar/execution_policy.hpp @@ -58,6 +58,32 @@ namespace hpx::execution { HPX_FORWARD(Parameters_, params)) { } + + template , + simd_task_policy_shim> && + std::is_convertible_v && + std::is_convertible_v>> + explicit constexpr simd_task_policy_shim( + simd_task_policy_shim const& rhs) + : base_type( + simd_task_policy_shim(rhs.executor(), rhs.parameters())) + { + } + + template && + std::is_convertible_v>> + simd_task_policy_shim& operator=( + simd_task_policy_shim const& rhs) + { + base_type::operator=( + simd_task_policy_shim(rhs.executor(), rhs.parameters())); + return *this; + } /// \endcond }; } // namespace detail @@ -70,7 +96,8 @@ namespace hpx::execution { /// /// The algorithm returns a future representing the result of the /// corresponding algorithm when invoked with the sequenced_policy. - using simd_task_policy = detail::simd_task_policy_shim; + using simd_task_policy = detail::simd_task_policy_shim>; namespace detail { @@ -96,6 +123,30 @@ namespace hpx::execution { HPX_FORWARD(Parameters_, params)) { } + + template , + simd_policy_shim> && + std::is_convertible_v && + std::is_convertible_v>> + explicit constexpr simd_policy_shim( + simd_policy_shim const& rhs) + : base_type(simd_policy_shim(rhs.executor(), rhs.parameters())) + { + } + + template && + std::is_convertible_v>> + simd_policy_shim& operator=( + simd_policy_shim const& rhs) + { + base_type::operator=( + simd_policy_shim(rhs.executor(), rhs.parameters())); + return *this; + } /// \endcond }; } // namespace detail @@ -104,7 +155,8 @@ namespace hpx::execution { /// The class simd_policy is an execution policy type used as a unique type /// to disambiguate parallel algorithm overloading and require that a /// parallel algorithm's execution may not be parallelized. - using simd_policy = detail::simd_policy_shim; + using simd_policy = detail::simd_policy_shim>; /// Default sequential execution policy object. inline constexpr simd_policy simd{}; @@ -135,6 +187,32 @@ namespace hpx::execution { HPX_FORWARD(Parameters_, params)) { } + + template , + par_simd_task_policy_shim> && + std::is_convertible_v && + std::is_convertible_v>> + explicit constexpr par_simd_task_policy_shim( + par_simd_task_policy_shim const& rhs) + : base_type( + par_simd_task_policy_shim(rhs.executor(), rhs.parameters())) + { + } + + template && + std::is_convertible_v>> + par_simd_task_policy_shim& operator=( + par_simd_task_policy_shim const& rhs) + { + base_type::operator=(par_simd_task_policy_shim( + rhs.executor(), rhs.parameters())); + return *this; + } /// \endcond }; } // namespace detail @@ -147,7 +225,8 @@ namespace hpx::execution { /// The algorithm returns a future representing the result of the /// corresponding algorithm when invoked with the parallel_policy. using par_simd_task_policy = - detail::par_simd_task_policy_shim; + detail::par_simd_task_policy_shim>; namespace detail { @@ -174,6 +253,32 @@ namespace hpx::execution { HPX_FORWARD(Parameters_, params)) { } + + template , + par_simd_policy_shim> && + std::is_convertible_v && + std::is_convertible_v>> + explicit constexpr par_simd_policy_shim( + par_simd_policy_shim const& rhs) + : base_type( + par_simd_policy_shim(rhs.executor(), rhs.parameters())) + { + } + + template && + std::is_convertible_v>> + par_simd_policy_shim& operator=( + par_simd_policy_shim const& rhs) + { + base_type::operator=( + par_simd_policy_shim(rhs.executor(), rhs.parameters())); + return *this; + } /// \endcond }; } // namespace detail @@ -185,7 +290,8 @@ namespace hpx::execution { /// /// The algorithm returns a future representing the result of the /// corresponding algorithm when invoked with the parallel_policy. - using par_simd_policy = detail::par_simd_policy_shim; + using par_simd_policy = detail::par_simd_policy_shim>; /// Default data-parallel execution policy object. inline constexpr par_simd_policy par_simd{}; diff --git a/libs/core/executors/include/hpx/executors/datapar/execution_policy_fwd.hpp b/libs/core/executors/include/hpx/executors/datapar/execution_policy_fwd.hpp index e34c4c8a9289..e54f6731e76e 100644 --- a/libs/core/executors/include/hpx/executors/datapar/execution_policy_fwd.hpp +++ b/libs/core/executors/include/hpx/executors/datapar/execution_policy_fwd.hpp @@ -15,16 +15,16 @@ namespace hpx::execution::detail { /////////////////////////////////////////////////////////////////////////// - template + template struct simd_policy_shim; - template + template struct simd_task_policy_shim; - template + template struct par_simd_policy_shim; - template + template struct par_simd_task_policy_shim; } // namespace hpx::execution::detail diff --git a/libs/core/executors/include/hpx/executors/execution_policy.hpp b/libs/core/executors/include/hpx/executors/execution_policy.hpp index 1336d99d6241..e6ce801008fb 100644 --- a/libs/core/executors/include/hpx/executors/execution_policy.hpp +++ b/libs/core/executors/include/hpx/executors/execution_policy.hpp @@ -124,10 +124,7 @@ namespace hpx::execution { // The type of the associated executor parameters object which is // associated with this execution policy - using executor_parameters_type = - std::conditional_t, - hpx::traits::executor_parameters_type_t, - decayed_parameters_type>; + using executor_parameters_type = decayed_parameters_type; // The category of the execution agents created by this execution // policy. @@ -284,6 +281,32 @@ namespace hpx::execution { HPX_FORWARD(Parameters_, params)) { } + + template , + sequenced_task_policy_shim> && + std::is_convertible_v && + std::is_convertible_v>> + explicit constexpr sequenced_task_policy_shim( + sequenced_task_policy_shim const& rhs) + : base_type(sequenced_task_policy_shim( + rhs.executor(), rhs.parameters())) + { + } + + template && + std::is_convertible_v>> + sequenced_task_policy_shim& operator=( + sequenced_task_policy_shim const& rhs) + { + base_type::operator=(sequenced_task_policy_shim( + rhs.executor(), rhs.parameters())); + return *this; + } /// \endcond }; } // namespace detail @@ -297,7 +320,8 @@ namespace hpx::execution { /// The algorithm returns a future representing the result of the /// corresponding algorithm when invoked with the sequenced_policy. using sequenced_task_policy = - detail::sequenced_task_policy_shim; + detail::sequenced_task_policy_shim>; namespace detail { @@ -324,6 +348,32 @@ namespace hpx::execution { HPX_FORWARD(Parameters_, params)) { } + + template , + sequenced_policy_shim> && + std::is_convertible_v && + std::is_convertible_v>> + explicit constexpr sequenced_policy_shim( + sequenced_policy_shim const& rhs) + : base_type( + sequenced_policy_shim(rhs.executor(), rhs.parameters())) + { + } + + template && + std::is_convertible_v>> + sequenced_policy_shim& operator=( + sequenced_policy_shim const& rhs) + { + base_type::operator=( + sequenced_policy_shim(rhs.executor(), rhs.parameters())); + return *this; + } /// \endcond }; } // namespace detail @@ -332,7 +382,8 @@ namespace hpx::execution { /// The class sequenced_policy is an execution policy type used as a unique /// type to disambiguate parallel algorithm overloading and require that a /// parallel algorithm's execution may not be parallelized. - using sequenced_policy = detail::sequenced_policy_shim; + using sequenced_policy = detail::sequenced_policy_shim>; /// Default sequential execution policy object. inline constexpr sequenced_policy seq{}; @@ -364,6 +415,32 @@ namespace hpx::execution { HPX_FORWARD(Parameters_, params)) { } + + template , + parallel_task_policy_shim> && + std::is_convertible_v && + std::is_convertible_v>> + explicit constexpr parallel_task_policy_shim( + parallel_task_policy_shim const& rhs) + : base_type( + parallel_task_policy_shim(rhs.executor(), rhs.parameters())) + { + } + + template && + std::is_convertible_v>> + parallel_task_policy_shim& operator=( + parallel_task_policy_shim const& rhs) + { + base_type::operator=(parallel_task_policy_shim( + rhs.executor(), rhs.parameters())); + return *this; + } /// \endcond }; } // namespace detail @@ -376,7 +453,8 @@ namespace hpx::execution { /// The algorithm returns a future representing the result of the /// corresponding algorithm when invoked with the parallel_policy. using parallel_task_policy = - detail::parallel_task_policy_shim; + detail::parallel_task_policy_shim>; namespace detail { @@ -402,6 +480,32 @@ namespace hpx::execution { HPX_FORWARD(Parameters_, params)) { } + + template , + parallel_policy_shim> && + std::is_convertible_v && + std::is_convertible_v>> + explicit constexpr parallel_policy_shim( + parallel_policy_shim const& rhs) + : base_type( + parallel_policy_shim(rhs.executor(), rhs.parameters())) + { + } + + template && + std::is_convertible_v>> + parallel_policy_shim& operator=( + parallel_policy_shim const& rhs) + { + base_type::operator=( + parallel_policy_shim(rhs.executor(), rhs.parameters())); + return *this; + } /// \endcond }; } // namespace detail @@ -410,7 +514,8 @@ namespace hpx::execution { /// The class parallel_policy is an execution policy type used as a unique /// type to disambiguate parallel algorithm overloading and indicate that a /// parallel algorithm's execution may be parallelized. - using parallel_policy = detail::parallel_policy_shim; + using parallel_policy = detail::parallel_policy_shim>; /// Default parallel execution policy object. inline constexpr parallel_policy par{}; @@ -443,6 +548,34 @@ namespace hpx::execution { HPX_FORWARD(Parameters_, params)) { } + + template , + parallel_unsequenced_task_policy_shim> && + std::is_convertible_v && + std::is_convertible_v>> + explicit constexpr parallel_unsequenced_task_policy_shim( + parallel_unsequenced_task_policy_shim const& rhs) + : base_type(parallel_unsequenced_task_policy_shim( + rhs.executor(), rhs.parameters())) + { + } + + template && + std::is_convertible_v>> + parallel_unsequenced_task_policy_shim& operator=( + parallel_unsequenced_task_policy_shim const& rhs) + { + base_type::operator=(parallel_unsequenced_task_policy_shim( + rhs.executor(), rhs.parameters())); + return *this; + } /// \endcond }; } // namespace detail @@ -453,7 +586,8 @@ namespace hpx::execution { /// and indicate that a parallel algorithm's execution may be parallelized /// and vectorized. using parallel_unsequenced_task_policy = - detail::parallel_unsequenced_task_policy_shim; + detail::parallel_unsequenced_task_policy_shim>; namespace detail { @@ -480,6 +614,34 @@ namespace hpx::execution { HPX_FORWARD(Parameters_, params)) { } + + template , + parallel_unsequenced_policy_shim> && + std::is_convertible_v && + std::is_convertible_v>> + explicit constexpr parallel_unsequenced_policy_shim( + parallel_unsequenced_policy_shim const& + rhs) + : base_type(parallel_unsequenced_policy_shim( + rhs.executor(), rhs.parameters())) + { + } + + template && + std::is_convertible_v>> + parallel_unsequenced_policy_shim& operator=( + parallel_unsequenced_policy_shim const& + rhs) + { + base_type::operator=( + parallel_policy_shim(rhs.executor(), rhs.parameters())); + return *this; + } /// \endcond }; } // namespace detail @@ -490,7 +652,8 @@ namespace hpx::execution { /// indicate that a parallel algorithm's execution may be parallelized and /// vectorized. using parallel_unsequenced_policy = - detail::parallel_unsequenced_policy_shim; + detail::parallel_unsequenced_policy_shim>; /// Default vector execution policy object. inline constexpr parallel_unsequenced_policy par_unseq{}; @@ -524,6 +687,32 @@ namespace hpx::execution { HPX_FORWARD(Parameters_, params)) { } + + template , + unsequenced_task_policy_shim> && + std::is_convertible_v && + std::is_convertible_v>> + explicit constexpr unsequenced_task_policy_shim( + unsequenced_task_policy_shim const& rhs) + : base_type(unsequenced_task_policy_shim( + rhs.executor(), rhs.parameters())) + { + } + + template && + std::is_convertible_v>> + unsequenced_task_policy_shim& operator=( + unsequenced_task_policy_shim const& rhs) + { + base_type::operator=(unsequenced_task_policy_shim( + rhs.executor(), rhs.parameters())); + return *this; + } /// \endcond }; } // namespace detail @@ -533,7 +722,8 @@ namespace hpx::execution { /// unique type to disambiguate parallel algorithm overloading and indicate /// that a parallel algorithm's execution may be vectorized. using unsequenced_task_policy = - detail::unsequenced_task_policy_shim; + detail::unsequenced_task_policy_shim>; namespace detail { @@ -559,6 +749,32 @@ namespace hpx::execution { HPX_FORWARD(Parameters_, params)) { } + + template , + unsequenced_policy_shim> && + std::is_convertible_v && + std::is_convertible_v>> + explicit constexpr unsequenced_policy_shim( + unsequenced_policy_shim const& rhs) + : base_type( + unsequenced_policy_shim(rhs.executor(), rhs.parameters())) + { + } + + template && + std::is_convertible_v>> + unsequenced_policy_shim& operator=( + unsequenced_policy_shim const& rhs) + { + base_type::operator=( + unsequenced_policy_shim(rhs.executor(), rhs.parameters())); + return *this; + } /// \endcond }; } // namespace detail @@ -568,7 +784,8 @@ namespace hpx::execution { /// unique type to disambiguate parallel algorithm overloading and indicate /// that a parallel algorithm's execution may be vectorized. using unsequenced_policy = - detail::unsequenced_policy_shim; + detail::unsequenced_policy_shim>; /// Default vector execution policy object. inline constexpr unsequenced_policy unseq{}; diff --git a/libs/core/executors/include/hpx/executors/execution_policy_fwd.hpp b/libs/core/executors/include/hpx/executors/execution_policy_fwd.hpp index 557b0f6f5350..a07f8707c3ee 100644 --- a/libs/core/executors/include/hpx/executors/execution_policy_fwd.hpp +++ b/libs/core/executors/include/hpx/executors/execution_policy_fwd.hpp @@ -11,27 +11,27 @@ namespace hpx::execution::detail { // forward declarations, see execution_policy.hpp - template + template struct sequenced_policy_shim; - template + template struct sequenced_task_policy_shim; - template + template struct parallel_policy_shim; - template + template struct parallel_task_policy_shim; - template + template struct unsequenced_task_policy_shim; - template + template struct unsequenced_policy_shim; - template + template struct parallel_unsequenced_task_policy_shim; - template + template struct parallel_unsequenced_policy_shim; } // namespace hpx::execution::detail diff --git a/libs/core/executors/include/hpx/executors/execution_policy_mappings.hpp b/libs/core/executors/include/hpx/executors/execution_policy_mappings.hpp index 83149ed60f32..2994f699d701 100644 --- a/libs/core/executors/include/hpx/executors/execution_policy_mappings.hpp +++ b/libs/core/executors/include/hpx/executors/execution_policy_mappings.hpp @@ -135,7 +135,7 @@ namespace hpx::execution::experimental { }; /////////////////////////////////////////////////////////////////////////// - // Return the matching non-unsequences execution policy + // Return the matching non-unsequenced execution policy inline constexpr struct to_non_unseq_t final : hpx::functional::detail::tag_fallback { diff --git a/libs/core/executors/include/hpx/executors/explicit_scheduler_executor.hpp b/libs/core/executors/include/hpx/executors/explicit_scheduler_executor.hpp index 233bd98849a3..e6c64a0da9c2 100644 --- a/libs/core/executors/include/hpx/executors/explicit_scheduler_executor.hpp +++ b/libs/core/executors/include/hpx/executors/explicit_scheduler_executor.hpp @@ -98,17 +98,23 @@ namespace hpx::execution::experimental { return sched_; } + // clang-format off + template + )> + // clang-format on friend auto tag_invoke( hpx::parallel::execution::processing_units_count_t tag, - explicit_scheduler_executor const& exec, + Parameters&& params, explicit_scheduler_executor const& exec, hpx::chrono::steady_duration const& = hpx::chrono::null_duration, std::size_t = 0) -> decltype(std::declval< hpx::parallel::execution::processing_units_count_t>()( - std::declval(), + std::declval(), std::declval(), std::declval(), 0)) { - return tag(exec.sched_); + return tag(HPX_FORWARD(Parameters, params), exec.sched_); } // Associate the parallel_execution_tag executor tag type as a default @@ -250,16 +256,16 @@ namespace hpx::execution::experimental { HPX_CONCEPT_REQUIRES_( hpx::execution::experimental::is_scheduling_property_v )> - // clang-format on auto tag_invoke(Tag tag, explicit_scheduler_executor const& exec, Property&& prop) - -> decltype( - explicit_scheduler_executor(std::declval()( + -> decltype(explicit_scheduler_executor( + std::declval()( std::declval(), std::declval()))) { return explicit_scheduler_executor( tag(exec.sched(), HPX_FORWARD(Property, prop))); } + // clang-format on // clang-format off template ::call()) + constexpr explicit parallel_policy_executor(Policy l) : pool_(nullptr) , policy_(l) { } + constexpr parallel_policy_executor() + : pool_(nullptr) + , policy_( + parallel::execution::detail::get_default_policy::call()) + { + } + constexpr explicit parallel_policy_executor( threads::thread_pool_base* pool, Policy l, std::size_t hierarchical_threshold = @@ -175,18 +180,29 @@ namespace hpx::execution { // property implementations #if defined(HPX_HAVE_THREAD_DESCRIPTION) - friend constexpr parallel_policy_executor tag_invoke( + // clang-format off + template + )> + // clang-format on + friend constexpr auto tag_invoke( hpx::execution::experimental::with_annotation_t, - parallel_policy_executor const& exec, char const* annotation) + Executor_ const& exec, char const* annotation) { auto exec_with_annotation = exec; exec_with_annotation.annotation_ = annotation; return exec_with_annotation; } - friend parallel_policy_executor tag_invoke( - hpx::execution::experimental::with_annotation_t, - parallel_policy_executor const& exec, std::string annotation) + // clang-format off + template + )> + // clang-format on + friend auto tag_invoke(hpx::execution::experimental::with_annotation_t, + Executor_ const& exec, std::string annotation) { auto exec_with_annotation = exec; exec_with_annotation.annotation_ = @@ -202,18 +218,29 @@ namespace hpx::execution { } #endif - friend constexpr parallel_policy_executor tag_invoke( + // clang-format off + template + )> + // clang-format on + friend constexpr auto tag_invoke( hpx::parallel::execution::with_processing_units_count_t, - parallel_policy_executor const& exec, - std::size_t num_cores) noexcept + Executor_ const& exec, std::size_t num_cores) noexcept { auto exec_with_num_cores = exec; exec_with_num_cores.num_cores_ = num_cores; return exec_with_num_cores; } + // clang-format off + template + )> + // clang-format on friend constexpr std::size_t tag_invoke( - hpx::parallel::execution::processing_units_count_t, + hpx::parallel::execution::processing_units_count_t, Parameters&&, parallel_policy_executor const& exec, hpx::chrono::steady_duration const& = hpx::chrono::null_duration, std::size_t = 0) @@ -221,10 +248,15 @@ namespace hpx::execution { return exec.get_num_cores(); } - friend constexpr parallel_policy_executor tag_invoke( + // clang-format off + template + )> + // clang-format on + friend constexpr auto tag_invoke( hpx::execution::experimental::with_first_core_t, - parallel_policy_executor const& exec, - std::size_t first_core) noexcept + Executor_ const& exec, std::size_t first_core) noexcept { auto exec_with_first_core = exec; exec_with_first_core.first_core_ = first_core; diff --git a/libs/core/executors/include/hpx/executors/restricted_thread_pool_executor.hpp b/libs/core/executors/include/hpx/executors/restricted_thread_pool_executor.hpp index 6404f60243df..e4929a69f55c 100644 --- a/libs/core/executors/include/hpx/executors/restricted_thread_pool_executor.hpp +++ b/libs/core/executors/include/hpx/executors/restricted_thread_pool_executor.hpp @@ -148,18 +148,23 @@ namespace hpx::parallel::execution { friend decltype(auto) tag_invoke( Tag tag, restricted_policy_executor const& exec) { - return hpx::functional::tag_invoke( - tag, exec.generate_executor(exec.get_current_thread_num())); + return tag(exec.generate_executor(exec.get_current_thread_num())); } + // clang-format off + template + )> + // clang-format on friend constexpr std::size_t tag_invoke( hpx::parallel::execution::processing_units_count_t tag, - restricted_policy_executor const& exec, + Parameters&& params, restricted_policy_executor const& exec, hpx::chrono::steady_duration const& duration = hpx::chrono::null_duration, std::size_t num_tasks = 0) { - return hpx::functional::tag_invoke(tag, + return tag(HPX_FORWARD(Parameters, params), exec.generate_executor(exec.get_current_thread_num()), duration, num_tasks); } @@ -242,7 +247,7 @@ namespace hpx::parallel::execution { /// \endcond private: - std::uint16_t const first_thread_; + std::uint16_t first_thread_; mutable std::atomic os_thread_; embedded_executor exec_; diff --git a/libs/core/executors/include/hpx/executors/scheduler_executor.hpp b/libs/core/executors/include/hpx/executors/scheduler_executor.hpp index 439d1d569447..a152d6202c1f 100644 --- a/libs/core/executors/include/hpx/executors/scheduler_executor.hpp +++ b/libs/core/executors/include/hpx/executors/scheduler_executor.hpp @@ -130,17 +130,25 @@ namespace hpx::execution::experimental { using future_type = hpx::future; private: + // clang-format off + template + )> + // clang-format on friend auto tag_invoke( hpx::parallel::execution::processing_units_count_t tag, - scheduler_executor const& exec, - hpx::chrono::steady_duration const& = hpx::chrono::null_duration, - std::size_t = 0) + Parameters&& params, scheduler_executor const& exec, + hpx::chrono::steady_duration const& duration = + hpx::chrono::null_duration, + std::size_t num_cores = 0) -> decltype(std::declval< hpx::parallel::execution::processing_units_count_t>()( - std::declval(), + std::declval(), std::declval(), std::declval(), 0)) { - return tag(exec.sched_); + return tag(HPX_FORWARD(Parameters, params), exec.sched_, duration, + num_cores); } // NonBlockingOneWayExecutor interface diff --git a/libs/core/executors/include/hpx/executors/sequenced_executor.hpp b/libs/core/executors/include/hpx/executors/sequenced_executor.hpp index 24b774308386..53162b7966ba 100644 --- a/libs/core/executors/include/hpx/executors/sequenced_executor.hpp +++ b/libs/core/executors/include/hpx/executors/sequenced_executor.hpp @@ -185,18 +185,29 @@ namespace hpx::execution { } #if defined(HPX_HAVE_THREAD_DESCRIPTION) - friend constexpr sequenced_executor tag_invoke( + // clang-format off + template + )> + // clang-format on + friend constexpr auto tag_invoke( hpx::execution::experimental::with_annotation_t, - sequenced_executor const& exec, char const* annotation) + Executor_ const& exec, char const* annotation) { auto exec_with_annotation = exec; exec_with_annotation.annotation_ = annotation; return exec_with_annotation; } - friend sequenced_executor tag_invoke( - hpx::execution::experimental::with_annotation_t, - sequenced_executor const& exec, std::string annotation) + // clang-format off + template + )> + // clang-format on + friend auto tag_invoke(hpx::execution::experimental::with_annotation_t, + Executor_ const& exec, std::string annotation) { auto exec_with_annotation = exec; exec_with_annotation.annotation_ = @@ -212,8 +223,14 @@ namespace hpx::execution { } #endif + // clang-format off + template + )> + // clang-format on friend constexpr std::size_t tag_invoke( - hpx::parallel::execution::processing_units_count_t, + hpx::parallel::execution::processing_units_count_t, Parameters&&, sequenced_executor const&, hpx::chrono::steady_duration const& = hpx::chrono::null_duration, std::size_t = 0) diff --git a/libs/core/executors/include/hpx/executors/thread_pool_scheduler.hpp b/libs/core/executors/include/hpx/executors/thread_pool_scheduler.hpp index 888e9abe4d4c..e9d2c7d25ddf 100644 --- a/libs/core/executors/include/hpx/executors/thread_pool_scheduler.hpp +++ b/libs/core/executors/include/hpx/executors/thread_pool_scheduler.hpp @@ -99,18 +99,29 @@ namespace hpx::execution::experimental { return pool_; } - friend constexpr thread_pool_policy_scheduler tag_invoke( + // clang-format off + template + )> + // clang-format on + friend constexpr auto tag_invoke( hpx::parallel::execution::with_processing_units_count_t, - thread_pool_policy_scheduler const& scheduler, - std::size_t num_cores) noexcept + Executor_ const& scheduler, std::size_t num_cores) noexcept { auto scheduler_with_num_cores = scheduler; scheduler_with_num_cores.num_cores_ = num_cores; return scheduler_with_num_cores; } + // clang-format off + template + )> + // clang-format on friend constexpr std::size_t tag_invoke( - hpx::parallel::execution::processing_units_count_t, + hpx::parallel::execution::processing_units_count_t, Parameters&&, thread_pool_policy_scheduler const& scheduler, hpx::chrono::steady_duration const& = hpx::chrono::null_duration, std::size_t = 0) @@ -118,10 +129,15 @@ namespace hpx::execution::experimental { return scheduler.get_num_cores(); } - friend constexpr thread_pool_policy_scheduler tag_invoke( + // clang-format off + template + )> + // clang-format on + friend constexpr auto tag_invoke( hpx::execution::experimental::with_first_core_t, - thread_pool_policy_scheduler const& exec, - std::size_t first_core) noexcept + Executor_ const& exec, std::size_t first_core) noexcept { auto exec_with_first_core = exec; exec_with_first_core.first_core_ = first_core; @@ -137,20 +153,29 @@ namespace hpx::execution::experimental { #if defined(HPX_HAVE_THREAD_DESCRIPTION) // support with_annotation property - friend constexpr thread_pool_policy_scheduler tag_invoke( + // clang-format off + template + )> + // clang-format on + friend constexpr auto tag_invoke( hpx::execution::experimental::with_annotation_t, - thread_pool_policy_scheduler const& scheduler, - char const* annotation) + Executor_ const& scheduler, char const* annotation) { auto sched_with_annotation = scheduler; sched_with_annotation.annotation_ = annotation; return sched_with_annotation; } - friend thread_pool_policy_scheduler tag_invoke( - hpx::execution::experimental::with_annotation_t, - thread_pool_policy_scheduler const& scheduler, - std::string annotation) + // clang-format off + template + )> + // clang-format on + friend auto tag_invoke(hpx::execution::experimental::with_annotation_t, + Executor_ const& scheduler, std::string annotation) { auto sched_with_annotation = scheduler; sched_with_annotation.annotation_ = diff --git a/libs/core/executors/include/hpx/executors/thread_pool_scheduler_bulk.hpp b/libs/core/executors/include/hpx/executors/thread_pool_scheduler_bulk.hpp index 6f5eb98943d5..fb826e25e93f 100644 --- a/libs/core/executors/include/hpx/executors/thread_pool_scheduler_bulk.hpp +++ b/libs/core/executors/include/hpx/executors/thread_pool_scheduler_bulk.hpp @@ -643,7 +643,9 @@ namespace hpx::execution::experimental::detail { , f(HPX_FORWARD(F_, f)) , pu_mask(detail::full_mask( hpx::execution::experimental::get_first_core(scheduler), - hpx::parallel::execution::processing_units_count(scheduler))) + hpx::parallel::execution::processing_units_count( + hpx::parallel::execution::null_parameters, scheduler, + hpx::chrono::null_duration, 0))) { } @@ -740,7 +742,9 @@ namespace hpx::execution::experimental::detail { , first_thread( hpx::execution::experimental::get_first_core(scheduler)) , num_worker_threads( - hpx::parallel::execution::processing_units_count(scheduler)) + hpx::parallel::execution::processing_units_count( + hpx::parallel::execution::null_parameters, scheduler, + hpx::chrono::null_duration, 0)) , pu_mask(HPX_MOVE(pumask)) , queues(num_worker_threads) , shape(HPX_FORWARD(Shape_, shape)) diff --git a/libs/core/executors/tests/regressions/pu_count_6184.cpp b/libs/core/executors/tests/regressions/pu_count_6184.cpp index 825e4a65b959..59a2dfb4fa85 100644 --- a/libs/core/executors/tests/regressions/pu_count_6184.cpp +++ b/libs/core/executors/tests/regressions/pu_count_6184.cpp @@ -16,7 +16,7 @@ int hpx_main() { hpx::parallel::execution::restricted_thread_pool_executor executor{0, 3}; HPX_TEST_EQ(hpx::parallel::execution::processing_units_count(executor), - std::size_t(3)); + static_cast(3)); return hpx::local::finalize(); } diff --git a/libs/core/resiliency/include/hpx/resiliency/replay_executor.hpp b/libs/core/resiliency/include/hpx/resiliency/replay_executor.hpp index 23cecc84c582..8610afa54b58 100644 --- a/libs/core/resiliency/include/hpx/resiliency/replay_executor.hpp +++ b/libs/core/resiliency/include/hpx/resiliency/replay_executor.hpp @@ -43,9 +43,9 @@ namespace hpx::resiliency::experimental { using future_type = hpx::traits::executor_future_t; - template - explicit replay_executor(BaseExecutor& exec, std::size_t n, F&& f) - : exec_(exec) + template + explicit replay_executor(BaseExecutor_&& exec, std::size_t n, F&& f) + : exec_(HPX_FORWARD(BaseExecutor_, exec)) , replay_count_(n) , validator_(HPX_FORWARD(F, f)) { @@ -154,12 +154,60 @@ namespace hpx::resiliency::experimental { } /// \endcond + public: + BaseExecutor const& get_executor() const + { + return exec_; + } + std::size_t get_replay_count() const + { + return replay_count_; + } + Validate const& get_validator() const + { + return validator_; + } + private: - BaseExecutor& exec_; + BaseExecutor exec_; std::size_t replay_count_; Validate validator_; }; + /////////////////////////////////////////////////////////////////////////// + // support all properties exposed by the wrapped executor + // clang-format off + template + )> + // clang-format on + auto tag_invoke(Tag tag, + replay_executor const& exec, Property&& prop) + -> decltype(replay_executor( + std::declval()( + std::declval(), std::declval()), + std::declval(), std::declval())) + { + return replay_executor( + tag(exec.get_executor(), HPX_FORWARD(Property, prop)), + exec.get_replay_count(), exec.get_validator()); + } + + // clang-format off + template + )> + // clang-format on + auto tag_invoke( + Tag tag, replay_executor const& exec) + -> decltype(std::declval()(std::declval())) + { + return tag(exec.get_executor()); + } + /////////////////////////////////////////////////////////////////////////// template replay_executor> make_replay_executor( diff --git a/libs/core/resiliency/include/hpx/resiliency/replicate_executor.hpp b/libs/core/resiliency/include/hpx/resiliency/replicate_executor.hpp index 81f499fd4b28..2fee3fe6eb2e 100644 --- a/libs/core/resiliency/include/hpx/resiliency/replicate_executor.hpp +++ b/libs/core/resiliency/include/hpx/resiliency/replicate_executor.hpp @@ -43,10 +43,10 @@ namespace hpx::resiliency::experimental { using future_type = hpx::traits::executor_future_t; - template + template explicit replicate_executor( - BaseExecutor& exec, std::size_t n, V&& v, F&& f) - : exec_(exec) + BaseExecutor_&& exec, std::size_t n, V&& v, F&& f) + : exec_(HPX_FORWARD(BaseExecutor_, exec)) , replicate_count_(n) , voter_(HPX_FORWARD(V, v)) , validator_(HPX_FORWARD(F, f)) @@ -157,13 +157,68 @@ namespace hpx::resiliency::experimental { } /// \endcond + public: + BaseExecutor const& get_executor() const + { + return exec_; + } + std::size_t get_replicate_count() const + { + return replicate_count_; + } + Vote const& get_voter() const + { + return voter_; + } + Validate const& get_validator() const + { + return validator_; + } + private: - BaseExecutor& exec_; + BaseExecutor exec_; std::size_t replicate_count_; Vote voter_; Validate validator_; }; + /////////////////////////////////////////////////////////////////////////// + // support all properties exposed by the wrapped executor + // clang-format off + template + )> + // clang-format on + auto tag_invoke(Tag tag, + replicate_executor const& exec, + Property&& prop) + -> decltype(replicate_executor( + std::declval()( + std::declval(), std::declval()), + std::declval(), std::declval(), + std::declval())) + { + return replicate_executor( + tag(exec.get_executor(), HPX_FORWARD(Property, prop)), + exec.get_replicate_count(), exec.get_voter(), exec.get_validator()); + } + + // clang-format off + template + )> + // clang-format on + auto tag_invoke( + Tag tag, replicate_executor const& exec) + -> decltype(std::declval()(std::declval())) + { + return tag(exec.get_executor()); + } + /////////////////////////////////////////////////////////////////////////// template replicate_executor, diff --git a/libs/core/tag_invoke/include/hpx/functional/detail/tag_fallback_invoke.hpp b/libs/core/tag_invoke/include/hpx/functional/detail/tag_fallback_invoke.hpp index 3a8c959b934b..801569cef949 100644 --- a/libs/core/tag_invoke/include/hpx/functional/detail/tag_fallback_invoke.hpp +++ b/libs/core/tag_invoke/include/hpx/functional/detail/tag_fallback_invoke.hpp @@ -274,7 +274,7 @@ namespace hpx::functional::detail { Args&&...>>>> HPX_HOST_DEVICE HPX_FORCEINLINE constexpr auto operator()( Args&&... args) const - noexcept(is_nothrow_tag_invocable_v) + noexcept(is_nothrow_tag_invocable_v) -> tag_invoke_result_t { return tag_invoke( @@ -289,7 +289,7 @@ namespace hpx::functional::detail { enable_tag_fallback_invoke_t, Args&&...>>>> HPX_HOST_DEVICE HPX_FORCEINLINE constexpr auto operator()( Args&&... args) const - noexcept(is_nothrow_tag_fallback_invocable_v) + noexcept(is_nothrow_tag_fallback_invocable_v) -> tag_fallback_invoke_result_t { return tag_fallback_invoke( diff --git a/libs/core/tag_invoke/include/hpx/functional/detail/tag_priority_invoke.hpp b/libs/core/tag_invoke/include/hpx/functional/detail/tag_priority_invoke.hpp index d759841102d9..593a93034604 100644 --- a/libs/core/tag_invoke/include/hpx/functional/detail/tag_priority_invoke.hpp +++ b/libs/core/tag_invoke/include/hpx/functional/detail/tag_priority_invoke.hpp @@ -258,7 +258,7 @@ namespace hpx::functional::detail { enable_tag_override_invoke_t, Args&&...>>>> HPX_HOST_DEVICE HPX_FORCEINLINE constexpr auto operator()( Args&&... args) const - noexcept(is_nothrow_tag_override_invocable_v) + noexcept(is_nothrow_tag_override_invocable_v) -> tag_override_invoke_result_t { return tag_override_invoke( @@ -274,7 +274,7 @@ namespace hpx::functional::detail { meta::invoke>>> HPX_HOST_DEVICE HPX_FORCEINLINE constexpr auto operator()( Args&&... args) const - noexcept(is_nothrow_tag_invocable_v) + noexcept(is_nothrow_tag_invocable_v) -> tag_invoke_result_t { return tag_invoke( @@ -292,7 +292,7 @@ namespace hpx::functional::detail { enable_tag_fallback_invoke_t, Args&&...>>>> HPX_HOST_DEVICE HPX_FORCEINLINE constexpr auto operator()( Args&&... args) const - noexcept(is_nothrow_tag_fallback_invocable_v) + noexcept(is_nothrow_tag_fallback_invocable_v) -> tag_fallback_invoke_result_t { return tag_fallback_invoke( diff --git a/libs/core/tag_invoke/include/hpx/functional/tag_invoke.hpp b/libs/core/tag_invoke/include/hpx/functional/tag_invoke.hpp index 08b9cbafef1e..00e8ba48f7a6 100644 --- a/libs/core/tag_invoke/include/hpx/functional/tag_invoke.hpp +++ b/libs/core/tag_invoke/include/hpx/functional/tag_invoke.hpp @@ -237,7 +237,7 @@ namespace hpx::functional { meta::invoke>>> HPX_HOST_DEVICE HPX_FORCEINLINE constexpr auto operator()( Args&&... args) const - noexcept(is_nothrow_tag_invocable_v) + noexcept(is_nothrow_tag_invocable_v) -> tag_invoke_result_t { return tag_invoke( diff --git a/libs/full/checkpoint/examples/1d_stencil_4_checkpoint.cpp b/libs/full/checkpoint/examples/1d_stencil_4_checkpoint.cpp index 7e52a55f9632..9a8fcf5f933d 100644 --- a/libs/full/checkpoint/examples/1d_stencil_4_checkpoint.cpp +++ b/libs/full/checkpoint/examples/1d_stencil_4_checkpoint.cpp @@ -6,25 +6,26 @@ // 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) -// This is the fourth in a series of examples demonstrating the development of -// a fully distributed solver for a simple 1D heat distribution problem. +// This is the fourth in a series of examples demonstrating the development of a +// fully distributed solver for a simple 1D heat distribution problem. // // This example builds on example three. It futurizes the code from that // example. Compared to example two this code runs much more efficiently. It // allows for changing the amount of work executed in one HPX thread which -// enables tuning the performance for the optimal grain size of the -// computation. This example is still fully local but demonstrates nice -// scalability on SMP machines. +// enables tuning the performance for the optimal grain size of the computation. +// This example is still fully local but demonstrates nice scalability on SMP +// machines. // // In this variation of stencil we use the save_checkpoint and -// revive_checkpint functions to back up the state of the application -// every n time steps. +// restore_checkpoint functions to back up the state of the application every n +// time steps. // #include #include #include +#include #include #include #include @@ -63,16 +64,12 @@ inline std::size_t idx(std::size_t i, int dir, std::size_t size) struct partition_data { private: - typedef hpx::serialization::serialize_buffer buffer_type; + using buffer_type = hpx::serialization::serialize_buffer; public: - partition_data() - : data_() - , size_(0) - { - } + partition_data() = default; - partition_data(std::size_t size) + explicit partition_data(std::size_t size) : data_(std::allocator().allocate(size), size, buffer_type::take) , size_(size) { @@ -82,12 +79,12 @@ struct partition_data : data_(std::allocator().allocate(size), size, buffer_type::take) , size_(size) { - double base_value = double(initial_value * size); + double const base_value = static_cast(initial_value * size); for (std::size_t i = 0; i != size; ++i) - data_[i] = base_value + double(i); + data_[i] = base_value + static_cast(i); } - partition_data(const partition_data& old_part) + partition_data(partition_data const& old_part) : data_(std::allocator().allocate(old_part.size()), old_part.size(), buffer_type::take) , size_(old_part.size()) @@ -114,12 +111,12 @@ struct partition_data private: buffer_type data_; - std::size_t size_; + std::size_t size_ = 0; // Serialization Definitions friend class hpx::serialization::access; template - void serialize(Volume& vol, const unsigned int) + void serialize(Volume& vol, unsigned int const) { // clang-format off vol & data_ & size_; @@ -153,12 +150,12 @@ struct backup , file_name_(file_name) { } - backup(backup&& old) + backup(backup&& old) noexcept : bin(std::move(old.bin)) , file_name_(std::move(old.file_name_)) { } - ~backup() {} + ~backup() = default; void save(partition_data const& status, std::size_t index) { @@ -167,9 +164,10 @@ struct backup void write() { - hpx::util::checkpoint archive_data = + hpx::util::checkpoint const archive_data = hpx::util::save_checkpoint(hpx::launch::sync, bin); - // Make sure file stream is bianary for Windows/Mac machines + + // Make sure file stream is binary for Windows/Mac machines std::ofstream file_archive( file_name_, std::ios::binary | std::ios::out); if (file_archive.is_open()) @@ -180,20 +178,19 @@ struct backup { std::cout << "Error opening file!" << std::endl; } - file_archive.close(); } void revive(std::vector>>& U, std::size_t nx) { hpx::util::checkpoint temp_archive; - // Make sure file stream is bianary for Windows/Mac machines + // Make sure file stream is binary for Windows/Mac machines std::ifstream ist(file_name_, std::ios::binary | std::ios::in); ist >> temp_archive; hpx::util::restore_checkpoint(temp_archive, bin); for (std::size_t i = 0; i < U[0].size(); i++) { - partition_data temp(nx, double(i)); + partition_data temp(nx, static_cast(i)); hpx::util::restore_checkpoint(bin[i], temp); //Check for (std::size_t e = 0; e < temp.size(); e++) @@ -206,7 +203,8 @@ struct backup } }; -void print(std::vector>> U) +void print( + std::vector>> const& U) { for (std::size_t out = 0; out < U[0].size(); out++) { @@ -220,7 +218,7 @@ void print(std::vector>> U) } std::cout << std::endl; } -void print_space(std::vector> next) +void print_space(std::vector> const& next) { for (std::size_t out = 0; out < next.size(); out++) { @@ -239,8 +237,8 @@ void print_space(std::vector> next) struct stepper { // Our data for one time step - typedef hpx::shared_future partition; - typedef std::vector space; + using partition = hpx::shared_future; + using space = std::vector; // Our operator static double heat(double left, double middle, double right) @@ -253,7 +251,7 @@ struct stepper static partition_data heat_part(partition_data const& left, partition_data const& middle, partition_data const& right) { - std::size_t size = middle.size(); + std::size_t const size = middle.size(); partition_data next(size); next[0] = heat(left[size - 1], middle[0], middle[1]); @@ -270,8 +268,9 @@ struct stepper // do all the work on 'np' partitions, 'nx' data points each, for 'nt' // time steps, limit depth of dependency tree to 'nd' - hpx::future do_work(std::size_t np, std::size_t nx, std::size_t nt, - std::uint64_t nd, std::uint64_t cp, std::string rsf, std::string fn) + static hpx::future do_work(std::size_t np, std::size_t nx, + std::size_t nt, std::uint64_t nd, std::uint64_t cp, std::string rsf, + std::string fn) { using hpx::dataflow; using hpx::unwrapping; @@ -302,7 +301,8 @@ struct stepper auto range = hpx::util::counting_shape(np); using hpx::execution::par; hpx::ranges::for_each(par, range, [&U, nx](std::size_t i) { - U[0][i] = hpx::make_ready_future(partition_data(nx, double(i))); + U[0][i] = hpx::make_ready_future( + partition_data(nx, static_cast(i))); }); //Initialize from backup @@ -404,16 +404,18 @@ struct stepper /////////////////////////////////////////////////////////////////////////////// int hpx_main(hpx::program_options::variables_map& vm) { - std::uint64_t np = vm["np"].as(); // Number of partitions. - std::uint64_t nx = + std::uint64_t const np = + vm["np"].as(); // Number of partitions. + std::uint64_t const nx = vm["nx"].as(); // Number of grid points. - std::uint64_t nt = vm["nt"].as(); // Number of steps. - std::uint64_t nd = + std::uint64_t const nt = + vm["nt"].as(); // Number of steps. + std::uint64_t const nd = vm["nd"].as(); // Max depth of dep tree. - std::uint64_t cp = + std::uint64_t const cp = vm["cp"].as(); // Num. steps to checkpoint - std::string rsf = vm["restart-file"].as(); - std::string fn = vm["output-file"].as(); + std::string const rsf = vm["restart-file"].as(); + std::string const fn = vm["output-file"].as(); if (vm.count("no-header")) header = false; @@ -422,7 +424,7 @@ int hpx_main(hpx::program_options::variables_map& vm) stepper step; // Measure execution time. - std::uint64_t t = hpx::chrono::high_resolution_clock::now(); + std::uint64_t const t = hpx::chrono::high_resolution_clock::now(); // Execute nt time steps on nx grid points and print the final solution. hpx::future result = @@ -431,7 +433,7 @@ int hpx_main(hpx::program_options::variables_map& vm) stepper::space solution = result.get(); hpx::wait_all(solution); - std::uint64_t elapsed = hpx::chrono::high_resolution_clock::now() - t; + std::uint64_t const elapsed = hpx::chrono::high_resolution_clock::now() - t; // Print the final solution if (vm.count("results")) From 3d39b6e51ab41eabddbb3b08b575d29721d8ac15 Mon Sep 17 00:00:00 2001 From: Hartmut Kaiser Date: Sun, 20 Aug 2023 12:03:02 -0500 Subject: [PATCH 14/25] Fixing test scheduler_priority_check --- .../tests/unit/scheduler_priority_check.cpp | 101 +++++++++++------- 1 file changed, 60 insertions(+), 41 deletions(-) diff --git a/libs/core/resource_partitioner/tests/unit/scheduler_priority_check.cpp b/libs/core/resource_partitioner/tests/unit/scheduler_priority_check.cpp index 7be77c7ebeda..f38853cf81fb 100644 --- a/libs/core/resource_partitioner/tests/unit/scheduler_priority_check.cpp +++ b/libs/core/resource_partitioner/tests/unit/scheduler_priority_check.cpp @@ -32,7 +32,7 @@ void dummy_task(std::size_t n) { // no other work can take place on this thread whilst it sleeps bool sleep = true; - auto start = std::chrono::steady_clock::now(); + auto const start = std::chrono::steady_clock::now(); do { std::this_thread::sleep_for(std::chrono::microseconds(n) / 25); @@ -45,7 +45,7 @@ void dummy_task(std::size_t n) inline std::size_t st_rand() { - return std::size_t(std::rand()); + return static_cast(std::rand()); } int hpx_main(variables_map& vm) @@ -86,25 +86,31 @@ int hpx_main(variables_map& vm) // randomly create normal priority tasks // and then a set of HP tasks in periodic bursts // Use task plotting tools to validate that scheduling is correct - const int np_loop = vm["nnp"].as(); - const int hp_loop = vm["nhp"].as(); - const int np_m = vm["mnp"].as(); - const int hp_m = vm["mhp"].as(); - const int cycles = vm["cycles"].as(); - - const int np_total = np_loop * cycles; - // + int const np_loop = vm["nnp"].as(); + int const hp_loop = vm["nhp"].as(); + int const np_m = vm["mnp"].as(); + int const hp_m = vm["mhp"].as(); + int const cycles = vm["cycles"].as(); + + int const np_total = np_loop * cycles; + struct dec_counter { explicit dec_counter(std::atomic& counter) : counter_(counter) { } + + dec_counter(dec_counter const&) = delete; + dec_counter(dec_counter&&) = delete; + dec_counter& operator=(dec_counter const&) = delete; + dec_counter& operator=(dec_counter&&) = delete; + ~dec_counter() { --counter_; } - // + std::atomic& counter_; }; @@ -113,52 +119,63 @@ int hpx_main(variables_map& vm) std::atomic hp_task_count(0); std::atomic hp_launch_count(0); std::atomic launch_count(0); - // + std::atomic count_down((np_loop + hp_loop) * cycles); std::atomic counter(0); auto f3 = hpx::async(NP_executor, hpx::annotated_function( - [&]() { + [&]() -> hpx::future { ++launch_count; + + std::vector> v; + v.reserve(np_total); for (int i = 0; i < np_total; ++i) { // normal priority - auto f3 = hpx::async(NP_executor, + auto f = hpx::async(NP_executor, hpx::annotated_function( [&, np_m]() { - np_task_count++; + ++np_task_count; dec_counter dec(count_down); - dummy_task(std::size_t(np_m)); + dummy_task(static_cast(np_m)); }, "NP task")); // continuation runs as a sync task - f3.then(hpx::launch::sync, [&](hpx::future&&) { - // on every Nth task, spawn new HP tasks, otherwise quit - if ((++counter) % np_loop != 0) - return; - - // Launch HP tasks using an HP task to do it - hpx::async(HP_executor, - hpx::annotated_function( - [&]() { - ++hp_launch_count; - for (int j = 0; j < hp_loop; ++j) - { - hpx::async(HP_executor, - hpx::annotated_function( - [&]() { - ++hp_task_count; - dec_counter dec(count_down); - dummy_task( - std::size_t(hp_m)); - }, - "HP task")); - } - }, - "Launch HP")); - }); + v.push_back(f.then(hpx::launch::sync, + [&](hpx::future&&) -> hpx::future { + // on every Nth task, spawn new HP tasks, otherwise quit + if ((++counter) % np_loop != 0) + return hpx::make_ready_future(); + + // Launch HP tasks using an HP task to do it + return hpx::async(HP_executor, + hpx::annotated_function( + [&]() -> hpx::future { + ++hp_launch_count; + + std::vector> v1; + v1.reserve(hp_loop); + for (int j = 0; j < hp_loop; ++j) + { + v1.push_back(hpx::async(HP_executor, + hpx::annotated_function( + [&]() { + ++hp_task_count; + dec_counter dec( + count_down); + dummy_task(static_cast< + std::size_t>(hp_m)); + }, + "HP task"))); + } + return hpx::when_all(std::move(v1)); + }, + "Launch HP")); + })); } + + return hpx::when_all(std::move(v)); }, "Launch")); @@ -168,6 +185,8 @@ int hpx_main(variables_map& vm) hpx::this_thread::yield(); } while (count_down > 0); + f3.get(); + std::cout << "Tasks NP : " << np_task_count << "\n" << "Tasks HP : " << hp_task_count << "\n" << "Launch : " << launch_count << "\n" From 7f61e4cd00d1e1a76d4c624cfe60c4a27bedabdd Mon Sep 17 00:00:00 2001 From: Hartmut Kaiser Date: Sat, 22 Oct 2022 14:23:46 -0500 Subject: [PATCH 15/25] Investigating partitioned_vector problems - flyby: reduce the need for make_ready_future for various AGAS operations --- .../partitioned_vector_component_impl.hpp | 6 +- .../partitioned_vector_decl.hpp | 2 +- .../partitioned_vector_impl.hpp | 12 +- .../partitioned_vector_segmented_iterator.hpp | 2 +- examples/throttle/spin.cpp | 3 +- libs/core/futures/CMakeLists.txt | 1 + .../include/hpx/futures/future_or_value.hpp | 71 +++++++++++ .../lcos_local/detail/preprocess_future.hpp | 10 ++ .../include/hpx/actions/transfer_action.hpp | 12 +- .../include/hpx/agas/addressing_service.hpp | 33 ++++-- libs/full/agas/src/addressing_service.cpp | 112 ++++++++++++------ libs/full/agas/src/detail/interface.cpp | 43 +++---- .../hpx/agas_base/primary_namespace.hpp | 11 +- libs/full/agas_base/src/primary_namespace.cpp | 27 +++-- .../src/server/symbol_namespace_server.cpp | 36 +++--- .../hpx/async_colocated/get_colocation_id.hpp | 4 +- .../async_colocated/src/get_colocation_id.cpp | 10 +- .../hpx/async_distributed/put_parcel.hpp | 27 ++++- .../include/hpx/components/client_base.hpp | 10 +- .../include/hpx/components/get_ptr.hpp | 86 +++++++++++--- libs/full/components/src/client_base.cpp | 2 +- .../hpx/components_base/agas_interface.hpp | 10 +- .../detail/agas_interface_functions.hpp | 11 +- .../components_base/src/agas_interface.cpp | 26 +++- .../src/detail/agas_interface_functions.cpp | 13 +- .../naming/include/hpx/naming/split_gid.hpp | 12 +- libs/full/naming/src/credit_handling.cpp | 76 +++++++++--- .../tests/unit/agas/local_address_rebind.cpp | 11 +- .../partitioned_vector_inclusive_scan.cpp | 5 +- .../tests/unit/partitioned_vector_scan.hpp | 4 +- 30 files changed, 483 insertions(+), 205 deletions(-) create mode 100644 libs/core/futures/include/hpx/futures/future_or_value.hpp diff --git a/components/containers/partitioned_vector/include/hpx/components/containers/partitioned_vector/partitioned_vector_component_impl.hpp b/components/containers/partitioned_vector/include/hpx/components/containers/partitioned_vector/partitioned_vector_component_impl.hpp index 944690fb987c..a2c139ca5dab 100644 --- a/components/containers/partitioned_vector/include/hpx/components/containers/partitioned_vector/partitioned_vector_component_impl.hpp +++ b/components/containers/partitioned_vector/include/hpx/components/containers/partitioned_vector/partitioned_vector_component_impl.hpp @@ -1,5 +1,5 @@ // Copyright (c) 2014 Anuj R. Sharma -// Copyright (c) 2014-2017 Hartmut Kaiser +// Copyright (c) 2014-2022 Hartmut Kaiser // // SPDX-License-Identifier: BSL-1.0 // Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -339,8 +339,8 @@ namespace hpx { partitioned_vector_partition::get_ptr() const { error_code ec(throwmode::lightweight); - return hpx::get_ptr>(this->get_id()) - .get(ec); + return hpx::get_ptr>( + hpx::launch::sync, this->get_id(), ec); } template */> diff --git a/components/containers/partitioned_vector/include/hpx/components/containers/partitioned_vector/partitioned_vector_decl.hpp b/components/containers/partitioned_vector/include/hpx/components/containers/partitioned_vector/partitioned_vector_decl.hpp index 17c2d2122213..0e9afacaa09f 100644 --- a/components/containers/partitioned_vector/include/hpx/components/containers/partitioned_vector/partitioned_vector_decl.hpp +++ b/components/containers/partitioned_vector/include/hpx/components/containers/partitioned_vector/partitioned_vector_decl.hpp @@ -1,5 +1,5 @@ // Copyright (c) 2014 Anuj R. Sharma -// Copyright (c) 2014-2017 Hartmut Kaiser +// Copyright (c) 2014-2022 Hartmut Kaiser // // SPDX-License-Identifier: BSL-1.0 // Distributed under the Boost Software License, Version 1.0. (See accompanying diff --git a/components/containers/partitioned_vector/include/hpx/components/containers/partitioned_vector/partitioned_vector_impl.hpp b/components/containers/partitioned_vector/include/hpx/components/containers/partitioned_vector/partitioned_vector_impl.hpp index d06bbe53c72d..bce6ca1d2229 100644 --- a/components/containers/partitioned_vector/include/hpx/components/containers/partitioned_vector/partitioned_vector_impl.hpp +++ b/components/containers/partitioned_vector/include/hpx/components/containers/partitioned_vector/partitioned_vector_impl.hpp @@ -1,5 +1,5 @@ // Copyright (c) 2014 Anuj R. Sharma -// Copyright (c) 2014-2017 Hartmut Kaiser +// Copyright (c) 2014-2022 Hartmut Kaiser // // SPDX-License-Identifier: BSL-1.0 // Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -73,6 +72,7 @@ namespace hpx { std::uint32_t this_locality = get_locality_id(); std::vector> ptrs; + ptrs.reserve(partitions_.size()); typedef typename partitions_vector_type::const_iterator const_iterator; @@ -346,6 +346,7 @@ namespace hpx { // now initialize our data structures std::uint32_t this_locality = get_locality_id(); std::vector> ptrs; + ptrs.reserve(num_parts); std::size_t num_part = 0; std::size_t allocated_size = 0; @@ -397,7 +398,7 @@ namespace hpx { } HPX_ASSERT(l == num_parts); - hpx::when_all(ptrs).get(); + hpx::wait_all(ptrs); // cache our partition size partition_size_ = get_partition_size(); @@ -440,11 +441,12 @@ namespace hpx { std::uint32_t this_locality = get_locality_id(); std::vector> ptrs; + ptrs.reserve(rhs.partitions_.size()); - partitions_vector_type partitions; // Fixing the size of partitions to avoid race conditions between // possible reallocations during push back and the continuation // to set the local partition data + partitions_vector_type partitions; partitions.resize(rhs.partitions_.size()); for (std::size_t i = 0; i != rhs.partitions_.size(); ++i) { @@ -461,7 +463,7 @@ namespace hpx { } } - hpx::when_all(ptrs).get(); + hpx::wait_all(ptrs); size_ = rhs.size_; partition_size_ = rhs.partition_size_; diff --git a/components/containers/partitioned_vector/include/hpx/components/containers/partitioned_vector/partitioned_vector_segmented_iterator.hpp b/components/containers/partitioned_vector/include/hpx/components/containers/partitioned_vector/partitioned_vector_segmented_iterator.hpp index 0c5571fbe041..86693f038c23 100644 --- a/components/containers/partitioned_vector/include/hpx/components/containers/partitioned_vector/partitioned_vector_segmented_iterator.hpp +++ b/components/containers/partitioned_vector/include/hpx/components/containers/partitioned_vector/partitioned_vector_segmented_iterator.hpp @@ -1,5 +1,5 @@ // Copyright (c) 2014 Anuj R. Sharma -// Copyright (c) 2014-2016 Hartmut Kaiser +// Copyright (c) 2014-2022 Hartmut Kaiser // // SPDX-License-Identifier: BSL-1.0 // Distributed under the Boost Software License, Version 1.0. (See accompanying diff --git a/examples/throttle/spin.cpp b/examples/throttle/spin.cpp index 7ccc45a6a07b..06631248f42e 100644 --- a/examples/throttle/spin.cpp +++ b/examples/throttle/spin.cpp @@ -47,7 +47,8 @@ int hpx_main() for (id_type const& locality_ : localities) { - address addr = hpx::agas::resolve(locality_).get(); + address addr = + hpx::agas::resolve(hpx::launch::sync, locality_); hpx::util::format_to(std::cout, " [{1}] {2}\n", get_locality_id_from_gid(locality_.get_gid()), diff --git a/libs/core/futures/CMakeLists.txt b/libs/core/futures/CMakeLists.txt index f914351c40d4..a7b48127e601 100644 --- a/libs/core/futures/CMakeLists.txt +++ b/libs/core/futures/CMakeLists.txt @@ -11,6 +11,7 @@ set(futures_headers hpx/futures/future.hpp hpx/futures/future_fwd.hpp hpx/futures/futures_factory.hpp + hpx/futures/future_or_value.hpp hpx/futures/detail/future_data.hpp hpx/futures/detail/future_transforms.hpp hpx/futures/packaged_continuation.hpp diff --git a/libs/core/futures/include/hpx/futures/future_or_value.hpp b/libs/core/futures/include/hpx/futures/future_or_value.hpp new file mode 100644 index 000000000000..31af55ae0651 --- /dev/null +++ b/libs/core/futures/include/hpx/futures/future_or_value.hpp @@ -0,0 +1,71 @@ +// Copyright (c) 2022 Hartmut Kaiser +// +// SPDX-License-Identifier: BSL-1.0 +// 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) + +#pragma once + +#include +#include +#include + +namespace hpx { + + template + struct future_or_value + { + future_or_value(T const& value) + : data(value) + { + } + + future_or_value(T&& value) noexcept + : data(HPX_MOVE(value)) + { + } + + future_or_value(hpx::future&& value) noexcept + : data(HPX_MOVE(value)) + { + } + + constexpr bool has_value() const noexcept + { + return hpx::holds_alternative(data); + } + constexpr bool has_future() const noexcept + { + return hpx::holds_alternative>(data); + } + + T& get_value() & + { + return hpx::get(data); + } + T const& get_value() const& + { + return hpx::get(data); + } + T&& get_value() && + { + return hpx::get(HPX_MOVE(data)); + } + + hpx::future& get_future() & + { + return hpx::get>(data); + } + hpx::future const& get_future() const& + { + return hpx::get>(data); + } + hpx::future&& get_future() && + { + return hpx::get>(HPX_MOVE(data)); + } + + private: + hpx::variant> data; + }; +} // namespace hpx diff --git a/libs/core/lcos_local/include/hpx/lcos_local/detail/preprocess_future.hpp b/libs/core/lcos_local/include/hpx/lcos_local/detail/preprocess_future.hpp index b0774571dc9e..9fa015d211a3 100644 --- a/libs/core/lcos_local/include/hpx/lcos_local/detail/preprocess_future.hpp +++ b/libs/core/lcos_local/include/hpx/lcos_local/detail/preprocess_future.hpp @@ -123,6 +123,16 @@ namespace hpx::serialization::detail { ++num_futures_; } + void decrement_future_count() + { + std::lock_guard l(mtx_); + HPX_ASSERT(num_futures_ > 0); + if (--num_futures_ == 0) + { + done_ = true; + } + } + void reset() { std::lock_guard l(mtx_); diff --git a/libs/full/actions/include/hpx/actions/transfer_action.hpp b/libs/full/actions/include/hpx/actions/transfer_action.hpp index 52ee265ea866..d80bd6a33d50 100644 --- a/libs/full/actions/include/hpx/actions/transfer_action.hpp +++ b/libs/full/actions/include/hpx/actions/transfer_action.hpp @@ -223,16 +223,14 @@ namespace hpx::actions { { // If this is a direct action and deferred schedule was requested, // that is we are not the last parcel, return immediately - if (base_type::direct_execution::value) + if constexpr (base_type::direct_execution::value) { return; } - else - { - // If this is not a direct action, we can safely set - // deferred_schedule to false - deferred_schedule = false; - } + + // If this is not a direct action, we can safely set + // deferred_schedule to false + deferred_schedule = false; } schedule_thread(HPX_MOVE(target), lva, comptype, num_thread); diff --git a/libs/full/agas/include/hpx/agas/addressing_service.hpp b/libs/full/agas/include/hpx/agas/addressing_service.hpp index c7b4e1e3163e..400d491ae522 100644 --- a/libs/full/agas/include/hpx/agas/addressing_service.hpp +++ b/libs/full/agas/include/hpx/agas/addressing_service.hpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -177,7 +178,7 @@ namespace hpx { namespace agas { void garbage_collect(error_code& ec = throws); static std::int64_t synchronize_with_async_incref( - hpx::future fut, hpx::id_type const& id, + std::int64_t old_credit, hpx::id_type const& id, std::int64_t compensated_credit); server::primary_namespace& get_local_primary_namespace_service() @@ -221,7 +222,7 @@ namespace hpx { namespace agas { util::runtime_configuration& rtcfg); naming::address resolve_full_postproc(naming::gid_type const& id, - future f); + primary_namespace::resolved_type const&); bool bind_postproc( naming::gid_type const& id, gva const& g, future f); @@ -856,15 +857,17 @@ namespace hpx { namespace agas { } /////////////////////////////////////////////////////////////////////////// - hpx::future resolve_async(naming::gid_type const& id); + hpx::future_or_value resolve_async( + naming::gid_type const& id); - hpx::future resolve_async(hpx::id_type const& id) + hpx::future_or_value resolve_async( + hpx::id_type const& id) { return resolve_async(id.get_gid()); } /////////////////////////////////////////////////////////////////////////// - hpx::future get_colocation_id_async( + hpx::future_or_value get_colocation_id_async( hpx::id_type const& id); /////////////////////////////////////////////////////////////////////////// @@ -893,10 +896,11 @@ namespace hpx { namespace agas { return addr; } - hpx::future resolve_full_async( + hpx::future_or_value resolve_full_async( naming::gid_type const& id); - hpx::future resolve_full_async(hpx::id_type const& id) + hpx::future_or_value resolve_full_async( + hpx::id_type const& id) { return resolve_full_async(id.get_gid()); } @@ -978,14 +982,25 @@ namespace hpx { namespace agas { /// throw but returns the result code using the /// parameter \a ec. Otherwise it throws an instance /// of hpx#exception. - hpx::future incref_async(naming::gid_type const& gid, + hpx::future_or_value incref_async( + naming::gid_type const& gid, std::int64_t credits = 1, + hpx::id_type const& keep_alive = hpx::invalid_id); + + /// \cond NOINTERN + std::int64_t incref_async_helper(naming::gid_type const& gid, std::int64_t credits = 1, hpx::id_type const& keep_alive = hpx::invalid_id); + /// \endcond std::int64_t incref(naming::gid_type const& gid, std::int64_t credits = 1, error_code& ec = throws) { - return incref_async(gid, credits).get(ec); + auto result = incref_async(gid, credits); + if (result.has_value()) + { + return HPX_MOVE(result).get_value(); + } + return result.get_future().get(ec); } /// \brief Decrement the global reference count for the given id diff --git a/libs/full/agas/src/addressing_service.cpp b/libs/full/agas/src/addressing_service.cpp index d4a7a1a0a238..c36106c4884c 100644 --- a/libs/full/agas/src/addressing_service.cpp +++ b/libs/full/agas/src/addressing_service.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -291,7 +292,8 @@ namespace hpx::agas { } } - // Search again ... might have been added by a different thread already + // Search again ... might have been added by a different thread + // already it = resolved_localities_.find(gid); if (it == resolved_localities_.end()) { @@ -315,8 +317,8 @@ namespace hpx::agas { return it->second; } - // TODO: We need to ensure that the locality isn't unbound while it still holds - // referenced objects. + // TODO: We need to ensure that the locality isn't unbound while it still + // holds referenced objects. bool addressing_service::unregister_locality( naming::gid_type const& gid, error_code& ec) { @@ -1058,13 +1060,14 @@ namespace hpx::agas { return false; } - hpx::future addressing_service::resolve_async( + hpx::future_or_value addressing_service::resolve_async( naming::gid_type const& gid) { if (!gid) { HPX_THROW_EXCEPTION(hpx::error::bad_parameter, "addressing_service::resolve_async", "invalid reference id"); + return naming::address(); } // Try the cache. @@ -1073,7 +1076,9 @@ namespace hpx::agas { naming::address addr; error_code ec; if (resolve_cached(gid, addr, ec)) - return make_ready_future(addr); + { + return addr; + } if (ec) { @@ -1086,7 +1091,7 @@ namespace hpx::agas { return resolve_full_async(gid); } - hpx::future addressing_service::get_colocation_id_async( + hpx::future_or_value addressing_service::get_colocation_id_async( hpx::id_type const& id) { if (!id) @@ -1094,6 +1099,7 @@ namespace hpx::agas { HPX_THROW_EXCEPTION(hpx::error::bad_parameter, "addressing_service::get_colocation_id_async", "invalid reference id"); + return hpx::invalid_id; } return primary_ns_.colocate(id.get_gid()); @@ -1101,15 +1107,12 @@ namespace hpx::agas { /////////////////////////////////////////////////////////////////////////// naming::address addressing_service::resolve_full_postproc( - naming::gid_type const& id, future f) + naming::gid_type const& id, primary_namespace::resolved_type const& rep) { - using hpx::get; - naming::address addr; - auto rep = f.get(); - if (get<0>(rep) == naming::invalid_gid || - get<2>(rep) == naming::invalid_gid) + if (hpx::get<0>(rep) == naming::invalid_gid || + hpx::get<2>(rep) == naming::invalid_gid) { HPX_THROW_EXCEPTION(hpx::error::bad_parameter, "addressing_service::resolve_full_postproc", @@ -1118,8 +1121,8 @@ namespace hpx::agas { // Resolve the gva to the real resolved address (which is just a gva // with as fully resolved LVA and and offset of zero). - naming::gid_type const base_gid = get<0>(rep); - gva const base_gva = get<1>(rep); + naming::gid_type const base_gid = hpx::get<0>(rep); + gva const base_gva = hpx::get<1>(rep); gva const g = base_gva.resolve(id, base_gid); @@ -1144,23 +1147,37 @@ namespace hpx::agas { return addr; } - hpx::future addressing_service::resolve_full_async( - naming::gid_type const& gid) + hpx::future_or_value + addressing_service::resolve_full_async(naming::gid_type const& gid) { if (!gid) { HPX_THROW_EXCEPTION(hpx::error::bad_parameter, "addressing_service::resolve_full_async", "invalid reference id"); + return naming::address(); } // ask server - future f = - primary_ns_.resolve_full(gid); + auto result = primary_ns_.resolve_full(gid); - return f.then(hpx::launch::sync, - util::one_shot(hpx::bind_front( - &addressing_service::resolve_full_postproc, this, gid))); + if (result.has_value()) + { + try + { + return resolve_full_postproc(gid, result.get_value()); + } + catch (...) + { + return hpx::make_exceptional_future( + std::current_exception()); + } + } + + return result.get_future().then( + hpx::launch::sync, [this, gid](auto&& f) { + return resolve_full_postproc(gid, f.get()); + }); } /////////////////////////////////////////////////////////////////////////// @@ -1301,26 +1318,38 @@ namespace hpx::agas { // incref was sent. The pending decref was subtracted from the amount of // credits to incref. std::int64_t addressing_service::synchronize_with_async_incref( - hpx::future fut, hpx::id_type const&, + std::int64_t old_credit, hpx::id_type const&, std::int64_t compensated_credit) { - return fut.get() + compensated_credit; + return old_credit + compensated_credit; } - hpx::future addressing_service::incref_async( + std::int64_t addressing_service::incref_async_helper( naming::gid_type const& id, std::int64_t credit, hpx::id_type const& keep_alive) { + auto result = incref_async(id, credit, keep_alive); + if (result.has_value()) + { + return HPX_MOVE(result).get_value(); + } + return result.get_future().get(); + } + + hpx::future_or_value addressing_service::incref_async( + naming::gid_type const& id, std::int64_t credit, + hpx::id_type const& keep_alive) + { // {{{ incref implementation naming::gid_type raw(naming::detail::get_stripped_gid(id)); if (HPX_UNLIKELY(nullptr == threads::get_self_ptr())) { // reschedule this call as an HPX thread - hpx::future (addressing_service::*incref_async_ptr)( + std::int64_t (addressing_service::*incref_async_ptr)( naming::gid_type const&, std::int64_t, hpx::id_type const&) = - &addressing_service::incref_async; + &addressing_service::incref_async_helper; - return async(incref_async_ptr, this, raw, credit, keep_alive); + return hpx::async(incref_async_ptr, this, raw, credit, keep_alive); } if (HPX_UNLIKELY(0 >= credit)) @@ -1328,6 +1357,7 @@ namespace hpx::agas { HPX_THROW_EXCEPTION(hpx::error::bad_parameter, "addressing_service::incref_async", "invalid credit count of {1}", credit); + return std::int64_t(-1); } HPX_ASSERT(keep_alive != hpx::invalid_id); @@ -1390,23 +1420,29 @@ namespace hpx::agas { } } + // no need to talk to AGAS, acknowledge the incref immediately if (!has_pending_incref) { - // no need to talk to AGAS, acknowledge the incref immediately - return hpx::make_ready_future(pending_decrefs); + return pending_decrefs; } naming::gid_type const e_lower = pending_incref.first; - - hpx::future f = primary_ns_.increment_credit( + auto result = primary_ns_.increment_credit( pending_incref.second, e_lower, e_lower); // pass the amount of compensated decrefs to the callback - return f.then(hpx::launch::sync, - util::one_shot( - hpx::bind(&addressing_service::synchronize_with_async_incref, - hpx::placeholders::_1, keep_alive, pending_decrefs))); - } + if (result.has_value()) + { + return synchronize_with_async_incref( + result.get_value(), keep_alive, pending_decrefs); + } + + return result.get_future().then( + hpx::launch::sync, [keep_alive, pending_decrefs](auto&& f) { + return synchronize_with_async_incref( + f.get(), keep_alive, pending_decrefs); + }); + } // }}} /////////////////////////////////////////////////////////////////////////// void addressing_service::decref( @@ -1509,7 +1545,7 @@ namespace hpx::agas { // We need to modify the reference count. naming::gid_type& mutable_gid = const_cast(id).get_gid(); naming::gid_type const new_gid = - naming::detail::split_gid_if_needed(mutable_gid).get(); + naming::detail::split_gid_if_needed(hpx::launch::sync, mutable_gid); std::int64_t const new_credit = naming::detail::get_credit_from_gid(new_gid); @@ -1534,7 +1570,7 @@ namespace hpx::agas { // We need to modify the reference count. naming::gid_type& mutable_gid = const_cast(id).get_gid(); naming::gid_type const new_gid = - naming::detail::split_gid_if_needed(mutable_gid).get(); + naming::detail::split_gid_if_needed(hpx::launch::sync, mutable_gid); std::int64_t new_credit = naming::detail::get_credit_from_gid(new_gid); future f = symbol_ns_.bind_async(name, new_gid); diff --git a/libs/full/agas/src/detail/interface.cpp b/libs/full/agas/src/detail/interface.cpp index 727b8f970c85..e9e1cd63567e 100644 --- a/libs/full/agas/src/detail/interface.cpp +++ b/libs/full/agas/src/detail/interface.cpp @@ -10,8 +10,8 @@ #include #include #include -#include -#include +#include +#include #include #include @@ -154,14 +154,19 @@ namespace hpx::agas::detail::impl { } /////////////////////////////////////////////////////////////////////////// - hpx::future resolve_async(hpx::id_type const& id) + hpx::future_or_value resolve_async(hpx::id_type const& id) { return naming::get_agas_client().resolve_async(id); } naming::address resolve(hpx::id_type const& id, error_code& ec) { - return naming::get_agas_client().resolve_async(id).get(ec); + auto result = naming::get_agas_client().resolve_async(id); + if (result.has_value()) + { + return HPX_MOVE(result).get_value(); + } + return result.get_future().get(ec); } bool resolve_local( @@ -396,13 +401,12 @@ namespace hpx::agas::detail::impl { } /////////////////////////////////////////////////////////////////////////// - hpx::future incref_async(naming::gid_type const& gid, + hpx::future_or_value incref_async(naming::gid_type const& gid, std::int64_t credits, hpx::id_type const& keep_alive_) { HPX_ASSERT(!naming::detail::is_locked(gid)); naming::resolver_client& resolver = naming::get_agas_client(); - if (keep_alive_) return resolver.incref_async(gid, credits, keep_alive_); @@ -411,31 +415,21 @@ namespace hpx::agas::detail::impl { return resolver.incref_async(gid, credits, keep_alive); } - std::int64_t incref(naming::gid_type const& gid, std::int64_t credits, - hpx::id_type const& keep_alive_, error_code&) - { - HPX_ASSERT(!naming::detail::is_locked(gid)); - - naming::resolver_client& resolver = naming::get_agas_client(); - - if (keep_alive_) - { - return resolver.incref_async(gid, credits, keep_alive_).get(); - } - hpx::id_type const keep_alive = - hpx::id_type(gid, hpx::id_type::management_type::unmanaged); - return resolver.incref_async(gid, credits, keep_alive).get(); - } - /////////////////////////////////////////////////////////////////////////// - hpx::future get_colocation_id_async(hpx::id_type const& id) + hpx::future_or_value get_colocation_id_async( + hpx::id_type const& id) { return naming::get_agas_client().get_colocation_id_async(id); } hpx::id_type get_colocation_id(hpx::id_type const& id, error_code& ec) { - return get_colocation_id_async(id).get(ec); + auto result = get_colocation_id_async(id); + if (result.has_value()) + { + return HPX_MOVE(result).get_value(); + } + return result.get_future().get(ec); } /////////////////////////////////////////////////////////////////////////// @@ -616,7 +610,6 @@ namespace hpx::agas { detail::decref = &detail::impl::decref; detail::incref_async = &detail::impl::incref_async; - detail::incref = &detail::impl::incref; detail::get_colocation_id_async = &detail::impl::get_colocation_id_async; diff --git a/libs/full/agas_base/include/hpx/agas_base/primary_namespace.hpp b/libs/full/agas_base/include/hpx/agas_base/primary_namespace.hpp index 993ff5b4c7f9..1a2afc353c30 100644 --- a/libs/full/agas_base/include/hpx/agas_base/primary_namespace.hpp +++ b/libs/full/agas_base/include/hpx/agas_base/primary_namespace.hpp @@ -1,5 +1,6 @@ //////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2016 Thomas Heller +// Copyright (c) 2022 Hartmut Kaiser // // SPDX-License-Identifier: BSL-1.0 // Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -11,8 +12,8 @@ #include #include #include -#include -#include +#include +#include #include #include @@ -72,16 +73,16 @@ namespace hpx { namespace agas { #endif resolved_type resolve_gid(naming::gid_type const& id); - future resolve_full(naming::gid_type id); + hpx::future_or_value resolve_full(naming::gid_type id); - future colocate(naming::gid_type id); + hpx::future_or_value colocate(naming::gid_type id); naming::address unbind_gid( std::uint64_t count, naming::gid_type const& id); future unbind_gid_async( std::uint64_t count, naming::gid_type const& id); - future increment_credit(std::int64_t credits, + future_or_value increment_credit(std::int64_t credits, naming::gid_type lower, naming::gid_type upper); std::pair allocate( diff --git a/libs/full/agas_base/src/primary_namespace.cpp b/libs/full/agas_base/src/primary_namespace.cpp index 1793bb16dc73..3d5a3bfd7d89 100644 --- a/libs/full/agas_base/src/primary_namespace.cpp +++ b/libs/full/agas_base/src/primary_namespace.cpp @@ -1,5 +1,6 @@ //////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2016 Thomas Heller +// Copyright (c) 2022 Hartmut Kaiser // // SPDX-License-Identifier: BSL-1.0 // Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -15,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -238,40 +240,43 @@ namespace hpx { namespace agas { return server_->resolve_gid(id); } - future primary_namespace::resolve_full( - naming::gid_type id) + hpx::future_or_value + primary_namespace::resolve_full(naming::gid_type id) { hpx::id_type dest = hpx::id_type( get_service_instance(id), hpx::id_type::management_type::unmanaged); if (naming::get_locality_id_from_id(dest) == agas::get_locality_id()) { - return hpx::make_ready_future(server_->resolve_gid(id)); + return server_->resolve_gid(id); } + #if !defined(HPX_COMPUTE_DEVICE_CODE) server::primary_namespace::resolve_gid_action action; return hpx::async(action, HPX_MOVE(dest), id); #else HPX_ASSERT(false); - return hpx::make_ready_future(primary_namespace::resolved_type{}); + return primary_namespace::resolved_type{}; #endif } - hpx::future primary_namespace::colocate(naming::gid_type id) + hpx::future_or_value primary_namespace::colocate( + naming::gid_type id) { hpx::id_type dest = hpx::id_type( get_service_instance(id), hpx::id_type::management_type::unmanaged); if (naming::get_locality_id_from_id(dest) == agas::get_locality_id()) { - return hpx::make_ready_future(server_->colocate(id)); + return server_->colocate(id); } + #if !defined(HPX_COMPUTE_DEVICE_CODE) server::primary_namespace::colocate_action action; return hpx::async(action, HPX_MOVE(dest), id); #else HPX_ASSERT(false); - return hpx::make_ready_future(hpx::invalid_id); + return hpx::invalid_id; #endif } @@ -316,7 +321,7 @@ namespace hpx { namespace agas { #endif } - future primary_namespace::increment_credit( + future_or_value primary_namespace::increment_credit( std::int64_t credits, naming::gid_type lower, naming::gid_type upper) { hpx::id_type dest = hpx::id_type(get_service_instance(lower), @@ -324,15 +329,15 @@ namespace hpx { namespace agas { if (naming::get_locality_id_from_id(dest) == agas::get_locality_id()) { - return hpx::make_ready_future( - server_->increment_credit(credits, lower, upper)); + return server_->increment_credit(credits, lower, upper); } + #if !defined(HPX_COMPUTE_DEVICE_CODE) server::primary_namespace::increment_credit_action action; return hpx::async(action, HPX_MOVE(dest), credits, lower, upper); #else HPX_ASSERT(false); - return hpx::make_ready_future(std::int64_t{}); + return std::int64_t(-1); #endif } diff --git a/libs/full/agas_base/src/server/symbol_namespace_server.cpp b/libs/full/agas_base/src/server/symbol_namespace_server.cpp index 3c0eedd171b2..a30561eea37a 100644 --- a/libs/full/agas_base/src/server/symbol_namespace_server.cpp +++ b/libs/full/agas_base/src/server/symbol_namespace_server.cpp @@ -91,7 +91,7 @@ namespace hpx::agas::server { naming::gid_type gid = gid_; - gid_table_type::iterator const it = gids_.find(key); + auto const it = gids_.find(key); if (auto const end = gids_.end(); it != end) { std::int64_t const credits = @@ -155,7 +155,7 @@ namespace hpx::agas::server { auto iter = first; while (iter != last) { - lcos.push_back((*iter).second); + lcos.push_back(iter->second); ++iter; } @@ -187,7 +187,8 @@ namespace hpx::agas::server { // split the credit as the receiving end will expect to keep // the object alive naming::gid_type new_gid = - naming::detail::split_gid_if_needed(*current_gid).get(); + naming::detail::split_gid_if_needed( + hpx::launch::sync, *current_gid); // trigger the lco set_lco_value(id, new_gid); @@ -216,7 +217,7 @@ namespace hpx::agas::server { std::unique_lock l(mutex_); - gid_table_type::iterator const it = gids_.find(key); + auto const it = gids_.find(key); if (auto const end = gids_.end(); it == end) { l.unlock(); @@ -233,8 +234,8 @@ namespace hpx::agas::server { l.unlock(); - naming::gid_type gid = - naming::detail::split_gid_if_needed(*current_gid).get(); + naming::gid_type gid = naming::detail::split_gid_if_needed( + hpx::launch::sync, *current_gid); LAGAS_(info).format("symbol_namespace::resolve, key({1}), " "stored_gid({2}), gid({3})", @@ -292,33 +293,33 @@ namespace hpx::agas::server { std::regex const rx(str_rx); std::unique_lock l(mutex_); - for (auto it = gids_.begin(); it != gids_.end(); ++it) + for (auto& gid : gids_) { - if (!std::regex_match(it->first, rx)) + if (!std::regex_match(gid.first, rx)) continue; // hold on to entry while map is unlocked - std::shared_ptr current_gid(it->second); + std::shared_ptr current_gid(gid.second); unlock_guard> ul(l); - found[it->first] = - naming::detail::split_gid_if_needed(*current_gid).get(); + found[gid.first] = naming::detail::split_gid_if_needed( + hpx::launch::sync, *current_gid); } } else { std::unique_lock l(mutex_); - for (auto it = gids_.begin(); it != gids_.end(); ++it) + for (auto& gid : gids_) { - if (!pattern.empty() && pattern != it->first) + if (!pattern.empty() && pattern != gid.first) continue; // hold on to entry while map is unlocked - std::shared_ptr current_gid(it->second); + std::shared_ptr current_gid(gid.second); unlock_guard> ul(l); - found[it->first] = - naming::detail::split_gid_if_needed(*current_gid).get(); + found[gid.first] = naming::detail::split_gid_if_needed( + hpx::launch::sync, *current_gid); } } @@ -351,7 +352,8 @@ namespace hpx::agas::server { unlock_guard> ul(l); naming::gid_type new_gid = - naming::detail::split_gid_if_needed(*current_gid).get(); + naming::detail::split_gid_if_needed( + hpx::launch::sync, *current_gid); // trigger the lco handled = true; diff --git a/libs/full/async_colocated/include/hpx/async_colocated/get_colocation_id.hpp b/libs/full/async_colocated/include/hpx/async_colocated/get_colocation_id.hpp index e48f1fe757ff..a434294d6154 100644 --- a/libs/full/async_colocated/include/hpx/async_colocated/get_colocation_id.hpp +++ b/libs/full/async_colocated/include/hpx/async_colocated/get_colocation_id.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2007-2020 Hartmut Kaiser +// Copyright (c) 2007-2022 Hartmut Kaiser // Copyright (c) 2011 Bryce Lelbach // // SPDX-License-Identifier: BSL-1.0 @@ -9,8 +9,8 @@ #pragma once -#include #include +#include #include #include diff --git a/libs/full/async_colocated/src/get_colocation_id.cpp b/libs/full/async_colocated/src/get_colocation_id.cpp index 9a3c85dd87d1..fa6b48a1bffb 100644 --- a/libs/full/async_colocated/src/get_colocation_id.cpp +++ b/libs/full/async_colocated/src/get_colocation_id.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include namespace hpx { @@ -20,8 +21,13 @@ namespace hpx { return agas::get_colocation_id(launch::sync, id, ec); } - future get_colocation_id(hpx::id_type const& id) + hpx::future get_colocation_id(hpx::id_type const& id) { - return agas::get_colocation_id(id); + auto result = agas::get_colocation_id(id); + if (result.has_value()) + { + return hpx::make_ready_future(HPX_MOVE(result).get_value()); + } + return HPX_MOVE(result).get_future(); } } // namespace hpx diff --git a/libs/full/async_distributed/include/hpx/async_distributed/put_parcel.hpp b/libs/full/async_distributed/include/hpx/async_distributed/put_parcel.hpp index 7486883b3f9c..a1e2a26ddb6c 100644 --- a/libs/full/async_distributed/include/hpx/async_distributed/put_parcel.hpp +++ b/libs/full/async_distributed/include/hpx/async_distributed/put_parcel.hpp @@ -1,4 +1,5 @@ // Copyright (c) 2016 Thomas Heller +// Copyright (c) 2022 Hartmut Kaiser // // SPDX-License-Identifier: BSL-1.0 // Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -10,6 +11,7 @@ #if defined(HPX_HAVE_NETWORKING) #include +#include #include #include #include @@ -126,19 +128,32 @@ namespace hpx::parcelset { } else { - future split_gid = + auto result = naming::detail::split_gid_if_needed(dest.get_gid()); - if (split_gid.is_ready()) + if (result.has_value()) { pp(detail::create_parcel::call_with_action( - split_gid.get(), HPX_MOVE(addr), HPX_MOVE(action))); + HPX_MOVE(result).get_value(), HPX_MOVE(addr), + HPX_MOVE(action))); } else { - split_gid.then(hpx::launch::sync, - put_parcel_cont{HPX_FORWARD(PutParcel, pp), - HPX_MOVE(dest), HPX_MOVE(addr), HPX_MOVE(action)}); + HPX_ASSERT(result.has_future()); + + auto&& split_gid = HPX_MOVE(result).get_future(); + if (split_gid.is_ready()) + { + pp(detail::create_parcel::call_with_action( + split_gid.get(), HPX_MOVE(addr), HPX_MOVE(action))); + } + else + { + split_gid.then(hpx::launch::sync, + put_parcel_cont{ + HPX_FORWARD(PutParcel, pp), HPX_MOVE(dest), + HPX_MOVE(addr), HPX_MOVE(action)}); + } } } } diff --git a/libs/full/components/include/hpx/components/client_base.hpp b/libs/full/components/include/hpx/components/client_base.hpp index 7dbca12b5c12..2869d547ecc7 100644 --- a/libs/full/components/include/hpx/components/client_base.hpp +++ b/libs/full/components/include/hpx/components/client_base.hpp @@ -218,7 +218,15 @@ struct HPX_EXPORT hpx::lcos::detail::future_data { } - ~future_data() noexcept override; + // The constructor for the base template is defaulted. Some compilers + // generate duplicate symbols for this is the destructor definition is not + // visible to it. We hide the implementation in tidy() instead. + ~future_data() noexcept override + { + tidy(); + } + + void tidy() const noexcept; [[nodiscard]] std::string const& get_registered_name() const noexcept; void set_registered_name(std::string name); diff --git a/libs/full/components/include/hpx/components/get_ptr.hpp b/libs/full/components/include/hpx/components/get_ptr.hpp index c39a6dee9b14..5c072fbc9c45 100644 --- a/libs/full/components/include/hpx/components/get_ptr.hpp +++ b/libs/full/components/include/hpx/components/get_ptr.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2007-2021 Hartmut Kaiser +// Copyright (c) 2007-2022 Hartmut Kaiser // // SPDX-License-Identifier: BSL-1.0 // Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -17,8 +17,8 @@ #include #include #include -#include #include +#include #include #include @@ -134,6 +134,61 @@ namespace hpx { return get_ptr_postproc( addr, id, false); } + + /////////////////////////////////////////////////////////////////////// + template + std::shared_ptr resolve_get_ptr_local(hpx::id_type const& id) + { + return std::shared_ptr( + get_lva::call( + reinterpret_cast(id.get_lsb())), + detail::get_ptr_no_unpin_deleter(id)); + } + + template + hpx::future_or_value> get_ptr( + hpx::id_type const& id) + { + hpx::error_code ec(hpx::throwmode::lightweight); + + // shortcut for local, non-migratable objects + naming::gid_type gid = id.get_gid(); + if (naming::refers_to_local_lva(gid) && + naming::get_locality_id_from_gid(gid) == + agas::get_locality_id(ec) && + !ec) + { + return resolve_get_ptr_local(id); + } + + if (ec) + { + return hpx::make_exceptional_future>( + hpx::detail::access_exception(ec)); + } + + auto result = agas::resolve_async(id); + if (result.has_value()) + { + try + { + return get_ptr_postproc( + HPX_MOVE(result).get_value(), id); + } + catch (...) + { + return hpx::make_exceptional_future< + std::shared_ptr>(std::current_exception()); + } + } + + return result.get_future().then(hpx::launch::sync, + [=](hpx::future&& f) + -> std::shared_ptr { + return get_ptr_postproc( + f.get(), id); + }); + } } // namespace detail /// \endcond @@ -164,12 +219,12 @@ namespace hpx { template hpx::future> get_ptr(hpx::id_type const& id) { - hpx::future f = agas::resolve(id); - return f.then(hpx::launch::sync, - [=](hpx::future f) -> std::shared_ptr { - return detail::get_ptr_postproc(f.get(), id); - }); + auto result = detail::get_ptr(id); + if (result.has_value()) + { + return hpx::make_ready_future(HPX_MOVE(result).get_value()); + } + return HPX_MOVE(result).get_future(); } /// \brief Returns a future referring to the pointer to the @@ -247,19 +302,12 @@ namespace hpx { std::shared_ptr get_ptr( launch::sync_policy, hpx::id_type const& id, error_code& ec = throws) { - // shortcut for local, non-migratable objects - naming::gid_type gid = id.get_gid(); - if (naming::refers_to_local_lva(gid) && - naming::get_locality_id_from_gid(gid) == agas::get_locality_id(ec)) + auto result = detail::get_ptr(id); + if (result.has_value()) { - return std::shared_ptr( - get_lva::call( - reinterpret_cast(gid.get_lsb())), - detail::get_ptr_no_unpin_deleter(id)); + return HPX_MOVE(result).get_value(); } - - hpx::future> ptr = get_ptr(id); - return ptr.get(ec); + return result.get_future().get(ec); } #endif diff --git a/libs/full/components/src/client_base.cpp b/libs/full/components/src/client_base.cpp index ffbef9cd9de9..347f15949095 100644 --- a/libs/full/components/src/client_base.cpp +++ b/libs/full/components/src/client_base.cpp @@ -43,7 +43,7 @@ namespace hpx::util { namespace hpx::lcos::detail { - future_data::~future_data() noexcept + void future_data::tidy() const noexcept { auto* registered_name = try_get_extra_data(); if (registered_name != nullptr && !registered_name->empty()) diff --git a/libs/full/components_base/include/hpx/components_base/agas_interface.hpp b/libs/full/components_base/include/hpx/components_base/agas_interface.hpp index 6349abe92c74..15162135a02f 100644 --- a/libs/full/components_base/include/hpx/components_base/agas_interface.hpp +++ b/libs/full/components_base/include/hpx/components_base/agas_interface.hpp @@ -165,6 +165,9 @@ namespace hpx::agas { } /////////////////////////////////////////////////////////////////////////// + HPX_EXPORT hpx::future_or_value resolve_async( + hpx::id_type const& id); + HPX_EXPORT hpx::future resolve(hpx::id_type const& id); HPX_EXPORT naming::address resolve( @@ -240,8 +243,9 @@ namespace hpx::agas { error_code& ec = throws); /////////////////////////////////////////////////////////////////////////// - HPX_EXPORT hpx::future incref(naming::gid_type const& gid, - std::int64_t credits, hpx::id_type const& keep_alive = hpx::invalid_id); + HPX_EXPORT hpx::future_or_value incref( + naming::gid_type const& gid, std::int64_t credits, + hpx::id_type const& keep_alive = hpx::invalid_id); HPX_EXPORT std::int64_t incref(launch::sync_policy, naming::gid_type const& gid, std::int64_t credits = 1, @@ -252,7 +256,7 @@ namespace hpx::agas { HPX_EXPORT std::int64_t replenish_credits(naming::gid_type& gid); /////////////////////////////////////////////////////////////////////////// - HPX_EXPORT hpx::future get_colocation_id( + HPX_EXPORT hpx::future_or_value get_colocation_id( hpx::id_type const& id); HPX_EXPORT hpx::id_type get_colocation_id( diff --git a/libs/full/components_base/include/hpx/components_base/detail/agas_interface_functions.hpp b/libs/full/components_base/include/hpx/components_base/detail/agas_interface_functions.hpp index ec6044dbf322..866f04115609 100644 --- a/libs/full/components_base/include/hpx/components_base/detail/agas_interface_functions.hpp +++ b/libs/full/components_base/include/hpx/components_base/detail/agas_interface_functions.hpp @@ -11,8 +11,8 @@ #include #include #include -#include #include +#include #include #include #include @@ -115,7 +115,7 @@ namespace hpx::agas::detail { naming::gid_type const& gid); /////////////////////////////////////////////////////////////////////////// - extern HPX_EXPORT hpx::future (*resolve_async)( + extern HPX_EXPORT hpx::future_or_value (*resolve_async)( hpx::id_type const& id); extern HPX_EXPORT naming::address (*resolve)( @@ -184,18 +184,15 @@ namespace hpx::agas::detail { naming::gid_type const& id, std::int64_t credits, error_code& ec); /////////////////////////////////////////////////////////////////////////// - extern HPX_EXPORT hpx::future (*incref_async)( + extern HPX_EXPORT hpx::future_or_value (*incref_async)( naming::gid_type const& gid, std::int64_t credits, hpx::id_type const& keep_alive); - extern HPX_EXPORT std::int64_t (*incref)(naming::gid_type const& gid, - std::int64_t credits, hpx::id_type const& keep_alive, error_code& ec); - /////////////////////////////////////////////////////////////////////////// extern HPX_EXPORT std::int64_t (*replenish_credits)(naming::gid_type& gid); /////////////////////////////////////////////////////////////////////////// - extern HPX_EXPORT hpx::future (*get_colocation_id_async)( + extern HPX_EXPORT hpx::future_or_value (*get_colocation_id_async)( hpx::id_type const& id); extern HPX_EXPORT hpx::id_type (*get_colocation_id)( diff --git a/libs/full/components_base/src/agas_interface.cpp b/libs/full/components_base/src/agas_interface.cpp index 1f9562ab3dff..9f152c84888a 100644 --- a/libs/full/components_base/src/agas_interface.cpp +++ b/libs/full/components_base/src/agas_interface.cpp @@ -1,11 +1,12 @@ // Copyright (c) 2011 Bryce Adelstein-Lelbach -// Copyright (c) 2007-2021 Hartmut Kaiser +// Copyright (c) 2007-2022 Hartmut Kaiser // // SPDX-License-Identifier: BSL-1.0 // 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 +#include #include #include #include @@ -150,11 +151,21 @@ namespace hpx::agas { } /////////////////////////////////////////////////////////////////////////// - hpx::future resolve(hpx::id_type const& id) + hpx::future_or_value resolve_async(hpx::id_type const& id) { return detail::resolve_async(id); } + hpx::future resolve(hpx::id_type const& id) + { + auto result = detail::resolve_async(id); + if (result.has_value()) + { + return hpx::make_ready_future(HPX_MOVE(result).get_value()); + } + return HPX_MOVE(result).get_future(); + } + naming::address resolve( launch::sync_policy, hpx::id_type const& id, error_code& ec) { @@ -303,7 +314,7 @@ namespace hpx::agas { } /////////////////////////////////////////////////////////////////////////// - hpx::future incref(naming::gid_type const& gid, + hpx::future_or_value incref(naming::gid_type const& gid, std::int64_t credits, hpx::id_type const& keep_alive) { return detail::incref_async(gid, credits, keep_alive); @@ -312,7 +323,12 @@ namespace hpx::agas { std::int64_t incref(launch::sync_policy, naming::gid_type const& gid, std::int64_t credits, hpx::id_type const& keep_alive, error_code& ec) { - return detail::incref(gid, credits, keep_alive, ec); + auto result = detail::incref_async(gid, credits, keep_alive); + if (result.has_value()) + { + return HPX_MOVE(result).get_value(); + } + return result.get_future().get(ec); } /////////////////////////////////////////////////////////////////////////// @@ -322,7 +338,7 @@ namespace hpx::agas { } /////////////////////////////////////////////////////////////////////////// - hpx::future get_colocation_id(hpx::id_type const& id) + hpx::future_or_value get_colocation_id(hpx::id_type const& id) { return detail::get_colocation_id_async(id); } diff --git a/libs/full/components_base/src/detail/agas_interface_functions.cpp b/libs/full/components_base/src/detail/agas_interface_functions.cpp index 8aa6bb325079..2061138779aa 100644 --- a/libs/full/components_base/src/detail/agas_interface_functions.cpp +++ b/libs/full/components_base/src/detail/agas_interface_functions.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -109,7 +110,7 @@ namespace hpx::agas::detail { bool (*is_local_lva_encoded_address)(naming::gid_type const& gid) = nullptr; /////////////////////////////////////////////////////////////////////////// - hpx::future (*resolve_async)( + hpx::future_or_value (*resolve_async)( hpx::id_type const& id) = nullptr; naming::address (*resolve)( @@ -177,17 +178,15 @@ namespace hpx::agas::detail { error_code& ec) = nullptr; /////////////////////////////////////////////////////////////////////////// - hpx::future (*incref_async)(naming::gid_type const& gid, - std::int64_t credits, hpx::id_type const& keep_alive) = nullptr; - - std::int64_t (*incref)(naming::gid_type const& gid, std::int64_t credits, - hpx::id_type const& keep_alive, error_code& ec) = nullptr; + hpx::future_or_value (*incref_async)( + naming::gid_type const& gid, std::int64_t credits, + hpx::id_type const& keep_alive) = nullptr; /////////////////////////////////////////////////////////////////////////// std::int64_t (*replenish_credits)(naming::gid_type& gid) = nullptr; /////////////////////////////////////////////////////////////////////////// - hpx::future (*get_colocation_id_async)( + hpx::future_or_value (*get_colocation_id_async)( hpx::id_type const& id) = nullptr; hpx::id_type (*get_colocation_id)( diff --git a/libs/full/naming/include/hpx/naming/split_gid.hpp b/libs/full/naming/include/hpx/naming/split_gid.hpp index 6aabf9073b16..78b0423250a2 100644 --- a/libs/full/naming/include/hpx/naming/split_gid.hpp +++ b/libs/full/naming/include/hpx/naming/split_gid.hpp @@ -9,14 +9,20 @@ #pragma once #include -#include +#include +#include +#include #include #include namespace hpx::naming::detail { - HPX_EXPORT hpx::future split_gid_if_needed(gid_type& id); - HPX_EXPORT hpx::future split_gid_if_needed_locked( + HPX_EXPORT hpx::future_or_value split_gid_if_needed(gid_type& id); + + HPX_EXPORT gid_type split_gid_if_needed( + hpx::launch::sync_policy, gid_type& id); + + HPX_EXPORT hpx::future_or_value split_gid_if_needed_locked( std::unique_lock& l, gid_type& gid); } // namespace hpx::naming::detail diff --git a/libs/full/naming/src/credit_handling.cpp b/libs/full/naming/src/credit_handling.cpp index 230faac199e8..bbea22c11dc0 100644 --- a/libs/full/naming/src/credit_handling.cpp +++ b/libs/full/naming/src/credit_handling.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -178,12 +179,25 @@ namespace hpx::naming { } /////////////////////////////////////////////////////////////////////// - hpx::future split_gid_if_needed(gid_type& gid) + hpx::future_or_value split_gid_if_needed(gid_type& gid) { std::unique_lock l(gid.get_mutex()); return split_gid_if_needed_locked(l, gid); } + gid_type split_gid_if_needed(hpx::launch::sync_policy, gid_type& gid) + { + auto result = split_gid_if_needed(gid); + if (result.has_value()) + { + return result.get_value(); + } + + HPX_ASSERT(result.has_future()); + return result.get_future().get(); + } + + /////////////////////////////////////////////////////////////////////// gid_type postprocess_incref(gid_type& gid) { std::unique_lock l(gid.get_mutex()); @@ -234,7 +248,7 @@ namespace hpx::naming { return new_gid; } - hpx::future split_gid_if_needed_locked( + hpx::future_or_value split_gid_if_needed_locked( std::unique_lock& l, gid_type& gid) { HPX_ASSERT_OWNS_LOCK(l); @@ -286,9 +300,26 @@ namespace hpx::naming { naming::gid_type const new_gid = gid; // strips lock-bit HPX_ASSERT(new_gid != invalid_gid); - return agas::incref(new_gid, new_credit) - .then(hpx::launch::sync, - hpx::bind(postprocess_incref, std::ref(gid))); + + auto result = agas::incref(new_gid, new_credit); + if (result.has_value()) + { + try + { + return postprocess_incref(gid); + } + catch (...) + { + return hpx::make_exceptional_future( + std::current_exception()); + } + } + + return result.get_future().then( + hpx::launch::sync, [&gid](auto&& f) { + f.get(); + return postprocess_incref(gid); + }); } HPX_ASSERT(src_log2credits > 1); @@ -298,11 +329,11 @@ namespace hpx::naming { HPX_ASSERT(detail::has_credits(gid)); HPX_ASSERT(detail::has_credits(new_gid)); - return hpx::make_ready_future(new_gid); + return new_gid; } naming::gid_type new_gid = gid; // strips lock-bit - return hpx::make_ready_future(new_gid); + return new_gid; } /////////////////////////////////////////////////////////////////////// @@ -479,17 +510,26 @@ namespace hpx::naming { // preprocessing handle_futures.increment_future_count(); - auto f = split_gid_if_needed(gid).then(hpx::launch::sync, - [&split_gids, &handle_futures, &gid]( - hpx::future&& gid_future) { - HPX_UNUSED(handle_futures); - HPX_ASSERT(handle_futures.has_futures()); - split_gids.add_gid(gid, gid_future.get()); - }); - - handle_futures.await_future( - *traits::future_access::get_shared_state(f), - false); + auto result = split_gid_if_needed(gid); + if (result.has_value()) + { + handle_futures.decrement_future_count(); + split_gids.add_gid(gid, result.get_value()); + } + else + { + auto f = result.get_future().then(hpx::launch::sync, + [&split_gids, &handle_futures, &gid]( + hpx::future&& gid_future) { + HPX_UNUSED(handle_futures); + HPX_ASSERT(handle_futures.has_futures()); + split_gids.add_gid(gid, gid_future.get()); + }); + + handle_futures.await_future( + *traits::future_access::get_shared_state(f), + false); + } } void preprocess_gid( diff --git a/libs/full/runtime_components/tests/unit/agas/local_address_rebind.cpp b/libs/full/runtime_components/tests/unit/agas/local_address_rebind.cpp index 3c4286b4d8c1..3d807fad0744 100644 --- a/libs/full/runtime_components/tests/unit/agas/local_address_rebind.cpp +++ b/libs/full/runtime_components/tests/unit/agas/local_address_rebind.cpp @@ -47,11 +47,11 @@ int hpx_main() std::uint64_t b_lva = b.get_lva(); // Resolve a_gid. - address addr = hpx::agas::resolve(a_id).get(); + address addr = hpx::agas::resolve(hpx::launch::sync, a_id); /////////////////////////////////////////////////////////////////////// HPX_TEST_EQ(addr.address_, reinterpret_cast(a.get_lva())); - HPX_SANITY_EQ(hpx::agas::resolve(a_id).get().address_, + HPX_SANITY_EQ(hpx::agas::resolve(hpx::launch::sync, a_id).address_, reinterpret_cast(a.get_lva())); /////////////////////////////////////////////////////////////////////// @@ -67,7 +67,7 @@ int hpx_main() /////////////////////////////////////////////////////////////////////// HPX_TEST_EQ(b_lva, a.get_lva()); - HPX_SANITY_EQ(hpx::agas::resolve(a_id).get().address_, + HPX_SANITY_EQ(hpx::agas::resolve(hpx::launch::sync, a_id).address_, reinterpret_cast(a.get_lva())); /////////////////////////////////////////////////////////////////////// @@ -81,8 +81,9 @@ int hpx_main() hpx::agas::update_cache_entry(a_gid, addr); /////////////////////////////////////////////////////////////////////// - HPX_TEST_EQ(hpx::agas::resolve(a_id).get().address_, a_lva); - HPX_SANITY_EQ(hpx::agas::resolve(a_id).get().address_, + HPX_TEST_EQ( + hpx::agas::resolve(hpx::launch::sync, a_id).address_, a_lva); + HPX_SANITY_EQ(hpx::agas::resolve(hpx::launch::sync, a_id).address_, reinterpret_cast(a.get_lva())); } diff --git a/libs/full/segmented_algorithms/tests/unit/partitioned_vector_inclusive_scan.cpp b/libs/full/segmented_algorithms/tests/unit/partitioned_vector_inclusive_scan.cpp index b896a740a160..16587be0207b 100644 --- a/libs/full/segmented_algorithms/tests/unit/partitioned_vector_inclusive_scan.cpp +++ b/libs/full/segmented_algorithms/tests/unit/partitioned_vector_inclusive_scan.cpp @@ -1,4 +1,5 @@ // Copyright (c) 2016 Minh-Khanh Do +// Copyright (c) 2022 Hartmut Kaiser // // SPDX-License-Identifier: BSL-1.0 // Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -75,7 +76,7 @@ void inclusive_scan_algo_tests_with_policy(std::size_t size, template void inclusive_scan_algo_tests_segmented_out_with_policy(std::size_t size, DistPolicy const& in_dist_policy, DistPolicy const& out_dist_policy, - hpx::partitioned_vector& in, hpx::partitioned_vector out, + hpx::partitioned_vector& in, hpx::partitioned_vector& out, std::vector ver, ExPolicy const& policy) { msg9(typeid(ExPolicy).name(), typeid(DistPolicy).name(), typeid(T).name(), @@ -168,7 +169,7 @@ void inclusive_scan_algo_tests_with_policy_async(std::size_t size, template void inclusive_scan_algo_tests_segmented_out_with_policy_async(std::size_t size, DistPolicy const& in_dist_policy, DistPolicy const& out_dist_policy, - hpx::partitioned_vector& in, hpx::partitioned_vector out, + hpx::partitioned_vector& in, hpx::partitioned_vector& out, std::vector ver, ExPolicy const& policy) { msg9(typeid(ExPolicy).name(), typeid(DistPolicy).name(), typeid(T).name(), diff --git a/libs/full/segmented_algorithms/tests/unit/partitioned_vector_scan.hpp b/libs/full/segmented_algorithms/tests/unit/partitioned_vector_scan.hpp index e8f6164b1910..742c9bad33c2 100644 --- a/libs/full/segmented_algorithms/tests/unit/partitioned_vector_scan.hpp +++ b/libs/full/segmented_algorithms/tests/unit/partitioned_vector_scan.hpp @@ -1,4 +1,5 @@ // Copyright (c) 2016 Minh-Khanh Do +// Copyright (c) 2022 Hartmut Kaiser // // SPDX-License-Identifier: BSL-1.0 // Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -87,7 +88,8 @@ struct verify_ : public hpx::parallel::detail::algorithm, Value> }; template -void verify_values(hpx::partitioned_vector v1, std::vector v2) +void verify_values( + hpx::partitioned_vector const& v1, std::vector const& v2) { auto first = v1.begin(); auto last = v1.end(); From 4c05bbf27776e97281f76babf9ab975bc914d7e5 Mon Sep 17 00:00:00 2001 From: dimitraka Date: Wed, 23 Aug 2023 11:24:12 +0200 Subject: [PATCH 16/25] Add scatter and gather doc --- docs/sphinx/manual/migration_guide.rst | 252 +++++++++++++++++++++---- 1 file changed, 214 insertions(+), 38 deletions(-) diff --git a/docs/sphinx/manual/migration_guide.rst b/docs/sphinx/manual/migration_guide.rst index 5011307c16fc..c7c40674d05d 100644 --- a/docs/sphinx/manual/migration_guide.rst +++ b/docs/sphinx/manual/migration_guide.rst @@ -1158,7 +1158,6 @@ Having said that, we conclude to the following table: ========================= ============================================================== |openmpi| function |hpx| equivalent ========================= ============================================================== - MPI_Comm_create `hpx::collectives::create_channel_communicator()` MPI_Comm_size `hpx::get_num_localities` MPI_Comm_rank `hpx::get_locality_id()` MPI_Isend `hpx::collectives::set()` @@ -1176,54 +1175,90 @@ the gathered data in the root process. .. code-block:: c++ + #include #include + #include + #include - int main(int argc, char* argv[]) - { - int num_localities, this_locality; - int gather_data[10]; + int main(int argc, char *argv[]) { + MPI_Init(&argc, &argv); + + int num_localities, this_locality; + MPI_Comm_size(MPI_COMM_WORLD, &num_localities); + MPI_Comm_rank(MPI_COMM_WORLD, &this_locality); - // Initialize MPI - MPI_Init(&argc, &argv); - MPI_Comm_size(MPI_COMM_WORLD, &num_localities); - MPI_Comm_rank(MPI_COMM_WORLD, &this_locality); + std::vector local_data; // Data to be gathered - // Test functionality based on immediate local result value - for (int i = 0; i < 10; ++i) + if (this_locality == 0) { + local_data.resize(num_localities); // Resize the vector on the root process + } + + // Each process calculates its local data value + int my_data = 42 + this_locality; + + for (std::uint32_t i = 0; i != 10; ++i) { + + // Gather data from all processes to the root process (process 0) + MPI_Gather(&my_data, 1, MPI_INT, local_data.data(), 1, MPI_INT, 0, + MPI_COMM_WORLD); + + // Only the root process (process 0) will print the gathered data + if (this_locality == 0) { + std::cout << "Gathered data on the root: "; + for (int i = 0; i < num_localities; ++i) { + std::cout << local_data[i] << " "; + } + std::cout << std::endl; + } + } + + MPI_Finalize(); + return 0; + } + + +|hpx| equivalent: + +.. code-block:: c++ + + std::uint32_t num_localities = hpx::get_num_localities(hpx::launch::sync); + std::uint32_t this_locality = hpx::get_locality_id(); + + // test functionality based on immediate local result value + auto gather_direct_client = create_communicator(gather_direct_basename, + num_sites_arg(num_localities), this_site_arg(this_locality)); + + for (std::uint32_t i = 0; i != 10; ++i) + { + if (this_locality == 0) { - if (this_locality == 0) - { - int value = 42; - MPI_Gather(&value, 1, MPI_INT, gather_data, 1, MPI_INT, 0, MPI_COMM_WORLD); + hpx::future> overall_result = + gather_here(gather_direct_client, std::uint32_t(42)); - if (this_locality == 0) - { - for (int j = 0; j < num_localities; ++j) - { - // Verify gathered data - assert(j + 42 == gather_data[j]); - } - } - } - else + std::vector sol = overall_result.get(); + std::cout << "Gathered data on the root:"; + + for (std::size_t j = 0; j != sol.size(); ++j) { - int value = this_locality + 42; - MPI_Gather(&value, 1, MPI_INT, nullptr, 0, MPI_INT, 0, MPI_COMM_WORLD); + HPX_TEST(j + 42 == sol[j]); + std::cout << " " << sol[j]; } + std::cout << std::endl; + } + else + { + hpx::future overall_result = + gather_there(gather_direct_client, this_locality + 42); + overall_result.get(); } - // Finalize MPI - MPI_Finalize(); - - return 0; } +This code will print 10 times the following message: -|hpx| equivalent: +.. code-block:: c++ -.. literalinclude:: ../../libs/full/collectives/tests/unit/gather.cpp - :start-after: //[doc - :end-before: //doc] + Gathered data on the root: 42 43 |hpx| uses two functions to implement the functionality of `MPI_Gather`: `hpx::gather_here` and `hpx::gather_there`. `hpx::gather_here` is gathering data from all localities to the locality @@ -1233,18 +1268,21 @@ gather operation by sending data to the root locality. In more detail: - `hpx::get_num_localities(hpx::launch::sync)` retrieves the number of localities, while `hpx::get_locality_id()` returns the ID of the current locality. +- The function `create_communicator()` is used to create a communicator called + `gather_direct_client`. + - If the current locality is the root (its ID is equal to 0): - the `hpx::gather_here` function is used to perform the gather operation. It collects data from all other localities into the `overall_result` future object. The function arguments provide the necessary - information, such as the base name for the gather operation (`gather_direct_basename`), the value - to be gathered (`value`), the number of localities (`num_localities`), the current locality ID + information, such as the base name for the gather operation (`gather_direct_basename`), the value + to be gathered (`value`), the number of localities (`num_localities`), the current locality ID (`this_locality`), and the generation number (related to the gather operation). - The `get()` member function of the `overall_result` future is used to retrieve the gathered data. - The next `for` loop is used to verify the correctness of the gathered data (`sol`). `HPX_TEST` - is a macro provided by the |hpx| testing utilities to perform similar testing withthe Standard + is a macro provided by the |hpx| testing utilities to perform similar testing with the Standard C++ macro `assert`. - If the current locality is not the root: @@ -1266,3 +1304,141 @@ gather operation by sending data to the root locality. In more detail: MPI_Comm_rank `hpx::get_locality_id()` MPI_Gather `hpx::gather_here()` and `hpx::gather_there()` both used with `get()` ========================= ===================================================================== + +MPI_Scatter +----------- + +The following code gathers data from all processes to the root process and verifies +the gathered data in the root process. + +|mpi| code: + +.. code-block:: c++ + + #include + #include + #include + + int main(int argc, char *argv[]) { + MPI_Init(&argc, &argv); + + int num_localities, this_locality; + MPI_Comm_size(MPI_COMM_WORLD, &num_localities); + MPI_Comm_rank(MPI_COMM_WORLD, &this_locality); + + int num_localities = num_localities; + std::vector data(num_localities); + + if (this_locality == 0) { + // Fill the data vector on the root locality (locality 0) + for (int i = 0; i < num_localities; ++i) { + data[i] = 42 + i; + } + } + + int local_data; // Variable to store the received data + + // Scatter data from the root locality to all other localities + MPI_Scatter(&data[0], 1, MPI_INT, &local_data, 1, MPI_INT, 0, MPI_COMM_WORLD); + + // Now, each locality has its own local_data + + // Print the local_data on each locality + std::cout << "Locality " << this_locality << " received " << local_data + << std::endl; + + MPI_Finalize(); + return 0; + } + +|hpx| equivalent: + +.. code-block:: c++ + + std::uint32_t num_localities = hpx::get_num_localities(hpx::launch::sync); + HPX_TEST_LTE(std::uint32_t(2), num_localities); + + std::uint32_t this_locality = hpx::get_locality_id(); + + auto scatter_direct_client = + hpx::collectives::create_communicator(scatter_direct_basename, + num_sites_arg(num_localities), this_site_arg(this_locality)); + + // test functionality based on immediate local result value + for (std::uint32_t i = 0; i != 10; ++i) + { + if (this_locality == 0) + { + std::vector data(num_localities); + std::iota(data.begin(), data.end(), 42 + i); + + hpx::future result = + scatter_to(scatter_direct_client, std::move(data)); + + HPX_TEST_EQ(i + 42 + this_locality, result.get()); + } + else + { + hpx::future result = + scatter_from(scatter_direct_client); + + HPX_TEST_EQ(i + 42 + this_locality, result.get()); + + std::cout << "Locality " << this_locality << " received " + << i + 42 + this_locality << std::endl; + } + } + +For num_localities = 2 and since we run for 10 iterations this code will print +the following message: + +.. code-block:: c++ + + Locality 1 received 43 + Locality 1 received 44 + Locality 1 received 45 + Locality 1 received 46 + Locality 1 received 47 + Locality 1 received 48 + Locality 1 received 49 + Locality 1 received 50 + Locality 1 received 51 + Locality 1 received 52 + +|hpx| uses two functions to implement the functionality of `MPI_Scatter`: `hpx::scatter_to` and +`hpx::scatter_from`. `hpx::scatter_to` is distributing the data from the locality with ID 0 +(root locality) to all other localities. `hpx::scatter_from` allows non-root localities to receive +the data from the root locality. In more detail: + +- `hpx::get_num_localities(hpx::launch::sync)` retrieves the number of localities, while + `hpx::get_locality_id()` returns the ID of the current locality. + +- The function `hpx::collectives::create_communicator()` is used to create a communicator called + `scatter_direct_client`. + +- If the current locality is the root (its ID is equal to 0): + + - The data vector is filled with values ranging from `42 + i` to `42 + i + num_localities - 1`. + + - The `hpx::scatter_to` function is used to perform the scatter operation using the communicator + `scatter_direct_client`. This scatters the data vector to other localities and + returns a future representing the result. + + - `HPX_TEST_EQ` is a macro provided by the |hpx| testing utilities to test the distributed values. + +- If the current locality is not the root: + + - The `hpx::scatter_from` function is used to collect the data by the root locality. + + - `HPX_TEST_EQ` is a macro provided by the |hpx| testing utilities to test the collected values. + + +.. table:: |hpx| equivalent functions of |mpi| + + ========================= ============================================= + |openmpi| function |hpx| equivalent + ========================= ============================================= + MPI_Comm_size `hpx::get_num_localities` + MPI_Comm_rank `hpx::get_locality_id()` + MPI_Scatter `hpx::scatter_to()` and `hpx::scatter_from()` + ========================= ============================================= From fbc9149188be941eefff52b44f99adfbc42dfc34 Mon Sep 17 00:00:00 2001 From: dimitraka Date: Thu, 24 Aug 2023 13:36:18 +0200 Subject: [PATCH 17/25] Add MPI_Allgather doc --- docs/sphinx/manual/migration_guide.rst | 185 +++++++++++++++++++------ 1 file changed, 141 insertions(+), 44 deletions(-) diff --git a/docs/sphinx/manual/migration_guide.rst b/docs/sphinx/manual/migration_guide.rst index c7c40674d05d..360c351617bd 100644 --- a/docs/sphinx/manual/migration_guide.rst +++ b/docs/sphinx/manual/migration_guide.rst @@ -1181,39 +1181,39 @@ the gathered data in the root process. #include int main(int argc, char *argv[]) { - MPI_Init(&argc, &argv); + MPI_Init(&argc, &argv); - int num_localities, this_locality; - MPI_Comm_size(MPI_COMM_WORLD, &num_localities); - MPI_Comm_rank(MPI_COMM_WORLD, &this_locality); + int num_localities, this_locality; + MPI_Comm_size(MPI_COMM_WORLD, &num_localities); + MPI_Comm_rank(MPI_COMM_WORLD, &this_locality); - std::vector local_data; // Data to be gathered + std::vector local_data; // Data to be gathered - if (this_locality == 0) { - local_data.resize(num_localities); // Resize the vector on the root process - } + if (this_locality == 0) { + local_data.resize(num_localities); // Resize the vector on the root process + } - // Each process calculates its local data value - int my_data = 42 + this_locality; + // Each process calculates its local data value + int my_data = 42 + this_locality; - for (std::uint32_t i = 0; i != 10; ++i) { + for (std::uint32_t i = 0; i != 10; ++i) { - // Gather data from all processes to the root process (process 0) - MPI_Gather(&my_data, 1, MPI_INT, local_data.data(), 1, MPI_INT, 0, - MPI_COMM_WORLD); + // Gather data from all processes to the root process (process 0) + MPI_Gather(&my_data, 1, MPI_INT, local_data.data(), 1, MPI_INT, 0, + MPI_COMM_WORLD); - // Only the root process (process 0) will print the gathered data - if (this_locality == 0) { - std::cout << "Gathered data on the root: "; - for (int i = 0; i < num_localities; ++i) { - std::cout << local_data[i] << " "; - } - std::cout << std::endl; + // Only the root process (process 0) will print the gathered data + if (this_locality == 0) { + std::cout << "Gathered data on the root: "; + for (int i = 0; i < num_localities; ++i) { + std::cout << local_data[i] << " "; + } + std::cout << std::endl; + } } - } - MPI_Finalize(); - return 0; + MPI_Finalize(); + return 0; } @@ -1320,35 +1320,35 @@ the gathered data in the root process. #include int main(int argc, char *argv[]) { - MPI_Init(&argc, &argv); + MPI_Init(&argc, &argv); - int num_localities, this_locality; - MPI_Comm_size(MPI_COMM_WORLD, &num_localities); - MPI_Comm_rank(MPI_COMM_WORLD, &this_locality); + int num_localities, this_locality; + MPI_Comm_size(MPI_COMM_WORLD, &num_localities); + MPI_Comm_rank(MPI_COMM_WORLD, &this_locality); - int num_localities = num_localities; - std::vector data(num_localities); + int num_localities = num_localities; + std::vector data(num_localities); - if (this_locality == 0) { - // Fill the data vector on the root locality (locality 0) - for (int i = 0; i < num_localities; ++i) { - data[i] = 42 + i; + if (this_locality == 0) { + // Fill the data vector on the root locality (locality 0) + for (int i = 0; i < num_localities; ++i) { + data[i] = 42 + i; + } } - } - int local_data; // Variable to store the received data + int local_data; // Variable to store the received data - // Scatter data from the root locality to all other localities - MPI_Scatter(&data[0], 1, MPI_INT, &local_data, 1, MPI_INT, 0, MPI_COMM_WORLD); + // Scatter data from the root locality to all other localities + MPI_Scatter(&data[0], 1, MPI_INT, &local_data, 1, MPI_INT, 0, MPI_COMM_WORLD); - // Now, each locality has its own local_data + // Now, each locality has its own local_data - // Print the local_data on each locality - std::cout << "Locality " << this_locality << " received " << local_data - << std::endl; + // Print the local_data on each locality + std::cout << "Locality " << this_locality << " received " << local_data + << std::endl; - MPI_Finalize(); - return 0; + MPI_Finalize(); + return 0; } |hpx| equivalent: @@ -1442,3 +1442,100 @@ the data from the root locality. In more detail: MPI_Comm_rank `hpx::get_locality_id()` MPI_Scatter `hpx::scatter_to()` and `hpx::scatter_from()` ========================= ============================================= + +MPI_Allgather +------------- + +The following code gathers data from all processes and sends the data to all +processes. + +|mpi| code: + +.. code-block:: c++ + + #include + #include + #include + #include + + int main(int argc, char **argv) { + MPI_Init(&argc, &argv); + + int rank, size; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + + // Get the number of MPI processes (equivalent to HPX localities). + int num_localities = size; + + // Get the MPI process rank (equivalent to HPX locality ID). + int here = rank; + + std::uint32_t value = here; + + std::vector r(num_localities); + + // Perform an all-gather operation to gather values from all processes. + MPI_Allgather(&value, 1, MPI_UINT32_T, r.data(), 1, MPI_UINT32_T, + MPI_COMM_WORLD); + + // Print the result. + std::cout << "Locality " << here << " has values:"; + for (size_t j = 0; j < r.size(); ++j) { + std::cout << " " << r[j]; + } + std::cout << std::endl; + + MPI_Finalize(); + return 0; + } + +|hpx| equivalent: + +.. code-block:: c++ + + std::uint32_t num_localities = hpx::get_num_localities(hpx::launch::sync); + std::uint32_t here = hpx::get_locality_id(); + + // test functionality based on immediate local result value + auto all_gather_direct_client = + create_communicator(all_gather_direct_basename, + num_sites_arg(num_localities), this_site_arg(here)); + + std::uint32_t value = here; + + hpx::future> overall_result = + all_gather(all_gather_direct_client, value); + + std::vector r = overall_result.get(); + + std::cout << "Locality " << here << " has values:"; + for (std::size_t j = 0; j != r.size(); ++j) + { + std::cout << " " << j; + } + std::cout << std::endl; + +For num_localities = 2 this code will print the following message: + +.. code-block:: c++ + + Locality 0 has values: 0 1 + Locality 1 has values: 0 1 + +|hpx| uses the function `all_gather` to implement the functionality of `MPI_Allgather`. In more +detail: + +- `hpx::get_num_localities(hpx::launch::sync)` retrieves the number of localities, while + `hpx::get_locality_id()` returns the ID of the current locality. + +- The function `hpx::collectives::create_communicator()` is used to create a communicator called + `all_gather_direct_client`. + +- The values that the localities exchange with each other are equal to each locality's ID. + +- The gather operation is performed using `all_gather`. The result is stored in an `hpx::future` + object called `overall_result`, which represents a future result that can be retrieved later when + needed. + +- The `get()` function waits until the result is available and then stores it in the vector called `r`. From b0c6c51c96514f162053dcc9e2df7ddc50b92e41 Mon Sep 17 00:00:00 2001 From: dimitraka Date: Thu, 24 Aug 2023 14:13:07 +0200 Subject: [PATCH 18/25] Add MPI_Allreduce doc --- docs/sphinx/manual/migration_guide.rst | 89 ++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/docs/sphinx/manual/migration_guide.rst b/docs/sphinx/manual/migration_guide.rst index 360c351617bd..9ce4011e7c9b 100644 --- a/docs/sphinx/manual/migration_guide.rst +++ b/docs/sphinx/manual/migration_guide.rst @@ -1539,3 +1539,92 @@ detail: needed. - The `get()` function waits until the result is available and then stores it in the vector called `r`. + + +MPI_Allreduce +------------- + +The following code combines values from all processes and distributes the result back to all processes. + +|mpi| code: + +.. code-block:: c++ + + #include + #include + #include + + int main(int argc, char **argv) { + MPI_Init(&argc, &argv); + + int rank, size; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + + // Get the number of MPI processes + int num_localities = size; + + // Get the MPI process rank + int here = rank; + + // Create a communicator for the all reduce operation. + MPI_Comm all_reduce_direct_client; + MPI_Comm_split(MPI_COMM_WORLD, 0, rank, &all_reduce_direct_client); + + // Perform the all reduce operation to calculate the sum of 'here' values. + std::uint32_t value = here; + std::uint32_t res = 0; + MPI_Allreduce(&value, &res, 1, MPI_UINT32_T, MPI_SUM, + all_reduce_direct_client); + + std::cout << "Locality " << rank << " has value: " << res << std::endl; + + MPI_Finalize(); + return 0; + } + + + +|hpx| equivalent: + +.. code-block:: c++ + + std::uint32_t const num_localities = + hpx::get_num_localities(hpx::launch::sync); + std::uint32_t const here = hpx::get_locality_id(); + + auto const all_reduce_direct_client = + create_communicator(all_reduce_direct_basename, + num_sites_arg(num_localities), this_site_arg(here)); + + std::uint32_t value = here; + + hpx::future overall_result = + all_reduce(all_reduce_direct_client, value, std::plus{}); + + std::uint32_t res = overall_result.get(); + std::cout << "Locality " << here << " has value: " << res << std::endl; + +For num_localities = 2 this code will print the following message: + +.. code-block:: c++ + + Locality 0 has value: 1 + Locality 1 has value: 1 + +|hpx| uses the function `all_reduce` to implement the functionality of `MPI_Allreduce`. In more +detail: + +- `hpx::get_num_localities(hpx::launch::sync)` retrieves the number of localities, while + `hpx::get_locality_id()` returns the ID of the current locality. + +- The function `hpx::collectives::create_communicator()` is used to create a communicator called + `all_reduce_direct_client`. + +- The value of each locality is equal to its ID. + +- The reduce operation is performed using `all_reduce`. The result is stored in an `hpx::future` + object called `overall_result`, which represents a future result that can be retrieved later when + needed. + +- The `get()` function waits until the result is available and then stores it in the variable `res`. From 7d4a9de062c90e0eaba990c1188743a59895c987 Mon Sep 17 00:00:00 2001 From: Hartmut Kaiser Date: Sun, 14 May 2023 15:49:21 -0500 Subject: [PATCH 19/25] Modernize modules in level 17 and 18 --- cmake/HPX_SetupLCI.cmake | 4 +- .../debugging/include/hpx/debugging/print.hpp | 4 +- .../detail/async_launch_policy_dispatch.hpp | 2 +- .../execution/detail/post_policy_dispatch.hpp | 2 +- .../hpx/executors/parallel_executor.hpp | 2 +- .../hpx/executors/thread_pool_scheduler.hpp | 1 + .../include/hpx/futures/futures_factory.hpp | 1 + .../hpx/io_service/io_service_pool.hpp | 5 +- .../hpx/io_service/io_service_thread_pool.hpp | 2 - libs/core/io_service/src/io_service_pool.cpp | 6 +- .../io_service/src/io_service_thread_pool.cpp | 2 - .../hpx/runtime_local/run_as_hpx_thread.hpp | 3 +- .../hpx/schedulers/background_scheduler.hpp | 19 +-- .../local_priority_queue_scheduler.hpp | 8 +- .../hpx/schedulers/local_queue_scheduler.hpp | 95 ++++++------ .../schedulers/lockfree_queue_backends.hpp | 20 +-- .../schedulers/maintain_queue_wait_times.hpp | 4 +- .../include/hpx/schedulers/queue_helpers.hpp | 8 +- .../hpx/schedulers/queue_holder_numa.hpp | 46 +++--- .../hpx/schedulers/queue_holder_thread.hpp | 56 +++---- .../shared_priority_queue_scheduler.hpp | 139 ++++++++++-------- .../static_priority_queue_scheduler.hpp | 4 +- .../hpx/schedulers/static_queue_scheduler.hpp | 10 +- .../include/hpx/schedulers/thread_queue.hpp | 7 +- libs/core/threading_base/CMakeLists.txt | 1 + .../hpx/threading_base/annotated_function.hpp | 43 +++--- .../detail/get_default_pool.hpp | 15 +- .../threading_base/detail/switch_status.hpp | 9 +- .../hpx/threading_base/execution_agent.hpp | 2 +- .../hpx/threading_base/register_thread.hpp | 86 +++-------- .../hpx/threading_base/scheduler_base.hpp | 7 +- .../hpx/threading_base/scoped_annotation.hpp | 3 +- .../hpx/threading_base/thread_data.hpp | 86 +---------- .../hpx/threading_base/thread_helpers.hpp | 3 + .../hpx/threading_base/thread_pool_base.hpp | 3 +- .../hpx/threading_base/threading_base_fwd.hpp | 87 ++++++++++- .../threading_base/src/annotated_function.cpp | 2 +- .../core/threading_base/src/create_thread.cpp | 4 +- libs/core/threading_base/src/create_work.cpp | 2 +- .../threading_base/src/execution_agent.cpp | 17 +-- .../threading_base/src/get_default_pool.cpp | 5 +- libs/core/threading_base/src/print.cpp | 3 +- .../threading_base/src/register_thread.cpp | 103 +++++++++++++ .../threading_base/src/thread_description.cpp | 3 +- .../command_line_handling.hpp | 1 - .../src/command_line_handling.cpp | 103 +++++++------ .../src/late_command_line_handling.cpp | 7 +- .../src/parse_command_line.cpp | 32 ++-- 48 files changed, 560 insertions(+), 517 deletions(-) create mode 100644 libs/core/threading_base/src/register_thread.cpp diff --git a/cmake/HPX_SetupLCI.cmake b/cmake/HPX_SetupLCI.cmake index 26b1ecd18076..d34cc6e08ec0 100644 --- a/cmake/HPX_SetupLCI.cmake +++ b/cmake/HPX_SetupLCI.cmake @@ -38,14 +38,14 @@ macro(hpx_setup_lci) ) else() hpx_info( - "HPX_WITH_FETCH_LCI=${HPX_WITH_FETCH_LCI}, LCI will be fetched using CMake's FetchContent and installed alongside HPX (HPX_WITH_Lci_TAG=${HPX_WITH_Lci_TAG})" + "HPX_WITH_FETCH_LCI=${HPX_WITH_FETCH_LCI}, LCI will be fetched using CMake's FetchContent and installed alongside HPX (HPX_WITH_LCI_TAG=${HPX_WITH_LCI_TAG})" ) endif() include(FetchContent) fetchcontent_declare( lci GIT_REPOSITORY https://github.com/uiuc-hpc/LC.git - GIT_TAG ${HPX_WITH_Lci_TAG} + GIT_TAG ${HPX_WITH_LCI_TAG} ) fetchcontent_getproperties(lci) diff --git a/libs/core/debugging/include/hpx/debugging/print.hpp b/libs/core/debugging/include/hpx/debugging/print.hpp index bf914ec72b31..9a5fd6ae29e6 100644 --- a/libs/core/debugging/include/hpx/debugging/print.hpp +++ b/libs/core/debugging/include/hpx/debugging/print.hpp @@ -370,7 +370,7 @@ namespace hpx::debug { std::string buffered_msg; // - scoped_var(char const* p, Args const&... args) + explicit scoped_var(char const* p, Args const&... args) : prefix_(p) , message_(args...) { @@ -395,7 +395,7 @@ namespace hpx::debug { double const delay_; std::tuple const message_; // - timed_var(double delay, Args const&... args) + explicit timed_var(double delay, Args const&... args) : time_start_(std::chrono::steady_clock::now()) , delay_(delay) , message_(args...) diff --git a/libs/core/execution/include/hpx/execution/detail/async_launch_policy_dispatch.hpp b/libs/core/execution/include/hpx/execution/detail/async_launch_policy_dispatch.hpp index a314139d54a0..dd3af81985f9 100644 --- a/libs/core/execution/include/hpx/execution/detail/async_launch_policy_dispatch.hpp +++ b/libs/core/execution/include/hpx/execution/detail/async_launch_policy_dispatch.hpp @@ -17,10 +17,10 @@ #include #include #include +#include #include #include #include -#include #include #include diff --git a/libs/core/execution/include/hpx/execution/detail/post_policy_dispatch.hpp b/libs/core/execution/include/hpx/execution/detail/post_policy_dispatch.hpp index 2d3365ccebdb..0a68afb21dcd 100644 --- a/libs/core/execution/include/hpx/execution/detail/post_policy_dispatch.hpp +++ b/libs/core/execution/include/hpx/execution/detail/post_policy_dispatch.hpp @@ -13,10 +13,10 @@ #include #include #include +#include #include #include #include -#include #include #include diff --git a/libs/core/executors/include/hpx/executors/parallel_executor.hpp b/libs/core/executors/include/hpx/executors/parallel_executor.hpp index 010c082497d7..814d7dff5c26 100644 --- a/libs/core/executors/include/hpx/executors/parallel_executor.hpp +++ b/libs/core/executors/include/hpx/executors/parallel_executor.hpp @@ -30,8 +30,8 @@ #include #include #include +#include #include -#include #include #include diff --git a/libs/core/executors/include/hpx/executors/thread_pool_scheduler.hpp b/libs/core/executors/include/hpx/executors/thread_pool_scheduler.hpp index 888e9abe4d4c..1414f8052642 100644 --- a/libs/core/executors/include/hpx/executors/thread_pool_scheduler.hpp +++ b/libs/core/executors/include/hpx/executors/thread_pool_scheduler.hpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include diff --git a/libs/core/futures/include/hpx/futures/futures_factory.hpp b/libs/core/futures/include/hpx/futures/futures_factory.hpp index 853969c0979c..685261a8a97b 100644 --- a/libs/core/futures/include/hpx/futures/futures_factory.hpp +++ b/libs/core/futures/include/hpx/futures/futures_factory.hpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include diff --git a/libs/core/io_service/include/hpx/io_service/io_service_pool.hpp b/libs/core/io_service/include/hpx/io_service/io_service_pool.hpp index 2c499b613eb3..39f163bfd081 100644 --- a/libs/core/io_service/include/hpx/io_service/io_service_pool.hpp +++ b/libs/core/io_service/include/hpx/io_service/io_service_pool.hpp @@ -100,7 +100,7 @@ namespace hpx::util { } /// \brief Activate the thread \a index for this thread pool - void thread_run(std::size_t index, barrier* startup = nullptr); + void thread_run(std::size_t index, barrier* startup = nullptr) const; /// \brief Return name of this pool constexpr char const* get_name() const noexcept @@ -122,7 +122,8 @@ namespace hpx::util { using io_service_ptr = std::unique_ptr; using work_type = std::unique_ptr; - HPX_FORCEINLINE work_type initialize_work(asio::io_context& io_service) + HPX_FORCEINLINE work_type initialize_work( + asio::io_context& io_service) const { return work_type( std::make_unique(io_service)); diff --git a/libs/core/io_service/include/hpx/io_service/io_service_thread_pool.hpp b/libs/core/io_service/include/hpx/io_service/io_service_thread_pool.hpp index ea58e4650cd0..cb64fa1fcbbe 100644 --- a/libs/core/io_service/include/hpx/io_service/io_service_thread_pool.hpp +++ b/libs/core/io_service/include/hpx/io_service/io_service_thread_pool.hpp @@ -8,8 +8,6 @@ #include #include -#include -#include #include #include diff --git a/libs/core/io_service/src/io_service_pool.cpp b/libs/core/io_service/src/io_service_pool.cpp index a5ff061d2e63..041d87109c33 100644 --- a/libs/core/io_service/src/io_service_pool.cpp +++ b/libs/core/io_service/src/io_service_pool.cpp @@ -37,8 +37,6 @@ namespace hpx::util { , pool_name_(pool_name) , pool_name_postfix_(name_postfix) , waiting_(false) - , wait_barrier_() - , continue_barrier_() { LPROGRESS_ << pool_name; init(pool_size); @@ -52,7 +50,6 @@ namespace hpx::util { HPX_THROW_EXCEPTION(hpx::error::bad_parameter, "io_service_pool::io_service_pool", "io_service_pool size is 0"); - return; } wait_barrier_.reset(new barrier(pool_size + 1)); @@ -93,7 +90,8 @@ namespace hpx::util { clear_locked(); } - void io_service_pool::thread_run(std::size_t index, util::barrier* startup) + void io_service_pool::thread_run( + std::size_t index, util::barrier* startup) const { // wait for all threads to start up before before starting HPX work if (startup != nullptr) diff --git a/libs/core/io_service/src/io_service_thread_pool.cpp b/libs/core/io_service/src/io_service_thread_pool.cpp index 2ab7303c6d4d..ec05ba5775a4 100644 --- a/libs/core/io_service/src/io_service_thread_pool.cpp +++ b/libs/core/io_service/src/io_service_thread_pool.cpp @@ -10,8 +10,6 @@ #include #include #include -#include -#include #include #include diff --git a/libs/core/runtime_local/include/hpx/runtime_local/run_as_hpx_thread.hpp b/libs/core/runtime_local/include/hpx/runtime_local/run_as_hpx_thread.hpp index 6443a4c25860..3d917d40158a 100644 --- a/libs/core/runtime_local/include/hpx/runtime_local/run_as_hpx_thread.hpp +++ b/libs/core/runtime_local/include/hpx/runtime_local/run_as_hpx_thread.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2018 Hartmut Kaiser +// Copyright (c) 2016-2023 Hartmut Kaiser // // SPDX-License-Identifier: BSL-1.0 // Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -14,6 +14,7 @@ #include #include #include +#include #include #include diff --git a/libs/core/schedulers/include/hpx/schedulers/background_scheduler.hpp b/libs/core/schedulers/include/hpx/schedulers/background_scheduler.hpp index f3c64d8e12ef..62515866a3ea 100644 --- a/libs/core/schedulers/include/hpx/schedulers/background_scheduler.hpp +++ b/libs/core/schedulers/include/hpx/schedulers/background_scheduler.hpp @@ -8,21 +8,15 @@ #pragma once #include -#include -#include -#include #include #include #include #include -#include #include #include -#include #include #include -#include #include @@ -67,8 +61,10 @@ namespace hpx::threads::policies { { // this scheduler does not support stealing or numa stealing, but // needs to enable background work - mode = scheduler_mode(mode & ~scheduler_mode::enable_stealing); - mode = scheduler_mode(mode & ~scheduler_mode::enable_stealing_numa); + mode = static_cast( + mode & ~scheduler_mode::enable_stealing); + mode = static_cast( + mode & ~scheduler_mode::enable_stealing_numa); mode = mode | ~scheduler_mode::do_background_work; mode = mode | ~scheduler_mode::do_background_work_only; scheduler_base::set_scheduler_mode(mode); @@ -76,7 +72,7 @@ namespace hpx::threads::policies { // Return the next thread to be executed, return false if none is // available - constexpr bool get_next_thread( + static constexpr bool get_next_thread( std::size_t, bool, threads::thread_id_ref_type&, bool) noexcept { // this scheduler does not maintain any thread queues @@ -87,8 +83,9 @@ namespace hpx::threads::policies { // manager to allow for maintenance tasks to be executed in the // scheduler. Returns true if the OS thread calling this function has to // be terminated (i.e. no more work has to be done). - constexpr bool wait_or_add_new(std::size_t, bool running, std::int64_t&, - bool, std::size_t&, thread_id_ref_type* = nullptr) + static constexpr bool wait_or_add_new(std::size_t, bool running, + std::int64_t&, bool, std::size_t&, + thread_id_ref_type* = nullptr) noexcept { return !running; } diff --git a/libs/core/schedulers/include/hpx/schedulers/local_priority_queue_scheduler.hpp b/libs/core/schedulers/include/hpx/schedulers/local_priority_queue_scheduler.hpp index 19b7010173fc..fa46c396fc81 100644 --- a/libs/core/schedulers/include/hpx/schedulers/local_priority_queue_scheduler.hpp +++ b/libs/core/schedulers/include/hpx/schedulers/local_priority_queue_scheduler.hpp @@ -78,7 +78,7 @@ namespace hpx::threads::policies { detail::affinity_data const& affinity_data, std::size_t num_high_priority_queues = static_cast( -1), - thread_queue_init_parameters thread_queue_init = + thread_queue_init_parameters const& thread_queue_init = thread_queue_init_parameters{}, char const* description = "local_priority_queue_scheduler") noexcept @@ -111,7 +111,7 @@ namespace hpx::threads::policies { }; using init_parameter_type = init_parameter; - local_priority_queue_scheduler(init_parameter_type const& init, + explicit local_priority_queue_scheduler(init_parameter_type const& init, bool deferred_initialization = true) : scheduler_base( init.num_queues_, init.description_, init.thread_queue_init_) @@ -801,7 +801,7 @@ namespace hpx::threads::policies { num_thread = select_active_pu(num_thread, allow_fallback); - [[maybe_unused]] auto* thrdptr = get_thread_id_data(thrd); + [[maybe_unused]] auto const* thrdptr = get_thread_id_data(thrd); switch (priority) { case thread_priority::high_recursive: @@ -1007,7 +1007,7 @@ namespace hpx::threads::policies { std::int64_t get_thread_count( thread_schedule_state state = thread_schedule_state::unknown, thread_priority priority = thread_priority::default_, - std::size_t num_thread = std::size_t(-1), + std::size_t num_thread = static_cast(-1), bool /* reset */ = false) const override { // Return thread count of one specific queue. diff --git a/libs/core/schedulers/include/hpx/schedulers/local_queue_scheduler.hpp b/libs/core/schedulers/include/hpx/schedulers/local_queue_scheduler.hpp index 56437c8180c8..27c8423a85c7 100644 --- a/libs/core/schedulers/include/hpx/schedulers/local_queue_scheduler.hpp +++ b/libs/core/schedulers/include/hpx/schedulers/local_queue_scheduler.hpp @@ -34,8 +34,6 @@ #include -// TODO: add branch prediction and function heat - /////////////////////////////////////////////////////////////////////////////// namespace hpx::threads::policies { @@ -67,7 +65,7 @@ namespace hpx::threads::policies { { init_parameter(std::size_t num_queues, detail::affinity_data const& affinity_data, - thread_queue_init_parameters thread_queue_init = + thread_queue_init_parameters const& thread_queue_init = thread_queue_init_parameters{}, char const* description = "local_queue_scheduler") : num_queues_(num_queues) @@ -81,7 +79,6 @@ namespace hpx::threads::policies { detail::affinity_data const& affinity_data, char const* description) : num_queues_(num_queues) - , thread_queue_init_() , affinity_data_(affinity_data) , description_(description) { @@ -101,11 +98,6 @@ namespace hpx::threads::policies { , queues_(init.num_queues_) , curr_queue_(0) , affinity_data_(init.affinity_data_) - // we know that the MIC has one NUMA domain only) -#if !defined(HPX_NATIVE_MIC) - , steals_in_numa_domain_() - , steals_outside_numa_domain_() -#endif , numa_domain_masks_( init.num_queues_, create_topology().get_machine_affinity_mask()) , outside_numa_domain_masks_( @@ -125,7 +117,12 @@ namespace hpx::threads::policies { } } - ~local_queue_scheduler() + local_queue_scheduler(local_queue_scheduler const&) = delete; + local_queue_scheduler(local_queue_scheduler&&) = delete; + local_queue_scheduler& operator=(local_queue_scheduler const&) = delete; + local_queue_scheduler& operator=(local_queue_scheduler&&) = delete; + + ~local_queue_scheduler() override { for (std::size_t i = 0; i != queues_.size(); ++i) delete queues_[i]; @@ -296,11 +293,11 @@ namespace hpx::threads::policies { std::size_t num_thread = data.schedulehint.mode == thread_schedule_hint_mode::thread ? data.schedulehint.hint : - std::size_t(-1); + static_cast(-1); - std::size_t queue_size = queues_.size(); + std::size_t const queue_size = queues_.size(); - if (std::size_t(-1) == num_thread) + if (static_cast(-1) == num_thread) { num_thread = curr_queue_++ % queue_size; } @@ -330,25 +327,24 @@ namespace hpx::threads::policies { bool get_next_thread(std::size_t num_thread, bool running, threads::thread_id_ref_type& thrd, bool /*enable_stealing*/) { - std::size_t queues_size = queues_.size(); + std::size_t const queues_size = queues_.size(); { HPX_ASSERT(num_thread < queues_size); thread_queue_type* q = queues_[num_thread]; - bool result = q->get_next_thread(thrd); + bool const result = q->get_next_thread(thrd); q->increment_num_pending_accesses(); if (result) return true; q->increment_num_pending_misses(); - bool have_staged = - q->get_staged_queue_length(std::memory_order_relaxed) != 0; - // Give up, we should have work to convert. - if (have_staged) + if (q->get_staged_queue_length(std::memory_order_relaxed) != 0) + { return false; + } } if (!running) @@ -356,13 +352,14 @@ namespace hpx::threads::policies { return false; } - bool numa_stealing = has_scheduler_mode( + bool const numa_stealing = has_scheduler_mode( policies::scheduler_mode::enable_stealing_numa); if (!numa_stealing) { // steal work items: first try to steal from other cores in // the same NUMA node - std::size_t pu_number = affinity_data_.get_pu_num(num_thread); + std::size_t const pu_number = + affinity_data_.get_pu_num(num_thread); // we know that the MIC has one NUMA domain only #if !defined(HPX_NATIVE_MIC) @@ -380,10 +377,13 @@ namespace hpx::threads::policies { HPX_ASSERT(idx != num_thread); - std::size_t pu_num = affinity_data_.get_pu_num(idx); - if (!test(this_numa_domain, + if (std::size_t const pu_num = + affinity_data_.get_pu_num(idx); + !test(this_numa_domain, pu_num)) //-V560 //-V600 //-V111 + { continue; + } thread_queue_type* q = queues_[idx]; if (q->get_next_thread(thrd, running)) @@ -413,7 +413,8 @@ namespace hpx::threads::policies { HPX_ASSERT(idx != num_thread); - std::size_t pu_num = affinity_data_.get_pu_num(idx); + std::size_t const pu_num = + affinity_data_.get_pu_num(idx); if (!test(numa_domain, pu_num)) //-V560 //-V600 //-V111 continue; @@ -459,7 +460,7 @@ namespace hpx::threads::policies { thread_priority /* priority */ = thread_priority::default_) override { // NOTE: This scheduler ignores NUMA hints. - std::size_t num_thread = std::size_t(-1); + auto num_thread = static_cast(-1); if (schedulehint.mode == thread_schedule_hint_mode::thread) //-V1051 { @@ -470,9 +471,9 @@ namespace hpx::threads::policies { allow_fallback = false; } - std::size_t queue_size = queues_.size(); + std::size_t const queue_size = queues_.size(); - if (std::size_t(-1) == num_thread) + if (static_cast(-1) == num_thread) { num_thread = curr_queue_++ % queue_size; } @@ -502,7 +503,7 @@ namespace hpx::threads::policies { thread_priority /* priority */ = thread_priority::default_) override { // NOTE: This scheduler ignores NUMA hints. - std::size_t num_thread = std::size_t(-1); + auto num_thread = static_cast(-1); if (schedulehint.mode == thread_schedule_hint_mode::thread) //-V1051 { @@ -513,9 +514,9 @@ namespace hpx::threads::policies { allow_fallback = false; } - std::size_t queue_size = queues_.size(); + std::size_t const queue_size = queues_.size(); - if (std::size_t(-1) == num_thread) + if (static_cast(-1) == num_thread) { num_thread = curr_queue_++ % queue_size; } @@ -541,12 +542,11 @@ namespace hpx::threads::policies { /////////////////////////////////////////////////////////////////////// // This returns the current length of the queues (work items and new items) - std::int64_t get_queue_length( - std::size_t num_thread = std::size_t(-1)) const override + std::int64_t get_queue_length(std::size_t num_thread) const override { // Return queue length of one specific queue. std::int64_t count = 0; - if (std::size_t(-1) != num_thread) + if (static_cast(-1) != num_thread) { HPX_ASSERT(num_thread < queues_.size()); @@ -564,12 +564,12 @@ namespace hpx::threads::policies { std::int64_t get_thread_count( thread_schedule_state state = thread_schedule_state::unknown, thread_priority priority = thread_priority::default_, - std::size_t num_thread = std::size_t(-1), + std::size_t num_thread = static_cast(-1), bool /* reset */ = false) const override { // Return thread count of one specific queue. std::int64_t count = 0; - if (std::size_t(-1) != num_thread) + if (static_cast(-1) != num_thread) { HPX_ASSERT(num_thread < queues_.size()); @@ -593,10 +593,8 @@ namespace hpx::threads::policies { "local_queue_scheduler::get_thread_count", "unknown thread priority value " "(thread_priority::unknown)"); - return 0; } } - return 0; } // Return the cumulative count for all queues. @@ -624,7 +622,6 @@ namespace hpx::threads::policies { "local_queue_scheduler::get_thread_count", "unknown thread priority value " "(thread_priority::unknown)"); - return 0; } } return count; @@ -711,7 +708,7 @@ namespace hpx::threads::policies { std::int64_t& idle_loop_count, bool /* enable_stealing */, std::size_t& added, thread_id_ref_type* = nullptr) { - std::size_t queues_size = queues_.size(); + std::size_t const queues_size = queues_.size(); HPX_ASSERT(num_thread < queues_.size()); added = 0; @@ -729,14 +726,14 @@ namespace hpx::threads::policies { return true; } - bool numa_stealing_ = has_scheduler_mode( - policies::scheduler_mode::enable_stealing_numa); // limited or no stealing across domains - if (!numa_stealing_) + if (!has_scheduler_mode( + policies::scheduler_mode::enable_stealing_numa)) { // steal work items: first try to steal from other cores in the // same NUMA node - std::size_t pu_number = affinity_data_.get_pu_num(num_thread); + std::size_t const pu_number = + affinity_data_.get_pu_num(num_thread); // we know that the MIC has one NUMA domain only #if !defined(HPX_NATIVE_MIC) @@ -875,7 +872,7 @@ namespace hpx::threads::policies { auto const& topo = create_topology(); // pre-calculate certain constants for the given thread number - std::size_t num_pu = affinity_data_.get_pu_num(num_thread); + std::size_t const num_pu = affinity_data_.get_pu_num(num_thread); mask_cref_type machine_mask = topo.get_machine_affinity_mask(); mask_cref_type core_mask = topo.get_thread_affinity_mask(num_pu); mask_cref_type node_mask = topo.get_numa_node_affinity_mask(num_pu); @@ -892,15 +889,15 @@ namespace hpx::threads::policies { mask_type first_mask = mask_type(); resize(first_mask, mask_size(core_mask)); - std::size_t first = find_first(node_mask); - if (first != std::size_t(-1)) + std::size_t const first = find_first(node_mask); + if (first != static_cast(-1)) set(first_mask, first); else first_mask = core_mask; - bool numa_stealing = has_scheduler_mode( - policies::scheduler_mode::enable_stealing_numa); - if (numa_stealing && any(first_mask & core_mask)) + if (has_scheduler_mode( + policies::scheduler_mode::enable_stealing_numa) && + any(first_mask & core_mask)) { #if !defined(HPX_NATIVE_MIC) // we know that the MIC has one NUMA domain only set(steals_outside_numa_domain_, num_pu); diff --git a/libs/core/schedulers/include/hpx/schedulers/lockfree_queue_backends.hpp b/libs/core/schedulers/include/hpx/schedulers/lockfree_queue_backends.hpp index c9ef72bdc07e..65296f65cdd0 100644 --- a/libs/core/schedulers/include/hpx/schedulers/lockfree_queue_backends.hpp +++ b/libs/core/schedulers/include/hpx/schedulers/lockfree_queue_backends.hpp @@ -51,8 +51,8 @@ namespace hpx::threads::policies { using size_type = std::uint64_t; explicit lockfree_fifo_backend(size_type initial_size = 0, - size_type /* num_thread */ = size_type(-1)) - : queue_(std::size_t(initial_size)) + size_type /* num_thread */ = static_cast(-1)) + : queue_(static_cast(initial_size)) { } @@ -115,8 +115,8 @@ namespace hpx::threads::policies { using size_type = std::uint64_t; explicit moodycamel_fifo_backend(size_type initial_size = 0, - size_type /* num_thread */ = size_type(-1)) - : queue_(std::size_t(initial_size)) + size_type /* num_thread */ = static_cast(-1)) + : queue_(static_cast(initial_size)) { } @@ -171,8 +171,8 @@ namespace hpx::threads::policies { using size_type = std::uint64_t; explicit lockfree_lifo_backend(size_type initial_size = 0, - size_type /* num_thread */ = size_type(-1)) - : queue_(std::size_t(initial_size)) + size_type /* num_thread */ = static_cast(-1)) + : queue_(static_cast(initial_size)) { } @@ -231,8 +231,8 @@ namespace hpx::threads::policies { using size_type = std::uint64_t; explicit lockfree_abp_fifo_backend(size_type initial_size = 0, - size_type /* num_thread */ = size_type(-1)) - : queue_(std::size_t(initial_size)) + size_type /* num_thread */ = static_cast(-1)) + : queue_(static_cast(initial_size)) { } @@ -288,8 +288,8 @@ namespace hpx::threads::policies { using size_type = std::uint64_t; explicit lockfree_abp_lifo_backend(size_type initial_size = 0, - size_type /* num_thread */ = size_type(-1)) - : queue_(std::size_t(initial_size)) + size_type /* num_thread */ = static_cast(-1)) + : queue_(static_cast(initial_size)) { } diff --git a/libs/core/schedulers/include/hpx/schedulers/maintain_queue_wait_times.hpp b/libs/core/schedulers/include/hpx/schedulers/maintain_queue_wait_times.hpp index 0f407a85f5a7..ef7674aae59c 100644 --- a/libs/core/schedulers/include/hpx/schedulers/maintain_queue_wait_times.hpp +++ b/libs/core/schedulers/include/hpx/schedulers/maintain_queue_wait_times.hpp @@ -9,11 +9,11 @@ #include +#ifdef HPX_HAVE_THREAD_QUEUE_WAITTIME namespace hpx::threads::policies { -#ifdef HPX_HAVE_THREAD_QUEUE_WAITTIME HPX_CORE_EXPORT void set_maintain_queue_wait_times_enabled( bool enabled) noexcept; HPX_CORE_EXPORT bool get_maintain_queue_wait_times_enabled() noexcept; -#endif } // namespace hpx::threads::policies +#endif diff --git a/libs/core/schedulers/include/hpx/schedulers/queue_helpers.hpp b/libs/core/schedulers/include/hpx/schedulers/queue_helpers.hpp index 1b18ad17eb29..1e5f13203d13 100644 --- a/libs/core/schedulers/include/hpx/schedulers/queue_helpers.hpp +++ b/libs/core/schedulers/include/hpx/schedulers/queue_helpers.hpp @@ -14,14 +14,10 @@ #include #include #include -#include #include -#include #include #include -#include -#include /////////////////////////////////////////////////////////////////////////////// namespace hpx::threads::policies { @@ -56,9 +52,9 @@ namespace hpx::threads::policies { for (typename Map::const_iterator it = tm.begin(); it != end; ++it) { threads::thread_data const* thrd = get_thread_id_data(*it); - threads::thread_schedule_state state = + threads::thread_schedule_state const state = thrd->get_state().state(); - threads::thread_schedule_state marked_state = + threads::thread_schedule_state const marked_state = thrd->get_marked_state(); if (state != marked_state) diff --git a/libs/core/schedulers/include/hpx/schedulers/queue_holder_numa.hpp b/libs/core/schedulers/include/hpx/schedulers/queue_holder_numa.hpp index 0d26d2502db7..aa46a09d8fcd 100644 --- a/libs/core/schedulers/include/hpx/schedulers/queue_holder_numa.hpp +++ b/libs/core/schedulers/include/hpx/schedulers/queue_holder_numa.hpp @@ -7,32 +7,16 @@ #pragma once #include -#include #include #include #include // -#include -#include -#include -// #include // -#include #include #include -#include -#include -#include -#include - -#include #include -#include -#include -#include -#include -#include +#include #if !defined(QUEUE_HOLDER_NUMA_DEBUG) #if defined(HPX_DEBUG) @@ -232,7 +216,7 @@ namespace hpx::threads::policies { } // ---------------------------------------------------------------- - inline std::int64_t get_thread_count( + inline std::size_t get_thread_count( thread_schedule_state state = thread_schedule_state::unknown, thread_priority priority = thread_priority::default_) const { @@ -265,33 +249,33 @@ namespace hpx::threads::policies { std::vector queues_; public: - constexpr void increment_num_pending_misses( + static constexpr void increment_num_pending_misses( std::size_t /* num */ = 1) noexcept { } - constexpr void increment_num_pending_accesses( + static constexpr void increment_num_pending_accesses( std::size_t /* num */ = 1) noexcept { } - constexpr void increment_num_stolen_from_pending( + static constexpr void increment_num_stolen_from_pending( std::size_t /* num */ = 1) noexcept { } - constexpr void increment_num_stolen_from_staged( + static constexpr void increment_num_stolen_from_staged( std::size_t /* num */ = 1) noexcept { } - constexpr void increment_num_stolen_to_pending( + static constexpr void increment_num_stolen_to_pending( std::size_t /* num */ = 1) noexcept { } - constexpr void increment_num_stolen_to_staged( + static constexpr void increment_num_stolen_to_staged( std::size_t /* num */ = 1) noexcept { } // ------------------------------------------------------------ - bool dump_suspended_threads(std::size_t /* num_thread */, + static bool dump_suspended_threads(std::size_t /* num_thread */, std::int64_t& /* idle_loop_count */, bool /* running */) noexcept { return false; @@ -305,9 +289,15 @@ namespace hpx::threads::policies { } // ------------------------------------------------------------ - constexpr void on_start_thread(std::size_t /* num_thread */) noexcept {} - constexpr void on_stop_thread(std::size_t /* num_thread */) noexcept {} - constexpr void on_error(std::size_t /* num_thread */, + static constexpr void on_start_thread( + std::size_t /* num_thread */) noexcept + { + } + static constexpr void on_stop_thread( + std::size_t /* num_thread */) noexcept + { + } + static constexpr void on_error(std::size_t /* num_thread */, std::exception_ptr const& /* e */) noexcept { } diff --git a/libs/core/schedulers/include/hpx/schedulers/queue_holder_thread.hpp b/libs/core/schedulers/include/hpx/schedulers/queue_holder_thread.hpp index 4837cbe5623f..b5de546e3351 100644 --- a/libs/core/schedulers/include/hpx/schedulers/queue_holder_thread.hpp +++ b/libs/core/schedulers/include/hpx/schedulers/queue_holder_thread.hpp @@ -8,7 +8,6 @@ #include #include -#include #include #include #include @@ -17,7 +16,6 @@ #include #include #include -#include #include #include @@ -25,12 +23,11 @@ #include #include #include -#include #include -#include #include #include #include +#include #include #include #include @@ -356,14 +353,14 @@ namespace hpx::threads::policies { tq_deb.debug(debug::str<>("cleanup"), "delete", queue_data_print(this), debug::threadinfo(todelete)); - thread_id_type tid(todelete); + thread_id_type const tid(todelete); remove_from_thread_map(tid, true); } } else { // delete only this many threads - std::int64_t delete_count = static_cast( + auto delete_count = static_cast( terminated_items_count_.data_.load( std::memory_order_relaxed) / 2); @@ -505,7 +502,7 @@ namespace hpx::threads::policies { #endif { // Allocate a new thread object. - threads::thread_data* p = nullptr; + threads::thread_data* p; if (stacksize == parameters_.nostack_stacksize_) { p = threads::thread_data_stackless::create( @@ -528,7 +525,7 @@ namespace hpx::threads::policies { void recycle_thread(thread_id_type tid) { #if !defined(HPX_HAVE_ADDRESS_SANITIZER) - std::ptrdiff_t stacksize = + std::ptrdiff_t const stacksize = get_thread_id_data(tid)->get_stack_size(); if (stacksize == parameters_.small_stacksize_) @@ -575,12 +572,12 @@ namespace hpx::threads::policies { scoped_lock lk(thread_map_mtx_.data_); // add a new entry in the map for this thread - std::pair p = + std::pair const p = thread_map_.insert(tid); if (/*HPX_UNLIKELY*/ (!p.second)) { - std::string map_size = std::to_string(thread_map_.size()); + std::string const map_size = std::to_string(thread_map_.size()); tq_deb.error(debug::str<>("map add"), "Couldn't add new thread to the thread map", @@ -609,7 +606,7 @@ namespace hpx::threads::policies { HPX_ASSERT(thread_map_.find(tid) != thread_map_.end()); HPX_ASSERT(thread_map_count_.data_ >= 0); - [[maybe_unused]] bool deleted = thread_map_.erase(tid) != 0; + [[maybe_unused]] bool const deleted = thread_map_.erase(tid) != 0; HPX_ASSERT(deleted); tq_deb.debug(debug::str<>("map remove"), queue_data_print(this), @@ -680,8 +677,8 @@ namespace hpx::threads::policies { } // ---------------------------------------------------------------- - std::size_t add_new_HP( - std::int64_t add_count, thread_holder_type* addfrom, bool stealing) + std::size_t add_new_HP(std::int64_t add_count, + thread_holder_type const* addfrom, bool stealing) { std::size_t added; if (owns_bp_queue() && !stealing) @@ -794,7 +791,6 @@ namespace hpx::threads::policies { "unknown thread priority value (thread_priority::unknown)"); } } - return 0; } // ---------------------------------------------------------------- @@ -845,7 +841,6 @@ namespace hpx::threads::policies { "unknown thread priority value (thread_priority::unknown)"); } } - return 0; } // ---------------------------------------------------------------- @@ -873,9 +868,8 @@ namespace hpx::threads::policies { scoped_lock lk(thread_map_mtx_.data_); std::int64_t num_threads = 0; - thread_map_type::const_iterator end = thread_map_.end(); - for (thread_map_type::const_iterator it = thread_map_.begin(); - it != end; ++it) + auto const end = thread_map_.end(); + for (auto it = thread_map_.begin(); it != end; ++it) { if (get_thread_id_data(*it)->get_state().state() == state) ++num_threads; @@ -896,8 +890,8 @@ namespace hpx::threads::policies { "xthread", xthread, queue_data_print(this), debug::threadinfo(thrd)); terminated_items_.push(thrd); - std::int64_t count = ++terminated_items_count_.data_; + std::int64_t const count = ++terminated_items_count_.data_; if (!xthread && (count > parameters_.max_terminated_threads_)) { // clean up all terminated threads @@ -909,16 +903,17 @@ namespace hpx::threads::policies { void abort_all_suspended_threads() { scoped_lock lk(thread_map_mtx_.data_); - thread_map_type::iterator end = thread_map_.end(); - for (thread_map_type::iterator it = thread_map_.begin(); it != end; - ++it) + auto const end = thread_map_.end(); + for (auto it = thread_map_.begin(); it != end; ++it) { if (get_thread_id_data(*it)->get_state().state() == thread_schedule_state::suspended) { - get_thread_id_data(*it)->set_state( - thread_schedule_state::pending, - thread_restart_state::abort); + [[maybe_unused]] auto const s = + get_thread_id_data(*it)->set_state( + thread_schedule_state::pending, + thread_restart_state::abort); + // np queue always exists so use that as priority doesn't matter np_queue_->schedule_work(*it, true); } @@ -940,7 +935,6 @@ namespace hpx::threads::policies { HPX_THROW_EXCEPTION(hpx::error::bad_parameter, "queue_holder_thread::iterate_threads", "can't iterate over thread ids of staged threads"); - return false; } std::vector tids; @@ -949,9 +943,8 @@ namespace hpx::threads::policies { if (state == thread_schedule_state::unknown) { scoped_lock lk(thread_map_mtx_.data_); - thread_map_type::const_iterator end = thread_map_.end(); - for (thread_map_type::const_iterator it = thread_map_.begin(); - it != end; ++it) + auto const end = thread_map_.end(); + for (auto it = thread_map_.begin(); it != end; ++it) { tids.push_back(*it); } @@ -959,9 +952,8 @@ namespace hpx::threads::policies { else { scoped_lock lk(thread_map_mtx_.data_); - thread_map_type::const_iterator end = thread_map_.end(); - for (thread_map_type::const_iterator it = thread_map_.begin(); - it != end; ++it) + auto const end = thread_map_.end(); + for (auto it = thread_map_.begin(); it != end; ++it) { if (get_thread_id_data(*it)->get_state().state() == state) tids.push_back(*it); diff --git a/libs/core/schedulers/include/hpx/schedulers/shared_priority_queue_scheduler.hpp b/libs/core/schedulers/include/hpx/schedulers/shared_priority_queue_scheduler.hpp index d37ffb9c915b..69ad15e9343d 100644 --- a/libs/core/schedulers/include/hpx/schedulers/shared_priority_queue_scheduler.hpp +++ b/libs/core/schedulers/include/hpx/schedulers/shared_priority_queue_scheduler.hpp @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include @@ -64,12 +63,10 @@ namespace hpx { hpx::debug::enable_print; using print_on = hpx::debug::enable_print; - static print_onoff spq_deb("SPQUEUE"); - static print_on spq_arr("SPQUEUE"); + inline constexpr print_onoff spq_deb("SPQUEUE"); + inline constexpr print_on spq_arr("SPQUEUE"); } // namespace hpx -#define SHARED_PRIORITY_QUEUE_SCHEDULER_API 3 - namespace hpx::threads::policies { /////////////////////////////////////////////////////////////////////////// @@ -141,7 +138,6 @@ namespace hpx::threads::policies { char const* description) : num_worker_threads_(num_worker_threads) , cores_per_queue_(cores_per_queue) - , thread_queue_init_() , affinity_data_(affinity_data) , description_(description) { @@ -173,12 +169,21 @@ namespace hpx::threads::policies { , initialized_(false) , debug_init_(false) , thread_init_counter_(0) - , pool_index_(std::size_t(-1)) + , pool_index_(static_cast(-1)) { scheduler_base::set_scheduler_mode(scheduler_mode::default_); HPX_ASSERT(num_workers_ != 0); } + shared_priority_queue_scheduler( + shared_priority_queue_scheduler const&) = delete; + shared_priority_queue_scheduler( + shared_priority_queue_scheduler&&) = delete; + shared_priority_queue_scheduler& operator=( + shared_priority_queue_scheduler const&) = delete; + shared_priority_queue_scheduler& operator=( + shared_priority_queue_scheduler&&) = delete; + virtual ~shared_priority_queue_scheduler() = default; static std::string_view get_scheduler_name() @@ -221,14 +226,14 @@ namespace hpx::threads::policies { // node. It should not be used without care as the thread numbering // internal to the scheduler is not a simple linear indexing // returns -1 to indicate an invalid thread/value/state - inline std::size_t local_thread_number() + inline std::size_t local_thread_number() const { using namespace hpx::threads::detail; std::size_t const thread_pool_num = get_thread_pool_num_tss(); // if the thread belongs to this pool return local Id if (pool_index_ == thread_pool_num) return get_local_thread_num_tss(); - return std::size_t(-1); + return static_cast(-1); } // ------------------------------------------------------------ @@ -240,7 +245,7 @@ namespace hpx::threads::policies { spq_deb.timed(cleanup); std::size_t local_num = local_thread_number(); - if (local_num == std::size_t(-1)) + if (local_num == static_cast(-1)) { // clang-format off using namespace hpx::threads::detail; @@ -258,7 +263,7 @@ namespace hpx::threads::policies { } std::size_t domain_num = d_lookup_[local_num]; - std::size_t q_index = q_lookup_[local_num]; + std::size_t const q_index = q_lookup_[local_num]; spq_deb.debug(debug::str<>("cleanup_terminated"), "v1", "D", debug::dec<2>(domain_num), "Q", debug::dec<3>(q_index), @@ -278,7 +283,7 @@ namespace hpx::threads::policies { // find the numa domain from the local thread index std::size_t domain_num = d_lookup_[local_num]; - std::size_t q_index = q_lookup_[local_num]; + std::size_t const q_index = q_lookup_[local_num]; spq_deb.debug(debug::str<>("cleanup_terminated"), "v2", "D", debug::dec<2>(domain_num), "Q", debug::dec<3>(q_index), @@ -319,7 +324,7 @@ namespace hpx::threads::policies { { spq_deb.set(msg, "HINT_NONE "); // Create thread on this worker thread if possible - if (local_num == std::size_t(-1)) + if (local_num == static_cast(-1)) { // clang-format off using namespace hpx::threads::detail; @@ -340,14 +345,15 @@ namespace hpx::threads::policies { } else if (!round_robin_) /* thread parent */ { - if (spq_deb.is_enabled()) + if constexpr (spq_deb.is_enabled()) { domain_num = d_lookup_[thread_num]; q_index = q_lookup_[thread_num]; + + spq_deb.debug(debug::str<>("create_thread"), + "assign_work_thread_parent", "thread_num", + thread_num, "pool", parent_pool_->get_pool_name()); } - spq_deb.debug(debug::str<>("create_thread"), - "assign_work_thread_parent", "thread_num", thread_num, - "pool", parent_pool_->get_pool_name()); } else /*(round_robin)*/ { @@ -390,7 +396,7 @@ namespace hpx::threads::policies { domain_num = fast_mod(data.schedulehint.hint, num_domains_); // if the thread creating the new task is on the domain // assigned to the new task - try to reuse the core as well - if (local_num != std::size_t(-1) && + if (local_num != static_cast(-1) && d_lookup_[local_num] == domain_num) { thread_num = local_num; //-V1048 @@ -603,7 +609,7 @@ namespace hpx::threads::policies { bool get_next_thread(std::size_t thread_num, bool running, threads::thread_id_ref_type& thrd, bool enable_stealing) { - std::size_t this_thread = local_thread_number(); + std::size_t const this_thread = local_thread_number(); HPX_ASSERT(this_thread < num_workers_); // just cleanup the thread we were called by rather than all threads @@ -615,19 +621,19 @@ namespace hpx::threads::policies { auto get_next_thread_function_HP = [&](std::size_t domain, std::size_t q_index, thread_holder_type* /* receiver */, - threads::thread_id_ref_type& thrd, bool stealing, + threads::thread_id_ref_type& th, bool stealing, bool allow_stealing) { return numa_holder_[domain].get_next_thread_HP( - q_index, thrd, stealing, allow_stealing); + q_index, th, stealing, allow_stealing); }; auto get_next_thread_function = [&](std::size_t domain, std::size_t q_index, thread_holder_type* /* receiver */, - threads::thread_id_ref_type& thrd, bool stealing, + threads::thread_id_ref_type& th, bool stealing, bool allow_stealing) { return numa_holder_[domain].get_next_thread( - q_index, thrd, stealing, allow_stealing); + q_index, th, stealing, allow_stealing); }; std::size_t domain = d_lookup_[this_thread]; @@ -636,13 +642,15 @@ namespace hpx::threads::policies { // first try a high priority task, allow stealing if stealing of HP // tasks in on, this will be fine but send a null function for // normal tasks - bool result = steal_by_function(domain, - q_index, numa_stealing_, core_stealing_, nullptr, thrd, - "SBF-get_next_thread", get_next_thread_function_HP, - get_next_thread_function); - if (result) + if (bool const result = + steal_by_function(domain, + q_index, numa_stealing_, core_stealing_, nullptr, thrd, + "SBF-get_next_thread", get_next_thread_function_HP, + get_next_thread_function)) + { return result; + } // if we did not get a task at all, then try converting tasks in the // pending queue into staged ones @@ -650,8 +658,10 @@ namespace hpx::threads::policies { std::int64_t idle_loop_count = 0; wait_or_add_new(thread_num, true, idle_loop_count, true, added); if (added > 0) + { return get_next_thread( this_thread, running, thrd, enable_stealing); + } return false; } @@ -660,7 +670,7 @@ namespace hpx::threads::policies { std::int64_t& /* idle_loop_count */, bool /*enable_stealing*/, std::size_t& added, thread_id_ref_type* = nullptr) { - std::size_t this_thread = local_thread_number(); + std::size_t const this_thread = local_thread_number(); HPX_ASSERT(this_thread < num_workers_); // just cleanup the thread we were called by rather than all threads @@ -671,18 +681,18 @@ namespace hpx::threads::policies { auto add_new_function_HP = [&](std::size_t domain, std::size_t q_index, - thread_holder_type* receiver, std::size_t& added, + thread_holder_type* receiver, std::size_t& add, bool stealing, bool allow_stealing) { return numa_holder_[domain].add_new_HP( - receiver, q_index, added, stealing, allow_stealing); + receiver, q_index, add, stealing, allow_stealing); }; auto add_new_function = [&](std::size_t domain, std::size_t q_index, thread_holder_type* receiver, - std::size_t& added, bool stealing, + std::size_t& add, bool stealing, bool allow_stealing) { return numa_holder_[domain].add_new( - receiver, q_index, added, stealing, allow_stealing); + receiver, q_index, add, stealing, allow_stealing); }; std::size_t domain = d_lookup_[this_thread]; @@ -694,8 +704,8 @@ namespace hpx::threads::policies { q_index, "numa_stealing ", numa_stealing_, "core_stealing ", core_stealing_); - bool added_tasks = steal_by_function(domain, q_index, - numa_stealing_, core_stealing_, receiver, added, + bool const added_tasks = steal_by_function(domain, + q_index, numa_stealing_, core_stealing_, receiver, added, "wait_or_add_new", add_new_function_HP, add_new_function); return !added_tasks; @@ -711,7 +721,7 @@ namespace hpx::threads::policies { std::size_t local_num = local_thread_number(); std::size_t thread_num = local_num; std::size_t domain_num = 0; - std::size_t q_index = std::size_t(-1); + auto q_index = static_cast(-1); auto msg = spq_deb.declare_variable(nullptr); @@ -725,7 +735,7 @@ namespace hpx::threads::policies { { // Create thread on this worker thread if possible spq_deb.set(msg, "HINT_NONE "); - if (local_num == std::size_t(-1)) + if (local_num == static_cast(-1)) { // This is a task being injected from a thread on another // pool - we can schedule on any thread available @@ -863,16 +873,15 @@ namespace hpx::threads::policies { // This returns the current length of the queues // (work items and new items) //--------------------------------------------------------------------- - std::int64_t get_queue_length( - std::size_t thread_num = std::size_t(-1)) const override + std::int64_t get_queue_length(std::size_t thread_num) const override { spq_deb.debug(debug::str<>("get_queue_length"), "thread_num ", debug::dec<>(thread_num)); - HPX_ASSERT(thread_num != std::size_t(-1)); + HPX_ASSERT(thread_num != static_cast(-1)); std::int64_t count = 0; - if (thread_num != std::size_t(-1)) + if (thread_num != static_cast(-1)) { std::size_t domain_num = d_lookup_[thread_num]; std::size_t q_index = q_lookup_[thread_num]; @@ -893,13 +902,13 @@ namespace hpx::threads::policies { std::int64_t get_thread_count( thread_schedule_state state = thread_schedule_state::unknown, thread_priority priority = thread_priority::default_, - std::size_t thread_num = std::size_t(-1), + std::size_t thread_num = static_cast(-1), bool /* reset */ = false) const override { spq_deb.debug(debug::str<>("get_thread_count"), "thread_num ", debug::dec<3>(thread_num)); - if (thread_num != std::size_t(-1)) + if (thread_num != static_cast(-1)) { std::size_t domain_num = d_lookup_[thread_num]; std::size_t q_index = q_lookup_[thread_num]; @@ -962,7 +971,8 @@ namespace hpx::threads::policies { initialized_ = true; // used to make sure thread ids are valid for this scheduler - pool_index_ = std::size_t(parent_pool_->get_pool_index()); + pool_index_ = + static_cast(parent_pool_->get_pool_index()); // For each worker thread, count which numa domain each // belongs to and build lists of useful indexes/refs @@ -976,9 +986,10 @@ namespace hpx::threads::policies { for (std::size_t local_id = 0; local_id != num_workers_; ++local_id) { - std::size_t global_id = + std::size_t const global_id = local_to_global_thread_index(local_id); - std::size_t pu_num = affinity_data_.get_pu_num(global_id); + std::size_t const pu_num = + affinity_data_.get_pu_num(global_id); std::size_t domain = topo.get_numa_node_number(pu_num); #if defined(SHARED_PRIORITY_SCHEDULER_DEBUG_NUMA) if (local_id >= (num_workers_ + 1) / 2) @@ -1028,13 +1039,13 @@ namespace hpx::threads::policies { std::vector locations; for (std::size_t local_id = 0; local_id != num_workers_; ++local_id) { - std::size_t global_id = local_to_global_thread_index(local_id); + std::size_t const global_id = + local_to_global_thread_index(local_id); std::size_t pu_num = affinity_data_.get_pu_num(global_id); std::size_t core = topo.get_core_number(pu_num); std::size_t domain = d_lookup_[local_id]; // - locations.push_back( - std::make_tuple(domain, core, pu_num, local_id)); + locations.emplace_back(domain, core, pu_num, local_id); } // sort by 1) domain, 2) core, 3) pu so that we can iterate over @@ -1067,7 +1078,6 @@ namespace hpx::threads::policies { parent_pool_->get_pool_id().index()); // one thread holder per core (shared by PUs) - thread_holder_type* thread_holder = nullptr; // queue pointers we will assign to each thread thread_queue_type* bp_queue = nullptr; @@ -1076,12 +1086,11 @@ namespace hpx::threads::policies { thread_queue_type* lp_queue = nullptr; // for each worker thread, assign queues - std::size_t previous_domain = std::size_t(-1); + auto previous_domain = static_cast(-1); std::size_t index = 0; for (auto& tup : locations) { - std::int16_t owner_mask = 0; std::size_t domain = std::get<0>(tup); std::size_t local_id = std::get<3>(tup); std::size_t numa_id = local_id - q_offset_[domain]; @@ -1102,6 +1111,7 @@ namespace hpx::threads::policies { if (local_thread == local_id) { + std::int16_t owner_mask = 0; q_lookup_[local_thread] = static_cast(index); // bound queues are never shared @@ -1171,13 +1181,14 @@ namespace hpx::threads::policies { local_thread, "domain", domain, "index", index, "local_id", local_id, "owner_mask", owner_mask); - thread_holder = new queue_holder_thread( - bp_queue, hp_queue, np_queue, lp_queue, - static_cast(domain), - static_cast(index), - static_cast(local_id), - static_cast(owner_mask), - queue_parameters_); + thread_holder_type* thread_holder = + new queue_holder_thread(bp_queue, + hp_queue, np_queue, lp_queue, + static_cast(domain), + static_cast(index), + static_cast(local_id), + static_cast(owner_mask), + queue_parameters_); numa_holder_[domain].queues_[numa_id] = thread_holder; } @@ -1191,7 +1202,7 @@ namespace hpx::threads::policies { } // increment the thread counter and allow the next thread to init - thread_init_counter_++; + ++thread_init_counter_; // we do not want to allow threads to start stealing from others // until all threads have initialized their structures. We therefore @@ -1206,10 +1217,10 @@ namespace hpx::threads::policies { if (!debug_init_) { debug_init_ = true; - spq_arr.array("# d_lookup_ ", &d_lookup_[0], num_workers_); - spq_arr.array("# q_lookup_ ", &q_lookup_[0], num_workers_); - spq_arr.array("# q_counts_ ", &q_counts_[0], num_domains_); - spq_arr.array("# q_offset_ ", &q_offset_[0], num_domains_); + spq_arr.array("# d_lookup_ ", d_lookup_.data(), num_workers_); + spq_arr.array("# q_lookup_ ", q_lookup_.data(), num_workers_); + spq_arr.array("# q_counts_ ", q_counts_.data(), num_domains_); + spq_arr.array("# q_offset_ ", q_offset_.data(), num_domains_); #ifdef SHARED_PRIORITY_SCHEDULER_LINUX spq_arr.array("# schedcpu_ ", &schedcpu_[0], num_workers_); #endif diff --git a/libs/core/schedulers/include/hpx/schedulers/static_priority_queue_scheduler.hpp b/libs/core/schedulers/include/hpx/schedulers/static_priority_queue_scheduler.hpp index 1933fe3dade4..57c03ff3af21 100644 --- a/libs/core/schedulers/include/hpx/schedulers/static_priority_queue_scheduler.hpp +++ b/libs/core/schedulers/include/hpx/schedulers/static_priority_queue_scheduler.hpp @@ -69,9 +69,9 @@ namespace hpx::threads::policies { void set_scheduler_mode(scheduler_mode mode) noexcept override { // this scheduler does not support stealing or numa stealing - mode = policies::scheduler_mode( + mode = static_cast( mode & ~policies::scheduler_mode::enable_stealing); - mode = policies::scheduler_mode( + mode = static_cast( mode & ~policies::scheduler_mode::enable_stealing_numa); scheduler_base::set_scheduler_mode(mode); } diff --git a/libs/core/schedulers/include/hpx/schedulers/static_queue_scheduler.hpp b/libs/core/schedulers/include/hpx/schedulers/static_queue_scheduler.hpp index d1b0bcb234b7..e74457cd6a12 100644 --- a/libs/core/schedulers/include/hpx/schedulers/static_queue_scheduler.hpp +++ b/libs/core/schedulers/include/hpx/schedulers/static_queue_scheduler.hpp @@ -13,16 +13,12 @@ #include #include #include -#include #include -#include #include #include -#include #include #include -#include /////////////////////////////////////////////////////////////////////////////// namespace hpx::threads::policies { @@ -66,8 +62,10 @@ namespace hpx::threads::policies { void set_scheduler_mode(scheduler_mode mode) noexcept override { // this scheduler does not support stealing or numa stealing - mode = scheduler_mode(mode & ~scheduler_mode::enable_stealing); - mode = scheduler_mode(mode & ~scheduler_mode::enable_stealing_numa); + mode = static_cast( + mode & ~scheduler_mode::enable_stealing); + mode = static_cast( + mode & ~scheduler_mode::enable_stealing_numa); scheduler_base::set_scheduler_mode(mode); } diff --git a/libs/core/schedulers/include/hpx/schedulers/thread_queue.hpp b/libs/core/schedulers/include/hpx/schedulers/thread_queue.hpp index 7758770b9306..4c8524bad734 100644 --- a/libs/core/schedulers/include/hpx/schedulers/thread_queue.hpp +++ b/libs/core/schedulers/include/hpx/schedulers/thread_queue.hpp @@ -342,7 +342,7 @@ namespace hpx::threads::policies { return addednew != 0; } - void recycle_thread(thread_id_type thrd) + void recycle_thread(thread_id_type const& thrd) { std::ptrdiff_t const stacksize = get_thread_id_data(thrd)->get_stack_size(); @@ -961,8 +961,9 @@ namespace hpx::threads::policies { if (thrd->get_state().state() == thread_schedule_state::suspended) { - thrd->set_state(thread_schedule_state::pending, - thread_restart_state::abort); + [[maybe_unused]] auto const s = + thrd->set_state(thread_schedule_state::pending, + thread_restart_state::abort); // thread holds self-reference HPX_ASSERT(thrd->count_ > 1); diff --git a/libs/core/threading_base/CMakeLists.txt b/libs/core/threading_base/CMakeLists.txt index 3da1b8e31110..72f7b64b6ffc 100644 --- a/libs/core/threading_base/CMakeLists.txt +++ b/libs/core/threading_base/CMakeLists.txt @@ -73,6 +73,7 @@ set(threading_base_sources get_default_pool.cpp get_default_timer_service.cpp print.cpp + register_thread.cpp scheduler_base.cpp set_thread_state.cpp set_thread_state_timed.cpp diff --git a/libs/core/threading_base/include/hpx/threading_base/annotated_function.hpp b/libs/core/threading_base/include/hpx/threading_base/annotated_function.hpp index e7f1f6942ddd..b212ff01625a 100644 --- a/libs/core/threading_base/include/hpx/threading_base/annotated_function.hpp +++ b/libs/core/threading_base/include/hpx/threading_base/annotated_function.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2022 Hartmut Kaiser +// Copyright (c) 2017-2023 Hartmut Kaiser // // SPDX-License-Identifier: BSL-1.0 // Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -25,7 +25,6 @@ #endif #include -#include #include #include #include @@ -77,7 +76,6 @@ namespace hpx { /// \brief Returns the function address /// /// This function returns the passed function address. - /// \param none constexpr std::size_t get_function_address() const noexcept { return traits::get_function_address::call(f_); @@ -89,8 +87,6 @@ namespace hpx { /// This function returns the function annotation, if it has a name /// name is returned, name is returned; if name is empty the typeid /// is returned - /// - /// \param none constexpr char const* get_function_annotation() const noexcept { return name_ ? name_ : typeid(f_).name(); @@ -150,31 +146,28 @@ namespace hpx { #endif } // namespace hpx -namespace hpx::traits { - #if defined(HPX_HAVE_THREAD_DESCRIPTION) - /////////////////////////////////////////////////////////////////////////// - template - struct get_function_address> +/////////////////////////////////////////////////////////////////////////// +template +struct hpx::traits::get_function_address> +{ + static constexpr std::size_t call( + hpx::detail::annotated_function const& f) noexcept { - static constexpr std::size_t call( - hpx::detail::annotated_function const& f) noexcept - { - return f.get_function_address(); - } - }; + return f.get_function_address(); + } +}; - template - struct get_function_annotation> +template +struct hpx::traits::get_function_annotation> +{ + static constexpr char const* call( + hpx::detail::annotated_function const& f) noexcept { - static constexpr char const* call( - hpx::detail::annotated_function const& f) noexcept - { - return f.get_function_annotation(); - } - }; + return f.get_function_annotation(); + } +}; #endif -} // namespace hpx::traits namespace hpx::util { diff --git a/libs/core/threading_base/include/hpx/threading_base/detail/get_default_pool.hpp b/libs/core/threading_base/include/hpx/threading_base/detail/get_default_pool.hpp index aa6be5bea26d..59eddd1eaf77 100644 --- a/libs/core/threading_base/include/hpx/threading_base/detail/get_default_pool.hpp +++ b/libs/core/threading_base/include/hpx/threading_base/detail/get_default_pool.hpp @@ -11,11 +11,14 @@ #include #include -#include -namespace hpx::threads::detail { +namespace hpx::threads { - using get_default_pool_type = hpx::function; - HPX_CORE_EXPORT void set_get_default_pool(get_default_pool_type f); - HPX_CORE_EXPORT thread_pool_base* get_self_or_default_pool(); -} // namespace hpx::threads::detail + class HPX_CORE_EXPORT thread_pool_base; + + namespace detail { + using get_default_pool_type = hpx::function; + HPX_CORE_EXPORT void set_get_default_pool(get_default_pool_type f); + HPX_CORE_EXPORT thread_pool_base* get_self_or_default_pool(); + } // namespace detail +} // namespace hpx::threads diff --git a/libs/core/threading_base/include/hpx/threading_base/detail/switch_status.hpp b/libs/core/threading_base/include/hpx/threading_base/detail/switch_status.hpp index 9e1e4cdec822..6a735c0f8f0c 100644 --- a/libs/core/threading_base/include/hpx/threading_base/detail/switch_status.hpp +++ b/libs/core/threading_base/include/hpx/threading_base/detail/switch_status.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2007-2022 Hartmut Kaiser +// Copyright (c) 2007-2023 Hartmut Kaiser // // SPDX-License-Identifier: BSL-1.0 // Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -11,8 +11,6 @@ #include #include -#include - namespace hpx::threads::detail { /////////////////////////////////////////////////////////////////////// @@ -30,6 +28,11 @@ namespace hpx::threads::detail { { } + switch_status(switch_status const&) = delete; + switch_status(switch_status&&) = delete; + switch_status& operator=(switch_status const&) = delete; + switch_status& operator=(switch_status&&) = delete; + ~switch_status() { if (need_restore_state_) diff --git a/libs/core/threading_base/include/hpx/threading_base/execution_agent.hpp b/libs/core/threading_base/include/hpx/threading_base/execution_agent.hpp index b3af3fff6ae5..9fd5653a2399 100644 --- a/libs/core/threading_base/include/hpx/threading_base/execution_agent.hpp +++ b/libs/core/threading_base/include/hpx/threading_base/execution_agent.hpp @@ -64,7 +64,7 @@ namespace hpx::threads { char const* desc, threads::thread_schedule_state state); void do_resume( - char const* desc, hpx::threads::thread_restart_state statex); + char const* desc, hpx::threads::thread_restart_state statex) const; execution_context context_; }; diff --git a/libs/core/threading_base/include/hpx/threading_base/register_thread.hpp b/libs/core/threading_base/include/hpx/threading_base/register_thread.hpp index 5fb4df759336..5de9b8fc2b67 100644 --- a/libs/core/threading_base/include/hpx/threading_base/register_thread.hpp +++ b/libs/core/threading_base/include/hpx/threading_base/register_thread.hpp @@ -10,13 +10,10 @@ #pragma once #include -#include #include -#include -#include -#include +#include +#include -#include #include #include @@ -24,6 +21,8 @@ namespace hpx::threads { namespace detail { + HPX_CORE_EXPORT threads::thread_result_type cleanup_thread(); + template struct thread_function { @@ -35,19 +34,7 @@ namespace hpx::threads { // execute the actual thread function f(threads::thread_restart_state::signaled); - // Verify that there are no more registered locks for this - // OS-thread. This will throw if there are still any locks held. - util::force_error_on_lock(); - - // run and free all registered exit functions for this thread - auto* p = get_self_id_data(); - - p->run_thread_exit_callbacks(); - p->free_thread_exit_callbacks(); - - return threads::thread_result_type( - threads::thread_schedule_state::terminated, - threads::invalid_thread_id); + return cleanup_thread(); } }; @@ -62,19 +49,7 @@ namespace hpx::threads { // execute the actual thread function f(); - // Verify that there are no more registered locks for this - // OS-thread. This will throw if there are still any locks held. - util::force_error_on_lock(); - - // run and free all registered exit functions for this thread - auto* p = get_self_id_data(); - - p->run_thread_exit_callbacks(); - p->free_thread_exit_callbacks(); - - return threads::thread_result_type( - threads::thread_schedule_state::terminated, - threads::invalid_thread_id); + return cleanup_thread(); } }; } // namespace detail @@ -112,23 +87,13 @@ namespace hpx::threads { /// throw but returns the result code using the parameter /// \a ec. Otherwise it throws an instance /// of hpx#exception. - inline void register_thread(threads::thread_init_data& data, + HPX_CORE_EXPORT void register_thread(threads::thread_init_data& data, threads::thread_pool_base* pool, threads::thread_id_ref_type& id, - error_code& ec = throws) - { - HPX_ASSERT(pool); - data.run_now = true; - pool->create_thread(data, id, ec); - } + error_code& ec = hpx::throws); - inline threads::thread_id_ref_type register_thread( + HPX_CORE_EXPORT threads::thread_id_ref_type register_thread( threads::thread_init_data& data, threads::thread_pool_base* pool, - error_code& ec = throws) - { - threads::thread_id_ref_type id = threads::invalid_thread_id; - register_thread(data, pool, id, ec); - return id; - } + error_code& ec = hpx::throws); /////////////////////////////////////////////////////////////////////////// /// \brief Create a new \a thread using the given data on the same thread @@ -150,17 +115,11 @@ namespace hpx::threads { /// \a hpx#throws this function doesn't throw but returns /// the result code using the parameter \a ec. Otherwise /// it throws an instance of hpx#exception. - inline void register_thread(threads::thread_init_data& data, - threads::thread_id_ref_type& id, error_code& ec = throws) - { - register_thread(data, detail::get_self_or_default_pool(), id, ec); - } + HPX_CORE_EXPORT void register_thread(threads::thread_init_data& data, + threads::thread_id_ref_type& id, error_code& ec = throws); - inline threads::thread_id_ref_type register_thread( - threads::thread_init_data& data, error_code& ec = throws) - { - return register_thread(data, detail::get_self_or_default_pool(), ec); - } + HPX_CORE_EXPORT threads::thread_id_ref_type register_thread( + threads::thread_init_data& data, error_code& ec = throws); /// \brief Create a new work item using the given data. /// @@ -176,13 +135,9 @@ namespace hpx::threads { /// \a hpx#throws this function doesn't throw but returns /// the result code using the parameter \a ec. Otherwise /// it throws an instance of hpx#exception. - inline thread_id_ref_type register_work(threads::thread_init_data& data, - threads::thread_pool_base* pool, error_code& ec = throws) - { - HPX_ASSERT(pool); - data.run_now = false; - return pool->create_work(data, ec); - } + HPX_CORE_EXPORT thread_id_ref_type register_work( + threads::thread_init_data& data, threads::thread_pool_base* pool, + error_code& ec = hpx::throws); /// \brief Create a new work item using the given data on the same thread /// pool as the calling thread, or on the default thread pool if @@ -200,11 +155,8 @@ namespace hpx::threads { /// throw but returns the result code using the /// parameter \a ec. Otherwise it throws an instance /// of hpx#exception. - inline thread_id_ref_type register_work( - threads::thread_init_data& data, error_code& ec = throws) - { - return register_work(data, detail::get_self_or_default_pool(), ec); - } + HPX_CORE_EXPORT thread_id_ref_type register_work( + threads::thread_init_data& data, error_code& ec = throws); } // namespace hpx::threads /// \endcond diff --git a/libs/core/threading_base/include/hpx/threading_base/scheduler_base.hpp b/libs/core/threading_base/include/hpx/threading_base/scheduler_base.hpp index 23a1ba2b1485..0974fc98245a 100644 --- a/libs/core/threading_base/include/hpx/threading_base/scheduler_base.hpp +++ b/libs/core/threading_base/include/hpx/threading_base/scheduler_base.hpp @@ -57,10 +57,11 @@ namespace hpx::threads::policies { /// scheduler policies struct scheduler_base { - public: - HPX_NON_COPYABLE(scheduler_base); + scheduler_base(scheduler_base const&) = delete; + scheduler_base(scheduler_base&&) = delete; + scheduler_base& operator=(scheduler_base const&) = delete; + scheduler_base& operator=(scheduler_base&&) = delete; - public: using pu_mutex_type = std::mutex; explicit scheduler_base(std::size_t num_threads, diff --git a/libs/core/threading_base/include/hpx/threading_base/scoped_annotation.hpp b/libs/core/threading_base/include/hpx/threading_base/scoped_annotation.hpp index 9f33c17d5494..4d7cbc5271c7 100644 --- a/libs/core/threading_base/include/hpx/threading_base/scoped_annotation.hpp +++ b/libs/core/threading_base/include/hpx/threading_base/scoped_annotation.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2022 Hartmut Kaiser +// Copyright (c) 2017-2023 Hartmut Kaiser // // SPDX-License-Identifier: BSL-1.0 // Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -11,6 +11,7 @@ #include #if defined(HPX_HAVE_THREAD_DESCRIPTION) +#include #include #include diff --git a/libs/core/threading_base/include/hpx/threading_base/thread_data.hpp b/libs/core/threading_base/include/hpx/threading_base/thread_data.hpp index 5f30957f7e40..81a28601f2e9 100644 --- a/libs/core/threading_base/include/hpx/threading_base/thread_data.hpp +++ b/libs/core/threading_base/include/hpx/threading_base/thread_data.hpp @@ -23,6 +23,7 @@ #include #include #include +#include #if defined(HPX_HAVE_APEX) #include #endif @@ -51,15 +52,6 @@ namespace hpx::threads { HPX_CORE_EXPORT std::uint32_t get_locality_id(hpx::error_code&); } // namespace detail - //////////////////////////////////////////////////////////////////////////// - class HPX_CORE_EXPORT thread_data; // forward declaration only - - //////////////////////////////////////////////////////////////////////////// - /// The function \a get_self_id_data returns the data of the HPX thread id - /// associated with the current thread (or nullptr if the current thread is - /// not a HPX thread). - HPX_CORE_EXPORT thread_data* get_self_id_data() noexcept; - //////////////////////////////////////////////////////////////////////////// /// A \a thread is the representation of a HPX thread. It's a first class /// object in HPX. In our implementation this is a user level thread running @@ -675,82 +667,6 @@ namespace hpx::threads { { return static_cast(tid.get()); } - - namespace detail { - - HPX_CORE_EXPORT void set_self_ptr(thread_self*) noexcept; - } - - /////////////////////////////////////////////////////////////////////// - /// The function \a get_self returns a reference to the (OS thread - /// specific) self reference to the current HPX thread. - HPX_CORE_EXPORT thread_self& get_self(); - - /// The function \a get_self_ptr returns a pointer to the (OS thread - /// specific) self reference to the current HPX thread. - HPX_CORE_EXPORT thread_self* get_self_ptr() noexcept; - - /// The function \a get_ctx_ptr returns a pointer to the internal data - /// associated with each coroutine. - HPX_CORE_EXPORT thread_self_impl_type* get_ctx_ptr(); - - /// The function \a get_self_ptr_checked returns a pointer to the (OS - /// thread specific) self reference to the current HPX thread. - HPX_CORE_EXPORT thread_self* get_self_ptr_checked(error_code& ec = throws); - - /// The function \a get_self_id returns the HPX thread id of the current - /// thread (or zero if the current thread is not a HPX thread). - HPX_CORE_EXPORT thread_id_type get_self_id() noexcept; - - /// The function \a get_outer_self_id returns the HPX thread id of - /// the current outer thread (or zero if the current thread is not a HPX - /// thread). This usually returns the same as \a get_self_id, except for - /// directly executed threads, in which case this returns the thread id - /// of the outermost HPX thread. - HPX_CORE_EXPORT thread_id_type get_outer_self_id() noexcept; - - /// The function \a get_parent_id returns the HPX thread id of the - /// current thread's parent (or zero if the current thread is not a - /// HPX thread). - /// - /// \note This function will return a meaningful value only if the - /// code was compiled with HPX_HAVE_THREAD_PARENT_REFERENCE - /// being defined. - HPX_CORE_EXPORT thread_id_type get_parent_id() noexcept; - - /// The function \a get_parent_phase returns the HPX phase of the - /// current thread's parent (or zero if the current thread is not a - /// HPX thread). - /// - /// \note This function will return a meaningful value only if the - /// code was compiled with HPX_HAVE_THREAD_PARENT_REFERENCE - /// being defined. - HPX_CORE_EXPORT std::size_t get_parent_phase() noexcept; - - /// The function \a get_self_stacksize returns the stack size of the - /// current thread (or zero if the current thread is not a HPX thread). - HPX_CORE_EXPORT std::ptrdiff_t get_self_stacksize() noexcept; - - /// The function \a get_self_stacksize_enum returns the stack size of the / - //current thread (or thread_stacksize::default if the current thread is not - //a HPX thread). - HPX_CORE_EXPORT thread_stacksize get_self_stacksize_enum() noexcept; - - /// The function \a get_parent_locality_id returns the id of the locality of - /// the current thread's parent (or zero if the current thread is not a - /// HPX thread). - /// - /// \note This function will return a meaningful value only if the - /// code was compiled with HPX_HAVE_THREAD_PARENT_REFERENCE - /// being defined. - HPX_CORE_EXPORT std::uint32_t get_parent_locality_id() noexcept; - - /// The function \a get_self_component_id returns the lva of the component - /// the current thread is acting on - /// - /// \note This function will return a meaningful value only if the code was - /// compiled with HPX_HAVE_THREAD_TARGET_ADDRESS being defined. - HPX_CORE_EXPORT std::uint64_t get_self_component_id() noexcept; } // namespace hpx::threads #include diff --git a/libs/core/threading_base/include/hpx/threading_base/thread_helpers.hpp b/libs/core/threading_base/include/hpx/threading_base/thread_helpers.hpp index 82db59ebe895..131369ccdc6c 100644 --- a/libs/core/threading_base/include/hpx/threading_base/thread_helpers.hpp +++ b/libs/core/threading_base/include/hpx/threading_base/thread_helpers.hpp @@ -17,6 +17,9 @@ #include #include #include +#if !defined(HPX_HAVE_THREAD_FULLBACKTRACE_ON_SUSPENSION) +#include +#endif #include #include diff --git a/libs/core/threading_base/include/hpx/threading_base/thread_pool_base.hpp b/libs/core/threading_base/include/hpx/threading_base/thread_pool_base.hpp index c27e0babb6da..89d6789c33d9 100644 --- a/libs/core/threading_base/include/hpx/threading_base/thread_pool_base.hpp +++ b/libs/core/threading_base/include/hpx/threading_base/thread_pool_base.hpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -107,7 +108,7 @@ namespace hpx::threads { // note: this data structure has to be protected from races from the outside /// \brief The base class used to manage a pool of OS threads. - class HPX_CORE_EXPORT thread_pool_base + class thread_pool_base { public: /// \cond NOINTERNAL diff --git a/libs/core/threading_base/include/hpx/threading_base/threading_base_fwd.hpp b/libs/core/threading_base/include/hpx/threading_base/threading_base_fwd.hpp index 97e9780e88df..230468b44c42 100644 --- a/libs/core/threading_base/include/hpx/threading_base/threading_base_fwd.hpp +++ b/libs/core/threading_base/include/hpx/threading_base/threading_base_fwd.hpp @@ -12,8 +12,11 @@ #include #include #include +#include #include +#include +#include #include #if defined(HPX_HAVE_APEX) @@ -27,7 +30,7 @@ namespace hpx::util::external_timer { namespace hpx::threads { - class thread_data; + class HPX_CORE_EXPORT thread_data; // forward declaration only class thread_data_stackful; class thread_data_stackless; @@ -63,4 +66,86 @@ namespace hpx::threads { std::shared_ptr data); #endif /// \endcond + + //////////////////////////////////////////////////////////////////////////// + /// The function \a get_self_id_data returns the data of the HPX thread id + /// associated with the current thread (or nullptr if the current thread is + /// not a HPX thread). + HPX_CORE_EXPORT thread_data* get_self_id_data() noexcept; + + namespace detail { + + HPX_CORE_EXPORT void set_self_ptr(thread_self*) noexcept; + } + + /////////////////////////////////////////////////////////////////////// + /// The function \a get_self returns a reference to the (OS thread + /// specific) self reference to the current HPX thread. + HPX_CORE_EXPORT thread_self& get_self(); + + /// The function \a get_self_ptr returns a pointer to the (OS thread + /// specific) self reference to the current HPX thread. + HPX_CORE_EXPORT thread_self* get_self_ptr() noexcept; + + /// The function \a get_ctx_ptr returns a pointer to the internal data + /// associated with each coroutine. + HPX_CORE_EXPORT thread_self_impl_type* get_ctx_ptr(); + + /// The function \a get_self_ptr_checked returns a pointer to the (OS + /// thread specific) self reference to the current HPX thread. + HPX_CORE_EXPORT thread_self* get_self_ptr_checked(error_code& ec = throws); + + /// The function \a get_self_id returns the HPX thread id of the current + /// thread (or zero if the current thread is not a HPX thread). + HPX_CORE_EXPORT thread_id_type get_self_id() noexcept; + + /// The function \a get_outer_self_id returns the HPX thread id of + /// the current outer thread (or zero if the current thread is not a HPX + /// thread). This usually returns the same as \a get_self_id, except for + /// directly executed threads, in which case this returns the thread id + /// of the outermost HPX thread. + HPX_CORE_EXPORT thread_id_type get_outer_self_id() noexcept; + + /// The function \a get_parent_id returns the HPX thread id of the + /// current thread's parent (or zero if the current thread is not a + /// HPX thread). + /// + /// \note This function will return a meaningful value only if the + /// code was compiled with HPX_HAVE_THREAD_PARENT_REFERENCE + /// being defined. + HPX_CORE_EXPORT thread_id_type get_parent_id() noexcept; + + /// The function \a get_parent_phase returns the HPX phase of the + /// current thread's parent (or zero if the current thread is not a + /// HPX thread). + /// + /// \note This function will return a meaningful value only if the + /// code was compiled with HPX_HAVE_THREAD_PARENT_REFERENCE + /// being defined. + HPX_CORE_EXPORT std::size_t get_parent_phase() noexcept; + + /// The function \a get_self_stacksize returns the stack size of the + /// current thread (or zero if the current thread is not a HPX thread). + HPX_CORE_EXPORT std::ptrdiff_t get_self_stacksize() noexcept; + + /// The function \a get_self_stacksize_enum returns the stack size of the / + //current thread (or thread_stacksize::default if the current thread is not + //a HPX thread). + HPX_CORE_EXPORT thread_stacksize get_self_stacksize_enum() noexcept; + + /// The function \a get_parent_locality_id returns the id of the locality of + /// the current thread's parent (or zero if the current thread is not a + /// HPX thread). + /// + /// \note This function will return a meaningful value only if the + /// code was compiled with HPX_HAVE_THREAD_PARENT_REFERENCE + /// being defined. + HPX_CORE_EXPORT std::uint32_t get_parent_locality_id() noexcept; + + /// The function \a get_self_component_id returns the lva of the component + /// the current thread is acting on + /// + /// \note This function will return a meaningful value only if the code was + /// compiled with HPX_HAVE_THREAD_TARGET_ADDRESS being defined. + HPX_CORE_EXPORT std::uint64_t get_self_component_id() noexcept; } // namespace hpx::threads diff --git a/libs/core/threading_base/src/annotated_function.cpp b/libs/core/threading_base/src/annotated_function.cpp index 59f41a9d6f64..6274002b5255 100644 --- a/libs/core/threading_base/src/annotated_function.cpp +++ b/libs/core/threading_base/src/annotated_function.cpp @@ -18,7 +18,7 @@ namespace hpx::detail { char const* store_function_annotation(std::string name) { static thread_local std::unordered_set names; - auto r = names.emplace(HPX_MOVE(name)); + auto const r = names.emplace(HPX_MOVE(name)); return (*std::get<0>(r)).c_str(); } } // namespace hpx::detail diff --git a/libs/core/threading_base/src/create_thread.cpp b/libs/core/threading_base/src/create_thread.cpp index 14e3168baa66..dfbc4deaa6ad 100644 --- a/libs/core/threading_base/src/create_thread.cpp +++ b/libs/core/threading_base/src/create_thread.cpp @@ -13,8 +13,6 @@ #include #include -#include - namespace hpx::threads::detail { void create_thread(policies::scheduler_base* scheduler, @@ -52,7 +50,7 @@ namespace hpx::threads::detail { } #endif - thread_self* self = get_self_ptr(); + thread_self const* self = get_self_ptr(); #ifdef HPX_HAVE_THREAD_PARENT_REFERENCE if (nullptr == data.parent_id) diff --git a/libs/core/threading_base/src/create_work.cpp b/libs/core/threading_base/src/create_work.cpp index c0aaca600949..ed3ebeee2d91 100644 --- a/libs/core/threading_base/src/create_work.cpp +++ b/libs/core/threading_base/src/create_work.cpp @@ -61,7 +61,7 @@ namespace hpx::threads::detail { #endif ; - thread_self* self = get_self_ptr(); + thread_self const* self = get_self_ptr(); #ifdef HPX_HAVE_THREAD_PARENT_REFERENCE if (nullptr == data.parent_id) diff --git a/libs/core/threading_base/src/execution_agent.cpp b/libs/core/threading_base/src/execution_agent.cpp index 64952d6f736a..7369490260a1 100644 --- a/libs/core/threading_base/src/execution_agent.cpp +++ b/libs/core/threading_base/src/execution_agent.cpp @@ -43,7 +43,7 @@ namespace hpx::threads { std::string execution_agent::description() const { - thread_id_type id = self_.get_thread_id(); + thread_id_type const id = self_.get_thread_id(); if (HPX_UNLIKELY(!id)) { HPX_THROW_EXCEPTION(hpx::error::null_thread_id, @@ -109,9 +109,9 @@ namespace hpx::threads { // Just yield until time has passed by... auto now = std::chrono::steady_clock::now(); - // Note: we yield at least once to allow for other threads to - // make progress in any case. We also use yield instead of yield_k - // for the same reason. + // Note: we yield at least once to allow for other threads to make + // progress in any case. We also use yield instead of yield_k for the + // same reason. std::size_t k = 0; do { @@ -177,16 +177,15 @@ namespace hpx::threads { thrd_data->set_last_worker_thread_num( hpx::get_local_worker_thread_num()); - threads::thread_restart_state statex = - threads::thread_restart_state::unknown; + threads::thread_restart_state statex; { #ifdef HPX_HAVE_THREAD_DESCRIPTION - threads::detail::reset_lco_description desc( + [[maybe_unused]] threads::detail::reset_lco_description reset_desc( id.noref(), threads::thread_description(desc)); #endif #ifdef HPX_HAVE_THREAD_BACKTRACE_ON_SUSPENSION - threads::detail::reset_backtrace bt(id); + [[maybe_unused]] threads::detail::reset_backtrace reset_bt(id); #endif [[maybe_unused]] on_exit_reset_held_lock_data held_locks; @@ -219,7 +218,7 @@ namespace hpx::threads { } void execution_agent::do_resume( - char const* /* desc */, hpx::threads::thread_restart_state statex) + char const* /* desc */, hpx::threads::thread_restart_state statex) const { threads::detail::set_thread_state(self_.get_thread_id(), thread_schedule_state::pending, statex, thread_priority::normal, diff --git a/libs/core/threading_base/src/get_default_pool.cpp b/libs/core/threading_base/src/get_default_pool.cpp index ce63964f077c..2a5454df4cdd 100644 --- a/libs/core/threading_base/src/get_default_pool.cpp +++ b/libs/core/threading_base/src/get_default_pool.cpp @@ -22,7 +22,7 @@ namespace hpx_start { // Redefining weak variables defined in hpx_main.hpp to facilitate error // checking and make sure correct errors are thrown. It is added again to // make sure that these variables are defined correctly in cases where - // hpx_main functionalities are not used. + // hpx_main functionality is not used. HPX_SYMBOL_EXPORT bool is_linked __attribute__((weak)) = false; HPX_SYMBOL_EXPORT bool include_libhpx_wrap __attribute__((weak)) = false; } // namespace hpx_start @@ -41,8 +41,7 @@ namespace hpx::threads::detail { thread_pool_base* get_self_or_default_pool() { thread_pool_base* pool = nullptr; - auto thrd_data = get_self_id_data(); - if (thrd_data) + if (auto const* thrd_data = get_self_id_data()) { pool = thrd_data->get_scheduler_base()->get_parent_pool(); } diff --git a/libs/core/threading_base/src/print.cpp b/libs/core/threading_base/src/print.cpp index 0b70873c92f4..3f9e5540bda9 100644 --- a/libs/core/threading_base/src/print.cpp +++ b/libs/core/threading_base/src/print.cpp @@ -9,6 +9,7 @@ #include #include +#include #include /// \cond NODETAIL @@ -76,7 +77,7 @@ namespace hpx::debug { } else { - hpx::threads::thread_data* dummy = + hpx::threads::thread_data const* dummy = hpx::threads::get_self_id_data(); os << dummy << " "; } diff --git a/libs/core/threading_base/src/register_thread.cpp b/libs/core/threading_base/src/register_thread.cpp new file mode 100644 index 000000000000..b8184162d40b --- /dev/null +++ b/libs/core/threading_base/src/register_thread.cpp @@ -0,0 +1,103 @@ +// Copyright (c) 2007-2023 Hartmut Kaiser +// Copyright (c) 2018 Thomas Heller +// Copyright (c) 2011 Bryce Lelbach +// Copyright (c) 2008-2009 Chirag Dekate, Anshul Tandon +// +// SPDX-License-Identifier: BSL-1.0 +// 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 +#include +#include +#include +#include +#include +#include + +namespace hpx::threads { + + /////////////////////////////////////////////////////////////////////////// + namespace detail { + + threads::thread_result_type cleanup_thread() + { + // Verify that there are no more registered locks for this + // OS-thread. This will throw if there are still any locks held. + util::force_error_on_lock(); + + // run and free all registered exit functions for this thread + auto* p = get_self_id_data(); + + p->run_thread_exit_callbacks(); + p->free_thread_exit_callbacks(); + + return threads::thread_result_type( + threads::thread_schedule_state::terminated, + threads::invalid_thread_id); + } + } // namespace detail + + /////////////////////////////////////////////////////////////////////////// + threads::thread_id_ref_type register_thread(threads::thread_init_data& data, + threads::thread_pool_base* pool, error_code& ec) + { + HPX_ASSERT(pool); + + threads::thread_id_ref_type id = threads::invalid_thread_id; + data.run_now = true; + pool->create_thread(data, id, ec); + return id; + } + + void register_thread(threads::thread_init_data& data, + threads::thread_pool_base* pool, threads::thread_id_ref_type& id, + error_code& ec) + { + HPX_ASSERT(pool); + + data.run_now = true; + pool->create_thread(data, id, ec); + } + + void register_thread(threads::thread_init_data& data, + threads::thread_id_ref_type& id, error_code& ec) + { + auto* pool = detail::get_self_or_default_pool(); + HPX_ASSERT(pool); + + data.run_now = true; + pool->create_thread(data, id, ec); + } + + threads::thread_id_ref_type register_thread( + threads::thread_init_data& data, error_code& ec) + { + auto* pool = detail::get_self_or_default_pool(); + HPX_ASSERT(pool); + + threads::thread_id_ref_type id = threads::invalid_thread_id; + data.run_now = true; + pool->create_thread(data, id, ec); + return id; + } + + /////////////////////////////////////////////////////////////////////////// + thread_id_ref_type register_work(threads::thread_init_data& data, + threads::thread_pool_base* pool, error_code& ec) + { + HPX_ASSERT(pool); + data.run_now = false; + return pool->create_work(data, ec); + } + + thread_id_ref_type register_work( + threads::thread_init_data& data, error_code& ec) + { + auto* pool = detail::get_self_or_default_pool(); + HPX_ASSERT(pool); + + data.run_now = false; + return pool->create_work(data, ec); + } +} // namespace hpx::threads diff --git a/libs/core/threading_base/src/thread_description.cpp b/libs/core/threading_base/src/thread_description.cpp index 358c192deb94..684082e512f9 100644 --- a/libs/core/threading_base/src/thread_description.cpp +++ b/libs/core/threading_base/src/thread_description.cpp @@ -60,8 +60,7 @@ namespace hpx::threads { return; } - hpx::threads::thread_id_type const id = hpx::threads::get_self_id(); - if (id) + if (hpx::threads::thread_id_type const id = hpx::threads::get_self_id()) { // get the current task description thread_description const desc = diff --git a/libs/full/command_line_handling/include/hpx/command_line_handling/command_line_handling.hpp b/libs/full/command_line_handling/include/hpx/command_line_handling/command_line_handling.hpp index 55ed47532afd..3d31a6703527 100644 --- a/libs/full/command_line_handling/include/hpx/command_line_handling/command_line_handling.hpp +++ b/libs/full/command_line_handling/include/hpx/command_line_handling/command_line_handling.hpp @@ -16,7 +16,6 @@ #include #include #include -#include #include #include diff --git a/libs/full/command_line_handling/src/command_line_handling.cpp b/libs/full/command_line_handling/src/command_line_handling.cpp index a04e3073bd8d..1e5697ca4b88 100644 --- a/libs/full/command_line_handling/src/command_line_handling.cpp +++ b/libs/full/command_line_handling/src/command_line_handling.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2007-2022 Hartmut Kaiser +// Copyright (c) 2007-2023 Hartmut Kaiser // // SPDX-License-Identifier: BSL-1.0 // Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -25,7 +25,9 @@ #include #include #include +#if defined(HPX_HAVE_MAX_CPU_COUNT) #include +#endif #include #include @@ -33,9 +35,7 @@ #include #include #include -#include #include -#include #include #include #include @@ -106,18 +106,23 @@ namespace hpx::util { } /////////////////////////////////////////////////////////////////////// - std::size_t handle_num_localities(util::manage_config& cfgmap, - hpx::program_options::variables_map& vm, - util::batch_environment& env, bool using_nodelist, + std::size_t handle_num_localities(util::manage_config const& cfgmap, + hpx::program_options::variables_map const& vm, + util::batch_environment const& env, bool using_nodelist, std::size_t num_localities, bool initial) { - std::size_t batch_localities = env.retrieve_number_of_localities(); - if (num_localities == 1 && batch_localities != std::size_t(-1)) + std::size_t const batch_localities = + env.retrieve_number_of_localities(); + if (num_localities == 1 && + batch_localities != static_cast(-1)) { - std::size_t cfg_num_localities = cfgmap.get_value( - "hpx.localities", batch_localities); - if (cfg_num_localities > 1) + if (auto const cfg_num_localities = + cfgmap.get_value( + "hpx.localities", batch_localities); + cfg_num_localities > 1) + { num_localities = cfg_num_localities; + } } if (!initial && env.found_batch_environment() && using_nodelist && @@ -129,7 +134,8 @@ namespace hpx::util { if (vm.count("hpx:localities")) { - std::size_t localities = vm["hpx:localities"].as(); + std::size_t const localities = + vm["hpx:localities"].as(); if (localities == 0) { @@ -161,9 +167,9 @@ namespace hpx::util { /////////////////////////////////////////////////////////////////////// std::size_t get_number_of_default_cores( - util::batch_environment& env, bool use_process_mask) + util::batch_environment const& env, bool use_process_mask) { - std::size_t num_cores = + std::size_t const num_cores = hpx::local::detail::get_number_of_default_cores( use_process_mask); if (use_process_mask) @@ -172,13 +178,13 @@ namespace hpx::util { } std::size_t batch_threads = env.retrieve_number_of_threads(); - if (batch_threads == std::size_t(-1)) + if (batch_threads == static_cast(-1)) { return num_cores; } // assuming we assign the first N cores ... - threads::topology& top = threads::create_topology(); + threads::topology const& top = threads::create_topology(); std::size_t core = 0; for (/**/; core < num_cores; ++core) { @@ -190,11 +196,11 @@ namespace hpx::util { } /////////////////////////////////////////////////////////////////////// - std::size_t handle_num_threads(util::manage_config& cfgmap, + std::size_t handle_num_threads(util::manage_config const& cfgmap, util::runtime_configuration const& rtcfg, - hpx::program_options::variables_map& vm, - util::batch_environment& env, bool using_nodelist, bool initial, - bool use_process_mask) + hpx::program_options::variables_map const& vm, + util::batch_environment const& env, bool using_nodelist, + bool initial, bool use_process_mask) { // If using the process mask we override "cores" and "all" options // but keep explicit numeric values. @@ -205,16 +211,15 @@ namespace hpx::util { detail::get_number_of_default_cores(env, use_process_mask); std::size_t const batch_threads = env.retrieve_number_of_threads(); - std::string threads_str = - cfgmap.get_value("hpx.os_threads", - rtcfg.get_entry( - "hpx.os_threads", std::to_string(init_threads))); + auto threads_str = cfgmap.get_value("hpx.os_threads", + rtcfg.get_entry( + "hpx.os_threads", std::to_string(init_threads))); - std::size_t threads = 0; + std::size_t threads; if ("cores" == threads_str) { threads = init_cores; - if (batch_threads != std::size_t(-1)) + if (batch_threads != static_cast(-1)) { threads = batch_threads; } @@ -222,12 +227,12 @@ namespace hpx::util { else if ("all" == threads_str) { threads = init_threads; - if (batch_threads != std::size_t(-1)) + if (batch_threads != static_cast(-1)) { threads = batch_threads; } } - else if (batch_threads != std::size_t(-1)) + else if (batch_threads != static_cast(-1)) { threads = batch_threads; } @@ -243,7 +248,7 @@ namespace hpx::util { if ("all" == threads_str) { threads = init_threads; - if (batch_threads != std::size_t(-1)) + if (batch_threads != static_cast(-1)) { threads = batch_threads; } @@ -251,7 +256,7 @@ namespace hpx::util { else if ("cores" == threads_str) { threads = init_cores; - if (batch_threads != std::size_t(-1)) + if (batch_threads != static_cast(-1)) { threads = batch_threads; } @@ -281,7 +286,7 @@ namespace hpx::util { } // make sure minimal requested number of threads is observed - std::size_t min_os_threads = cfgmap.get_value( + auto min_os_threads = cfgmap.get_value( "hpx.force_min_os_threads", threads); if (min_os_threads == 0) @@ -318,7 +323,7 @@ namespace hpx::util { /////////////////////////////////////////////////////////////////////// #if !defined(HPX_HAVE_NETWORKING) void check_networking_option( - hpx::program_options::variables_map& vm, char const* option) + hpx::program_options::variables_map const& vm, char const* option) { if (vm.count(option) != 0) { @@ -331,7 +336,7 @@ namespace hpx::util { #endif void check_networking_options( - [[maybe_unused]] hpx::program_options::variables_map& vm) + [[maybe_unused]] hpx::program_options::variables_map const& vm) { #if !defined(HPX_HAVE_NETWORKING) check_networking_option(vm, "hpx:agas"); @@ -355,7 +360,7 @@ namespace hpx::util { std::vector ini_config, hpx::function hpx_main_f) : base_type(HPX_MOVE(rtcfg), HPX_MOVE(ini_config), HPX_MOVE(hpx_main_f)) - , node_(std::size_t(-1)) + , node_(static_cast(-1)) , num_localities_(1) { } @@ -371,7 +376,8 @@ namespace hpx::util { // disabled detail::check_networking_options(vm); - bool debug_clp = node != std::size_t(-1) && vm.count("hpx:debug-clp"); + bool debug_clp = + node != static_cast(-1) && vm.count("hpx:debug-clp"); // create host name mapping util::map_hostnames mapnames(debug_clp); @@ -384,12 +390,11 @@ namespace hpx::util { // The AGAS host name and port number are pre-initialized from //the command line - std::string agas_host = cfgmap.get_value( + auto agas_host = cfgmap.get_value( "hpx.agas.address", rtcfg_.get_entry("hpx.agas.address", "")); - std::uint16_t agas_port = - cfgmap.get_value("hpx.agas.port", - hpx::util::from_string( - rtcfg_.get_entry("hpx.agas.port", HPX_INITIAL_IP_PORT))); + auto agas_port = cfgmap.get_value("hpx.agas.port", + hpx::util::from_string( + rtcfg_.get_entry("hpx.agas.port", HPX_INITIAL_IP_PORT))); if (vm.count("hpx:agas")) { @@ -416,8 +421,8 @@ namespace hpx::util { vm["hpx:iftransform"].as())); } - typedef util::map_hostnames::transform_function_type - transform_function_type; + using transform_function_type = + util::map_hostnames::transform_function_type; mapnames.use_transform(transform_function_type(iftransform)); } @@ -435,6 +440,7 @@ namespace hpx::util { "one of the --hpx:nodefile and --hpx:nodes options at the " "same time."); } + std::string node_file = vm["hpx:nodefile"].as(); ini_config.emplace_back("hpx.nodefile!=" + node_file); std::ifstream ifs(node_file.c_str()); @@ -537,7 +543,7 @@ namespace hpx::util { "hpx.parcel.port", initial_hpx_port); run_agas_server = vm.count("hpx:run-agas-server") != 0; - if (node == std::size_t(-1)) + if (node == static_cast(-1)) node = env.retrieve_node_number(); #else num_localities_ = 1; @@ -622,7 +628,8 @@ namespace hpx::util { } #endif } - else if (node != std::size_t(-1) || vm.count("hpx:node")) + else if (node != static_cast(-1) || + vm.count("hpx:node")) { // command line overwrites the environment if (vm.count("hpx:node")) @@ -767,7 +774,8 @@ namespace hpx::util { #endif } - // write HPX and AGAS network parameters to the proper ini-file entries + // write HPX and AGAS network parameters to the proper ini-file + // entries ini_config.emplace_back("hpx.parcel.address=" + hpx_host); ini_config.emplace_back( "hpx.parcel.port=" + std::to_string(hpx_port)); @@ -949,7 +957,8 @@ namespace hpx::util { error_mode |= util::commandline_error_mode::ignore_aliases; hpx::program_options::variables_map prevm; if (!util::parse_commandline(rtcfg_, desc_cmdline, argv[0], args, - prevm, std::size_t(-1), error_mode, rtcfg_.mode_)) + prevm, static_cast(-1), error_mode, + rtcfg_.mode_)) { return -1; } @@ -997,7 +1006,7 @@ namespace hpx::util { // be considered now. // minimally assume one locality and this is the console - if (node_ == std::size_t(-1)) + if (node_ == static_cast(-1)) node_ = 0; for (std::shared_ptr& reg : diff --git a/libs/full/command_line_handling/src/late_command_line_handling.cpp b/libs/full/command_line_handling/src/late_command_line_handling.cpp index 962c3194fea3..a8f5598d7647 100644 --- a/libs/full/command_line_handling/src/late_command_line_handling.cpp +++ b/libs/full/command_line_handling/src/late_command_line_handling.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2007-2022 Hartmut Kaiser +// Copyright (c) 2007-2023 Hartmut Kaiser // // SPDX-License-Identifier: BSL-1.0 // Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -10,7 +10,6 @@ #include #include #include -#include #include #include @@ -43,7 +42,7 @@ namespace hpx::util { hpx::program_options::variables_map vm; std::vector still_unregistered_options; util::parse_commandline(ini, options, unknown_cmd_line, vm, - std::size_t(-1), mode, + static_cast(-1), mode, get_runtime_mode_from_name(runtime_mode), nullptr, &still_unregistered_options); @@ -65,7 +64,7 @@ namespace hpx::util { hpx::program_options::variables_map vm; util::parse_commandline(ini, options, cmd_line, vm, - std::size_t(-1), + static_cast(-1), util::commandline_error_mode::allow_unregistered | util::commandline_error_mode:: report_missing_config_file, diff --git a/libs/full/command_line_handling/src/parse_command_line.cpp b/libs/full/command_line_handling/src/parse_command_line.cpp index a2a6a0a4896e..2729ffa6db87 100644 --- a/libs/full/command_line_handling/src/parse_command_line.cpp +++ b/libs/full/command_line_handling/src/parse_command_line.cpp @@ -6,7 +6,6 @@ #include #include -#include #include #include #include @@ -14,9 +13,8 @@ #include #include -#include +#include #include -#include #include #include #include @@ -47,18 +45,19 @@ namespace hpx::util { // any --hpx: option without a second ':' is handled elsewhere as // well - std::string::size_type p = s.find_first_of(':', hpx_prefix_len); + std::string::size_type const p = + s.find_first_of(':', hpx_prefix_len); if (p == std::string::npos) return false; if (hpx::util::from_string( s.substr(hpx_prefix_len, p - hpx_prefix_len), - std::size_t(-1)) == node) + static_cast(-1)) == node) { using hpx::local::detail::trim_whitespace; // this option is for the current locality only - std::string::size_type p1 = s.find_first_of('=', p); + std::string::size_type const p1 = s.find_first_of('=', p); if (p1 != std::string::npos) { // the option has a value @@ -127,9 +126,9 @@ namespace hpx::util { using hpx::program_options::store; using hpx::program_options::command_line_style::unix_style; - util::commandline_error_mode mode = + util::commandline_error_mode const mode = error_mode & util::commandline_error_mode::ignore_aliases; - util::commandline_error_mode notmode = + util::commandline_error_mode const notmode = error_mode & ~util::commandline_error_mode::ignore_aliases; store(hpx::local::detail::get_commandline_parser( @@ -160,22 +159,21 @@ namespace hpx::util { return; filesystem::path dir(filesystem::initial_path()); - filesystem::path app(appname); + filesystem::path const app(appname); appname = filesystem::basename(app.filename()); // walk up the hierarchy, trying to find a file .cfg while (!dir.empty()) { filesystem::path filename = dir / (appname + ".cfg"); - util::commandline_error_mode mode = error_mode & + util::commandline_error_mode const mode = error_mode & ~util::commandline_error_mode::report_missing_config_file; std::vector options = hpx::local::detail::read_config_file_options( filename.string(), mode); - bool result = handle_config_file_options( - options, desc_cfgfile, vm, ini, node, mode); - if (result) + if (handle_config_file_options( + options, desc_cfgfile, vm, ini, node, mode)) { break; // break on the first options file found } @@ -204,7 +202,7 @@ namespace hpx::util { using hpx::program_options::options_description; if (vm.count("hpx:options-file")) { - std::vector const& cfg_files = + auto const& cfg_files = vm["hpx:options-file"].as>(); for (std::string const& cfg_file : cfg_files) @@ -454,7 +452,7 @@ namespace hpx::util { all_options[options_type::desc_cfgfile].add( all_options[options_type::counter_options]); #endif - bool result = hpx::local::detail::parse_commandline(rtcfg, + bool const result = hpx::local::detail::parse_commandline(rtcfg, all_options, app_options, args, vm, error_mode, visible, unregistered_options); @@ -491,8 +489,8 @@ namespace hpx::util { std::string extract_arg0(std::string const& cmdline) { - std::string::size_type p = cmdline.find_first_of(" \t"); - if (p != std::string::npos) + if (std::string::size_type const p = cmdline.find_first_of(" \t"); + p != std::string::npos) { return cmdline.substr(0, p); } From 6d5240bb9f5aec1cd4213244a3a71ab246650fb9 Mon Sep 17 00:00:00 2001 From: dimitraka Date: Thu, 24 Aug 2023 15:59:28 +0200 Subject: [PATCH 20/25] Add MPI_Alltoall doc --- docs/sphinx/manual/migration_guide.rst | 111 ++++++++++++++++++++++++- 1 file changed, 107 insertions(+), 4 deletions(-) diff --git a/docs/sphinx/manual/migration_guide.rst b/docs/sphinx/manual/migration_guide.rst index 9ce4011e7c9b..e870ad694dd2 100644 --- a/docs/sphinx/manual/migration_guide.rst +++ b/docs/sphinx/manual/migration_guide.rst @@ -1465,10 +1465,10 @@ processes. MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); - // Get the number of MPI processes (equivalent to HPX localities). + // Get the number of MPI processes int num_localities = size; - // Get the MPI process rank (equivalent to HPX locality ID). + // Get the MPI process rank int here = rank; std::uint32_t value = here; @@ -1583,8 +1583,6 @@ The following code combines values from all processes and distributes the result return 0; } - - |hpx| equivalent: .. code-block:: c++ @@ -1628,3 +1626,108 @@ detail: needed. - The `get()` function waits until the result is available and then stores it in the variable `res`. + +MPI_Alltoall +------------- + +The following code cGathers data from and scatters data to all processes. + +|mpi| code: + +.. code-block:: c++ + + #include + #include + #include + #include + #include + + int main(int argc, char **argv) { + MPI_Init(&argc, &argv); + + int rank, size; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + + // Get the number of MPI processes + int num_localities = size; + + // Get the MPI process rank + int this_locality = rank; + + // Create a communicator for all-to-all operation. + MPI_Comm all_to_all_direct_client; + MPI_Comm_split(MPI_COMM_WORLD, 0, rank, &all_to_all_direct_client); + + std::vector values(num_localities); + std::fill(values.begin(), values.end(), this_locality); + + // Create vectors to store received values. + std::vector r(num_localities); + + // Perform an all-to-all operation to exchange values with other localities. + MPI_Alltoall(values.data(), 1, MPI_UINT32_T, r.data(), 1, MPI_UINT32_T, + all_to_all_direct_client); + + // Print the results. + std::cout << "Locality " << this_locality << " has values:"; + for (std::size_t j = 0; j != r.size(); ++j) { + std::cout << " " << r[j]; + } + std::cout << std::endl; + + MPI_Finalize(); + return 0; + } + + +|hpx| equivalent: + +.. code-block:: c++ + + std::uint32_t num_localities = hpx::get_num_localities(hpx::launch::sync); + std::uint32_t this_locality = hpx::get_locality_id(); + + auto all_to_all_direct_client = + create_communicator(all_to_all_direct_basename, + num_sites_arg(num_localities), this_site_arg(this_locality)); + + std::vector values(num_localities); + std::fill(values.begin(), values.end(), this_locality); + + hpx::future> overall_result = + all_to_all(all_to_all_direct_client, std::move(values)); + + std::vector r = overall_result.get(); + std::cout << "Locality " << this_locality << " has values:"; + + for (std::size_t j = 0; j != r.size(); ++j) + { + std::cout << " " << r[j]; + } + std::cout << std::endl; + +For num_localities = 2 this code will print the following message: + +.. code-block:: c++ + + Locality 0 has values: 0 1 + Locality 1 has values: 0 1 + +|hpx| uses the function `all_to_all` to implement the functionality of `MPI_Alltoall`. In more +detail: + +- `hpx::get_num_localities(hpx::launch::sync)` retrieves the number of localities, while + `hpx::get_locality_id()` returns the ID of the current locality. + +- The function `hpx::collectives::create_communicator()` is used to create a communicator called + `all_to_all_direct_client`. + +- The value each locality sends is equal to its ID. + +- The all-to-all operation is performed using `all_to_all`. The result is stored in an `hpx::future` + object called `overall_result`, which represents a future result that can be retrieved later when + needed. + +- The `get()` function waits until the result is available and then stores it in the variable `r`. + From 40b755a5ca4ab26229e01447d468606d2c9abaac Mon Sep 17 00:00:00 2001 From: Hartmut Kaiser Date: Thu, 24 Aug 2023 11:45:15 -0500 Subject: [PATCH 21/25] More fixes for CMake V3.27 --- cmake/FindJemalloc.cmake | 12 ++++++------ cmake/HPX_SetupLCI.cmake | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cmake/FindJemalloc.cmake b/cmake/FindJemalloc.cmake index e828a39b5170..c6e111ede3a2 100644 --- a/cmake/FindJemalloc.cmake +++ b/cmake/FindJemalloc.cmake @@ -23,8 +23,8 @@ find_path( Jemalloc_INCLUDE_DIR jemalloc/jemalloc.h HINTS ${Jemalloc_ROOT} ENV - Jemalloc_ROOT - ${HPX_Jemalloc_ROOT} + JEMALLOC_ROOT + ${HPX_JEMALLOC_ROOT} ${PC_Jemalloc_MINIMAL_INCLUDEDIR} ${PC_Jemalloc_MINIMAL_INCLUDE_DIRS} ${PC_Jemalloc_INCLUDEDIR} @@ -39,8 +39,8 @@ if(MSVC) Jemalloc_ADDITIONAL_INCLUDE_DIR msvc_compat/strings.h HINTS ${Jemalloc_ROOT} ENV - Jemalloc_ROOT - ${HPX_Jemalloc_ROOT} + JEMALLOC_ROOT + ${HPX_JEMALLOC_ROOT} ${PC_Jemalloc_MINIMAL_INCLUDEDIR} ${PC_Jemalloc_MINIMAL_INCLUDE_DIRS} ${PC_Jemalloc_INCLUDEDIR} @@ -65,8 +65,8 @@ find_library( NAMES jemalloc libjemalloc HINTS ${Jemalloc_ROOT} ENV - Jemalloc_ROOT - ${HPX_Jemalloc_ROOT} + JEMALLOC_ROOT + ${HPX_JEMALLOC_ROOT} ${PC_Jemalloc_MINIMAL_LIBDIR} ${PC_Jemalloc_MINIMAL_LIBRARY_DIRS} ${PC_Jemalloc_LIBDIR} diff --git a/cmake/HPX_SetupLCI.cmake b/cmake/HPX_SetupLCI.cmake index 26b1ecd18076..d34cc6e08ec0 100644 --- a/cmake/HPX_SetupLCI.cmake +++ b/cmake/HPX_SetupLCI.cmake @@ -38,14 +38,14 @@ macro(hpx_setup_lci) ) else() hpx_info( - "HPX_WITH_FETCH_LCI=${HPX_WITH_FETCH_LCI}, LCI will be fetched using CMake's FetchContent and installed alongside HPX (HPX_WITH_Lci_TAG=${HPX_WITH_Lci_TAG})" + "HPX_WITH_FETCH_LCI=${HPX_WITH_FETCH_LCI}, LCI will be fetched using CMake's FetchContent and installed alongside HPX (HPX_WITH_LCI_TAG=${HPX_WITH_LCI_TAG})" ) endif() include(FetchContent) fetchcontent_declare( lci GIT_REPOSITORY https://github.com/uiuc-hpc/LC.git - GIT_TAG ${HPX_WITH_Lci_TAG} + GIT_TAG ${HPX_WITH_LCI_TAG} ) fetchcontent_getproperties(lci) From 5828ba2ef41a9f5abc0ef7090e3fed3cf96f72c8 Mon Sep 17 00:00:00 2001 From: Hartmut Kaiser Date: Mon, 28 Aug 2023 10:46:38 -0500 Subject: [PATCH 22/25] Listing HPX_WITH_GIT_BRANCH and HPX_WITH_GIT_TAG only if those are defined --- cmake/HPX_UpdateGitDocs.cmake | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/cmake/HPX_UpdateGitDocs.cmake b/cmake/HPX_UpdateGitDocs.cmake index 89fca2bb2334..6ecea2906076 100644 --- a/cmake/HPX_UpdateGitDocs.cmake +++ b/cmake/HPX_UpdateGitDocs.cmake @@ -57,9 +57,8 @@ string(REGEX REPLACE " " ";" HPX_WITH_DOCUMENTATION_OUTPUT_FORMATS ) # If a branch name has been set, we copy files to a corresponding directory -message("HPX_WITH_GIT_BRANCH=\"${HPX_WITH_GIT_BRANCH}\"") if(HPX_WITH_GIT_BRANCH) - message("Updating branch directory") + message("Updating branch directory, " "HPX_WITH_GIT_BRANCH=\"${HPX_WITH_GIT_BRANCH}\"") set(DOCS_BRANCH_DEST "${HPX_BINARY_DIR}/docs/gh-pages/branches/${HPX_WITH_GIT_BRANCH}" ) @@ -92,9 +91,8 @@ if(HPX_WITH_GIT_BRANCH) endif() # If a tag name has been set, we copy files to a corresponding directory -message("HPX_WITH_GIT_TAG=\"${HPX_WITH_GIT_TAG}\"") if(HPX_WITH_GIT_TAG) - message("Updating tag directory") + message("Updating tag directory, " "HPX_WITH_GIT_TAG=\"${HPX_WITH_GIT_TAG}\"") set(DOCS_TAG_DEST "${HPX_BINARY_DIR}/docs/gh-pages/tags/${HPX_WITH_GIT_TAG}") file(REMOVE_RECURSE "${DOCS_TAG_DEST}") if("html" IN_LIST HPX_WITH_DOCUMENTATION_OUTPUT_FORMATS) From 8edd9b394471bf12c95ad921510f57039667e040 Mon Sep 17 00:00:00 2001 From: Hartmut Kaiser Date: Mon, 28 Aug 2023 10:48:48 -0500 Subject: [PATCH 23/25] More tweaks to listing CMake variables --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dbac004e39f4..589fbce7e12f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2202,8 +2202,8 @@ hpx_include(SetOutputPaths) # ############################################################################## # Fixing git tag, if necessary -hpx_info("HPX_WITH_GIT_TAG: " ${HPX_WITH_GIT_TAG}) -hpx_info("HPX_WITH_GIT_BRANCH: " ${HPX_WITH_GIT_BRANCH}) +hpx_debug("HPX_WITH_GIT_TAG: " ${HPX_WITH_GIT_TAG}) +hpx_debug("HPX_WITH_GIT_BRANCH: " ${HPX_WITH_GIT_BRANCH}) if(HPX_WITH_GIT_BRANCH AND ((NOT HPX_WITH_GIT_TAG) OR "${HPX_WITH_GIT_TAG}x" STREQUAL "x") From a2c11545cf0429ac683aed04c1421afdc2d8c27c Mon Sep 17 00:00:00 2001 From: Hartmut Kaiser Date: Tue, 29 Aug 2023 09:58:41 -0500 Subject: [PATCH 24/25] Fixing codacy badge --- README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index fb46b5268338..a02bd0b404b2 100644 --- a/README.rst +++ b/README.rst @@ -151,8 +151,8 @@ Past and current funding and support for HPX is listed `here :target: https://doi.org/10.5281/zenodo.598202 :alt: Latest software release of HPX -.. |codacy| image:: https://api.codacy.com/project/badge/Grade/0b8cd5a874914edaba67ce3bb711e688 - :target: https://www.codacy.com/gh/STEllAR-GROUP/hpx +.. |codacy| .. image:: https://app.codacy.com/project/badge/Grade/0b8cd5a874914edaba67ce3bb711e688 + :target: https://app.codacy.com/gh/STEllAR-GROUP/hpx/dashboard :alt: HPX Code Quality Assessment .. |coveralls| image:: https://coveralls.io/repos/github/STEllAR-GROUP/hpx/badge.svg From c435525b4631c5028a9cb085fc0d27012adaab8c Mon Sep 17 00:00:00 2001 From: Hartmut Kaiser Date: Tue, 29 Aug 2023 09:59:39 -0500 Subject: [PATCH 25/25] More codacy badge changes --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index a02bd0b404b2..928941eb7038 100644 --- a/README.rst +++ b/README.rst @@ -151,7 +151,7 @@ Past and current funding and support for HPX is listed `here :target: https://doi.org/10.5281/zenodo.598202 :alt: Latest software release of HPX -.. |codacy| .. image:: https://app.codacy.com/project/badge/Grade/0b8cd5a874914edaba67ce3bb711e688 +.. |codacy| image:: https://app.codacy.com/project/badge/Grade/0b8cd5a874914edaba67ce3bb711e688 :target: https://app.codacy.com/gh/STEllAR-GROUP/hpx/dashboard :alt: HPX Code Quality Assessment