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.
Functions¶
hpx function |
C++ standard |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
hpx::ranges function |
C++ standard |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
hpx/any.hpp
¶
The header hpx/any.hpp corresponds to the C++ standard library header any.
hpx::any
is compatible with std::any
.
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.
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.
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.
Macros¶
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¶
Constant |
C++ standard |
---|---|
|
|
|
|
|
|
|
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¶
Class |
C++ standard |
---|---|
|
|
|
|
|
|
|
|
|
|
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¶
Class |
C++ standard |
---|---|
|
|
|
|
|
|
|
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.
hpx/mutex.hpp
¶
The header hpx/mutex.hpp corresponds to the C++ standard library header mutex.
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.
Functions¶
hpx function |
C++ standard |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
hpx::ranges function |
C++ standard |
---|---|
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.
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
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.
hpx/system_error.hpp
¶
The header hpx/system_error.hpp corresponds to the C++ standard library header system_error.
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.
Functions¶
hpx/semaphore.hpp
¶
The header hpx/semaphore.hpp corresponds to the C++ standard library header semaphore.
hpx/stop_token.hpp
¶
The header hpx/stop_token.hpp corresponds to the C++ standard library header stop_token.
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
.
hpx/type_traits.hpp
¶
The header hpx/type_traits.hpp corresponds to the C++ standard library header type_traits.
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.