1 /*
2  *  per_thread_bool_indicator.cpp
3  *
4  *  This file is part of NEST.
5  *
6  *  Copyright (C) 2004 The NEST Initiative
7  *
8  *  NEST is free software: you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation, either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  NEST is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with NEST.  If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 #include "per_thread_bool_indicator.h"
24 
25 namespace nest
26 {
27 
BoolIndicatorUInt64()28 BoolIndicatorUInt64::BoolIndicatorUInt64()
29   : status_( false_uint64 )
30 {
31 }
32 
BoolIndicatorUInt64(const bool status)33 BoolIndicatorUInt64::BoolIndicatorUInt64( const bool status )
34   : status_( status )
35 {
36 }
37 
operator [](const thread tid)38 BoolIndicatorUInt64& PerThreadBoolIndicator::operator[]( const thread tid )
39 {
40   return per_thread_status_[ tid ];
41 }
42 
43 void
initialize(const thread num_threads,const bool status)44 PerThreadBoolIndicator::initialize( const thread num_threads, const bool status )
45 {
46   VPManager::assert_single_threaded();
47   per_thread_status_.clear();
48   per_thread_status_.resize( num_threads, BoolIndicatorUInt64( status ) );
49 }
50 
51 bool
all_false() const52 PerThreadBoolIndicator::all_false() const
53 {
54 #pragma omp barrier
55   for ( auto it = per_thread_status_.begin(); it < per_thread_status_.end(); ++it )
56   {
57     if ( it->is_true() )
58     {
59       return false;
60     }
61   }
62   return true;
63 }
64 
65 bool
all_true() const66 PerThreadBoolIndicator::all_true() const
67 {
68 #pragma omp barrier
69   for ( auto it = per_thread_status_.begin(); it < per_thread_status_.end(); ++it )
70   {
71     if ( it->is_false() )
72     {
73       return false;
74     }
75   }
76   return true;
77 }
78 
79 bool
any_false() const80 PerThreadBoolIndicator::any_false() const
81 {
82 #pragma omp barrier
83   for ( auto it = per_thread_status_.begin(); it < per_thread_status_.end(); ++it )
84   {
85     if ( it->is_false() )
86     {
87       return true;
88     }
89   }
90   return false;
91 }
92 
93 bool
any_true() const94 PerThreadBoolIndicator::any_true() const
95 {
96 #pragma omp barrier
97   for ( auto it = per_thread_status_.begin(); it < per_thread_status_.end(); ++it )
98   {
99     if ( it->is_true() )
100     {
101       return true;
102     }
103   }
104   return false;
105 }
106 
107 } /* namespace nest */
108