11 template <
typename W,
typename B
idirectionalIterator,
typename Predicate>
12 inline BidirectionalIterator
13 stable_partition_aux(
const execution::parallel_policy<W>& policy,
14 BidirectionalIterator first,
15 BidirectionalIterator last,
17 std::size_t d = std::distance(first, last);
19 if (d <= policy.cutoff_count) {
21 ITYR_CHECK(policy.cutoff_count == policy.checkout_count);
23 auto&& [css, its] = checkout_global_iterators(d, first);
24 auto&& first_ = std::get<0>(its);
26 return std::next(first, std::distance(first_, m));
29 auto mid = std::next(first, d / 2);
32 [=] {
return stable_partition_aux(policy, first, mid , pred); },
33 [=] {
return stable_partition_aux(policy, mid , last, pred); });
35 return rotate(policy, m1, mid, m2);
75 template <
typename ExecutionPolicy,
typename B
idirectionalIterator,
typename Predicate>
77 BidirectionalIterator first,
78 BidirectionalIterator last,
80 if constexpr (ori::is_global_ptr_v<BidirectionalIterator>) {
88 return internal::stable_partition_aux(policy, first, last, pred);
92 ITYR_TEST_CASE(
"[ityr::pattern::parallel_filter] stable_partition") {
98 ori::global_ptr<long> p = ori::malloc_coll<long>(n);
102 execution::parallel_policy(100),
103 count_iterator<long>(0), count_iterator<long>(n), p,
104 [=](
long i) {
return i; });
107 execution::parallel_policy(100),
109 [](
long x) {
return x % 2 == 0; });
114 execution::parallel_policy(100),
117 count_iterator<long>(0),
118 [](
long x,
long i) {
ITYR_CHECK(x == i * 2); });
121 execution::parallel_policy(100),
124 count_iterator<long>(0),
125 [](
long x,
long i) {
ITYR_CHECK(x == i * 2 + 1); });
133 ori::global_ptr<long> p = ori::malloc_coll<long>(n);
137 execution::parallel_policy(100),
138 count_iterator<long>(0), count_iterator<long>(n), p,
139 [=](
long i) {
return i; });
142 execution::parallel_policy(100),
144 [](
long x) {
return x % 3 == 0; });
149 execution::parallel_policy(100),
152 count_iterator<long>(0),
153 [](
long x,
long i) {
ITYR_CHECK(x == i * 3); });
156 execution::parallel_policy(100),
159 count_iterator<long>(0),
160 [](
long x,
long i) {
ITYR_CHECK(x == (i / 2) * 3 + (i % 2) + 1); });
168 ori::global_ptr<long> p = ori::malloc_coll<long>(n);
172 execution::parallel_policy(100),
173 count_iterator<long>(0), count_iterator<long>(n), p,
174 [=](
long i) {
return i; });
177 execution::parallel_policy(100),
179 [](
long) {
return true; });
184 execution::parallel_policy(100),
187 count_iterator<long>(0),
191 execution::parallel_policy(100),
193 [](
long) {
return false; });
198 execution::parallel_policy(100),
201 count_iterator<long>(0),
246 template <
typename ExecutionPolicy,
typename B
idirectionalIterator,
typename Predicate>
247 inline BidirectionalIterator
partition(
const ExecutionPolicy& policy,
248 BidirectionalIterator first,
249 BidirectionalIterator last,
#define ITYR_SUBCASE(name)
Definition: util.hpp:41
#define ITYR_CHECK(cond)
Definition: util.hpp:48
constexpr read_write_t read_write
Read+Write checkout mode.
Definition: checkout_span.hpp:39
constexpr read_t read
Read-only checkout mode.
Definition: checkout_span.hpp:19
void fini()
Definition: ito.hpp:45
auto root_exec(Fn &&fn, Args &&... args)
Definition: ito.hpp:50
void init(MPI_Comm comm=MPI_COMM_WORLD)
Definition: ito.hpp:41
void fini()
Definition: ori.hpp:49
void init(MPI_Comm comm=MPI_COMM_WORLD)
Definition: ori.hpp:45
void free_coll(global_ptr< T > ptr)
Definition: ori.hpp:70
Definition: allocator.hpp:16
BidirectionalIterator rotate(const ExecutionPolicy &policy, BidirectionalIterator first, BidirectionalIterator middle, BidirectionalIterator last)
Rotate a range.
Definition: parallel_loop.hpp:1135
auto parallel_invoke(Args &&... args)
Fork parallel tasks and join them.
Definition: parallel_invoke.hpp:238
ForwardIteratorD transform(const ExecutionPolicy &policy, ForwardIterator1 first1, ForwardIterator1 last1, ForwardIteratorD first_d, UnaryOp unary_op)
Transform elements in a given range and store them in another range.
Definition: parallel_loop.hpp:583
BidirectionalIterator stable_partition(const ExecutionPolicy &policy, BidirectionalIterator first, BidirectionalIterator last, Predicate pred)
Partition elements into two disjoint parts in place.
Definition: parallel_filter.hpp:76
void for_each(const ExecutionPolicy &policy, ForwardIterator first, ForwardIterator last, Op op)
Apply an operator to each element in a range.
Definition: parallel_loop.hpp:136
BidirectionalIterator partition(const ExecutionPolicy &policy, BidirectionalIterator first, BidirectionalIterator last, Predicate pred)
Partition elements into two disjoint parts in place.
Definition: parallel_filter.hpp:247
global_iterator< T, Mode > make_global_iterator(ori::global_ptr< T > gptr, Mode)
Make a global iterator to enable/disable automatic checkout.
Definition: global_iterator.hpp:158