Skip to content

Commit 12b08ec

Browse files
committed
adding hpx support to master branch of pnnl
1 parent 25fee7b commit 12b08ec

File tree

22 files changed

+1786
-26
lines changed

22 files changed

+1786
-26
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ option(SHAD_ENABLE_PERFORMANCE_TEST "Enable the compilation of the Performance T
7878

7979
set(
8080
SHAD_RUNTIME_SYSTEM "CPP_SIMPLE" CACHE STRING
81-
"(Default) Runtime system to be used as backend of the Abstract Runtime API (Default=CPP_SIMPLE, Supported=CPP_SIMPLE | TBB | GMT)")
81+
"(Default) Runtime system to be used as backend of the Abstract Runtime API (Default=CPP_SIMPLE, Supported=CPP_SIMPLE | TBB | GMT | HPX)")
8282

8383

8484
include(config)

cmake/config.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ elseif (SHAD_RUNTIME_SYSTEM STREQUAL "GMT")
9898
include_directories(${GMT_INCLUDE_DIR})
9999
set(HAVE_GMT 1)
100100
set(SHAD_RUNTIME_LIB ${GMT_LIBRARIES})
101+
elseif (SHAD_RUNTIME_SYSTEM STREQUAL "HPX")
102+
message(STATUS "Using HPX as backend of the Abstract Runtime API.")
103+
find_package(HPX REQUIRED)
104+
include_directories(${HPX_INCLUDE_DIR})
105+
set(HAVE_HPX 1)
106+
set(SHAD_RUNTIME_LIB HPX::hpx)
101107
else()
102108
message(FATAL_ERROR "${SHAD_RUNTIME_SYSTEM} is not a supported runtime system.")
103109
endif()

examples/pi/pi.cc

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,30 @@ int main(int argc, char *argv[]) {
3939
const size_t numberOfPoints = 1e10;
4040
const size_t numberOfPointsPerSim = numberOfPoints / counters.size();
4141

42-
shad::generate(
43-
shad::distributed_parallel_tag{},
44-
counters.begin(), counters.end(),
45-
[=]() -> uint64_t {
46-
size_t counter = 0;
42+
auto generator = [=]() -> uint64_t {
43+
size_t counter = 0;
4744

48-
std::random_device rd;
49-
std::default_random_engine G(rd());
50-
std::uniform_real_distribution<double> dist(0.0, 1.0);
45+
std::random_device rd;
46+
std::default_random_engine G(rd());
47+
std::uniform_real_distribution<double> dist(0.0, 1.0);
5148

52-
for (size_t i = 0; i < numberOfPointsPerSim; ++i) {
53-
double x = dist(G);
54-
double y = dist(G);
55-
if ((x * x + y * y) < 1) {
56-
++counter;
57-
}
58-
}
59-
return counter;
60-
});
49+
for (size_t i = 0; i < numberOfPointsPerSim; ++i) {
50+
double x = dist(G);
51+
double y = dist(G);
52+
if ((x * x + y * y) < 1) {
53+
++counter;
54+
}
55+
}
56+
return counter;
57+
};
58+
59+
#ifdef HAVE_HPX
60+
shad::generate(shad::distributed_parallel_tag{}, counters.begin(),
61+
counters.end(), shad::rt::lambda_wrapper(generator));
62+
#else
63+
shad::generate(shad::distributed_parallel_tag{}, counters.begin(),
64+
counters.end(), generator);
65+
#endif
6166

6267
uint64_t count = shad::reduce(
6368
shad::distributed_parallel_tag{}, counters.begin(), counters.end());

include/shad/core/impl/impl_patterns.h

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,21 @@ S distributed_folding_map(ForwardIt first, ForwardIt last, MapF&& map_kernel,
9292
using itr_traits = distributed_iterator_traits<ForwardIt>;
9393
auto localities = itr_traits::localities(first, last);
9494
auto res = init_sol;
95+
#ifdef HAVE_HPX
96+
for (auto locality = localities.begin(), end = localities.end();
97+
locality != end; ++locality) {
98+
auto d_args = std::make_tuple(shad::rt::lambda_wrapper<std::decay_t<MapF>>(
99+
std::forward<MapF>(map_kernel)),
100+
first, last, res, args...);
101+
rt::executeAtWithRet(
102+
locality,
103+
[](const typeof(d_args)& d_args, S* result) {
104+
*result = apply_from<1>(::std::get<0>(d_args),
105+
::std::forward<typeof(d_args)>(d_args));
106+
},
107+
d_args, &res);
108+
}
109+
#else
95110
for (auto locality = localities.begin(), end = localities.end();
96111
locality != end; ++locality) {
97112
auto d_args = std::make_tuple(map_kernel, first, last, res, args...);
@@ -103,6 +118,7 @@ S distributed_folding_map(ForwardIt first, ForwardIt last, MapF&& map_kernel,
103118
},
104119
d_args, &res);
105120
}
121+
#endif
106122
return res;
107123
}
108124

