6 #ifndef OPENMPCD_CUDA_BUNCHITERATORRANGE_HPP
7 #define OPENMPCD_CUDA_BUNCHITERATORRANGE_HPP
13 #include <thrust/functional.h>
14 #include <thrust/iterator/counting_iterator.h>
15 #include <thrust/iterator/permutation_iterator.h>
16 #include <thrust/iterator/transform_iterator.h>
38 template<
typename UnderlyingIterator>
44 typename thrust::iterator_difference<UnderlyingIterator>::type
53 :
public thrust::unary_function<IteratorDifference, IteratorDifference>
68 const unsigned int bunchSize_,
const unsigned int gapSize_)
69 : bunchSize(bunchSize_), gapSize(gapSize_)
90 unsigned int positionInBunch = 0;
91 for(
unsigned int remaining = i; remaining != 0; --remaining)
96 if(positionInBunch == bunchSize)
107 const unsigned int bunchSize;
108 const unsigned int gapSize;
112 typename thrust::counting_iterator<IteratorDifference>
116 typename thrust::transform_iterator<AdvancingFunctor, CountingIterator>
120 typename thrust::permutation_iterator<
141 const UnderlyingIterator& start,
const UnderlyingIterator& pastTheEnd_,
142 const unsigned int bunchSize_,
const unsigned int gapSize_)
143 : first(start), pastTheEnd(pastTheEnd_),
144 bunchSize(bunchSize_), gapSize(gapSize_)
173 if(underlyingRemaining <= bunchSize)
175 effectiveCount += underlyingRemaining;
179 effectiveCount += bunchSize;
180 underlyingRemaining -= bunchSize;
182 if(underlyingRemaining <= gapSize)
185 underlyingRemaining -= gapSize;
188 return begin() + effectiveCount;
192 UnderlyingIterator first;
193 UnderlyingIterator pastTheEnd;
194 const unsigned int bunchSize;
195 const unsigned int gapSize;
203 #endif //OPENMPCD_CUDA_BUNCHITERATORRANGE_HPP