Public API

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.

Header hpx/algorithm.hpp

Corresponds to the C++ standard library header algorithm. See Using parallel algorithms for more information about the parallel algorithms.

Functions

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.

Header hpx/barrier.hpp

This header includes Header hpx/local/barrier.hpp and Header hpx/distributed/barrier.hpp.

Header hpx/local/barrier.hpp

Corresponds to the C++ standard library header barrier.

Classes

  • hpx::lcos::local::cpp20_barrier

Header hpx/distributed/barrier.hpp

Contains a distributed barrier implementation. This functionality is also exposed through the hpx::distributed namespace. The name in hpx::distributed should be preferred.

Header hpx/channel.hpp

This header includes Header hpx/local/channel.hpp and Header hpx/distributed/channel.hpp.

Header hpx/local/channel.hpp

Contains a local channel implementation.

Classes

  • hpx::lcos::local::channel

Header hpx/distributed/channel.hpp

Contains a distributed channel implementation. This functionality is also exposed through the hpx::distributed namespace. The name in hpx::distributed should be preferred.

Classes

  • hpx::lcos::channel

Header hpx/chrono.hpp

Corresponds to the C++ standard library header chrono. The following replacements and extensions are provided compared to chrono. The classes below are also available in the hpx::chrono namespace, not in the top-level hpx namespace.

Header hpx/condition_variable.hpp

Corresponds to the C++ standard library header condition_variable.

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.

Header hpx/functional.hpp

Corresponds to the C++ standard library header functional. hpx::util::function is a more efficient and serializable replacement for std::function.

Constants

The following constants are also available in hpx::placeholders, not the top-level hpx namespace.

Classes

Header hpx/future.hpp

This header includes Header hpx/local/future.hpp and Header hpx/distributed/future.hpp.

Header hpx/local/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.

Note

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

Classes

  • hpx::lcos::future

  • hpx::lcos::shared_future

  • hpx::lcos::local::promise

  • hpx::launch

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::lcos::local::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;
}

Header hpx/distributed/future.hpp

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.

Note

The alias from hpx::promise to hpx::lcos::promise is deprecated and will be removed in a future release. The alias hpx::distributed::promise should be used in new applications.

Classes

  • hpx::lcos::promise

Header hpx/init.hpp

This header 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.

Header hpx/latch.hpp

This header includes Header hpx/local/latch.hpp and Header hpx/distributed/latch.hpp.

Header hpx/local/latch.hpp

Corresponds to the C++ standard library header latch.

Header hpx/distributed/latch.hpp

Contains a distributed latch implementation. This functionality is also exposed through the hpx::distributed namespace. The name in hpx::distributed should be preferred.

Header hpx/optional.hpp

Corresponds to the C++ standard library header optional. hpx::util::optional is compatible with std::optional.

Header hpx/runtime.hpp

This header includes Header hpx/local/runtime.hpp and Header hpx/distributed/runtime.hpp.

Header hpx/distributed/runtime.hpp

This header contains functions for accessing distributed runtime information.

Header hpx/system_error.hpp

Corresponds to the C++ standard library header system_error.

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

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.

Header hpx/semaphore.hpp

Corresponds to the C++ standard library header semaphore.

Classes

  • hpx::lcos::local::cpp20_binary_semaphore

  • hpx::lcos::local::cpp20_counting_semaphore

Header hpx/shared_mutex.hpp

Corresponds to the C++ standard library header shared_mutex.

Header hpx/stop_token.hpp

Corresponds to the C++ standard library header stop_token.

Constants

  • hpx::nostopstate

Header hpx/tuple.hpp

Corresponds to the C++ standard library header tuple. hpx::util::tuple can be used in CUDA device code, unlike std::tuple.

Classes

Header hpx/type_traits.hpp

Corresponds to the C++ standard library header type_traits. Provides hpx::util::invoke_result as a replacement for std::invoke_result.

Classes

  • hpx::util::invoke_result

Header hpx/version.hpp

This header provides version information about HPX.

Macros

  • HPX_VERSION_MAJOR

  • HPX_VERSION_MINOR

  • HPX_VERSION_SUBMINOR

  • HPX_VERSION_FULL

  • HPX_VERSION_DATE

  • HPX_VERSION_TAG

  • HPX_AGAS_VERSION

Header hpx/wrap_main.hpp

This header 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.