21template <
typename Arg>
33template <
typename Arg,
typename... Args>
34inline typename std::enable_if<std::is_pointer<Arg>::value,
bool>::type
threadSafe(Arg
workspace, Args &&...others) {
43template <
typename Arg>
44inline typename std::enable_if<!std::is_pointer<Arg>::value,
bool>::type
threadSafe(
const Arg &
workspace) {
55template <
typename Arg,
typename... Args>
56inline typename std::enable_if<!std::is_pointer<Arg>::value,
bool>::type
threadSafe(
const Arg &
workspace,
67template <
typename T,
typename BinaryOp>
void AtomicOp(std::atomic<T> &f, T
d, BinaryOp op) {
72 }
while (!f.compare_exchange_weak(old, desired));
81#define PRAGMA __pragma
82#define PARALLEL_SET_CONFIG_THREADS
84#define PRAGMA(x) _Pragma(#x)
85#define PARALLEL_SET_CONFIG_THREADS \
86 setMaxCoresToConfig(); \
87 PARALLEL_SET_DYNAMIC(false);
94#define PARALLEL_START_INTERRUPT_REGION \
95 if (!m_parallelException && !m_cancel) { \
102#define PARALLEL_END_INTERRUPT_REGION \
104 catch (std::exception & ex) { \
105 if (!m_parallelException) { \
106 m_parallelException = true; \
107 g_log.error() << this->name() << ": " << ex.what() << "\n"; \
111 m_parallelException = true; \
117#define PARALLEL_CHECK_INTERRUPT_REGION \
118 if (m_parallelException) { \
119 g_log.debug("Exception thrown in parallel region"); \
120 throw std::runtime_error(this->name() + ": error (see log)"); \
122 interruption_point();
136#define PARALLEL_FOR_IF(condition) \
137 PARALLEL_SET_CONFIG_THREADS \
138 PRAGMA(omp parallel for if (condition) )
144#define PARALLEL_FOR_NO_WSP_CHECK() \
145 PARALLEL_SET_CONFIG_THREADS \
146 PRAGMA(omp parallel for)
153#define PARALLEL_FOR_NOWS_CHECK_FIRSTPRIVATE(variable) \
154 PARALLEL_SET_CONFIG_THREADS \
155 PRAGMA(omp parallel for firstprivate(variable) )
157#define PARALLEL_FOR_NO_WSP_CHECK_FIRSTPRIVATE2(variable1, variable2) \
158 PARALLEL_SET_CONFIG_THREADS \
159 PRAGMA(omp parallel for firstprivate(variable1, variable2) )
164#define IF_PARALLEL if (omp_get_num_threads() > 1)
169#define IF_NOT_PARALLEL if (omp_get_num_threads() == 1)
174#define PARALLEL_CRITICAL(name) PRAGMA(omp critical(name))
178#define PARALLEL_ATOMIC PRAGMA(omp atomic)
180#define PARALLEL_SET_NUM_THREADS(MaxCores) omp_set_num_threads(MaxCores);
188#define PARALLEL_SET_DYNAMIC(val) omp_set_dynamic(val)
190#define PARALLEL_NUMBER_OF_THREADS omp_get_num_threads()
192#define PARALLEL_GET_MAX_THREADS omp_get_max_threads()
194#define PARALLEL_THREAD_NUMBER omp_get_thread_num()
196#define PARALLEL PRAGMA(omp parallel)
198#define PARALLEL_SECTIONS PRAGMA(omp sections nowait)
200#define PARALLEL_SECTION PRAGMA(omp section)
202inline void setMaxCoresToConfig() {
204 if (maxCores.get_value_or(0) > 0) {
213#define PRAGMA_OMP(expression) PRAGMA(omp expression)
218#define PARALLEL_FOR_IF(condition)
219#define PARALLEL_FOR_NO_WSP_CHECK()
220#define PARALLEL_FOR_NOWS_CHECK_FIRSTPRIVATE(variable)
221#define PARALLEL_FOR_NO_WSP_CHECK_FIRSTPRIVATE2(variable1, variable2)
222#define IF_PARALLEL if (false)
223#define IF_NOT_PARALLEL
224#define PARALLEL_CRITICAL(name)
225#define PARALLEL_ATOMIC
226#define PARALLEL_THREAD_NUMBER 0
227#define PARALLEL_SET_NUM_THREADS(MaxCores)
228#define PARALLEL_SET_DYNAMIC(val)
229#define PARALLEL_NUMBER_OF_THREADS 1
230#define PARALLEL_GET_MAX_THREADS 1
232#define PARALLEL_SECTIONS
233#define PARALLEL_SECTION
234#define PRAGMA_OMP(expression)
IPeaksWorkspace_sptr workspace
#define PARALLEL_SET_NUM_THREADS(MaxCores)
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::enable_if< std::is_pointer< Arg >::value, bool >::type threadSafe(Arg workspace)
Thread-safety check Checks the workspace to ensure it is suitable for multithreaded access.
void AtomicOp(std::atomic< T > &f, T d, BinaryOp op)
Uses std::compare_exchange_weak to update the atomic value f = op(f, d) Used to improve parallel scal...
Helper class which provides the Collimation Length for SANS instruments.