PolyFEM
Loading...
Searching...
No Matches
par_for.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include <functional>
4
#include <thread>
5
6
#include <Eigen/Core>
7
8
#ifdef POLYFEM_WITH_TBB
9
#include <tbb/global_control.h>
10
#endif
11
12
namespace
polyfem
13
{
14
namespace
utils
15
{
16
class
NThread
17
{
18
public
:
19
static
NThread
&
get
()
20
{
21
static
NThread
instance;
22
return
instance;
23
}
24
25
inline
size_t
num_threads
()
const
{
return
num_threads_
; }
26
27
void
set_num_threads
(
const
int
max_threads
)
28
{
29
const
unsigned
int
tmp =
max_threads <= 0 ? std::numeric_limits<int>::max
() :
max_threads
;
30
const
unsigned
int
num_threads
= std::min(tmp, std::thread::hardware_concurrency());
31
32
num_threads_
=
num_threads
;
33
#ifdef POLYFEM_WITH_TBB
34
thread_limiter
= std::make_shared<tbb::global_control>(tbb::global_control::max_allowed_parallelism,
num_threads
);
35
#endif
36
Eigen::setNbThreads(
num_threads
);
37
}
38
39
private
:
40
NThread
() {}
41
42
size_t
num_threads_
;
43
44
#ifdef POLYFEM_WITH_TBB
46
std::shared_ptr<tbb::global_control>
thread_limiter
;
47
#endif
48
};
49
50
void
par_for
(
const
int
size,
const
std::function<
void
(
int
,
int
,
int
)> &func);
51
inline
size_t
get_n_threads
() {
return
NThread::get
().
num_threads
(); }
52
}
// namespace utils
53
}
// namespace polyfem
polyfem::utils::NThread
Definition
par_for.hpp:17
polyfem::utils::NThread::get
static NThread & get()
Definition
par_for.hpp:19
polyfem::utils::NThread::num_threads
size_t num_threads() const
Definition
par_for.hpp:25
polyfem::utils::NThread::num_threads_
size_t num_threads_
Definition
par_for.hpp:42
polyfem::utils::NThread::NThread
NThread()
Definition
par_for.hpp:40
polyfem::utils::NThread::set_num_threads
void set_num_threads(const int max_threads)
Definition
par_for.hpp:27
polyfem::utils::par_for
void par_for(const int size, const std::function< void(int, int, int)> &func)
Definition
par_for.cpp:10
polyfem::utils::get_n_threads
size_t get_n_threads()
Definition
par_for.hpp:51
polyfem
Definition
ActiveFiber.cpp:4
src
polyfem
utils
par_for.hpp
Generated by
1.9.8