Public API

Our API is semantically conforming; hence, the reader is highly encouraged to refer to the corresponding facility in the C++ Standard if needed. All names below are also available in the top-level hpx namespace unless otherwise noted. The names in hpx should be preferred. The names in sub-namespaces will eventually be removed.

hpx/algorithm.hpp

The header hpx/algorithm.hpp corresponds to the C++ standard library header algorithm. See Using parallel algorithms for more information about the parallel algorithms.

Classes

Table 34 Classes of header hpx/algorithm.hpp

Class

C++ standard

hpx::experimental::reduction

N4808

hpx::experimental::induction

N4808

Functions

Table 35 hpx functions of header hpx/algorithm.hpp

hpx function

C++ standard

hpx::adjacent_find

std::adjacent_find

hpx::all_of

std::all_of

hpx::any_of

std::any_of

hpx::copy

std::copy

hpx::copy_if

std::copy_if

hpx::copy_n

std::copy_n

hpx::count

std::count

hpx::count_if

std::count_if

hpx::ends_with

std::ends_with

hpx::equal

std::equal

hpx::fill

std::fill

hpx::fill_n

std::fill_n

hpx::find

std::find

hpx::find_end

std::find_end

hpx::find_first_of

std::find_first_of

hpx::find_if

std::find_if

hpx::find_if_not

std::find_if_not

hpx::for_each

std::for_each

hpx::for_each_n

std::for_each_n

hpx::generate

std::generate

hpx::generate_n

std::generate_n

hpx::includes

std::includes

hpx::inplace_merge

std::inplace_merge

hpx::is_heap

std::is_heap

hpx::is_heap_until

std::is_heap_until

hpx::is_partitioned

std::is_partitioned

hpx::is_sorted

std::is_sorted

hpx::is_sorted_until

std::is_sorted_until

hpx::lexicographical_compare

std::lexicographical_compare

hpx::make_heap

std::make_heap

hpx::max_element

std::max_element

hpx::merge

std::merge

hpx::min_element

std::min_element

hpx::minmax_element

std::minmax_element

hpx::mismatch

std::mismatch

hpx::move

std::move

hpx::none_of

std::none_of

hpx::nth_element

std::nth_element

hpx::partial_sort

std::partial_sort

hpx::partial_sort_copy

std::partial_sort_copy

hpx::partition

std::partition

hpx::partition_copy

std::partition_copy

hpx::remove

std::remove

hpx::remove_copy

std::remove_copy

hpx::remove_copy_if

std::remove_copy_if

hpx::remove_if

std::remove_if

hpx::replace

std::replace

hpx::replace_copy

std::replace_copy

hpx::replace_copy_if

std::replace_copy_if

hpx::replace_if

std::replace_if

hpx::reverse

std::reverse

hpx::reverse_copy

std::reverse_copy

hpx::rotate

std::rotate

hpx::rotate_copy

std::rotate_copy

hpx::search

std::search

hpx::search_n

std::search_n

hpx::set_difference

std::set_difference

hpx::set_intersection

std::set_intersection

hpx::set_symmetric_difference

std::set_symmetric_difference

hpx::set_union

std::set_union

hpx::shift_left

std::shift_left

hpx::shift_right

std::shift_right

hpx::sort

std::sort

hpx::stable_partition

std::stable_partition

hpx::stable_sort

std::stable_sort

hpx::starts_with

std::starts_with

hpx::swap_ranges

std::swap_ranges

hpx::transform

std::transform

hpx::unique

std::unique

hpx::unique_copy

std::unique_copy

hpx::experimental::for_loop

N4808

hpx::experimental::for_loop_strided

N4808

hpx::experimental::for_loop_n

N4808

hpx::experimental::for_loop_n_strided

N4808

Table 36 hpx::ranges functions of header hpx/algorithm.hpp

hpx::ranges function

C++ standard

hpx::ranges::adjacent_find

std::adjacent_find

hpx::ranges::all_of

std::all_of

hpx::ranges::any_of

std::any_of

hpx::ranges::copy

std::copy

