hpx/runtime_distributed.hpp#

Defined in header hpx/runtime_distributed.hpp.

See Public API for a list of names and headers that are part of the public HPX API.

namespace hpx
class runtime_distributed : public runtime#
#include <runtime_distributed.hpp>

The runtime class encapsulates the HPX runtime system in a simple to use way. It makes sure all required parts of the HPX runtime system are properly initialized.

Public Functions

explicit runtime_distributed(util::runtime_configuration &rtcfg, int (*pre_main)(runtime_mode) = nullptr, void (*post_main)() = nullptr)#

Construct a new HPX runtime instance

Parameters
  • rtcfg – Runtime configuration for this instance

  • pre_main – Function to be called before running the main action of this instance

  • post_main – Function to be called after running the main action of this instance

~runtime_distributed()#

The destructor makes sure all HPX runtime services are properly shut down before exiting.

int start(hpx::function<hpx_main_function_type> const &func, bool blocking = false) override#

Start the runtime system.

Parameters
  • func – [in] This is the main function of an HPX application. It will be scheduled for execution by the thread manager as soon as the runtime has been initialized. This function is expected to expose an interface as defined by the typedef hpx_main_function_type.

  • blocking – [in] This allows to control whether this call blocks until the runtime system has been stopped. If this parameter is true the function runtime::start will call runtime::wait internally.

Returns

If a blocking is a true, this function will return the value as returned as the result of the invocation of the function object given by the parameter func. Otherwise it will return zero.

int start(bool blocking = false) override#

Start the runtime system.

Parameters

blocking – [in] This allows to control whether this call blocks until the runtime system has been stopped. If this parameter is true the function runtime::start will call runtime::wait internally .

Returns

If a blocking is a true, this function will return the value as returned as the result of the invocation of the function object given by the parameter func. Otherwise it will return zero.

int wait() override#

Wait for the shutdown action to be executed.

Returns

This function will return the value as returned as the result of the invocation of the function object given by the parameter func.

void stop(bool blocking = true) override#

Initiate termination of the runtime system.

Parameters

blocking – [in] This allows to control whether this call blocks until the runtime system has been fully stopped. If this parameter is false then this call will initiate the stop action but will return immediately. Use a second call to stop with this parameter set to true to wait for all internal work to be completed.

int finalize(double shutdown_timeout) override#
void stop_helper(bool blocking, std::condition_variable &cond, std::mutex &mtx)#

Stop the runtime system, wait for termination.

Parameters
  • blocking – [in] This allows to control whether this call blocks until the runtime system has been fully stopped. If this parameter is false then this call will initiate the stop action but will return immediately. Use a second call to stop with this parameter set to true to wait for all internal work to be completed.

  • cond – Condition used to update all thread when done

  • mtx – Mutex used by this function to sync all threads

int suspend() override#

Suspend the runtime system.

int resume() override#

Resume the runtime system.

bool report_error(std::size_t num_thread, std::exception_ptr const &e, bool terminate_all = true) override#

Report a non-recoverable error to the runtime system.

Parameters
  • num_thread – [in] The number of the operating system thread the error has been detected in.

  • e – [in] This is an instance encapsulating an exception which lead to this function call.

  • terminate_all – [in] Kill all localities attached to the currently running application (default: true)

bool report_error(std::exception_ptr const &e, bool terminate_all = true) override#

Report a non-recoverable error to the runtime system.

Note

This function will retrieve the number of the current shepherd thread and forward to the report_error function above.

Parameters
  • e – [in] This is an instance encapsulating an exception which lead to this function call.

  • terminate_all – [in] Kill all localities attached to the currently running application (default: true)

int run(hpx::function<hpx_main_function_type> const &func) override#

Run the HPX runtime system, use the given function for the main thread and block waiting for all threads to finish.

Note

The parameter func is optional. If no function is supplied, the runtime system will simply wait for the shutdown action without explicitly executing any main thread.

Parameters

func – [in] This is the main function of an HPX application. It will be scheduled for execution by the thread manager as soon as the runtime has been initialized. This function is expected to expose an interface as defined by the typedef hpx_main_function_type. This parameter is optional and defaults to none main thread function, in which case all threads have to be scheduled explicitly.

Returns

This function will return the value as returned as the result of the invocation of the function object given by the parameter func.

int run() override#

Run the HPX runtime system, initially use the given number of (OS) threads in the thread-manager and block waiting for all threads to finish.

Returns

This function will always return 0 (zero).

bool is_networking_enabled() override#
template<typename F>
inline components::server::console_error_dispatcher::sink_type set_error_sink(F &&sink)#
performance_counters::registry &get_counter_registry()#

Allow access to the registry counter registry instance used by the HPX runtime.

performance_counters::registry const &get_counter_registry() const#

Allow access to the registry counter registry instance used by the HPX runtime.

