-
Notifications
You must be signed in to change notification settings - Fork 0
Library HPX
Source:
docs/libraries/hpx.mdin the main repository.
What it is: C++ runtime for fine-grained parallelism (and optionally distributed computing).
Install: Not on Homebrew — local prefix via make install-hpx → ~/cpp-deps/hpx
Enable: make hpx or -DLIB_SMOKE_WITH_HPX=ON
Smoke: tests/test_hpx.cpp, main smoke section “HPX”
| Use HPX when… | Prefer something else when… |
|---|---|
| You want parallel algorithms with a rich runtime | Simple loop parallel → TBB |
| You need millions of lightweight tasks | Explicit DAG of a few stages → Taskflow |
| You may scale to multi-node later | Pure networking → Asio |
| You like future-based composition | Standard-bound async → stdexec |
HPX is a runtime, not a utility grab-bag (that’s Folly).
There is no hpx formula in homebrew-core. HPX is large, version-sensitive (Asio APIs), and often built with custom options (networking on/off, allocators, MPI).
This project’s install script builds local-only HPX:
HPX_WITH_NETWORKING=OFFHPX_WITH_DISTRIBUTED_RUNTIME=OFF- Fetched Asio (avoids clash with Homebrew Asio 1.36)
- Install prefix:
~/cpp-deps/hpx
make install-hpx # once (several minutes)
make hpx # configure + build + test + smoke
# full stack:
make fullHPX programs typically use hpx/hpx_main.hpp so main runs inside the runtime
(this project’s tests do that).
#include <hpx/hpx_main.hpp>
#include <hpx/future.hpp>
#include <iostream>
int main() {
auto f = hpx::make_ready_future(7);
std::cout << f.get() << "\n";
return 0;
}#include <hpx/hpx_main.hpp>
#include <hpx/future.hpp>
int main() {
auto f = hpx::make_ready_future(3).then([](hpx::future<int> r) {
return r.get() + 4;
});
return f.get() == 7 ? 0 : 1;
}#include <hpx/hpx_main.hpp>
#include <hpx/algorithm.hpp>
#include <hpx/execution.hpp>
#include <numeric>
#include <vector>
int main() {
std::vector<int> v(1000);
std::iota(v.begin(), v.end(), 1);
auto sum = hpx::reduce(hpx::execution::par, v.begin(), v.end(), 0);
// sum == 1000*1001/2
return 0;
}#include <hpx/hpx_main.hpp>
#include <hpx/algorithm.hpp>
#include <hpx/execution.hpp>
#include <vector>
int main() {
std::vector<int> v(64, 1);
hpx::for_each(hpx::execution::par, v.begin(), v.end(),
[](int& x) { x *= 2; });
return 0;
}| Policy | Meaning |
|---|---|
hpx::execution::seq |
Sequential |
hpx::execution::par |
Parallel |
hpx::execution::par_unseq |
Parallel + vectorisation-friendly (where supported) |
Asio → I/O, sockets, timers
Taskflow → Explicit multi-stage DAGs (pipelines)
TBB → Shared-memory parallel algorithms (lighter dependency)
HPX → Parallel runtime (+ future distributed story)
stdexec → Standard-oriented async composition
Folly Future → Service-oriented async utilities
Rule of thumb:
- Feed ingestion / HTTP → Asio/Beast
- Pipeline stages → Taskflow
- Data-parallel hot loops → TBB or HPX
- Don’t run heavy HPX work on Asio io_context threads
find_package(HPX CONFIG REQUIRED)
target_link_libraries(my_app PRIVATE HPX::hpx)
hpx_setup_target(my_app) # entry-point / wrap as neededThis project:
LIB_SMOKE_WITH_HPX-
LIB_SMOKE_HPX_ROOT(default$HOME/cpp-deps/hpx) - Targets:
lib_smoke,test_hpxcallhpx_setup_target
make deps-check # shows whether HPX is installed
make install-hpx
make hpx
./build_hpx/test_hpx
cd build_hpx && ctest -R hpx --output-on-failure- Building HPX 1.11.0 against Homebrew Asio 1.36 — resolver API break; use master + fetch Asio (script does this).
-
Forgetting
hpx_setup_target/hpx_main— runtime may not start correctly. - Expecting networking — this install is local-only by design.
- Mixing HPX’s installed Asio headers with standalone Homebrew Asio carelessly — CMake prefers Homebrew for smoke Asio includes.
- HPX docs
- STEllAR-GROUP/hpx
- Project:
tests/test_hpx.cpp,scripts/install_hpx.sh
Wiki mirror of repository docs. Edit docs/ in the main repo, then python3 scripts/publish_wiki.py.