35 #ifndef _BLAZE_MATH_SMP_THREADS_THREADBACKEND_H_
36 #define _BLAZE_MATH_SMP_THREADS_THREADBACKEND_H_
43 #if BLAZE_CPP_THREADS_PARALLEL_MODE
44 # include <condition_variable>
47 #elif BLAZE_BOOST_THREADS_PARALLEL_MODE
48 # include <boost/thread/condition.hpp>
49 # include <boost/thread/mutex.hpp>
50 # include <boost/thread/thread.hpp>
92 static inline size_t size ();
93 static inline void resize(
size_t n,
bool block=
false );
94 static inline void wait ();
101 template<
typename Target,
typename Source >
102 static inline void scheduleAssign( Target& target,
const Source& source );
104 template<
typename Target,
typename Source >
105 static inline void scheduleAddAssign( Target& target,
const Source& source );
107 template<
typename Target,
typename Source >
108 static inline void scheduleSubAssign( Target& target,
const Source& source );
110 template<
typename Target,
typename Source >
111 static inline void scheduleMultAssign( Target& target,
const Source& source );
113 template<
typename Target,
typename Source >
114 static inline void scheduleDivAssign( Target& target,
const Source& source );
122 template<
typename Target
132 explicit inline Assigner( Target& target,
const Source& source )
143 inline void operator()() {
144 assign( target_, source_ );
150 const Source source_;
163 template<
typename Target
173 explicit inline AddAssigner( Target& target,
const Source& source )
184 inline void operator()() {
185 addAssign( target_, source_ );
191 const Source source_;
204 template<
typename Target
214 explicit inline SubAssigner( Target& target,
const Source& source )
225 inline void operator()() {
226 subAssign( target_, source_ );
232 const Source source_;
245 template<
typename Target
255 explicit inline MultAssigner( Target& target,
const Source& source )
266 inline void operator()() {
267 multAssign( target_, source_ );
273 const Source source_;
286 template<
typename Target
296 explicit inline DivAssigner( Target& target,
const Source& source )
307 inline void operator()() {
308 divAssign( target_, source_ );
314 const Source source_;
327 static inline size_t initPool();
334 static ThreadPool<TT,MT,LT,CT> threadpool_;
357 template<
typename TT,
typename MT,
typename LT,
typename CT >
358 ThreadPool<TT,MT,LT,CT> ThreadBackend<TT,MT,LT,CT>::threadpool_( initPool() );
377 template<
typename TT
383 return threadpool_.size();
405 template<
typename TT
411 return threadpool_.resize( n, block );
425 template<
typename TT
429 inline void ThreadBackend<TT,MT,LT,CT>::wait()
455 template<
typename TT
459 template<
typename Target
461 inline void ThreadBackend<TT,MT,LT,CT>::scheduleAssign( Target& target,
const Source& source )
464 threadpool_.schedule( Assigner<Target,Source>( target, source ) );
480 template<
typename TT
484 template<
typename Target
486 inline void ThreadBackend<TT,MT,LT,CT>::scheduleAddAssign( Target& target,
const Source& source )
489 threadpool_.schedule( AddAssigner<Target,Source>( target, source ) );
505 template<
typename TT
509 template<
typename Target
511 inline void ThreadBackend<TT,MT,LT,CT>::scheduleSubAssign( Target& target,
const Source& source )
514 threadpool_.schedule( SubAssigner<Target,Source>( target, source ) );
530 template<
typename TT
534 template<
typename Target
536 inline void ThreadBackend<TT,MT,LT,CT>::scheduleMultAssign( Target& target,
const Source& source )
539 threadpool_.schedule( MultAssigner<Target,Source>( target, source ) );
555 template<
typename TT
559 template<
typename Target
561 inline void ThreadBackend<TT,MT,LT,CT>::scheduleDivAssign( Target& target,
const Source& source )
564 threadpool_.schedule( DivAssigner<Target,Source>( target, source ) );
588 #if (defined _MSC_VER)
589 # pragma warning(push)
590 # pragma warning(disable:4996)
592 template<
typename TT
596 inline size_t ThreadBackend<TT,MT,LT,CT>::initPool()
598 const char* env = std::getenv(
"BLAZE_NUM_THREADS" );
602 else return max( 1, atoi( env ) );
604 #if (defined _MSC_VER)
605 # pragma warning(pop)
628 #if BLAZE_CPP_THREADS_PARALLEL_MODE
629 typedef ThreadBackend< std::thread
631 , std::unique_lock< std::mutex >
632 , std::condition_variable
634 #elif BLAZE_BOOST_THREADS_PARALLEL_MODE
635 typedef ThreadBackend< boost::thread
637 , boost::unique_lock< boost::mutex >
638 , boost::condition_variable
#define BLAZE_CONSTRAINT_MUST_NOT_BE_CONST(T)
Constraint on the data type.In case the given data type is a const-qualified type, a compilation error is created.
Definition: Const.h:79
Header file for mathematical functions.
Header file of the ThreadPool class.
Header file for basic type definitions.
#define BLAZE_CONSTRAINT_MUST_BE_EXPRESSION_TYPE(T)
Constraint on the data type.In case the given data type T is not an expression (i.e. a type derived from the Expression base class), a compilation error is created.
Definition: Expression.h:61
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector) noexcept
Returns the current size/dimension of the vector.
Definition: Vector.h:258
#define BLAZE_BOOST_THREADS_PARALLEL_MODE
Compilation switch for the Boost parallelization.This compilation switch enables/disables the paralle...
Definition: SMP.h:122
Constraint on the data type.
const ElementType_< MT > max(const DenseMatrix< MT, SO > &dm)
Returns the largest element of the dense matrix.
Definition: DenseMatrix.h:1716
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
System settings for the shared-memory parallelization.
#define BLAZE_CPP_THREADS_PARALLEL_MODE
Compilation switch for the C++11 parallelization.This compilation switch enables/disables the paralle...
Definition: SMP.h:95
BLAZE_ALWAYS_INLINE void resize(Matrix< MT, SO > &matrix, size_t rows, size_t columns, bool preserve=true)
Changing the size of the matrix.
Definition: Matrix.h:538
Constraint on the data type.
#define BLAZE_STATIC_ASSERT(expr)
Compile time assertion macro.In case of an invalid compile time expression, a compilation error is cr...
Definition: StaticAssert.h:112