Thrust
|
◆ gather() [1/2]
template<typename DerivedPolicy , typename InputIterator , typename RandomAccessIterator , typename OutputIterator >
The algorithm's execution is parallelized as determined by
The following code snippet demonstrates how to use #include <thrust/gather.h> #include <thrust/device_vector.h> #include <thrust/execution_policy.h> ... // mark even indices with a 1; odd indices with a 0 int values[10] = {1, 0, 1, 0, 1, 0, 1, 0, 1, 0}; thrust::device_vector<int> d_values(values, values + 10); // gather all even indices into the first half of the range // and odd indices to the last half of the range int map[10] = {0, 2, 4, 6, 8, 1, 3, 5, 7, 9}; thrust::device_vector<int> d_map(map, map + 10); thrust::device_vector<int> d_output(10); d_map.begin(), d_map.end(), d_values.begin(), d_output.begin()); // d_output is now {1, 1, 1, 1, 1, 0, 0, 0, 0, 0} |