Blaze
3.9
Toggle main menu visibility
Loading...
Searching...
No Matches
blaze
math
smp
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
43
#include <
blaze/math/Exception.h
>
44
#include <
blaze/util/Suffix.h
>
45
46
47
namespace
blaze {
48
49
//=================================================================================================
50
//
51
// CLASS DEFINITION
52
//
53
//=================================================================================================
54
55
//*************************************************************************************************
63
template
<
typename
T >
64
class
ParallelSection
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
//*************************************************************************************************
126
template
<
typename
T >
127
bool
ParallelSection<T>::active_
=
false
;
129
//*************************************************************************************************
130
131
132
133
134
//=================================================================================================
135
//
136
// CONSTRUCTORS
137
//
138
//=================================================================================================
139
140
//*************************************************************************************************
146
template
<
typename
T >
147
inline
ParallelSection<T>::ParallelSection
(
bool
activate )
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
//*************************************************************************************************
169
template
<
typename
T >
170
inline
ParallelSection<T>::~ParallelSection
()
171
{
172
active_
=
false
;
// Resetting the activity flag
173
}
174
//*************************************************************************************************
175
176
177
178
179
//=================================================================================================
180
//
181
// CONVERSION OPERATOR
182
//
183
//=================================================================================================
184
185
//*************************************************************************************************
191
template
<
typename
T >
192
inline
ParallelSection<T>::operator
bool()
const
193
{
194
return
active_
;
195
}
196
//*************************************************************************************************
197
198
199
200
201
//=================================================================================================
202
//
203
// GLOBAL FUNCTIONS
204
//
205
//=================================================================================================
206
207
//*************************************************************************************************
210
inline
bool
isParallelSectionActive
();
212
//*************************************************************************************************
213
214
215
//*************************************************************************************************
221
inline
bool
isParallelSectionActive
()
222
{
223
return
ParallelSection<int>::active_
;
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
Suffix.h
Header file for compile time constraints.
blaze::ParallelSection::active_
static bool active_
Activity flag for the parallel section.
Definition
ParallelSection.h:100
blaze::ParallelSection::~ParallelSection
~ParallelSection()
Destructor of the ParallelSection class.
Definition
ParallelSection.h:170
blaze::ParallelSection::ParallelSection
ParallelSection(bool activate)
Constructor for the ParallelSection class.
Definition
ParallelSection.h:147
blaze::isParallelSectionActive
bool isParallelSectionActive()
Returns whether a parallel section is active or not.
Definition
ParallelSection.h:221
BLAZE_THROW_RUNTIME_ERROR
#define BLAZE_THROW_RUNTIME_ERROR(MESSAGE)
Macro for the emission of a std::runtime_error exception.
Definition
Exception.h:379
Exception.h
Header file for the exception macros of the math module.
Generated by
1.18.0