G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
gsThreaded.h
Go to the documentation of this file.
1
14#pragma once
15
16#ifdef _OPENMP
17#include <omp.h>
18#endif
19
20namespace gismo
21{
22
23namespace util
24{
25
26// Usage:
27// gsThreaded<C> a;
28// a.mine();
29template<class C, class Allocator = std::allocator<C> >
30class gsThreaded
31{
32#ifdef _OPENMP
33 std::vector<C,Allocator> m_array;
34 #else
35 C m_c;
36#endif
37
38public:
39
40#ifdef _OPENMP
41 gsThreaded() : m_array(omp_get_max_threads()) { }
42
44 operator C&() { return m_array[omp_get_thread_num()]; }
45 operator const C&() const { return m_array[omp_get_thread_num()]; }
46
48 C& mine() { return m_array[omp_get_thread_num()]; }
49 const C& mine() const { return m_array[omp_get_thread_num()]; }
50
52 C& operator = (C other) { return m_array[omp_get_thread_num()] = give(other); }
53#else
55 operator C&() { return m_c; }
56 operator const C&() const { return m_c; }
57
59 C& mine() { return m_c; }
60 const C& mine() const { return m_c; }
61
63 C& operator = (C other) { return m_c = give(other); }
64#endif
65
66};//gsThreaded
67
68}//util
69
70}//gismo
The G+Smo namespace, containing all definitions for the library.
S give(S &x)
Definition gsMemory.h:266
This namespace gathers several utility functions for miscellaneous tasks.