Stride Reference Manual  1.0
dummy.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <memory>
4 #include "unipar.h"
5 #include "interface.h"
6 
7 namespace unipar {
8 namespace internal {
9 
10 template<typename Impl, typename... Types>
12 
13 template<typename Impl, typename Type, typename... Rest>
14 class DummyResourceManager<Impl, Type, Rest...> : public ResourceManager<Impl, Type, Rest...> {
15 public:
16  using ResourceManager<Impl, Type, Rest...>::ResourceManager;
17 
18  template<typename F, typename... Args>
19  typename std::result_of<F(Type&, Args...)>::type call(const F& func, Args&& ... args) {
20  if (m_value == nullptr) {
21  // Copy constructor is needed!
22  m_value = new Type(std::move(this->m_func()));
23  }
24  return this->m_rest.call(func, *m_value, std::forward<Args>(args)...);
25  }
26 
28  if (m_value) {
29  delete m_value;
30  m_value = nullptr;
31  }
32  }
33 
34 protected:
35  Type* m_value = nullptr;
36 };
37 
38 template<typename Impl>
39 class DummyResourceManager<Impl> : public ResourceManager<Impl> {
40 };
41 
42 
44 public:
45  template<typename Impl, typename... Types>
46  using RMType = DummyResourceManager<Impl, Types...>;
47 
48  // The dummy implementation will obviously never use more than 1 thread
49  // However, to remain compatible with otherwise multithreaded code, we allow
50  // this constructor.
51  _DummyParallel(int= 1) {}
52 
53  // Dummy non-multithreaded implementation
54  template<typename IndexF, typename IndexL, typename IndexS, typename Func, typename RM>
55  void parallelFor(IndexF first, IndexL last, IndexS step, const Func& f, RM& rm) {
56  for (IndexF i = first; i < last; i += step) {
57  rm.call(f, i);
58  }
59  }
60 
61  inline int getNumThreads() const { return 1; }
62 };
63 
64 }
65 
67 
68 }
std::result_of< F(Type &, Args...)>::type call(const F &func, Args &&...args)
Definition: dummy.h:19
int getNumThreads() const
Definition: dummy.h:61
Unified Parallelisation.
Definition: dummy.h:7
void parallelFor(IndexF first, IndexL last, IndexS step, const Func &f, RM &rm)
Definition: dummy.h:55