hpx::ranges::copy_if

std::copy_if

hpx::ranges::copy_n

std::copy_n

hpx::ranges::count

std::count

hpx::ranges::count_if

std::count_if

hpx::ranges::ends_with

std::ends_with

hpx::ranges::equal

std::equal

hpx::ranges::fill

std::fill

hpx::ranges::fill_n

std::fill_n

hpx::ranges::find

std::find

hpx::ranges::find_end

std::find_end

hpx::ranges::find_first_of

std::find_first_of

hpx::ranges::find_if

std::find_if

hpx::ranges::find_if_not

std::find_if_not

hpx::ranges::for_each

std::for_each

hpx::ranges::for_each_n

std::for_each_n

hpx::ranges::generate

std::generate

hpx::ranges::generate_n

std::generate_n

hpx::ranges::includes

std::includes

hpx::ranges::inplace_merge

std::inplace_merge

hpx::ranges::is_heap

std::is_heap

hpx::ranges::is_heap_until

std::is_heap_until

hpx::ranges::is_partitioned

std::is_partitioned

hpx::ranges::is_sorted

std::is_sorted

hpx::ranges::is_sorted_until

std::is_sorted_until

hpx::ranges::make_heap

std::make_heap

hpx::ranges::merge

std::merge

hpx::ranges::move

std::move

hpx::ranges::none_of

std::none_of

hpx::ranges::nth_element

std::nth_element

hpx::ranges::partial_sort

std::partial_sort

hpx::ranges::partial_sort_copy

std::partial_sort_copy

hpx::ranges::partition

std::partition

hpx::ranges::partition_copy

std::partition_copy

hpx::ranges::set_difference

std::set_difference

hpx::ranges::set_intersection

std::set_intersection

hpx::ranges::set_symmetric_difference

std::set_symmetric_difference

hpx::ranges::set_union

std::set_union

hpx::ranges::shift_left

P2440

hpx::ranges::shift_right

P2440

hpx::ranges::sort

std::sort

hpx::ranges::stable_partition

std::stable_partition

hpx::ranges::stable_sort

std::stable_sort

hpx::ranges::starts_with

std::starts_with

hpx::ranges::swap_ranges

std::swap_ranges

hpx::ranges::unique

std::unique

hpx::ranges::unique_copy

std::unique_copy

hpx::ranges::experimental::for_loop

N4808

hpx::ranges::experimental::for_loop_strided

N4808

hpx/any.hpp

The header hpx/any.hpp corresponds to the C++ standard library header any.

hpx::any is compatible with std::any.

Classes

Table 37 Classes of header hpx/any.hpp

Class

C++ standard

hpx::any

std::any

hpx::any_nonser

hpx::bad_any_cast

std::bad_any_cast

hpx::unique_any_nonser

Functions

Table 38 Functions of header hpx/any.hpp

Function

C++ standard

hpx::any_cast

std::any_cast

hpx::make_any

std::make_any

hpx::make_any_nonser

hpx::make_unique_any_nonser

hpx/assert.hpp

The header hpx/assert.hpp corresponds to the C++ standard library header cassert.

HPX_ASSERT is the HPX equivalent to assert in cassert. HPX_ASSERT can also be used in CUDA device code.

Macros

hpx/barrier.hpp

The header hpx/barrier.hpp corresponds to the C++ standard library header barrier and contains a distributed barrier implementation. This functionality is also exposed through the hpx::distributed namespace. The name in hpx::distributed should be preferred.

Classes

Table 39 Classes of header hpx/barrier.hpp

Class

C++ standard

hpx::barrier

std::barrier

hpx/channel.hpp

The header hpx/channel.hpp contains a local and a distributed channel implementation. This functionality is also exposed through the hpx::distributed namespace. The name in hpx::distributed should be preferred.

Classes

hpx/chrono.hpp

The header hpx/chrono.hpp corresponds to the C++ standard library header chrono. The following replacements and extensions are provided compared to chrono.

hpx/condition_variable.hpp

The header hpx/condition_variable.hpp corresponds to the C++ standard library header condition_variable.

