thrust::device_vector values
thrust::device_vector keys;
after initialization, keys contains elements equal -1. wanted delete elements in keys , in same position of values.
but not know how deal parallel?
there many ways this. 1 possible way:
- use stencil version of
thrust::remove_if
(documentation), keys stencil, removing elements in values corresponding key -1. need create functor predicate test. - use
thrust::remove
(documentation) on keys remove values -1
here's example:
#include <iostream> #include <thrust/device_vector.h> #include <thrust/copy.h> #include <thrust/remove.h> #include <thrust/sequence.h> #define n 12 typedef thrust::device_vector<int>::iterator dintiter; struct is_minus_one { __host__ __device__ bool operator()(const int x) { return (x == -1); } }; int main(){ thrust::device_vector<int> keys(n); thrust::device_vector<int> values(n); thrust::sequence(keys.begin(), keys.end()); thrust::sequence(values.begin(), values.end()); keys[3] = -1; keys[9] = -1; dintiter nve = thrust::remove_if(values.begin(), values.end(), keys.begin(), is_minus_one()); dintiter nke = thrust::remove(keys.begin(), keys.end(), -1); std::cout << "results values:" << std::endl; thrust::copy(values.begin(), nve, std::ostream_iterator<int>( std::cout, " ")); std::cout << std::endl << "results keys:" << std::endl; thrust::copy(keys.begin(), nke, std::ostream_iterator<int>( std::cout, " ")); std::cout << std::endl; return 0; }
Comments
Post a Comment