@@ -112,6 +128,21 @@ void distributed_folding_map_void(ForwardIt first, ForwardIt last,
112128
MapF&& map_kernel, Args&&... args) {
113129
using itr_traits = distributed_iterator_traits<ForwardIt>;
114130
auto localities = itr_traits::localities(first, last);
131+
#ifdef HAVE_HPX
132+
for (auto locality = localities.begin(), end = localities.end();
133+
locality != end; ++locality) {
134+
auto d_args = std::make_tuple(shad::rt::lambda_wrapper<std::decay_t<MapF>>(
135+
std::forward<MapF>(map_kernel)),
136+
first, last, args...);
137+
rt::executeAt(
138+
locality,
139+
[](const typeof(d_args)& d_args) {
140+
apply_from<1>(::std::get<0>(d_args),
141+
::std::forward<typeof(d_args)>(d_args));
142+
},
143+
d_args);
144+
}
145+
#else
115146
for (auto locality = localities.begin(), end = localities.end();
116147
locality != end; ++locality) {
117148
auto d_args = std::make_tuple(map_kernel, first, last, args...);
@@ -123,6 +154,7 @@ void distributed_folding_map_void(ForwardIt first, ForwardIt last,
123154
},
124155
d_args);
125156
}
157+
#endif
126158
}
127159

128160
// distributed_folding_map variant testing for early termination
@@ -134,6 +166,22 @@ S distributed_folding_map_early_termination(ForwardIt first, ForwardIt last,
134166
using itr_traits = distributed_iterator_traits<ForwardIt>;
135167
auto localities = itr_traits::localities(first, last);
136168
auto res = init_sol;
169+
#ifdef HAVE_HPX
170+
for (auto locality = localities.begin(), end = localities.end();
171+
locality != end; ++locality) {
172+
auto d_args = std::make_tuple(shad::rt::lambda_wrapper<std::decay_t<MapF>>(
173+
std::forward<MapF>(map_kernel)),
174+
first, last, res, args...);
175+
rt::executeAtWithRet(
176+
locality,
177+
[](const typeof(d_args)& d_args, S* result) {
178+
*result = apply_from<1>(::std::get<0>(d_args),
179+
::std::forward<typeof(d_args)>(d_args));
180+
},
181+
d_args, &res);
182+
if (halt(res)) return res;
183+
}
184+
#else
137185
for (auto locality = localities.begin(), end = localities.end();
138186
locality != end; ++locality) {
139187
auto d_args = std::make_tuple(map_kernel, first, last, res, args...);
@@ -146,6 +194,8 @@ S distributed_folding_map_early_termination(ForwardIt first, ForwardIt last,
146194
d_args, &res);
147195
if (halt(res)) return res;
148196
}
197+
#endif
198+
149199
return res;
150200
}
151201