void register_query_counters(std::shared_ptr<util::query_counters> const &active_counters)#
void start_active_counters(error_code &ec = throws) const#
void stop_active_counters(error_code &ec = throws) const#
void reset_active_counters(error_code &ec = throws) const#
void reinit_active_counters(bool reset = true, error_code &ec = throws) const#
void evaluate_active_counters(bool reset = false, char const *description = nullptr, error_code &ec = throws) const#
void stop_evaluating_counters(bool terminate = false) const#
naming::resolver_client &get_agas_client()#

Allow access to the AGAS client instance used by the HPX runtime.

hpx::threads::threadmanager &get_thread_manager() override#

Allow access to the thread manager instance used by the HPX runtime.

applier::applier &get_applier()#

Allow access to the applier instance used by the HPX runtime.

std::string here() const override#

Returns a string of the locality endpoints (usable in debug output)

naming::address_type get_runtime_support_lva() const#
naming::gid_type get_next_id(std::size_t count = 1)#
void init_id_pool_range()#
util::unique_id_ranges &get_id_pool()#
void initialize_agas()#

Initialize AGAS operation.

void add_pre_startup_function(startup_function_type f) override#

Add a function to be executed inside a HPX thread before hpx_main but guaranteed to be executed before any startup function registered with add_startup_function.

Note

The difference to a startup function is that all pre-startup functions will be (system-wide) executed before any startup function.

Parameters

f – The function ‘f’ will be called from inside a HPX thread before hpx_main is executed. This is very useful to setup the runtime environment of the application (install performance counters, etc.)

void add_startup_function(startup_function_type f) override#

Add a function to be executed inside a HPX thread before hpx_main

Parameters

f – The function ‘f’ will be called from inside a HPX thread before hpx_main is executed. This is very useful to setup the runtime environment of the application (install performance counters, etc.)

void add_pre_shutdown_function(shutdown_function_type f) override#

Add a function to be executed inside a HPX thread during hpx::finalize, but guaranteed before any of the shutdown functions is executed.

Note

The difference to a shutdown function is that all pre-shutdown functions will be (system-wide) executed before any shutdown function.

Parameters

f – The function ‘f’ will be called from inside a HPX thread while hpx::finalize is executed. This is very useful to tear down the runtime environment of the application (uninstall performance counters, etc.)

void add_shutdown_function(shutdown_function_type f) override#

Add a function to be executed inside a HPX thread during hpx::finalize

Parameters

f – The function ‘f’ will be called from inside a HPX thread while hpx::finalize is executed. This is very useful to tear down the runtime environment of the application (uninstall performance counters, etc.)

hpx::util::io_service_pool *get_thread_pool(char const *name) override#

Access one of the internal thread pools (io_service instances) HPX is using to perform specific tasks. The three possible values for the argument name are “main_pool”, “io_pool”, “parcel_pool”, and “timer_pool”. For any other argument value the function will return zero.

bool register_thread(char const *name, std::size_t num = 0, bool service_thread = true, error_code &ec = throws) override#

Register an external OS-thread with HPX.

notification_policy_type get_notification_policy(char const *prefix, runtime_local::os_thread_type type) override#

Generate a new notification policy instance for the given thread name prefix

std::uint32_t get_locality_id(error_code &ec) const override#
std::size_t get_num_worker_threads() const override#
std::uint32_t get_num_localities(hpx::launch::sync_policy, error_code &ec) const override#
std::uint32_t get_initial_num_localities() const override#
hpx::future<std::uint32_t> get_num_localities() const override#
std::string get_locality_name() const override#
std::uint32_t get_num_localities(hpx::launch::sync_policy, components::component_type type, error_code &ec) const#
hpx::future<std::uint32_t> get_num_localities(components::component_type type) const#
std::uint32_t assign_cores(std::string const &locality_basename, std::uint32_t num_threads) override#
std::uint32_t assign_cores() override#

Public Static Functions

static void register_counter_types()#

Install all performance counters related to this runtime instance.

Private Types

using used_cores_map_type = std::map<std::string, std::uint32_t>#

Private Functions

threads::thread_result_type run_helper(hpx::function<runtime::hpx_main_function_type> const &func, int &result)#
void init_global_data()#
void deinit_global_data()#
void wait_helper(std::mutex &mtx, std::condition_variable &cond, bool &running)#
void init_tss_helper(char const *context, runtime_local::os_thread_type type, std::size_t local_thread_num, std::size_t global_thread_num, char const *pool_name, char const *postfix, bool service_thread)#
void deinit_tss_helper(char const *context, std::size_t num) const#
void init_tss_ex(std::string const &locality, char const *context, runtime_local::os_thread_type type, std::size_t local_thread_num, std::size_t global_thread_num, char const *pool_name, char const *postfix, bool service_thread, error_code &ec) const#

Private Members

runtime_mode mode_#
util::unique_id_ranges id_pool_#
naming::resolver_client agas_client_#
applier::applier applier_#
used_cores_map_type used_cores_map_#
std::unique_ptr<components::server::runtime_support> runtime_support_#
std::shared_ptr<util::query_counters> active_counters_#
int (*pre_main_)(runtime_mode)#
void (*post_main_)()#

Private Static Functions

static void default_errorsink(std::string const&)#