Warning, file /include/Geant4/PTL/ThreadData.hh was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026 #pragma once
0027
0028 #ifndef G4GMAKE
0029 #include "PTL/Config.hh"
0030 #endif
0031
0032 #include <cstdint>
0033 #include <deque>
0034
0035 #if defined(PTL_USE_TBB)
0036 # if !defined(TBB_PREVIEW_GLOBAL_CONTROL)
0037 # define TBB_PREVIEW_GLOBAL_CONTROL 1
0038 # endif
0039 # include <tbb/global_control.h>
0040 # include <tbb/task_arena.h>
0041 # include <tbb/task_group.h>
0042 #else
0043 # include <cstddef>
0044 #endif
0045
0046 namespace PTL
0047 {
0048
0049
0050 #if defined(PTL_USE_TBB)
0051
0052 using tbb_global_control_t = ::tbb::global_control;
0053 using tbb_task_group_t = ::tbb::task_group;
0054 using tbb_task_arena_t = ::tbb::task_arena;
0055
0056 #else
0057
0058 namespace tbb
0059 {
0060 class task_group
0061 {
0062 public:
0063
0064 task_group() {}
0065
0066 inline void wait() {}
0067
0068 template <typename FuncT>
0069 inline void run(FuncT f)
0070 {
0071 f();
0072 }
0073
0074 template <typename FuncT>
0075 inline void run_and_wait(FuncT f)
0076 {
0077 f();
0078 }
0079 };
0080
0081 class global_control
0082 {
0083 public:
0084 enum parameter
0085 {
0086 max_allowed_parallelism,
0087 thread_stack_size
0088 };
0089
0090 global_control(parameter p, size_t value);
0091 ~global_control();
0092 static size_t active_value(parameter param);
0093 };
0094
0095 class task_arena
0096 {
0097 public:
0098 enum parameter
0099 {
0100 not_initialized = -2,
0101 automatic = -1
0102 };
0103
0104 task_arena(int max_concurrency = automatic, unsigned reserved_for_masters = 1)
0105 {
0106 (void) max_concurrency;
0107 (void) reserved_for_masters;
0108 }
0109
0110 ~task_arena() = default;
0111
0112 void initialize(int max_concurrency = automatic, unsigned reserved_for_masters = 1);
0113
0114 template <typename FuncT>
0115 auto execute(FuncT&& _func) -> decltype(_func())
0116 {
0117 return _func();
0118 }
0119 };
0120
0121 }
0122
0123 using tbb_global_control_t = tbb::global_control;
0124 using tbb_task_group_t = tbb::task_group;
0125 using tbb_task_arena_t = tbb::task_arena;
0126
0127 #endif
0128
0129
0130
0131 class ThreadPool;
0132 class VUserTaskQueue;
0133
0134
0135
0136 class ThreadData
0137 {
0138 public:
0139 template <typename Tp>
0140 using TaskStack = std::deque<Tp>;
0141
0142 ThreadData(ThreadPool* tp);
0143 ~ThreadData() = default;
0144
0145 void update();
0146
0147 public:
0148 bool is_main = false;
0149 bool within_task = false;
0150 intmax_t task_depth = 0;
0151 ThreadPool* thread_pool = nullptr;
0152 VUserTaskQueue* current_queue = nullptr;
0153 TaskStack<VUserTaskQueue*> queue_stack = {};
0154
0155 public:
0156
0157 static ThreadData*& GetInstance();
0158 };
0159
0160
0161
0162 }