Blaze 3.9
ParallelSection.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_SMP_PARALLELSECTION_H_
36#define _BLAZE_MATH_SMP_PARALLELSECTION_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
44#include <blaze/util/Suffix.h>
45
46
47namespace blaze {
48
49//=================================================================================================
50//
51// CLASS DEFINITION
52//
53//=================================================================================================
54
55//*************************************************************************************************
63template< typename T >
65{
66 public:
67 //**Constructors********************************************************************************
70 inline ParallelSection( bool activate );
71 ParallelSection( const ParallelSection& ) = default;
73 //**********************************************************************************************
74
75 //**Destructor**********************************************************************************
78 inline ~ParallelSection();
80 //**********************************************************************************************
81
82 //**Assignment operators************************************************************************
85 ParallelSection& operator=( const ParallelSection& ) = default;
87 //**********************************************************************************************
88
89 //**Conversion operator*************************************************************************
92 inline operator bool() const;
94 //**********************************************************************************************
95
96 private:
97 //**Member variables****************************************************************************
100 static bool active_;
105 //**********************************************************************************************
106
107 //**Friend declarations*************************************************************************
109 friend bool isParallelSectionActive();
111 //**********************************************************************************************
112};
113//*************************************************************************************************
114
115
116
117
118//=================================================================================================
119//
120// DEFINITION AND INITIALIZATION OF THE STATIC MEMBER VARIABLES
121//
122//=================================================================================================
123
124//*************************************************************************************************
126template< typename T >
127bool ParallelSection<T>::active_ = false;
129//*************************************************************************************************
130
131
132
133
134//=================================================================================================
135//
136// CONSTRUCTORS
137//
138//=================================================================================================
139
140//*************************************************************************************************
146template< typename T >
148{
149 if( active_ ) {
150 BLAZE_THROW_RUNTIME_ERROR( "Nested parallel sections detected" );
151 }
152
153 active_ = activate;
154}
155//*************************************************************************************************
156
157
158
159
160//=================================================================================================
161//
162// DESTRUCTOR
163//
164//=================================================================================================
165
166//*************************************************************************************************
169template< typename T >
171{
172 active_ = false; // Resetting the activity flag
173}
174//*************************************************************************************************
175
176
177
178
179//=================================================================================================
180//
181// CONVERSION OPERATOR
182//
183//=================================================================================================
184
185//*************************************************************************************************
191template< typename T >
193{
194 return active_;
195}
196//*************************************************************************************************
197
198
199
200
201//=================================================================================================
202//
203// GLOBAL FUNCTIONS
204//
205//=================================================================================================
206
207//*************************************************************************************************
210inline bool isParallelSectionActive();
212//*************************************************************************************************
213
214
215//*************************************************************************************************
222{
224}
225//*************************************************************************************************
226
227
228
229
230
231
232
233
234//=================================================================================================
235//
236// PARALLEL SECTION MACRO
237//
238//=================================================================================================
239
240//*************************************************************************************************
254#define BLAZE_PARALLEL_SECTION \
255 if( blaze::ParallelSection<int> BLAZE_JOIN( parallelSection, __LINE__ ) = true )
256//*************************************************************************************************
257
258} // namespace blaze
259
260#endif
Header file for compile time constraints.
Section for the debugging of the shared-memory parallelization.
Definition: ParallelSection.h:65
static bool active_
Activity flag for the parallel section.
Definition: ParallelSection.h:100
~ParallelSection()
Destructor of the ParallelSection class.
Definition: ParallelSection.h:170
ParallelSection(bool activate)
Constructor for the ParallelSection class.
Definition: ParallelSection.h:147
bool isParallelSectionActive()
Returns whether a parallel section is active or not.
Definition: ParallelSection.h:221
#define BLAZE_THROW_RUNTIME_ERROR(MESSAGE)
Macro for the emission of a std::runtime_error exception.
Definition: Exception.h:379
Header file for the exception macros of the math module.