Skip to content

Commit

Permalink
Make HPX_HAVE_RUN_MAIN_EVERYWHERE application specific
Browse files Browse the repository at this point in the history
  • Loading branch information
hkaiser committed Jan 7, 2025
1 parent a40e83e commit a5ea77e
Show file tree
Hide file tree
Showing 14 changed files with 131 additions and 45 deletions.
12 changes: 9 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1582,12 +1582,18 @@ if(HPX_WITH_THREAD_DEBUG_INFO)
hpx_add_config_define(HPX_HAVE_THREAD_MINIMAL_DEADLOCK_DETECTION)
endif()

# run hpx_main on all localities by default
# run hpx_main on all localities by default (will be removed after V1.11.0)
hpx_option(
HPX_WITH_RUN_MAIN_EVERYWHERE BOOL
"Run hpx_main by default on all localities (default: OFF)." OFF ADVANCED
HPX_WITH_RUN_MAIN_EVERYWHERE
BOOL
"Run hpx_main by default on all localities (default: OFF, deprecated, will be removed)."
OFF
ADVANCED
)
if(HPX_WITH_RUN_MAIN_EVERYWHERE)
hpx_info("Note: the configuration parameter HPX_WITH_RUN_MAIN_EVERYWHERE is\n"
" deprecated and will be removed in the future."
)
hpx_add_config_define(HPX_HAVE_RUN_MAIN_EVERYWHERE)
endif()

Expand Down
9 changes: 9 additions & 0 deletions docs/sphinx/releases/whats_new_1_11_0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
General changes
===============

- Added synchronous versions of all collective operations. Added global predefined
communicator objects that are accessible through new APIs:
``hpx::collectives::get_world_communicator()`` refers to all localities and
``hpx::collectives::get_local_communicator()`` refers to all threads on the
calling locality.

Breaking changes
================

Expand All @@ -22,6 +28,9 @@ Breaking changes
It was not possible to add compatibility facilities that will allow to continue
using the old APIs, applications will have to be changed in order to
continue functioning correctly.
- The CMake configuration parameter ``HPX_WITH_RUN_MAIN_EVERYWHERE`` is now
deprecated and will be removed in the future. Use the preprocessor macro
``HPX_HAVE_RUN_MAIN_EVERYWHERE`` on a target-by-target case instead.

Closed issues
=============
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <cstddef>
#include <cstring>
#include <functional>
#include <memory>
#include <new>
#include <string>
Expand Down Expand Up @@ -112,6 +113,13 @@ namespace hpx::util::detail {
return detail::is_empty_function_impl(&f);
}

template <typename Sig>
[[nodiscard]] constexpr bool is_empty_function(
std::function<Sig> const& f) noexcept
{
return !f;
}

///////////////////////////////////////////////////////////////////////////
template <typename Sig, bool Copyable, bool Serializable>
class basic_function;
Expand Down
14 changes: 3 additions & 11 deletions libs/full/command_line_handling/src/command_line_handling.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2023 Hartmut Kaiser
// Copyright (c) 2007-2025 Hartmut Kaiser
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand Down Expand Up @@ -584,15 +584,13 @@ namespace hpx::util {
{
rtcfg_.mode_ = hpx::runtime_mode::worker;

#if !defined(HPX_HAVE_RUN_MAIN_EVERYWHERE)
// do not execute any explicit hpx_main except if asked
// otherwise
if (!vm.count("hpx:run-hpx-main") &&
!cfgmap.get_value<int>("hpx.run_hpx_main", 0))
{
util::detail::reset_function(hpx_main_f_);
}
#endif
}
else if (vm.count("hpx:connect"))
{
Expand Down Expand Up @@ -628,15 +626,13 @@ namespace hpx::util {
hpx::util::from_string<std::uint16_t>(rtcfg_.get_entry(
"hpx.parcel.port", HPX_CONNECTING_IP_PORT)));

#if !defined(HPX_HAVE_RUN_MAIN_EVERYWHERE)
// do not execute any explicit hpx_main except if asked
// otherwise
if (!vm.count("hpx:run-hpx-main") &&
!cfgmap.get_value<int>("hpx.run_hpx_main", 0))
{
util::detail::reset_function(hpx_main_f_);
}
#endif
}
else if (node != static_cast<std::size_t>(-1) ||
vm.count("hpx:node"))
Expand Down Expand Up @@ -667,19 +663,17 @@ namespace hpx::util {
if (hpx_port == 0 && node != 0)
hpx_port = HPX_INITIAL_IP_PORT;

// each node gets an unique port
// each node gets a unique port
hpx_port = static_cast<std::uint16_t>(hpx_port + node);
rtcfg_.mode_ = hpx::runtime_mode::worker;

#if !defined(HPX_HAVE_RUN_MAIN_EVERYWHERE)
// do not execute any explicit hpx_main except if asked
// otherwise
if (!vm.count("hpx:run-hpx-main") &&
!cfgmap.get_value<int>("hpx.run_hpx_main", 0))
{
util::detail::reset_function(hpx_main_f_);
}
#endif
}
}

