Skip to content

Commit

Permalink
Merge pull request #6599 from STEllAR-GROUP/run_main_everywhere
Browse files Browse the repository at this point in the history
Make HPX_HAVE_RUN_MAIN_EVERYWHERE application specific
  • Loading branch information
hkaiser authored Jan 8, 2025
2 parents bcdfe70 + b5a5564 commit 09ffd2f
Show file tree
Hide file tree
Showing 14 changed files with 141 additions and 36 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
11 changes: 6 additions & 5 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,7 +124,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(
int argc, char** argv, init_params const& params = init_params());
Expand Down Expand Up @@ -158,7 +159,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
18 changes: 17 additions & 1 deletion 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 @@ -86,8 +87,15 @@ namespace hpx {
/// function given by \p f as a HPX thread.
inline int init(int argc, char** argv, init_params const& params)
{
#if defined(HPX_HAVE_RUN_MAIN_EVERYWHERE)
init_params pars = params;
pars.cfg.insert(pars.cfg.begin(), "hpx.run_hpx_main!=1");
return detail::init_impl(hpx_startup::get_main_func(), argc, argv, pars,
HPX_PREFIX, environ);
#else
return detail::init_impl(hpx_startup::get_main_func(), argc, argv,
params, HPX_PREFIX, environ);
#endif
}

/// \brief Main entry point for launching the HPX runtime system.
Expand All @@ -111,8 +119,16 @@ namespace hpx {
/// console mode or worker mode depending on the command line settings).
inline int init(init_params const& params)
{
#if defined(HPX_HAVE_RUN_MAIN_EVERYWHERE)
init_params pars = params;
pars.cfg.insert(pars.cfg.begin(), "hpx.run_hpx_main!=1");
return detail::init_impl(hpx_startup::get_main_func(),
hpx::local::detail::dummy_argc, hpx::local::detail::dummy_argv,
pars, HPX_PREFIX, environ);
#else
return detail::init_impl(hpx_startup::get_main_func(),
hpx::local::detail::dummy_argc, hpx::local::detail::dummy_argv,
params, HPX_PREFIX, environ);
#endif
}
} // namespace hpx
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
10 changes: 5 additions & 5 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,7 +127,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(
int argc, char** argv, init_params const& params = init_params());
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
18 changes: 17 additions & 1 deletion 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 @@ -91,8 +92,15 @@ namespace hpx {
/// with the runtime system's execution.
inline bool start(int argc, char** argv, init_params const& params)
{
#if defined(HPX_HAVE_RUN_MAIN_EVERYWHERE)
init_params pars = params;
pars.cfg.insert(pars.cfg.begin(), "hpx.run_hpx_main!=1");
return detail::start_impl(hpx_startup::get_main_func(), argc, argv,
pars, HPX_PREFIX, environ);
#else
return detail::start_impl(hpx_startup::get_main_func(), argc, argv,
params, HPX_PREFIX, environ);
#endif
}

/// \brief Main non-blocking entry point for launching the HPX runtime system.
Expand Down Expand Up @@ -121,8 +129,16 @@ namespace hpx {
/// with the runtime system's execution.
inline bool start(init_params const& params)
{
#if defined(HPX_HAVE_RUN_MAIN_EVERYWHERE)
init_params pars = params;
pars.cfg.insert(pars.cfg.begin(), "hpx.run_hpx_main!=1");
return detail::start_impl(hpx_startup::get_main_func(),
hpx::local::detail::dummy_argc, hpx::local::detail::dummy_argv,
pars, HPX_PREFIX, environ);
#else
return detail::start_impl(hpx_startup::get_main_func(),
hpx::local::detail::dummy_argc, hpx::local::detail::dummy_argv,
params, HPX_PREFIX, environ);
#endif
}
} // namespace hpx
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 09ffd2f

Please sign in to comment.