Classes

Table 41 Classes of header hpx/condition_variable.hpp

Class

C++ standard

hpx::condition_variable

std::condition_variable

hpx::condition_variable_any

std::condition_variable_any

hpx::cv_status

std::cv_status

hpx/exception.hpp

The header hpx/exception.hpp corresponds to the C++ standard library header exception. hpx::exception extends std::exception and is the base class for all exceptions thrown in HPX. HPX_THROW_EXCEPTION can be used to throw HPX exceptions with file and line information attached to the exception.

Classes

Table 42 Classes of header hpx/exception.hpp

Class

C++ standard

hpx::exception

std::exception

hpx/execution.hpp

The header hpx/execution.hpp corresponds to the C++ standard library header execution. See High level parallel facilities, Using parallel algorithms and Executor parameters and executor parameter traits for more information about execution policies and executor parameters.

Note

These names are only available in the hpx::execution namespace, not in the top-level hpx namespace.

Constants

Table 43 Constants of header hpx/execution.hpp

Constant

C++ standard

hpx::execution::seq

std::execution_policy_tag

hpx::execution::par

std::execution_policy_tag

hpx::execution::par_unseq

std::execution_policy_tag

hpx::execution::task

Classes

Table 44 Classes of header hpx/execution.hpp

Class

C++ standard

hpx::execution::sequenced_policy

std::execution_policy_tag_t

hpx::execution::parallel_policy

std::execution_policy_tag_t

hpx::execution::parallel_unsequenced_policy

std::execution_policy_tag_t

hpx::execution::sequenced_task_policy

hpx::execution::parallel_task_policy

hpx::execution::auto_chunk_size

hpx::execution::dynamic_chunk_size

hpx::execution::guided_chunk_size

hpx::execution::persistent_auto_chunk_size

hpx::execution::static_chunk_size

hpx/functional.hpp

The header hpx/functional.hpp corresponds to the C++ standard library header functional. hpx::function is a more efficient and serializable replacement for std::function.

Constants

The following constants correspond to the C++ standard std::placeholders

Classes

Table 45 Classes of header hpx/functional.hpp

Class

C++ standard

hpx::function

std::function

hpx::function_ref

hpx::move_only_function

std::move_only_function

hpx::traits::is_bind_expression

std::is_bind_expression

hpx::traits::is_placeholder

std::is_placeholder

hpx::scoped_annotation

Functions

Table 46 Functions of header hpx/functional.hpp

Function

C++ standard

hpx::annotated_function

hpx::bind

std::bind

hpx::experimental::bind_back

hpx::bind_front

std::bind_front

hpx::invoke

std::invoke

hpx::util::invoke_fused

hpx::mem_fn

std::mem_fn

hpx/future.hpp

The header hpx/future.hpp corresponds to the C++ standard library header future. See Extended facilities for futures for more information about extensions to futures compared to the C++ standard library.

This header file also contains overloads of hpx::async, hpx::apply, hpx::sync, and hpx::dataflow that can be used with actions. See Action invocation for more information about invoking actions.

Classes

Table 47 Classes of header hpx/future.hpp

Class

C++ standard

hpx::future

std::future

hpx::shared_future

std::shared_future

hpx::promise

std::promise

hpx::launch

std::launch

hpx::packaged_task

std::packaged_task

Note

All names except hpx::promise are also available in the top-level hpx namespace. hpx::promise refers to hpx::distributed::promise, a distributed variant of hpx::promise, but will eventually refer to hpx::promise after a deprecation period.

Examples

#include <hpx/assert.hpp>
#include <hpx/future.hpp>
#include <hpx/hpx_main.hpp>
#include <hpx/tuple.hpp>

#include <iostream>
#include <utility>

