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 );
119 template<
typename Target
129 explicit inline Assigner( Target& target,
const Source& source )
140 inline void operator()() {
141 assign( target_, source_ );
147 const Source source_;
160 template<
typename Target
170 explicit inline AddAssigner( Target& target,
const Source& source )
181 inline void operator()() {
182 addAssign( target_, source_ );
188 const Source source_;
201 template<
typename Target
211 explicit inline SubAssigner( Target& target,
const Source& source )
222 inline void operator()() {
223 subAssign( target_, source_ );
229 const Source source_;
242 template<
typename Target
252 explicit inline MultAssigner( Target& target,
const Source& source )
263 inline void operator()() {
264 multAssign( target_, source_ );
270 const Source source_;
283 static inline size_t initPool();
290 static ThreadPool<TT,MT,LT,CT> threadpool_;
313 template<
typename TT,
typename MT,
typename LT,
typename CT >
314 ThreadPool<TT,MT,LT,CT> ThreadBackend<TT,MT,LT,CT>::threadpool_( initPool() );
333 template<
typename TT
339 return threadpool_.size();
361 template<
typename TT
367 return threadpool_.resize( n, block );
381 template<
typename TT
385 inline void ThreadBackend<TT,MT,LT,CT>::wait()
411 template<
typename TT
415 template<
typename Target
417 inline void ThreadBackend<TT,MT,LT,CT>::scheduleAssign( Target& target,
const Source& source )
420 threadpool_.schedule( Assigner<Target,Source>( target, source ) );
436 template<
typename TT
440 template<
typename Target
442 inline void ThreadBackend<TT,MT,LT,CT>::scheduleAddAssign( Target& target,
const Source& source )
445 threadpool_.schedule( AddAssigner<Target,Source>( target, source ) );
461 template<
typename TT
465 template<
typename Target
467 inline void ThreadBackend<TT,MT,LT,CT>::scheduleSubAssign( Target& target,
const Source& source )
470 threadpool_.schedule( SubAssigner<Target,Source>( target, source ) );
486 template<
typename TT
490 template<
typename Target
492 inline void ThreadBackend<TT,MT,LT,CT>::scheduleMultAssign( Target& target,
const Source& source )
495 threadpool_.schedule( MultAssigner<Target,Source>( target, source ) );
519 #if (defined _MSC_VER)
520 # pragma warning(push)
521 # pragma warning(disable:4996)
523 template<
typename TT
527 inline size_t ThreadBackend<TT,MT,LT,CT>::initPool()
529 const char* env = std::getenv(
"BLAZE_NUM_THREADS" );
533 else return max( 1, atoi( env ) );
535 #if (defined _MSC_VER)
536 # pragma warning(pop)
559 #if BLAZE_CPP_THREADS_PARALLEL_MODE
560 typedef ThreadBackend< std::thread
562 , std::unique_lock< std::mutex >
563 , std::condition_variable
565 #elif BLAZE_BOOST_THREADS_PARALLEL_MODE
566 typedef ThreadBackend< boost::thread
568 , boost::unique_lock< boost::mutex >
569 , 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:116
const MT::ElementType max(const DenseMatrix< MT, SO > &dm)
Returns the largest element of the dense matrix.
Definition: DenseMatrix.h:1729
Header file for mathematical functions.
Header file of the ThreadPool class.
Header file for basic type definitions.
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector)
Returns the current size/dimension of the vector.
Definition: Vector.h:252
#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:79
#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.
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:532
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:143