13#ifdef TTK_ENABLE_OPENMP
19#ifndef TTK_ENABLE_KAMIKAZE
25 template <
typename type>
32 : std::vector<type>(), nextId(0) {
33#ifndef TTK_ENABLE_KAMIKAZE
35 std::cout <<
"Caution, Atomic vector need a non-0 init size !"
37 std::vector<type>::resize(initSize);
41 std::vector<type>::resize(initSize);
47 : std::vector<type>(other), nextId(other.nextId) {
48#ifndef TTK_ENABLE_KAMIKAZE
49 if(!std::vector<type>::size()) {
64 void reserve(
const std::size_t &newSize,
const bool fromOther =
false) {
65 if(newSize > std::vector<type>::size()) {
66#ifndef TTK_ENABLE_KAMIKAZE
67#ifdef TTK_ENABLE_OPENMP
68 if(omp_in_parallel()) {
71#pragma omp critical(AtomicUFReserve)
79 std::vector<type>::resize(newSize);
86 std::vector<type>::resize(newSize);
92 void reset(
const std::size_t &nId = 0) {
93#ifdef TTK_ENABLE_OPENMP
94#pragma omp atomic write
103 std::size_t oldSize = std::vector<type>::size();
104 std::vector<type>::clear();
110#ifdef TTK_ENABLE_OPENMP
111#pragma omp atomic capture
115 if(nextId == std::vector<type>::size()) {
116 reserve(std::vector<type>::size() * 2,
true);
131 const auto &curPos =
getNext();
132 (*this)[curPos] = elmt;
138 const auto &curPos =
getNext();
139 (*this)[curPos] = elmt;
143#ifdef TTK_ENABLE_OPENMP
144#pragma omp atomic update
155 std::vector<type>::operator=(other);
156 nextId = other.nextId;
162 nextId = std::move(other.nextId);
163 std::vector<type>::operator=(std::move(other));
172 using iterator =
typename std::vector<type>::iterator;
176 return this->
begin() + nextId;
180 return this->
begin() + nextId;
184 return this->cbegin() + nextId;
187 using riterator =
typename std::vector<type>::reverse_iterator;
191 return this->rend() - (nextId - 1);
195 return this->rend() - (nextId - 1);
199 return this->crend() - (nextId - 1);
#define TTK_FORCE_USE(x)
Force the compiler to use the function/method parameter.
TTK processing package that manage a parallel version of vector Same as in FTM: Common ?
virtual ~FTRAtomicVector()=default
void reserve(const std::size_t &newSize, const bool fromOther=false)
FTRAtomicVector< type > & operator=(const FTRAtomicVector< type > &other)
void push_back(const type &elmt)
void reset(const std::size_t &nId=0)
FTRAtomicVector(const FTRAtomicVector &other)
typename std::vector< type >::const_iterator const_iterator
const_riterator crbegin() const
FTRAtomicVector< type > & operator=(FTRAtomicVector< type > &&other) noexcept
const_riterator rbegin() const
FTRAtomicVector(const std::size_t initSize=1)
FTRAtomicVector(FTRAtomicVector &&other) noexcept=default
void emplace_back(const type &elmt)
typename std::vector< type >::const_reverse_iterator const_riterator
const_iterator end() const
typename std::vector< type >::iterator iterator
typename std::vector< type >::reverse_iterator riterator
const_iterator cend() const
T begin(std::pair< T, T > &p)