@@ -205,7 +255,13 @@ distributed_map_init(
205255
auto localities = itr_traits::localities(first, last);
206256
size_t i = 0;
207257
rt::Handle h;
258+
#ifdef HAVE_HPX
259+
auto d_args = std::make_tuple(shad::rt::lambda_wrapper<std::decay_t<MapF>>(
260+
std::forward<MapF>(map_kernel)),
261+
first, last, args...);
262+
#else
208263
auto d_args = std::make_tuple(map_kernel, first, last, args...);
264+
#endif
209265
optional_vector<mapped_t> opt_res(localities.size(), init);
210266
for (auto locality = localities.begin(), end = localities.end();
211267
locality != end; ++locality, ++i) {
@@ -255,7 +311,13 @@ void distributed_map_void(ForwardIt first, ForwardIt last, MapF&& map_kernel,
255311
auto localities = itr_traits::localities(first, last);
256312
size_t i = 0;
257313
rt::Handle h;
314+
#ifdef HAVE_HPX
315+
auto d_args = std::make_tuple(shad::rt::lambda_wrapper<std::decay_t<MapF>>(
316+
std::forward<MapF>(map_kernel)),
317+
first, last, args...);
318+
#else
258319
auto d_args = std::make_tuple(map_kernel, first, last, args...);
320+
#endif
259321
for (auto locality = localities.begin(), end = localities.end();
260322
locality != end; ++locality, ++i) {
261323
rt::asyncExecuteAt(
@@ -301,7 +363,15 @@ local_map_init(
301363
std::vector<mapped_t> map_res(parts.size(), init);
302364

303365
if (parts.size()) {
366+
#ifdef HAVE_HPX
367+
auto map_args =
368+
std::make_tuple(parts.data(),
369+
shad::rt::lambda_wrapper<std::decay_t<MapF>>(
370+
std::forward<MapF>(map_kernel)),
371+
map_res.data());
372+
#else
304373
auto map_args = std::make_tuple(parts.data(), map_kernel, map_res.data());
374+
#endif
305375
shad::rt::forEachAt(
306376
rt::thisLocality(),
307377
[](const typeof(map_args)& map_args, size_t iter) {
@@ -339,7 +409,13 @@ void local_map_void(ForwardIt first, ForwardIt last, MapF&& map_kernel) {
339409
first, last, rt::impl::getConcurrency());
340410

341411
if (parts.size()) {
412+
#ifdef HAVE_HPX
413+
auto map_args = std::make_tuple(
414+
parts.data(), shad::rt::lambda_wrapper<std::decay_t<MapF>>(
415+
std::forward<MapF>(map_kernel)));
416+
#else
342417
auto map_args = std::make_tuple(parts.data(), map_kernel);
418+
#endif
343419
shad::rt::forEachAt(
344420
rt::thisLocality(),
345421
[](const typeof(map_args)& map_args, size_t iter) {
@@ -361,7 +437,15 @@ void local_map_void_offset(ForwardIt first, ForwardIt last, MapF&& map_kernel) {
361437
first, last, rt::impl::getConcurrency());
362438

363439
if (parts.size()) {
440+
#ifdef HAVE_HPX
441+
auto map_args =
442+
std::make_tuple(parts.data(),
443+
shad::rt::lambda_wrapper<std::decay_t<MapF>>(
444+
std::forward<MapF>(map_kernel)),
445+
first);
446+
#else
364447
auto map_args = std::make_tuple(parts.data(), map_kernel, first);
448+
#endif
365449
shad::rt::forEachAt(
366450
rt::thisLocality(),
367451
[](const typeof(map_args)& map_args, size_t iter) {

include/shad/core/iterator.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
#include <memory>
3030

3131
#include "shad/runtime/runtime.h"
32+
#ifdef HAVE_HPX
33+
#include "hpx/serialization.hpp"
34+
#endif
3235

3336
namespace shad {
3437

@@ -59,6 +62,9 @@ class insert_iterator
5962
insert_iterator(Container& container, Iterator iterator)
6063
: global_id_(container.global_id()), iterator_(iterator) {}
6164

65+
#ifdef HAVE_HPX
66+
insert_iterator() = default;
67+
#endif
6268
/// @brief The assignment operator.
6369
///
6470
/// The assignment operator inserts a value (through buffering) and advance
@@ -114,6 +120,10 @@ class buffered_insert_iterator : public insert_iterator<Container> {
114120
buffered_insert_iterator(Container& container, Iterator iterator)
115121
: base_t(container, iterator) {}
116122

123+
#ifdef HAVE_HPX
124+
buffered_insert_iterator() = default;
125+
#endif
126+
117127
/// @brief The assignment operator.
118128
///
119129
/// The assignment operator inserts a value (through buffering) and advance
@@ -152,6 +162,17 @@ class buffered_insert_iterator : public insert_iterator<Container> {
152162
buffered_insert_iterator& operator++() { return *this; }
153163
buffered_insert_iterator& operator++(int) { return *this; }
154164

165+
#ifdef HAVE_HPX
166+
private:
167+
friend class hpx::serialization::access;
168+
169+
template <typename Archive>
170+
void serialize(Archive& ar, unsigned)
171+
{
172+
ar & handle_;
173+
}
174+
#endif
175+
155176
private:
156177
rt::Handle handle_;
157178
};

include/shad/data_structures/object_identifier.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ class ObjectIdentifier {
5656
static constexpr uint8_t kIdentifierBitsize = 48u;
5757

5858
/// @brief Constructor.
59+
#ifdef HAVE_HPX
60+
explicit constexpr ObjectIdentifier(uint64_t id = 0) : id_(id) {}
61+
#else
5962
explicit constexpr ObjectIdentifier(uint64_t id) : id_(id) {}
63+
#endif
6064

6165
/// @brief Constructor.
6266
/// @param[in] locality The locality identifier part.

include/shad/extensions/graph_library/edge_index.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,9 @@ class EdgeIndex
380380

381381
using LocalEdgeListChunk = typename StorageT::LocalEdgeListChunk;
382382
struct EdgeListChunk {
383+
#ifdef HAVE_HPX
384+
EdgeListChunk() = default;
385+
#endif
383386
EdgeListChunk(ObjectID &_oid, SrcT _src, LocalEdgeListChunk &_chunk)
384387
: oid(_oid), src(_src), chunk(_chunk) {}
385388
typename EdgeIndex<SrcT, DestT, StorageT>::ObjectID oid;

include/shad/extensions/graph_library/local_edge_index.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ class DefaultEdgeIndexStorage {
5151
public:
5252
struct EmptyAttr {};
5353
using SrcAttributesT = EmptyAttr;
54+
#ifdef HAVE_HPX
55+
DefaultEdgeIndexStorage() = default;
56+
#endif
5457
explicit DefaultEdgeIndexStorage(const size_t numVertices)
5558
: edgeList_(std::max(numVertices / constants::kDefaultNumEntriesPerBucket,
5659
1lu)) {}
@@ -59,6 +62,9 @@ class DefaultEdgeIndexStorage {
5962
1lu)) {}
6063
static constexpr size_t kEdgeListChunkSize_ = 3072 / sizeof(DestT);
6164
struct LocalEdgeListChunk {
65+
#ifdef HAVE_HPX
66+
LocalEdgeListChunk() = default;
67+
#endif
6268
LocalEdgeListChunk(size_t _numDest, bool _ow, DestT* _dest)
6369
: numDest(_numDest), overwrite(_ow) {
6470
memcpy(destinations.data(), _dest,

include/shad/runtime/handle.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "shad/runtime/mapping_traits.h"
3232
#include "shad/runtime/mappings/available_traits_mappings.h"
3333

34+
3435
namespace shad {
3536

3637
namespace rt {
@@ -87,8 +88,24 @@ class Handle {
8788
/// @brief Null Test.
8889
/// @return true if the Handle is null, false otherwise.
8990
bool IsNull() const {
91+
#ifdef HAVE_HPX
92+
return impl::HandleTrait<TargetSystemTag>::Equal(
93+
id_, impl::HandleTrait<TargetSystemTag>::NullValue());
94+
#else
9095
return id_ == impl::HandleTrait<TargetSystemTag>::NullValue();
96+
#endif
97+
}
98+
99+
#ifdef HAVE_HPX
100+
private:
101+
friend class hpx::serialization::access;
102+
103+
template <typename Archive>
104+
void serialize(Archive& ar, unsigned)
105+
{
106+
ar & id_;
91107
}
108+
#endif
92109

93110
private:
94111
friend void waitForCompletion(Handle &handle);

include/shad/runtime/mappings/available_mappings.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
#elif defined HAVE_GMT
3535
#include "shad/runtime/mappings/gmt/gmt_asynchronous_interface.h"
3636
#include "shad/runtime/mappings/gmt/gmt_synchronous_interface.h"
37+
#elif defined HAVE_HPX
38+
#include "shad/runtime/mappings/hpx/hpx_asynchronous_interface.h"
39+
#include "shad/runtime/mappings/hpx/hpx_synchronous_interface.h"
3740
#else
3841
#error Unsupported Runtime System
3942
#endif

0 commit comments

Comments
 (0)