OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
threading_std Namespace Reference

Classes

class  task_group
 

Functions

template<typename Fn , typename... Args, typename Result = std::result_of_t<Fn && (Args && ...)>>
future< Result > async (Fn &&fn, Args &&...args)
 
template<typename Int , typename Body , typename Partitioner = auto_partitioner>
void parallel_for (const blocked_range< Int > &range, const Body &body, const Partitioner &p=Partitioner())
 Parallel iteration over range with default partitioner. More...
 
template<typename Index , typename Function , typename Partitioner = auto_partitioner>
void parallel_for (Index first, Index last, const Function &f, const Partitioner &p=Partitioner())
 
template<typename Int , typename Value , typename RealBody , typename Reduction , typename Partitioner = auto_partitioner>
Value parallel_reduce (const blocked_range< Int > &range, const Value &identity, const RealBody &real_body, const Reduction &reduction, const Partitioner &p=Partitioner())
 Parallel iteration with reduction. More...
 

Variables

constexpr auto launch = std::launch::THREADING_STD_LAUNCH
 

Function Documentation

template<typename Fn , typename... Args, typename Result = std::result_of_t<Fn && (Args && ...)>>
future<Result> threading_std::async ( Fn &&  fn,
Args &&...  args 
)

Definition at line 105 of file threading_std.h.

References run_benchmark_import::args, threading_serial::async(), and launch.

Referenced by threading_std::task_group::run().

105  {
106  return std::async(launch, std::forward<Fn>(fn), std::forward<Args>(args)...);
107 }
constexpr auto launch
future< Result > async(Fn &&fn, Args &&...args)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename Int , typename Body , typename Partitioner = auto_partitioner>
void threading_std::parallel_for ( const blocked_range< Int > &  range,
const Body &  body,
const Partitioner &  p = Partitioner() 
)

Parallel iteration over range with default partitioner.

Definition at line 133 of file threading_std.h.

References threading_serial::async(), threading_common::blocked_range< Value >::begin(), cpu_threads(), threading_common::blocked_range< Value >::end(), launch, and threading_common::blocked_range< Value >::size().

Referenced by parallel_for().

135  {
136  const Int worker_count = cpu_threads();
137  std::vector<std::future<void>> worker_threads;
138  worker_threads.reserve(worker_count);
139 
140  for (Int i = 0,
141  start_entry = range.begin(),
142  stop_entry = range.end(),
143  stride = (range.size() + worker_count - 1) / worker_count;
144  i < worker_count && start_entry < stop_entry;
145  ++i, start_entry += stride) {
146  const auto end_entry = std::min(start_entry + stride, stop_entry);
147  // TODO grainsize?
148  worker_threads.emplace_back(
149  std::async(launch, body, blocked_range<Int>(start_entry, end_entry)));
150  }
151  for (auto& child : worker_threads) {
152  child.wait();
153  }
154 }
size_type size() const
Size of the range.
Definition: threading_std.h:47
constexpr auto launch
future< Result > async(Fn &&fn, Args &&...args)
A range over which to iterate.
Definition: threading_std.h:21
const_iterator end() const
One past last value in range.
Definition: threading_std.h:43
const_iterator begin() const
Beginning of range.
Definition: threading_std.h:40
int cpu_threads()
Definition: thread_count.h:25

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename Index , typename Function , typename Partitioner = auto_partitioner>
void threading_std::parallel_for ( Index  first,
Index  last,
const Function f,
const Partitioner &  p = Partitioner() 
)

Parallel iteration over a range of integers with a default step value and default partitioner

Definition at line 159 of file threading_std.h.

References threading_common::blocked_range< Value >::begin(), threading_common::blocked_range< Value >::end(), f(), and parallel_for().

162  {
163  parallel_for(
164  blocked_range<Index>(first, last),
165  [&f](const blocked_range<Index>& r) {
166  //#pragma ivdep
167  //#pragma omp simd
168  for (auto i = r.begin(), e = r.end(); i < e; i++) {
169  f(i);
170  }
171  },
172  p);
173 }
A range over which to iterate.
Definition: threading_std.h:21
torch::Tensor f(torch::Tensor x, torch::Tensor W_target, torch::Tensor b_target)
void parallel_for(const blocked_range< Int > &range, const Body &body, const Partitioner &p=Partitioner())
const_iterator end() const
One past last value in range.
Definition: threading_std.h:43
const_iterator begin() const
Beginning of range.
Definition: threading_std.h:40

+ Here is the call graph for this function:

template<typename Int , typename Value , typename RealBody , typename Reduction , typename Partitioner = auto_partitioner>
Value threading_std::parallel_reduce ( const blocked_range< Int > &  range,
const Value identity,
const RealBody &  real_body,
const Reduction &  reduction,
const Partitioner &  p = Partitioner() 
)

Parallel iteration with reduction.

Definition at line 182 of file threading_std.h.

References threading_serial::async(), threading_common::blocked_range< Value >::begin(), cpu_threads(), threading_common::blocked_range< Value >::end(), launch, and threading_common::blocked_range< Value >::size().

186  {
187  const size_t worker_count = cpu_threads();
188  std::vector<std::future<Value>> worker_threads;
189  worker_threads.reserve(worker_count);
190 
191  for (Int i = 0,
192  start_entry = range.begin(),
193  stop_entry = range.end(),
194  stride = (range.size() + worker_count - 1) / worker_count;
195  i < worker_count && start_entry < stop_entry;
196  ++i, start_entry += stride) {
197  const auto end_entry = std::min(start_entry + stride, stop_entry);
198  // TODO grainsize?
199  worker_threads.emplace_back(std::async(
200  launch, real_body, blocked_range<Int>(start_entry, end_entry), Value{}));
201  }
202  Value v = identity;
203  for (auto& child : worker_threads) {
204  v = reduction(v, child.get());
205  }
206 
207  return v;
208 }
size_type size() const
Size of the range.
Definition: threading_std.h:47
constexpr auto launch
future< Result > async(Fn &&fn, Args &&...args)
A range over which to iterate.
Definition: threading_std.h:21
const_iterator end() const
One past last value in range.
Definition: threading_std.h:43
const_iterator begin() const
Beginning of range.
Definition: threading_std.h:40
int cpu_threads()
Definition: thread_count.h:25

+ Here is the call graph for this function:

Variable Documentation

constexpr auto threading_std::launch = std::launch::THREADING_STD_LAUNCH

Definition at line 100 of file threading_std.h.

Referenced by async(), parallel_for(), and parallel_reduce().