Shiokaze Framework
A research-oriented fluid solver for computer graphics
parallel_core.h
Go to the documentation of this file.
1 /*
2 ** parallel_core.h
3 **
4 ** This is part of Shiokaze, a research-oriented fluid solver for computer graphics.
5 ** Created by Ryoichi Ando <rand@nii.ac.jp> on Feb 1, 2017.
6 **
7 ** Permission is hereby granted, free of charge, to any person obtaining a copy of
8 ** this software and associated documentation files (the "Software"), to deal in
9 ** the Software without restriction, including without limitation the rights to use,
10 ** copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
11 ** Software, and to permit persons to whom the Software is furnished to do so,
12 ** subject to the following conditions:
13 **
14 ** The above copyright notice and this permission notice shall be included in all copies
15 ** or substantial portions of the Software.
16 **
17 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
18 ** INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
19 ** PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 ** HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
21 ** CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
22 ** OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24 //
25 #ifndef SHKZ_PARALLEL_CORE_H
26 #define SHKZ_PARALLEL_CORE_H
27 //
29 #include <functional>
30 #include <vector>
31 #include <dlfcn.h>
32 //
34 //
35 static bool *g_shkz_force_single_thread {nullptr};
36 //
41 public:
42  //
43  DEFINE_MODULE(parallel_core,"Parallel Core","Parallel","Paralell operation dispatcher module")
54  virtual void for_each(
55  std::function<void(size_t n, int thread_index)> func,
56  std::function<size_t(int thread_index)> iterator_start,
57  std::function<bool(size_t &n, int thread_index)> iterator_advance,
58  int num_threads ) const = 0;
65  virtual void run( const std::vector<std::function<void()> > &functions ) const = 0;
72  static void force_single_thread( bool value ) {
73  if( ! g_shkz_force_single_thread ) {
74  g_shkz_force_single_thread = static_cast<bool *>(::dlsym(RTLD_DEFAULT,"g_shkz_force_single_thread"));
75  assert(g_shkz_force_single_thread);
76  }
77  *g_shkz_force_single_thread = value;
78  }
79 private:
80 };
81 //
82 using parallel_ptr = std::unique_ptr<parallel_core>;
83 //
85 //
86 #endif
87 //
parallel_core::for_each
virtual void for_each(std::function< void(size_t n, int thread_index)> func, std::function< size_t(int thread_index)> iterator_start, std::function< bool(size_t &n, int thread_index)> iterator_advance, int num_threads) const =0
Perform a parallel loop operation.
parallel_core
Abstract class that handles parallel operations. Used with loop_splitter. "stdthread" and "tbbthread"...
Definition: parallel_core.h:40
parallel_core::force_single_thread
static void force_single_thread(bool value)
Set if force single thread.
Definition: parallel_core.h:72
DEFINE_MODULE
#define DEFINE_MODULE(CLASS_T, LNG_NAME, ARG_NAME, DESCRIPTION)
Definition that simplifies the loading module.
Definition: recursive_configurable_module.h:39
SHKZ_BEGIN_NAMESPACE
#define SHKZ_BEGIN_NAMESPACE
Name space beggining definition for shiokaze.
Definition: common.h:39
parallel_core::run
virtual void run(const std::vector< std::function< void()> > &functions) const =0
Run operations in parallel.
SHKZ_END_NAMESPACE
#define SHKZ_END_NAMESPACE
Name space end definition for shiokaze.
Definition: common.h:44
recursive_configurable_module.h
recursive_configurable_module
recursive_configurable class that also inherits module.
Definition: recursive_configurable_module.h:49