Something like this:
thrust::device_vector<int> myvector(N);
thrust::transform( thrust::make_counting_iterator(0),
thrust::make_counting_iterator(N),
thrust::make_constant_iterator(3),
myvector.begin(),
thrust::divides<int>() );
(disclaimer, written in browser, never compiled or tested, use at own risk)
should give you the sequence you are looking for by computing [0..N]//3
and outputting the result on myvector
.
Seeing as you are having trouble compiling your version, here is a complete example which compiles and runs:
#include <thrust/device_vector.h>
#include <thrust/transform.h>
#include <thrust/functional.h>
#include <thrust/iterator/counting_iterator.h>
#include <thrust/iterator/constant_iterator.h>
#include <cstdio>
int main(void)
{
const int N = 18, M = 3;
thrust::device_vector<int> myvector(N);
thrust::transform( thrust::make_counting_iterator(0),
thrust::make_counting_iterator(N),
thrust::make_constant_iterator(M),
myvector.begin(),
thrust::divides<int>() );
for(int i=0; i<N; i++) {
int val = myvector[i];
printf("%d %d
", i, val);
}
return 0;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…