Itoyori  v0.0.1
execution.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "ityr/common/util.hpp"
4 #include "ityr/ito/ito.hpp"
6 
7 namespace ityr::execution {
8 
20  std::size_t checkout_count = 1;
21 
22  constexpr sequenced_policy() noexcept {}
23 
24  constexpr sequenced_policy(std::size_t checkout_count) noexcept
26 };
27 
35 template <typename W = void>
37  constexpr parallel_policy() noexcept {}
38 
39  constexpr parallel_policy(std::size_t cutoff_count) noexcept
41 
42  constexpr parallel_policy(std::size_t cutoff_count, std::size_t checkout_count) noexcept
44 
46  : workhint(workhint.view()) {}
47 
50 
51  parallel_policy(std::size_t cutoff_count, std::size_t checkout_count, const workhint_range<W>& workhint) noexcept
53 
55  : workhint(workhint) {}
56 
59 
62 
66  std::size_t cutoff_count = 1;
67 
71  std::size_t checkout_count = 1;
72 
77 };
78 
83 inline constexpr sequenced_policy seq;
84 
89 inline constexpr parallel_policy par;
90 
91 namespace internal {
92 
93 inline constexpr sequenced_policy to_sequenced_policy(const sequenced_policy& policy) noexcept {
94  return policy;
95 }
96 
97 template <typename W>
98 inline constexpr sequenced_policy to_sequenced_policy(const parallel_policy<W>& policy) noexcept {
99  return sequenced_policy(policy.checkout_count);
100 }
101 
102 inline void assert_policy(const sequenced_policy& policy) {
103  ITYR_CHECK(0 < policy.checkout_count);
104 }
105 
106 template <typename W>
107 inline void assert_policy(const parallel_policy<W>& policy) {
108  ITYR_CHECK(0 < policy.checkout_count);
109  ITYR_CHECK(policy.checkout_count <= policy.cutoff_count);
110 }
111 
112 template <typename W>
113 inline auto get_workhint(const parallel_policy<W>& policy) {
114  if constexpr (std::is_void_v<W>) {
115  return ito::workhint(1, 1);
116  } else {
117  if (policy.workhint.empty()) {
118  return ito::workhint(W(1), W(1));
119  } else {
120  auto [w_new, w_rest] = policy.workhint.get_workhint();
121  return ito::workhint(w_new, w_rest);
122  }
123  }
124 }
125 
126 template <typename W>
127 inline auto get_child_policies(const parallel_policy<W>& policy) {
128  if constexpr (std::is_void_v<W>) {
129  return std::make_pair(std::cref(policy), std::cref(policy));
130  } else {
131  if (policy.workhint.empty()) {
132  return std::make_pair(policy, policy);
133  } else if (!policy.workhint.has_children()) {
134  return std::make_pair(parallel_policy<W>(policy.cutoff_count, policy.checkout_count),
136  } else {
137  auto [c1, c2] = policy.workhint.get_children();
138  return std::make_pair(parallel_policy(policy.cutoff_count, policy.checkout_count, c1),
139  parallel_policy(policy.cutoff_count, policy.checkout_count, c2));
140  }
141  }
142 }
143 
144 }
145 }
Definition: workhint_view.hpp:12
Definition: workhint.hpp:12
#define ITYR_CHECK(cond)
Definition: util.hpp:48
Definition: execution.hpp:7
constexpr parallel_policy par
Default parallel execution policy for iterator-based loop functions.
Definition: execution.hpp:89
constexpr sequenced_policy seq
Default serial execution policy for iterator-based loop functions.
Definition: execution.hpp:83
Parallel execution policy for iterator-based loop functions.
Definition: execution.hpp:36
parallel_policy(const workhint_range< W > &workhint) noexcept
Definition: execution.hpp:45
parallel_policy(std::size_t cutoff_count, std::size_t checkout_count, workhint_range_view< W > workhint) noexcept
Definition: execution.hpp:60
constexpr parallel_policy(std::size_t cutoff_count) noexcept
Definition: execution.hpp:39
constexpr parallel_policy() noexcept
Definition: execution.hpp:37
parallel_policy(std::size_t cutoff_count, const workhint_range< W > &workhint) noexcept
Definition: execution.hpp:48
parallel_policy(std::size_t cutoff_count, std::size_t checkout_count, const workhint_range< W > &workhint) noexcept
Definition: execution.hpp:51
parallel_policy(std::size_t cutoff_count, workhint_range_view< W > workhint) noexcept
Definition: execution.hpp:57
parallel_policy(workhint_range_view< W > workhint) noexcept
Definition: execution.hpp:54
constexpr parallel_policy(std::size_t cutoff_count, std::size_t checkout_count) noexcept
Definition: execution.hpp:42
workhint_range_view< W > workhint
Work hints for ADWS.
Definition: execution.hpp:76
std::size_t checkout_count
The number of elements for leaf tasks to stop parallel recursion.
Definition: execution.hpp:71
std::size_t cutoff_count
The maximum number of elements to check out at the same time if automatic checkout is enabled.
Definition: execution.hpp:66
Serial execution policy for iterator-based loop functions.
Definition: execution.hpp:16
constexpr sequenced_policy(std::size_t checkout_count) noexcept
Definition: execution.hpp:24
constexpr sequenced_policy() noexcept
Definition: execution.hpp:22
std::size_t checkout_count
The maximum number of elements to check out at the same time if automatic checkout is enabled.
Definition: execution.hpp:20
Definition: thread.hpp:14
Definition: parallel_invoke.hpp:14