-
-
Notifications
You must be signed in to change notification settings - Fork 450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implemented segmented algorithms for partitioned vector #2725
Changes from 44 commits
80fc2a4
ba65be9
49b92cc
2f08111
ced4b85
183c99c
289f19a
29985e0
3bf5560
7d25ce9
20d0e95
412b047
2ba4c23
c0e46ce
de95410
b296c2e
6a199f5
7402061
87b0ac5
7d05f47
6dc4b74
3050b25
ecc31e2
0551850
cf194a4
66d4f53
3a38cbc
de1a5d7
58efd17
6262c28
c26956b
922359d
a83d652
878dd51
f78abad
e34fc2d
a73f70c
079c201
1da3b95
566a3b1
10df23f
e1a9128
0547a23
a513cde
db2111d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,3 @@ | |
#include <hpx/parallel/segmented_algorithms/for_each.hpp> | ||
|
||
#endif | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,5 @@ | |
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no need to modify the include guards on every edit. |
||
#include <hpx/parallel/algorithms/transform.hpp> | ||
#include <hpx/parallel/container_algorithms/transform.hpp> | ||
|
||
#include <hpx/parallel/segmented_algorithms/transform.hpp> | ||
#endif | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
#include <hpx/parallel/executors/execution.hpp> | ||
#include <hpx/parallel/util/detail/algorithm_result.hpp> | ||
#include <hpx/parallel/util/detail/scoped_executor_parameters.hpp> | ||
#include <hpx/util/tuple.hpp> | ||
|
||
#include <string> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please keep an empty line between the HPX headers and the std headers. This prevents clang-format from sorting those two groups of headers files into one block. |
||
#include <type_traits> | ||
|
@@ -50,6 +51,22 @@ namespace hpx { namespace parallel { inline namespace v1 { namespace detail | |
typedef std::pair<type1, type2> type; | ||
}; | ||
|
||
template <typename Result1, typename Result2, typename Result3> | ||
struct local_algorithm_result<hpx::util::tuple<Result1, Result2, Result3> > | ||
{ | ||
typedef typename hpx::traits::segmented_local_iterator_traits< | ||
Result1 | ||
>::local_raw_iterator type1; | ||
typedef typename hpx::traits::segmented_local_iterator_traits< | ||
Result2 | ||
>::local_raw_iterator type2; | ||
typedef typename hpx::traits::segmented_local_iterator_traits< | ||
Result3 | ||
>::local_raw_iterator type3; | ||
|
||
typedef hpx::util::tuple<type1, type2, type3> type; | ||
}; | ||
|
||
template <> | ||
struct local_algorithm_result<void> | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
#include <hpx/parallel/util/detail/algorithm_result.hpp> | ||
#include <hpx/parallel/util/loop.hpp> | ||
#include <hpx/parallel/util/partitioner.hpp> | ||
#include <hpx/parallel/util/projection_identity.hpp> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please try to keep the headers sorted alphabetically (inside each of the blocks). Clang-format will do that for you. |
||
#include <hpx/parallel/util/scan_partitioner.hpp> | ||
#include <hpx/util/unused.hpp> | ||
|
||
|
@@ -42,28 +43,30 @@ namespace hpx { namespace parallel { inline namespace v1 | |
|
||
/////////////////////////////////////////////////////////////////////// | ||
// Our own version of the sequential exclusive_scan. | ||
template <typename InIter, typename OutIter, typename T, typename Op> | ||
template <typename InIter, typename OutIter, typename T, typename Op, | ||
typename Conv = util::projection_identity> | ||
OutIter sequential_exclusive_scan(InIter first, InIter last, | ||
OutIter dest, T init, Op && op) | ||
OutIter dest, T init, Op && op, Conv && conv = Conv()) | ||
{ | ||
T temp = init; | ||
for (/* */; first != last; (void) ++first, ++dest) | ||
{ | ||
init = op(init, *first); | ||
init = hpx::util::invoke(op, init, hpx::util::invoke(conv, *first)); | ||
*dest = temp; | ||
temp = init; | ||
} | ||
return dest; | ||
} | ||
|
||
template <typename InIter, typename OutIter, typename T, typename Op> | ||
template <typename InIter, typename OutIter, typename T, typename Op, | ||
typename Conv = util::projection_identity> | ||
T sequential_exclusive_scan_n(InIter first, std::size_t count, | ||
OutIter dest, T init, Op && op) | ||
OutIter dest, T init, Op && op, Conv && conv = Conv()) | ||
{ | ||
T temp = init; | ||
for (/* */; count-- != 0; (void) ++first, ++dest) | ||
{ | ||
init = op(init, *first); | ||
init = hpx::util::invoke(op, init, hpx::util::invoke(conv, *first)); | ||
*dest = temp; | ||
temp = init; | ||
} | ||
|
@@ -80,21 +83,22 @@ namespace hpx { namespace parallel { inline namespace v1 | |
{} | ||
|
||
template <typename ExPolicy, typename InIter, typename OutIter, | ||
typename T, typename Op> | ||
typename T, typename Op, typename Conv = util::projection_identity> | ||
static OutIter | ||
sequential(ExPolicy, InIter first, InIter last, OutIter dest, | ||
T const& init, Op && op) | ||
T const& init, Op && op, Conv && conv = Conv()) | ||
{ | ||
return sequential_exclusive_scan(first, last, dest, | ||
init, std::forward<Op>(op)); | ||
init, std::forward<Op>(op), std::forward<Conv>(conv)); | ||
} | ||
|
||
template <typename ExPolicy, typename FwdIter1, typename T, typename Op> | ||
template <typename ExPolicy, typename FwdIter1, typename T, typename Op, | ||
typename Conv = util::projection_identity> | ||
static typename util::detail::algorithm_result< | ||
ExPolicy, FwdIter2 | ||
>::type | ||
parallel(ExPolicy && policy, FwdIter1 first, FwdIter1 last, | ||
FwdIter2 dest, T const& init, Op && op) | ||
FwdIter2 dest, T const& init, Op && op, Conv && conv = Conv()) | ||
{ | ||
typedef util::detail::algorithm_result<ExPolicy, FwdIter2> | ||
result; | ||
|
@@ -146,16 +150,20 @@ namespace hpx { namespace parallel { inline namespace v1 | |
std::forward<ExPolicy>(policy), | ||
make_zip_iterator(first, dest), count, init, | ||
// step 1 performs first part of scan algorithm | ||
[op](zip_iterator part_begin, std::size_t part_size) -> T | ||
[op, conv, last](zip_iterator part_begin, | ||
std::size_t part_size) -> T | ||
{ | ||
T part_init = get<0>(*part_begin++); | ||
T part_init = hpx::util::invoke(conv, get<0>(*part_begin++)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This additionally requires a check whether There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure what the lambda should return if part_begin has reached the end. The only scenario where that happens is if there is a partition with two elements. I looked at an example from algorithms/reduce.hpp L72, and even here there is no such check. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it should return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There it is not a problem as |
||
|
||
auto iters = part_begin.get_iterator_tuple(); | ||
return sequential_exclusive_scan_n( | ||
get<0>(iters), | ||
part_size - 1, | ||
get<1>(iters), | ||
part_init, op); | ||
if(get<0>(iters) != last) | ||
return sequential_exclusive_scan_n( | ||
get<0>(iters), | ||
part_size - 1, | ||
get<1>(iters), | ||
part_init, op, conv); | ||
else | ||
return part_init; | ||
}, | ||
// step 2 propagates the partition results from left | ||
// to right | ||
|
@@ -173,10 +181,10 @@ namespace hpx { namespace parallel { inline namespace v1 | |
}; | ||
|
||
template <typename ExPolicy, typename FwdIter1, typename FwdIter2, typename T, | ||
typename Op> | ||
typename Op, typename Conv = util::projection_identity> | ||
static typename util::detail::algorithm_result<ExPolicy, FwdIter2>::type | ||
exclusive_scan_(ExPolicy&& policy, FwdIter1 first, FwdIter1 last, FwdIter2 dest, | ||
T const& init, Op && op, std::false_type) { | ||
T const& init, Op && op, std::false_type, Conv && conv = Conv()) { | ||
|
||
#if defined(HPX_HAVE_ALGORITHM_INPUT_ITERATOR_SUPPORT) | ||
typedef std::integral_constant<bool, | ||
|
@@ -199,10 +207,10 @@ namespace hpx { namespace parallel { inline namespace v1 | |
|
||
// forward declare the segmented version of this algorithm | ||
template <typename ExPolicy, typename FwdIter1, typename FwdIter2, typename T, | ||
typename Op> | ||
typename Op, typename Conv = util::projection_identity> | ||
static typename util::detail::algorithm_result<ExPolicy, FwdIter2>::type | ||
exclusive_scan_(ExPolicy&& policy, FwdIter1 first, FwdIter1 last, FwdIter2 dest, | ||
T const& init, Op && op, std::true_type); | ||
T const& init, Op && op, std::true_type, Conv && conv = Conv()); | ||
/// \endcond | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change?