diff --git a/libs/core/init_runtime_local/include/hpx/init_runtime_local/init_runtime_local.hpp b/libs/core/init_runtime_local/include/hpx/init_runtime_local/init_runtime_local.hpp index 6f39debc0525..6cd7e68546fc 100644 --- a/libs/core/init_runtime_local/include/hpx/init_runtime_local/init_runtime_local.hpp +++ b/libs/core/init_runtime_local/include/hpx/init_runtime_local/init_runtime_local.hpp @@ -11,25 +11,40 @@ #pragma once #include -#include -#include -#include #include -#include -#include -#include -#include -#include + +namespace hpx { namespace program_options { + class variables_map; + class options_description; +}} // namespace hpx::program_options #include #include +#include #include #include -#include #include #include #include +#include +#include + +// Forward declaration of hpx::runtime to avoid pulling in the full runtime +// header -- the full type is only needed in the .cpp implementations. +namespace hpx { + + class runtime; + + using startup_function_type = hpx::move_only_function; + using shutdown_function_type = hpx::move_only_function; + + namespace resource { + + class partitioner; + } // namespace resource +} // namespace hpx + #if defined(__FreeBSD__) HPX_CXX_CORE_EXPORT extern HPX_CORE_EXPORT char** freebsd_environ; HPX_CXX_CORE_EXPORT extern char** environ; @@ -44,6 +59,10 @@ namespace hpx { HPX_CXX_CORE_EXPORT HPX_CORE_EXPORT int init_helper( hpx::program_options::variables_map&, hpx::function const&); + + HPX_CXX_CORE_EXPORT HPX_CORE_EXPORT void on_exit() noexcept; + HPX_CXX_CORE_EXPORT [[noreturn]] HPX_CORE_EXPORT void on_abort( + int signal) noexcept; } // namespace detail namespace local { @@ -57,13 +76,7 @@ namespace hpx { { } - void operator()() const - { - std::cout << "Configuration after runtime start:\n"; - std::cout << "----------------------------------\n"; - rt_.get().get_config().dump(0, std::cout); - std::cout << "----------------------------------\n"; - } + HPX_CORE_EXPORT void operator()() const; std::reference_wrapper rt_; }; @@ -71,12 +84,12 @@ namespace hpx { // Default params to initialize the init_params struct HPX_CXX_CORE_EXPORT [[maybe_unused]] inline int dummy_argc = 1; HPX_CXX_CORE_EXPORT [[maybe_unused]] inline char app_name[256] = - HPX_APPLICATION_STRING; + "unknown HPX application"; inline char* default_argv[2] = {app_name, nullptr}; HPX_CXX_CORE_EXPORT [[maybe_unused]] inline char** dummy_argv = default_argv; - // HPX_APPLICATION_STRING is specific to an application and therefore + // "unknown HPX application" is specific to an application and therefore // cannot be in the source file HPX_CXX_CORE_EXPORT HPX_CORE_EXPORT hpx::program_options::options_description const& @@ -92,13 +105,13 @@ namespace hpx { { init_params() { - std::strncpy(detail::app_name, HPX_APPLICATION_STRING, + std::strncpy(detail::app_name, "unknown HPX application", sizeof(detail::app_name) - 1); } std::reference_wrapper< hpx::program_options::options_description const> - desc_cmdline = detail::default_desc(HPX_APPLICATION_STRING); + desc_cmdline = detail::default_desc("unknown HPX application"); std::vector cfg; mutable startup_function_type startup; mutable shutdown_function_type shutdown; @@ -115,35 +128,11 @@ namespace hpx { int argc, char** argv, init_params const& params, bool blocking); - HPX_CXX_CORE_EXPORT inline int init_start_impl( + HPX_CXX_CORE_EXPORT int init_start_impl( hpx::function const& f, - int argc, char** argv, init_params const& params, bool blocking) - { - if (argc == 0 || argv == nullptr) - { - argc = dummy_argc; - argv = dummy_argv; - } - - util::set_hpx_prefix(HPX_PREFIX); -#if defined(__FreeBSD__) - freebsd_environ = environ; -#endif - // set a handler for std::abort - [[maybe_unused]] auto prev_sh = - std::signal(SIGABRT, hpx::detail::on_abort); - - [[maybe_unused]] auto ret = std::atexit(hpx::detail::on_exit); - HPX_ASSERT_MSG(ret == 0, "std::atexit returned error code"); - -#if defined(HPX_HAVE_CXX11_STD_QUICK_EXIT) - ret = std::at_quick_exit(hpx::detail::on_exit); - HPX_ASSERT_MSG( - ret == 0, "std::at_quick_exit returned error code"); -#endif - return run_or_start(f, argc, argv, params, blocking); - } + int argc, char** argv, init_params const& params, + bool blocking); } // namespace detail HPX_CXX_CORE_EXPORT inline int init( diff --git a/libs/core/init_runtime_local/src/init_runtime_local.cpp b/libs/core/init_runtime_local/src/init_runtime_local.cpp index 14301f53d6b5..409a7cb9eebc 100644 --- a/libs/core/init_runtime_local/src/init_runtime_local.cpp +++ b/libs/core/init_runtime_local/src/init_runtime_local.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -21,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -100,6 +102,16 @@ namespace hpx { namespace local { + namespace detail { + void dump_config::operator()() const + { + std::cout << "Configuration after runtime start:\n"; + std::cout << "----------------------------------\n"; + rt_.get().get_config().dump(0, std::cout); + std::cout << "----------------------------------\n"; + } + } // namespace detail + // Print stack trace and exit. #if defined(HPX_WINDOWS) extern BOOL WINAPI termination_handler(DWORD ctrl_type); @@ -540,3 +552,33 @@ namespace hpx { } // namespace detail } // namespace local } // namespace hpx + +namespace hpx::local::detail { + int init_start_impl( + hpx::function const& f, + int argc, char** argv, init_params const& params, bool blocking) + { + if (argc == 0 || argv == nullptr) + { + argc = dummy_argc; + argv = dummy_argv; + } + + util::set_hpx_prefix(HPX_PREFIX); +#if defined(__FreeBSD__) + freebsd_environ = environ; +#endif + // set a handler for std::abort + [[maybe_unused]] auto prev_sh = + std::signal(SIGABRT, hpx::detail::on_abort); + + [[maybe_unused]] auto ret = std::atexit(hpx::detail::on_exit); + HPX_ASSERT_MSG(ret == 0, "std::atexit returned error code"); + +#if defined(HPX_HAVE_CXX11_STD_QUICK_EXIT) + ret = std::at_quick_exit(hpx::detail::on_exit); + HPX_ASSERT_MSG(ret == 0, "std::at_quick_exit returned error code"); +#endif + return run_or_start(f, argc, argv, params, blocking); + } +} // namespace hpx::local::detail diff --git a/libs/core/resource_partitioner/CMakeLists.txt b/libs/core/resource_partitioner/CMakeLists.txt index 6bff921b4784..3c9b15658207 100644 --- a/libs/core/resource_partitioner/CMakeLists.txt +++ b/libs/core/resource_partitioner/CMakeLists.txt @@ -7,10 +7,12 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") set(resource_partitioner_headers + hpx/modules/resource_partitioner_mode.hpp hpx/resource_partitioner/detail/create_partitioner.hpp hpx/resource_partitioner/detail/partitioner.hpp hpx/resource_partitioner/partitioner.hpp hpx/resource_partitioner/partitioner_fwd.hpp + hpx/resource_partitioner/partitioner_mode.hpp ) # cmake-format: off diff --git a/libs/core/resource_partitioner/include/hpx/modules/resource_partitioner_mode.hpp b/libs/core/resource_partitioner/include/hpx/modules/resource_partitioner_mode.hpp new file mode 100644 index 000000000000..b74d54540cc9 --- /dev/null +++ b/libs/core/resource_partitioner/include/hpx/modules/resource_partitioner_mode.hpp @@ -0,0 +1,9 @@ +// Copyright (c) 2022-2026 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 diff --git a/libs/core/resource_partitioner/include/hpx/resource_partitioner/partitioner_fwd.hpp b/libs/core/resource_partitioner/include/hpx/resource_partitioner/partitioner_fwd.hpp index 4cb927558537..fc9364dee474 100644 --- a/libs/core/resource_partitioner/include/hpx/resource_partitioner/partitioner_fwd.hpp +++ b/libs/core/resource_partitioner/include/hpx/resource_partitioner/partitioner_fwd.hpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -36,19 +37,9 @@ namespace hpx::resource { /// Returns false otherwise. HPX_CXX_CORE_EXPORT HPX_CORE_EXPORT bool is_partitioner_valid(); - /// This enumeration describes the modes available when creating a - /// resource partitioner. - HPX_CXX_CORE_EXPORT enum class partitioner_mode : std::int8_t { - /// Default mode. - default_ = 0, - - /// Allow processing units to be oversubscribed, i.e. multiple - /// worker threads to share a single processing unit. - allow_oversubscription = 1, - - /// Allow worker threads to be added and removed from thread pools. - allow_dynamic_pools = 2 - }; + // partitioner_mode enum is defined in partitioner_mode.hpp + // (included above) to allow lightweight inclusion without the + // functional/threading_base transitive dependencies of this header. #define HPX_PARTITIONER_MODE_UNSCOPED_ENUM_DEPRECATION_MSG \ "The unscoped partitioner_mode names are deprecated. Please use " \ @@ -65,18 +56,6 @@ namespace hpx::resource { #undef HPX_PARTITIONER_MODE_UNSCOPED_ENUM_DEPRECATION_MSG - HPX_CXX_CORE_EXPORT constexpr partitioner_mode operator&( - partitioner_mode lhs, partitioner_mode rhs) noexcept - { - return static_cast( - static_cast(lhs) & static_cast(rhs)); - } - - HPX_CXX_CORE_EXPORT constexpr bool as_bool(partitioner_mode val) noexcept - { - return static_cast(val) != 0; - } - HPX_CXX_CORE_EXPORT using scheduler_function = hpx::function( hpx::threads::thread_pool_init_parameters, diff --git a/libs/core/resource_partitioner/include/hpx/resource_partitioner/partitioner_mode.hpp b/libs/core/resource_partitioner/include/hpx/resource_partitioner/partitioner_mode.hpp new file mode 100644 index 000000000000..b2da9caee039 --- /dev/null +++ b/libs/core/resource_partitioner/include/hpx/resource_partitioner/partitioner_mode.hpp @@ -0,0 +1,65 @@ +// Copyright (c) 2017 Shoshana Jakobovits +// Copyright (c) 2022-2026 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) + +/// \file partitioner_mode.hpp +/// \page hpx::resource::partitioner_mode +/// \headerfile hpx/resource_partitioner/partitioner_mode.hpp + +#pragma once + +#include +#include + +namespace hpx::resource { + + /// This enumeration describes the modes available when creating a + /// resource partitioner. + HPX_CXX_CORE_EXPORT enum class partitioner_mode : std::int8_t { + /// Default mode. + default_ = 0, + + /// Allow processing units to be oversubscribed, i.e. multiple + /// worker threads to share a single processing unit. + allow_oversubscription = 1, + + /// Allow worker threads to be added and removed from thread pools. + allow_dynamic_pools = 2 + }; + + HPX_CXX_CORE_EXPORT constexpr partitioner_mode operator&( + partitioner_mode lhs, partitioner_mode rhs) noexcept + { + return static_cast( + static_cast(lhs) & static_cast(rhs)); + } + + HPX_CXX_CORE_EXPORT constexpr partitioner_mode operator|( + partitioner_mode lhs, partitioner_mode rhs) noexcept + { + return static_cast( + static_cast(lhs) | static_cast(rhs)); + } + + HPX_CXX_CORE_EXPORT constexpr partitioner_mode operator^( + partitioner_mode lhs, partitioner_mode rhs) noexcept + { + return static_cast( + static_cast(lhs) ^ static_cast(rhs)); + } + + HPX_CXX_CORE_EXPORT constexpr partitioner_mode operator~( + partitioner_mode mode) noexcept + { + return static_cast(~static_cast(mode)); + } + + HPX_CXX_CORE_EXPORT constexpr bool as_bool(partitioner_mode val) noexcept + { + return static_cast(val) != 0; + } + +} // namespace hpx::resource diff --git a/libs/core/runtime_configuration/CMakeLists.txt b/libs/core/runtime_configuration/CMakeLists.txt index c662d85762e3..32329f0590b2 100644 --- a/libs/core/runtime_configuration/CMakeLists.txt +++ b/libs/core/runtime_configuration/CMakeLists.txt @@ -7,6 +7,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") set(runtime_configuration_headers + hpx/modules/runtime_mode.hpp hpx/runtime_configuration/agas_service_mode.hpp hpx/runtime_configuration/component_commandline_base.hpp hpx/runtime_configuration/component_factory_base.hpp diff --git a/libs/core/runtime_configuration/include/hpx/modules/runtime_mode.hpp b/libs/core/runtime_configuration/include/hpx/modules/runtime_mode.hpp new file mode 100644 index 000000000000..4e6dec9656a7 --- /dev/null +++ b/libs/core/runtime_configuration/include/hpx/modules/runtime_mode.hpp @@ -0,0 +1,10 @@ +// Copyright (c) 2007-2026 Hartmut Kaiser +// Copyright (c) 2011 Bryce Lelbach +// +// 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 diff --git a/libs/core/runtime_configuration/include/hpx/runtime_configuration/runtime_mode.hpp b/libs/core/runtime_configuration/include/hpx/runtime_configuration/runtime_mode.hpp index b694e65a2f1a..5683bdc0453e 100644 --- a/libs/core/runtime_configuration/include/hpx/runtime_configuration/runtime_mode.hpp +++ b/libs/core/runtime_configuration/include/hpx/runtime_configuration/runtime_mode.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2007-2025 Hartmut Kaiser +// Copyright (c) 2007-2026 Hartmut Kaiser // Copyright (c) 2011 Bryce Lelbach // // SPDX-License-Identifier: BSL-1.0 @@ -12,7 +12,6 @@ #pragma once #include - #include #include diff --git a/libs/full/agas/tests/regressions/duplicate_id_registration_1596.cpp b/libs/full/agas/tests/regressions/duplicate_id_registration_1596.cpp index cf5418cb1dba..78fdae7671c9 100644 --- a/libs/full/agas/tests/regressions/duplicate_id_registration_1596.cpp +++ b/libs/full/agas/tests/regressions/duplicate_id_registration_1596.cpp @@ -17,6 +17,7 @@ #include #include +#include using namespace std; diff --git a/libs/full/init_runtime/include/hpx/hpx_init.hpp b/libs/full/init_runtime/include/hpx/hpx_init.hpp index 34ceb2e7d853..f7eac4912b32 100644 --- a/libs/full/init_runtime/include/hpx/hpx_init.hpp +++ b/libs/full/init_runtime/include/hpx/hpx_init.hpp @@ -17,10 +17,12 @@ #include #include #include -#include -#include -#include +namespace hpx { + class runtime; + using startup_function_type = hpx::move_only_function; + using shutdown_function_type = hpx::move_only_function; +} #include #include @@ -192,8 +194,7 @@ namespace hpx { #if !defined(HPX_HAVE_STATIC_LINKING) inline #endif - int - init(init_params const& params = init_params()); + int init(init_params const& params = init_params()); } // namespace hpx #if !defined(DOXYGEN) diff --git a/libs/full/init_runtime/include/hpx/hpx_init_impl.hpp b/libs/full/init_runtime/include/hpx/hpx_init_impl.hpp index 0cafcfb2329b..2f21509de46c 100644 --- a/libs/full/init_runtime/include/hpx/hpx_init_impl.hpp +++ b/libs/full/init_runtime/include/hpx/hpx_init_impl.hpp @@ -17,10 +17,7 @@ #include #include #include -#include #include -#include -#include #include #include diff --git a/libs/full/init_runtime/include/hpx/hpx_init_params.hpp b/libs/full/init_runtime/include/hpx/hpx_init_params.hpp index 1a3216f86db2..275b9908cca1 100644 --- a/libs/full/init_runtime/include/hpx/hpx_init_params.hpp +++ b/libs/full/init_runtime/include/hpx/hpx_init_params.hpp @@ -1,5 +1,5 @@ // Copyright (c) 2020 ETH Zurich -// Copyright (c) 2022-2023 Hartmut Kaiser +// Copyright (c) 2022-2026 Hartmut Kaiser // // SPDX-License-Identifier: BSL-1.0 // Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -15,9 +15,8 @@ #include #include #include -#include -#include -#include +#include +#include #include #include @@ -113,9 +112,9 @@ namespace hpx { std::vector cfg; std::function startup; std::function shutdown; - hpx::runtime_mode mode = ::hpx::runtime_mode::default_; + hpx::runtime_mode mode = hpx::runtime_mode::default_; hpx::resource::partitioner_mode rp_mode = - ::hpx::resource::partitioner_mode::default_; + hpx::resource::partitioner_mode::default_; hpx::resource::rp_callback_type rp_callback; }; } // namespace hpx diff --git a/libs/full/init_runtime/include/hpx/hpx_start_impl.hpp b/libs/full/init_runtime/include/hpx/hpx_start_impl.hpp index 914b8abc5f0d..4102e3191c4b 100644 --- a/libs/full/init_runtime/include/hpx/hpx_start_impl.hpp +++ b/libs/full/init_runtime/include/hpx/hpx_start_impl.hpp @@ -16,10 +16,7 @@ #include #include #include -#include #include -#include -#include #include #include diff --git a/libs/full/init_runtime/src/init_logging.cpp b/libs/full/init_runtime/src/init_logging.cpp index 9bd1402825a5..3f61b9e1fa69 100644 --- a/libs/full/init_runtime/src/init_logging.cpp +++ b/libs/full/init_runtime/src/init_logging.cpp @@ -8,6 +8,7 @@ #if defined(HPX_HAVE_LOGGING) #include +#include #include #include