int main()
{
    // Asynchronous execution with futures
    hpx::future<void> f1 = hpx::async(hpx::launch::async, []() {});
    hpx::shared_future<int> f2 =
        hpx::async(hpx::launch::async, []() { return 42; });
    hpx::future<int> f3 =
        f2.then([](hpx::shared_future<int>&& f) { return f.get() * 3; });

    hpx::promise<double> p;
    auto f4 = p.get_future();
    HPX_ASSERT(!f4.is_ready());
    p.set_value(123.45);
    HPX_ASSERT(f4.is_ready());

    hpx::packaged_task<int()> t([]() { return 43; });
    hpx::future<int> f5 = t.get_future();
    HPX_ASSERT(!f5.is_ready());
    t();
    HPX_ASSERT(f5.is_ready());

    // Fire-and-forget
    hpx::apply([]() {
        std::cout << "This will be printed later\n" << std::flush;
    });

    // Synchronous execution
    hpx::sync([]() {
        std::cout << "This will be printed immediately\n" << std::flush;
    });

    // Combinators
    hpx::future<double> f6 = hpx::async([]() { return 3.14; });
    hpx::future<double> f7 = hpx::async([]() { return 42.0; });
    std::cout
        << hpx::when_all(f6, f7)
               .then([](hpx::future<
                         hpx::tuple<hpx::future<double>, hpx::future<double>>>
                             f) {
                   hpx::tuple<hpx::future<double>, hpx::future<double>> t =
                       f.get();
                   double pi = hpx::get<0>(t).get();
                   double r = hpx::get<1>(t).get();
                   return pi * r * r;
               })
               .get()
        << std::endl;

    // Easier continuations with dataflow; it waits for all future or
    // shared_future arguments before executing the continuation, and also
    // accepts non-future arguments
    hpx::future<double> f8 = hpx::async([]() { return 3.14; });
    hpx::future<double> f9 = hpx::make_ready_future(42.0);
    hpx::shared_future<double> f10 = hpx::async([]() { return 123.45; });
    hpx::future<hpx::tuple<double, double>> f11 = hpx::dataflow(
        [](hpx::future<double> a, hpx::future<double> b,
            hpx::shared_future<double> c, double d) {
            return hpx::make_tuple<>(a.get() + b.get(), c.get() / d);
        },
        f8, f9, f10, -3.9);

    // split_future gives a tuple of futures from a future of tuple
    hpx::tuple<hpx::future<double>, hpx::future<double>> f12 =
        hpx::split_future(std::move(f11));
    std::cout << hpx::get<1>(f12).get() << std::endl;

    return 0;
}

hpx/init.hpp

The header hpx/init.hpp contains functionality for starting, stopping, suspending, and resuming the HPX runtime. This is the main way to explicitly start the HPX runtime. See Starting the HPX runtime for more details on starting the HPX runtime.

Classes

Functions

hpx/latch.hpp

The header hpx/latch.hpp corresponds to the C++ standard library header latch. It contains a local and a distributed latch implementation. This functionality is also exposed through the hpx::distributed namespace. The name in hpx::distributed should be preferred.

Classes

Table 49 Classes of header hpx/latch.hpp

Class

C++ standard

hpx::latch

std::latch

hpx/mutex.hpp

The header hpx/mutex.hpp corresponds to the C++ standard library header mutex.

Functions

Table 51 Functions of header hpx/mutex.hpp

Function

C++ standard

hpx::call_once

std::call_once

hpx/memory.hpp

The header hpx/memory.hpp corresponds to the C++ standard library header memory. It contains parallel versions of the copy, fill, move, and construct helper functions in memory. See Using parallel algorithms for more information about the parallel algorithms.

hpx/numeric.hpp

The header hpx/numeric.hpp corresponds to the C++ standard library header numeric. See Using parallel algorithms for more information about the parallel algorithms.

Functions

Table 54 hpx functions of header hpx/numeric.hpp

hpx function

C++ standard

hpx::adjacent_difference

std::adjacent_difference

hpx::exclusive_scan

std::exclusive_scan

hpx::inclusive_scan

std::inclusive_scan

hpx::reduce

std::reduce

hpx::transform_exclusive_scan

std::transform_exclusive_scan

hpx::transform_inclusive_scan

std::transform_inclusive_scan

hpx::transform_reduce

