diff --git a/libs/core/config/CMakeLists.txt b/libs/core/config/CMakeLists.txt index 1373f6631388..32c3f6ab9fc8 100644 --- a/libs/core/config/CMakeLists.txt +++ b/libs/core/config/CMakeLists.txt @@ -27,6 +27,7 @@ set(config_macro_headers hpx/config/forward.hpp hpx/config/manual_profiling.hpp hpx/config/move.hpp + hpx/config/static_linker_check.hpp hpx/config/threads_stack.hpp hpx/config/warnings_prefix.hpp hpx/config/warnings_suffix.hpp diff --git a/libs/core/config/include/hpx/config/static_linker_check.hpp b/libs/core/config/include/hpx/config/static_linker_check.hpp new file mode 100644 index 000000000000..ab24c586e5f3 --- /dev/null +++ b/libs/core/config/include/hpx/config/static_linker_check.hpp @@ -0,0 +1,20 @@ +// Copyright (c) 2026 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) + +// hpxinspect:linelength +#pragma once + +#include + +#if defined(HPX_HAVE_DYNAMIC_HPX_MAIN) +#if (defined(__linux) || defined(__linux__) || defined(linux) || \ + defined(__APPLE__)) && \ + defined(HPX_HAVE_STATIC_LINKING) && \ + !defined(HPX_HAVE_WRAP_MAIN_CONFIGURED) +#warning \ + "You are statically linking HPX on Linux/macOS while using hpx_main.hpp. Please ensure you manually configure the linker to use wrap_main, or use the CMake target HPX::wrap_main to avoid linking errors." +#endif +#endif diff --git a/libs/core/include_local/CMakeLists.txt b/libs/core/include_local/CMakeLists.txt index eb19c9803e58..446eddb2887d 100644 --- a/libs/core/include_local/CMakeLists.txt +++ b/libs/core/include_local/CMakeLists.txt @@ -15,6 +15,7 @@ set(include_local_headers hpx/format.hpp hpx/functional.hpp hpx/generator.hpp + hpx/local.hpp hpx/memory.hpp hpx/mutex.hpp hpx/numeric.hpp diff --git a/libs/core/include_local/include/hpx/local.hpp b/libs/core/include_local/include/hpx/local.hpp new file mode 100644 index 000000000000..e34e41b6ed40 --- /dev/null +++ b/libs/core/include_local/include/hpx/local.hpp @@ -0,0 +1,36 @@ +// Copyright (c) 2020-2026 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) + +/// \file hpx/local.hpp +/// \brief Single-include convenience header for single-node HPX usage. +/// +/// This header bundles the **Standard Parallel Toolkit** -- the most commonly +/// used HPX facilities for local (single-node) execution: +/// +/// - \c hpx/modules/algorithms.hpp -- Parallel algorithms (for_each, sort, ...) +/// - \c hpx/modules/execution.hpp -- Execution policies (par, par_unseq, seq) +/// - \c hpx/modules/futures.hpp -- Futures and dataflow +/// - \c hpx/numeric.hpp -- Parallel numeric (reduce, transform_reduce, ...) +/// +/// **Selection criteria**: each header is part of the HPX core module, +/// provides ISO C++ Standard Library parallel equivalents, and has no +/// dependency on the distributed runtime or networking layer. +/// +/// \note This header intentionally does NOT include hpx/hpx_main.hpp. +/// Including hpx_main.hpp has observable side effects: it emits +/// non-weak symbol definitions and redefines 'main' via a +/// preprocessor macro. Users who need the zero-boilerplate HPX +/// runtime entry-point should include hpx/hpx_main.hpp explicitly. + +#pragma once + +#include + +// --- Standard Parallel Toolkit (core, no networking dependency) --- +#include +#include +#include +#include diff --git a/libs/core/include_local/tests/unit/CMakeLists.txt b/libs/core/include_local/tests/unit/CMakeLists.txt index 2f7420810a42..1bb8f9fcbfd8 100644 --- a/libs/core/include_local/tests/unit/CMakeLists.txt +++ b/libs/core/include_local/tests/unit/CMakeLists.txt @@ -1,5 +1,26 @@ -# Copyright (c) 2020-2021 The STE||AR-Group +# Copyright (c) 2026 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) + +set(tests local_header) + +set(local_header_FLAGS NOLIBS DEPENDENCIES HPX::hpx HPX::wrap_main) + +foreach(test ${tests}) + set(sources ${test}.cpp) + + source_group("Source Files" FILES ${sources}) + + set(folder_name "Tests/Unit/Modules/Core/IncludeLocal") + + add_hpx_executable( + ${test}_test INTERNAL_FLAGS + SOURCES ${sources} ${${test}_FLAGS} + EXCLUDE_FROM_ALL + FOLDER ${folder_name} + ) + + add_hpx_unit_test("modules.include_local" ${test} ${${test}_PARAMETERS}) +endforeach() diff --git a/libs/core/include_local/tests/unit/local_header.cpp b/libs/core/include_local/tests/unit/local_header.cpp new file mode 100644 index 000000000000..fe9a380aad14 --- /dev/null +++ b/libs/core/include_local/tests/unit/local_header.cpp @@ -0,0 +1,42 @@ +// Copyright (c) 2020-2026 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) + +// Verify that hpx/local.hpp provides access to the Standard Parallel Toolkit: +// parallel algorithms, numeric algorithms, and execution policies. +// +// We use hpx::local::init to drive the HPX runtime without requiring any +// dependency on the wrap module (hpx_main.hpp / HPX::wrap_main). + +#include +#include +#include + +#include +#include +#include +#include + +int test_main(int argc, char* argv[]) +{ + // 1. Verify parallel algorithms are reachable via hpx/local.hpp + std::vector v(100); + std::iota(v.begin(), v.end(), 1); + + hpx::for_each( + hpx::execution::par, v.begin(), v.end(), [](int& x) { x *= 2; }); + + // 2. Verify numeric algorithms are reachable + int sum = hpx::reduce(hpx::execution::par, v.begin(), v.end(), 0); + + std::cout << "reduce sum: " << sum << std::endl; + + return hpx::local::finalize(); +} + +int main(int argc, char* argv[]) +{ + return hpx::local::init(test_main, argc, argv); +} diff --git a/wrap/CMakeLists.txt b/wrap/CMakeLists.txt index 143952466006..d2d9bf230103 100644 --- a/wrap/CMakeLists.txt +++ b/wrap/CMakeLists.txt @@ -134,7 +134,11 @@ endif() if(HPX_WITH_DYNAMIC_HPX_MAIN) if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") target_link_libraries(hpx_wrap INTERFACE "-Wl,-wrap=main") + target_compile_definitions(hpx_wrap INTERFACE HPX_HAVE_WRAP_MAIN_CONFIGURED) target_link_libraries(hpx_auto_wrap INTERFACE "-Wl,-wrap=main") + target_compile_definitions( + hpx_auto_wrap INTERFACE HPX_HAVE_WRAP_MAIN_CONFIGURED + ) elseif(APPLE) target_link_libraries(hpx_wrap INTERFACE "-Wl,-e,_initialize_main") target_link_libraries(hpx_auto_wrap INTERFACE "-Wl,-e,_initialize_main") diff --git a/wrap/include/hpx/hpx_main.hpp b/wrap/include/hpx/hpx_main.hpp index 9b4077bba341..155f217fef9d 100644 --- a/wrap/include/hpx/hpx_main.hpp +++ b/wrap/include/hpx/hpx_main.hpp @@ -7,6 +7,7 @@ #pragma once +#include #include #if defined(HPX_HAVE_RUN_MAIN_EVERYWHERE)