Expand Down Expand Up @@ -778,15 +772,13 @@ namespace hpx::util {
// should not run the AGAS server we assume to be in worker mode
rtcfg_.mode_ = hpx::runtime_mode::worker;

#if !defined(HPX_HAVE_RUN_MAIN_EVERYWHERE)
// do not execute any explicit hpx_main except if asked
// otherwise
if (!vm.count("hpx:run-hpx-main") &&
!cfgmap.get_value<int>("hpx.run_hpx_main", 0))
{
util::detail::reset_function(hpx_main_f_);
}
#endif
}

// write HPX and AGAS network parameters to the proper ini-file
Expand Down Expand Up @@ -1051,7 +1043,7 @@ namespace hpx::util {
reg->init(&argc, &argv, rtcfg_);
}

// Now re-parse the command line using the node number (if given). This
// Now reparse the command line using the node number (if given). This
// will additionally detect any --hpx:N:foo options.
hpx::program_options::options_description help;
std::vector<std::string> unregistered_options;
Expand Down
16 changes: 8 additions & 8 deletions libs/full/init_runtime/include/hpx/hpx_init.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) 2018 Mikael Simberg
// Copyright (c) 2007-2023 Hartmut Kaiser
// Copyright (c) 2007-2025 Hartmut Kaiser
// Copyright (c) 2010-2011 Phillip LeBlanc, Dylan Stark
// Copyright (c) 2011 Bryce Lelbach
//
Expand Down Expand Up @@ -28,6 +28,7 @@
///////////////////////////////////////////////////////////////////////////////
/// \namespace hpx
namespace hpx {

/// \brief Main entry point for launching the HPX runtime system.
///
/// This is the main entry point for any HPX application. This function
Expand Down Expand Up @@ -58,7 +59,7 @@ namespace hpx {
/// the created runtime system instance will be
/// executed in console or worker mode depending on the
/// command line arguments passed in `argc`/`argv`.
/// Otherwise it will be executed as specified by the
/// Otherwise, it will be executed as specified by the
/// parameter\p mode.
inline int init(std::function<int(hpx::program_options::variables_map&)> f,
int argc, char** argv, init_params const& params = init_params());
Expand Down Expand Up @@ -93,7 +94,7 @@ namespace hpx {
/// the created runtime system instance will be
/// executed in console or worker mode depending on the
/// command line arguments passed in `argc`/`argv`.
/// Otherwise it will be executed as specified by the
/// Otherwise, it will be executed as specified by the
/// parameter\p mode.
inline int init(std::function<int(int, char**)> f, int argc, char** argv,
init_params const& params = init_params());
Expand Down Expand Up @@ -123,10 +124,9 @@ namespace hpx {
/// the created runtime system instance will be
/// executed in console or worker mode depending on the
/// command line arguments passed in `argc`/`argv`.
/// Otherwise it will be executed as specified by the
/// Otherwise, it will be executed as specified by the
/// parameter\p mode.
inline int init(
int argc, char** argv, init_params const& params = init_params());
inline int init(int argc, char** argv, init_params params = init_params());

/// \brief Main entry point for launching the HPX runtime system.
///
Expand Down Expand Up @@ -158,7 +158,7 @@ namespace hpx {
/// the created runtime system instance will be
/// executed in console or worker mode depending on the
/// command line arguments passed in `argc`/`argv`.
/// Otherwise it will be executed as specified by the
/// Otherwise, it will be executed as specified by the
/// parameter\p mode.
inline int init(std::nullptr_t f, int argc, char** argv,
init_params const& params = init_params());
Expand Down Expand Up @@ -190,7 +190,7 @@ namespace hpx {
inline
#endif
int
init(init_params const& params = init_params());
init(init_params params = init_params());
} // namespace hpx

#if !defined(DOXYGEN)
Expand Down
13 changes: 10 additions & 3 deletions libs/full/init_runtime/include/hpx/hpx_init_impl.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) 2018 Mikael Simberg
// Copyright (c) 2007-2023 Hartmut Kaiser
// Copyright (c) 2007-2025 Hartmut Kaiser
// Copyright (c) 2011 Bryce Lelbach
//
// SPDX-License-Identifier: BSL-1.0
Expand Down Expand Up @@ -50,6 +50,7 @@ namespace hpx_startup {
}

namespace hpx {

/// \brief Main entry point for launching the HPX runtime system.
///
/// This is the main entry point for any HPX application. This function
Expand Down Expand Up @@ -84,8 +85,11 @@ namespace hpx {
/// (or one of its overloads below) should be called from the users `main()`
/// function. It will set up the HPX runtime environment and schedule the
/// function given by \p f as a HPX thread.
inline int init(int argc, char** argv, init_params const& params)
inline int init(int argc, char** argv, init_params params)

Check notice

Code scanning / CodeQL

Large object passed by value Note

This parameter of type
init_params
is 144 bytes - consider passing a const pointer/reference instead.
{
#if defined(HPX_HAVE_RUN_MAIN_EVERYWHERE)
params.cfg.insert(params.cfg.begin(), "hpx.run_hpx_main!=1");
#endif
return detail::init_impl(hpx_startup::get_main_func(), argc, argv,
params, HPX_PREFIX, environ);
}
Expand All @@ -109,8 +113,11 @@ namespace hpx {
/// This is a simplified main entry point, which can be used to set up the
/// runtime for an HPX application (the runtime system will be set up in
/// console mode or worker mode depending on the command line settings).
inline int init(init_params const& params)
inline int init(init_params params)

Check notice

Code scanning / CodeQL

Large object passed by value Note

This parameter of type
init_params
is 144 bytes - consider passing a const pointer/reference instead.
{
#if defined(HPX_HAVE_RUN_MAIN_EVERYWHERE)
params.cfg.insert(params.cfg.begin(), "hpx.run_hpx_main!=1");
#endif
return detail::init_impl(hpx_startup::get_main_func(),
hpx::local::detail::dummy_argc, hpx::local::detail::dummy_argv,
params, HPX_PREFIX, environ);
Expand Down
8 changes: 4 additions & 4 deletions libs/full/init_runtime/include/hpx/hpx_init_params.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ namespace hpx {
/// 'hpx.component.enabled=1')
/// \var startup A function to be executed inside a HPX thread before
/// \p f is called. If this parameter is
/// not given no function will be executed.
/// not given, no function will be executed.
/// \var shutdown A function to be executed inside an HPX
/// thread while hpx::finalize is executed. If this
/// parameter is not given no function will be executed.
/// parameter is not given, no function will be executed.
/// \var mode The mode the created runtime environment
/// should be initialized in. There has to be exactly
/// one locality in each HPX application which is
Expand Down Expand Up @@ -112,8 +112,8 @@ namespace hpx {
desc_cmdline =
hpx::local::detail::default_desc(HPX_APPLICATION_STRING);
std::vector<std::string> cfg;
mutable startup_function_type startup;
mutable shutdown_function_type shutdown;
std::function<void()> startup;
std::function<void()> shutdown;
hpx::runtime_mode mode = ::hpx::runtime_mode::default_;
hpx::resource::partitioner_mode rp_mode =
::hpx::resource::partitioner_mode::default_;
Expand Down
14 changes: 7 additions & 7 deletions libs/full/init_runtime/include/hpx/hpx_start.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) 2018 Mikael Simberg
// Copyright (c) 2007-2023 Hartmut Kaiser
// Copyright (c) 2007-2025 Hartmut Kaiser
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand Down Expand Up @@ -57,7 +57,7 @@ namespace hpx {
/// the created runtime system instance will be
/// executed in console or worker mode depending on the
/// command line arguments passed in `argc`/`argv`.
/// Otherwise it will be executed as specified by the
/// Otherwise, it will be executed as specified by the
/// parameter\p mode.
inline bool start(
std::function<int(hpx::program_options::variables_map&)> f, int argc,
Expand Down Expand Up @@ -95,7 +95,7 @@ namespace hpx {
/// the created runtime system instance will be
/// executed in console or worker mode depending on the
/// command line arguments passed in `argc`/`argv`.
/// Otherwise it will be executed as specified by the
/// Otherwise, it will be executed as specified by the
/// parameter\p mode.
inline bool start(std::function<int(int, char**)> f, int argc, char** argv,
init_params const& params = init_params());
Expand Down Expand Up @@ -127,10 +127,10 @@ namespace hpx {
/// the created runtime system instance will be
/// executed in console or worker mode depending on the
/// command line arguments passed in `argc`/`argv`.
/// Otherwise it will be executed as specified by the
/// Otherwise, it will be executed as specified by the
/// parameter\p mode.
inline bool start(
int argc, char** argv, init_params const& params = init_params());
int argc, char** argv, init_params params = init_params());

/// \brief Main non-blocking entry point for launching the HPX runtime system.
///
Expand Down Expand Up @@ -164,7 +164,7 @@ namespace hpx {
/// the created runtime system instance will be
/// executed in console or worker mode depending on the
/// command line arguments passed in `argc`/`argv`.
/// Otherwise it will be executed as specified by the
/// Otherwise, it will be executed as specified by the
/// parameter\p mode.
inline bool start(std::nullptr_t f, int argc, char** argv,
init_params const& params = init_params());
Expand Down Expand Up @@ -194,7 +194,7 @@ namespace hpx {
/// runtime system will not support any of the default
/// command line options as described in the section
/// 'HPX Command Line Options'.
inline bool start(init_params const& params = init_params());
inline bool start(init_params params = init_params());
} // namespace hpx

#if !defined(DOXYGEN)
Expand Down
13 changes: 10 additions & 3 deletions libs/full/init_runtime/include/hpx/hpx_start_impl.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) 2018 Mikael Simberg
// Copyright (c) 2007-2023 Hartmut Kaiser
// Copyright (c) 2007-2025 Hartmut Kaiser
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand Down Expand Up @@ -48,6 +48,7 @@ namespace hpx_startup {
}

namespace hpx {

/// \brief Main non-blocking entry point for launching the HPX runtime system.
///
/// This is the main, non-blocking entry point for any HPX application.
Expand Down Expand Up @@ -89,8 +90,11 @@ namespace hpx {
/// schedule the function given by \p f as an HPX thread. It will return
/// immediately after that. Use `hpx::wait` and `hpx::stop` to synchronize
/// with the runtime system's execution.
inline bool start(int argc, char** argv, init_params const& params)
inline bool start(int argc, char** argv, init_params params)
{
#if defined(HPX_HAVE_RUN_MAIN_EVERYWHERE)
params.cfg.insert(params.cfg.begin(), "hpx.run_hpx_main!=1");
#endif
return detail::start_impl(hpx_startup::get_main_func(), argc, argv,
params, HPX_PREFIX, environ);
}
Expand Down Expand Up @@ -119,8 +123,11 @@ namespace hpx {
/// schedule the function given by \p f as an HPX thread. It will return
/// immediately after that. Use `hpx::wait` and `hpx::stop` to synchronize
/// with the runtime system's execution.
inline bool start(init_params const& params)
inline bool start(init_params params)
{
#if defined(HPX_HAVE_RUN_MAIN_EVERYWHERE)
params.cfg.insert(params.cfg.begin(), "hpx.run_hpx_main!=1");
#endif
return detail::start_impl(hpx_startup::get_main_func(),
hpx::local::detail::dummy_argc, hpx::local::detail::dummy_argv,
params, HPX_PREFIX, environ);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2015 Hartmut Kaiser
// Copyright (c) 2007-2055 Hartmut Kaiser
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand Down
Loading

0 comments on commit a5ea77e

Please sign in to comment.