libMesh
threads_none.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2026 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 #ifndef LIBMESH_THREADS_NONE_H
20 #define LIBMESH_THREADS_NONE_H
21 
22 // Do not try to #include this header directly, it is designed to be
23 // #included directly by threads.h
24 #ifndef LIBMESH_SQUASH_HEADER_WARNING
25 # warning "This file is designed to be included through libmesh/threads.h"
26 #else
27 
28 #if !defined(LIBMESH_HAVE_TBB_API) && !defined(LIBMESH_HAVE_PTHREAD)
29 
30 // Thread-Local-Storage macros
31 #define LIBMESH_TLS_TYPE(type) type
32 #define LIBMESH_TLS_REF(value) (value)
33 
34 namespace libMesh
35 {
36 
37 namespace Threads
38 {
39 
44 
49 {
50 public:
51  static const int automatic = -1;
52  explicit task_scheduler_init (int = automatic) {}
53  void initialize (int = automatic) {}
54  void terminate () {}
55 };
56 
57 
58 
63 class split {};
64 
65 
66 
71 template <typename Range, typename Body>
72 inline
73 void parallel_for (const Range & range, const Body & body,
74  unsigned int n_threads = libMesh::n_threads())
75 {
76  libmesh_error_msg_if(n_threads > libMesh::n_threads(),
77  "Requested n_threads (" << n_threads << ") exceeds the "
78  "global thread count (" << libMesh::n_threads() << ").");
79  BoolAcquire set_in_threads(in_threads);
80  body(range);
81 }
82 
83 
84 
89 template <typename Range, typename Body, typename Partitioner>
90 inline
91 void parallel_for (const Range & range, const Body & body, const Partitioner &,
92  unsigned int n_threads = libMesh::n_threads())
93 {
94  libmesh_error_msg_if(n_threads > libMesh::n_threads(),
95  "Requested n_threads (" << n_threads << ") exceeds the "
96  "global thread count (" << libMesh::n_threads() << ").");
97  BoolAcquire set_in_threads(in_threads);
98  body(range);
99 }
100 
101 
102 
107 template <typename Range, typename Body>
108 inline
109 void parallel_reduce (const Range & range, Body & body,
110  unsigned int n_threads = libMesh::n_threads())
111 {
112  libmesh_error_msg_if(n_threads > libMesh::n_threads(),
113  "Requested n_threads (" << n_threads << ") exceeds the "
114  "global thread count (" << libMesh::n_threads() << ").");
115  BoolAcquire set_in_threads(in_threads);
116  body(range);
117 }
118 
119 
120 
125 template <typename Range, typename Body, typename Partitioner>
126 inline
127 void parallel_reduce (const Range & range, Body & body, const Partitioner &,
128  unsigned int n_threads = libMesh::n_threads())
129 {
130  libmesh_error_msg_if(n_threads > libMesh::n_threads(),
131  "Requested n_threads (" << n_threads << ") exceeds the "
132  "global thread count (" << libMesh::n_threads() << ").");
133  BoolAcquire set_in_threads(in_threads);
134  body(range);
135 }
136 
137 
138 
144 {
145 public:
147  void lock () {}
148  void unlock () {}
149 
151  {
152  public:
154  explicit scoped_lock ( spin_mutex & ) {}
155  void acquire ( spin_mutex & ) {}
156  void release () {}
157  };
158 };
159 
160 
161 
167 {
168 public:
170 
172  {
173  public:
175  explicit scoped_lock ( recursive_mutex & ) {}
176  void acquire ( recursive_mutex & ) {}
177  void release () {}
178  };
179 };
180 
181 
182 
187 template <typename T>
188 class atomic
189 {
190 public:
191  atomic () : _val(0) {}
192  operator T & () { return _val; }
193 private:
194  T _val;
195 };
196 
197 } // namespace Threads
198 
199 } // namespace libMesh
200 
201 #endif // !defined(LIBMESH_HAVE_TBB_API) && !defined(LIBMESH_HAVE_PTHREAD)
202 
203 #endif // LIBMESH_SQUASH_HEADER_WARNING
204 
205 #endif // LIBMESH_THREADS_NONE_H
Simple compatibility class for std::thread &#39;concurrent&#39; execution.
Definition: threads.h:113
void parallel_for(const Range &range, const Body &body, unsigned int n_threads=libMesh::n_threads())
Execute the provided function object in parallel on the specified range.
Definition: threads_none.h:73
unsigned int n_threads()
Definition: libmesh_base.h:109
We use a class to turn Threads::in_threads on and off, to be exception-safe.
Definition: threads.h:65
Dummy "splitting object" used to distinguish splitting constructors from copy constructors.
Definition: threads_none.h:63
The libMesh namespace provides an interface to certain functionality in the library.
bool in_threads
A boolean which is true iff we are in a Threads:: function It may be useful to assert(!Threadsin_thre...
Definition: threads.C:33
The Partitioner class provides a uniform interface for partitioning algorithms.
Definition: partitioner.h:51
void parallel_reduce(const Range &range, Body &body, unsigned int n_threads=libMesh::n_threads())
Execute the provided reduction operation in parallel on the specified range.
Definition: threads_none.h:109
Defines atomic operations which can only be executed on a single thread at a time.
Definition: threads_none.h:188
Scheduler to manage threads.
Definition: threads_none.h:48
NonConcurrentThread Thread
Use the non-concurrent placeholder.
Definition: threads_none.h:43