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 scheduleSchurAssign( Target& target,
const Source& source );
113 template<
typename Target,
typename Source >
114 static inline void scheduleMultAssign( Target& target,
const Source& source );
116 template<
typename Target,
typename Source >
117 static inline void scheduleDivAssign( Target& target,
const Source& source );
125 template<
typename Target
135 explicit inline Assigner( Target& target,
const Source& source )
146 inline void operator()() {
147 assign( target_, source_ );
153 const Source source_;
166 template<
typename Target
176 explicit inline AddAssigner( Target& target,
const Source& source )
187 inline void operator()() {
188 addAssign( target_, source_ );
194 const Source source_;
207 template<
typename Target
217 explicit inline SubAssigner( Target& target,
const Source& source )
228 inline void operator()() {
229 subAssign( target_, source_ );
235 const Source source_;
248 template<
typename Target
258 explicit inline SchurAssigner( Target& target,
const Source& source )
269 inline void operator()() {
270 schurAssign( target_, source_ );
276 const Source source_;
289 template<
typename Target
299 explicit inline MultAssigner( Target& target,
const Source& source )
310 inline void operator()() {
311 multAssign( target_, source_ );
317 const Source source_;
330 template<
typename Target
340 explicit inline DivAssigner( Target& target,
const Source& source )
351 inline void operator()() {
352 divAssign( target_, source_ );
358 const Source source_;
371 static inline size_t initPool();
378 static ThreadPool<TT,MT,LT,CT> threadpool_;
401 template<
typename TT,
typename MT,
typename LT,
typename CT >
402 ThreadPool<TT,MT,LT,CT> ThreadBackend<TT,MT,LT,CT>::threadpool_( initPool() );
421 template<
typename TT
427 return threadpool_.size();
449 template<
typename TT
455 return threadpool_.resize( n, block );
469 template<
typename TT
473 inline void ThreadBackend<TT,MT,LT,CT>::wait()
499 template<
typename TT
503 template<
typename Target
505 inline void ThreadBackend<TT,MT,LT,CT>::scheduleAssign( Target& target,
const Source& source )
508 threadpool_.schedule( Assigner<Target,Source>( target, source ) );
524 template<
typename TT
528 template<
typename Target
530 inline void ThreadBackend<TT,MT,LT,CT>::scheduleAddAssign( Target& target,
const Source& source )
533 threadpool_.schedule( AddAssigner<Target,Source>( target, source ) );
549 template<
typename TT
553 template<
typename Target
555 inline void ThreadBackend<TT,MT,LT,CT>::scheduleSubAssign( Target& target,
const Source& source )
558 threadpool_.schedule( SubAssigner<Target,Source>( target, source ) );
574 template<
typename TT
578 template<
typename Target
580 inline void ThreadBackend<TT,MT,LT,CT>::scheduleSchurAssign( Target& target,
const Source& source )
583 threadpool_.schedule( SchurAssigner<Target,Source>( target, source ) );
599 template<
typename TT
603 template<
typename Target
605 inline void ThreadBackend<TT,MT,LT,CT>::scheduleMultAssign( Target& target,
const Source& source )
608 threadpool_.schedule( MultAssigner<Target,Source>( target, source ) );
624 template<
typename TT
628 template<
typename Target
630 inline void ThreadBackend<TT,MT,LT,CT>::scheduleDivAssign( Target& target,
const Source& source )
633 threadpool_.schedule( DivAssigner<Target,Source>( target, source ) );
657 #if (defined _MSC_VER) 658 # pragma warning(push) 659 # pragma warning(disable:4996) 661 template<
typename TT
665 inline size_t ThreadBackend<TT,MT,LT,CT>::initPool()
667 const char* env = std::getenv(
"BLAZE_NUM_THREADS" );
671 else return max( 1, atoi( env ) );
673 #if (defined _MSC_VER) 674 # pragma warning(pop) 697 #if BLAZE_CPP_THREADS_PARALLEL_MODE 698 using TheThreadBackend = ThreadBackend< std::thread
700 , std::unique_lock< std::mutex >
701 , std::condition_variable
703 #elif BLAZE_BOOST_THREADS_PARALLEL_MODE 704 using TheThreadBackend = ThreadBackend< boost::thread
706 , boost::unique_lock< boost::mutex >
707 , 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 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:265
#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:1809
Headerfile for the generic max algorithm.
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:548
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