libMesh
Loading...
Searching...
No Matches
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
34namespace libMesh
35{
36
37namespace Threads
38{
39
44
49{
50public:
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
63class split {};
64
65
66
71template <typename Range, typename Body>
72inline
73void 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
89template <typename Range, typename Body, typename Partitioner>
90inline
91void 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
107template <typename Range, typename Body>
108inline
109void 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
125template <typename Range, typename Body, typename Partitioner>
126inline
127void 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{
145public:
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{
168public:
170
172 {
173 public:
175 explicit scoped_lock ( recursive_mutex & ) {}
177 void release () {}
178 };
179};
180
181
182
187template <typename T>
189{
190public:
191 atomic () : _val(0) {}
192 operator T & () { return _val; }
193private:
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
The Partitioner class provides a uniform interface for partitioning algorithms.
Definition partitioner.h:52
Simple compatibility class for std::thread 'concurrent' execution.
Definition threads.h:114
We use a class to turn Threads::in_threads on and off, to be exception-safe.
Definition threads.h:66
Defines atomic operations which can only be executed on a single thread at a time.
Dummy "splitting object" used to distinguish splitting constructors from copy constructors.
Scheduler to manage threads.
bool in_threads
A boolean which is true iff we are in a Threads:: function It may be useful to assert(!...
Definition threads.C:33
NonConcurrentThread Thread
Use the non-concurrent placeholder.
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.
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.
The libMesh namespace provides an interface to certain functionality in the library.
unsigned int n_threads()