std::transform_reduce

hpx/optional.hpp

The header hpx/optional.hpp corresponds to the C++ standard library header optional. hpx::optional is compatible with std::optional.

Constants

  • hpx::nullopt

Classes

Table 55 Classes of header hpx/optional.hpp

Class

C++ standard

hpx::optional

std::optional

hpx::nullopt_t

std::nullopt_t

hpx::bad_optional_access

std::bad_optional_access

hpx/runtime.hpp

The header hpx/runtime.hpp contains functions for accessing local and distributed runtime information.

Typedefs

Functions

hpx/source_location.hpp

The header hpx/source_location.hpp corresponds to the C++ standard library header source_location.

Classes

Table 56 Classes of header hpx/system_error.hpp

Class

C++ standard

hpx::source_location

std::source_location

hpx/system_error.hpp

The header hpx/system_error.hpp corresponds to the C++ standard library header system_error.

Classes

Table 57 Classes of header hpx/system_error.hpp

Class

C++ standard

hpx::error_code

std::error_code

hpx/task_block.hpp

The header hpx/task_block.hpp corresponds to the task_block feature in N4411. See Using task blocks for more details on using task blocks.

Classes

Functions

hpx/thread.hpp

The header hpx/thread.hpp corresponds to the C++ standard library header thread. The functionality in this header is equivalent to the standard library thread functionality, with the exception that the HPX equivalents are implemented on top of lightweight threads and the HPX runtime.

Classes

Table 58 Classes of header hpx/thread.hpp

Class

C++ standard

hpx::thread

std::thread

hpx::jthread

std::jthread

Functions

hpx/semaphore.hpp

The header hpx/semaphore.hpp corresponds to the C++ standard library header semaphore.

Classes

Table 59 Classes of header hpx/semaphore.hpp

Class

C++ standard

hpx::binary_semaphore

std::counting_semaphore

hpx::counting_semaphore

std::counting_semaphore

hpx/shared_mutex.hpp

The header hpx/shared_mutex.hpp corresponds to the C++ standard library header shared_mutex.

Classes

Table 60 Classes of header hpx/shared_mutex.hpp

Class

C++ standard

hpx::shared_mutex

std::shared_mutex

hpx/stop_token.hpp

The header hpx/stop_token.hpp corresponds to the C++ standard library header stop_token.

Constants

Table 61 Constants of header hpx/stop_token.hpp

Constant

C++ standard

hpx::nostopstate

std::nostopstate

hpx/tuple.hpp

The header hpx/tuple.hpp corresponds to the C++ standard library header tuple. hpx::tuple can be used in CUDA device code, unlike std::tuple.

Constants

Table 63 Constants of header hpx/tuple.hpp

Constant

C++ standard

hpx::ignore

std::ignore

Classes

Table 64 Classes of header hpx/tuple.hpp

Class

C++ standard

hpx::tuple

std::tuple

hpx::tuple_size

std::tuple_size

hpx::tuple_element

std::tuple_element

Functions

Table 65 Functions of header hpx/tuple.hpp

Function

C++ standard

hpx::make_tuple

std::tuple_element

hpx::tie

std::tie

hpx::forward_as_tuple

std::forward_as_tuple

hpx::tuple_cat

std::tuple_cat

hpx::get

std::get

hpx/type_traits.hpp

The header hpx/type_traits.hpp corresponds to the C++ standard library header type_traits.

Classes

Table 66 Classes of header hpx/type_traits.hpp

Class

C++ standard

hpx::is_invocable

std::is_invocable

hpx::is_invocable_r

std::is_invocable

hpx/unwrap.hpp

The header hpx/unwrap.hpp contains utilities for unwrapping futures.

Classes

Functions

hpx/version.hpp

The header hpx/version.hpp provides version information about HPX.

Macros

Functions

hpx/wrap_main.hpp

The header hpx/wrap_main.hpp does not provide any direct functionality but is used for implicitly using main as the runtime entry point. See Re-use the main() function as the main HPX entry point for more details on implicitly starting the HPX runtime.