criptic v1
Cosmic Ray Interstellar Propagation Tool using Itô Calculus
Loading...
Searching...
No Matches
ThreadVec.H
Go to the documentation of this file.
1
12#ifndef THREADVEC_H_
13#define THREADVEC_H_
14
15#include <vector>
16#ifdef _OPENMP
17# include <omp.h>
18#endif
19#include "Types.H"
20
21namespace criptic {
22
35 template <class T> class ThreadVec {
36
37 public:
38
43#ifdef _OPENMP
44#pragma omp parallel
45 {
46 const int nthreads = omp_get_num_threads();
47#pragma omp single
48 obj.resize(nthreads);
49 }
50#else
51 obj.resize(1);
52#endif
53 }
54
59 IdxType size() const { return obj.size(); }
60
67#ifdef _OPENMP
68 const int ithread = omp_get_thread_num();
69#else
70 const int ithread = 0;
71#endif
72 return obj[ithread];
73 }
74
80 const T& operator()() const {
81#ifdef _OPENMP
82 const int ithread = omp_get_thread_num();
83#else
84 const int ithread = 0;
85#endif
86 return obj[ithread];
87 }
88
95 T& operator[] (const int i) {
96 return obj[i];
97 }
98
105 const T& operator[] (const int i) const {
106 return obj[i];
107 }
108
109 private:
110
111 std::vector<T> obj;
113 };
114
115}
116
117#endif
118// _THREADVEC_H_
Basic integer and real types.
A class to automate private thread copies of objects.
Definition ThreadVec.H:35
T & operator()()
Return the element private to this thread.
Definition ThreadVec.H:66
T & operator[](const int i)
Return the object belonging to the specified thread.
Definition ThreadVec.H:95
ThreadVec()
Construct an empty threadvec.
Definition ThreadVec.H:42
std::vector< T > obj
Definition ThreadVec.H:111
const T & operator()() const
Return the element private to this thread.
Definition ThreadVec.H:80
IdxType size() const
Return the number of distinct objects stored.
Definition ThreadVec.H:59
The primary namespace for criptic objects.
Definition AdvancePacket.H:25
std::vector< Real >::size_type IdxType
Definition Types.H:45