本文共 1285 字,大约阅读时间需要 4 分钟。
#include#include #include ...// mark even indices with a 1; odd indices with a 0int values[10] = {1, 0, 1, 0, 1, 0, 1, 0, 1, 0};thrust::device_vector d_values(values, values + 10);// scatter all even indices into the first half of the// range, and odd indices vice versaint map[10] = {0, 5, 1, 6, 2, 7, 3, 8, 4, 9};thrust::device_vector d_map(map, map + 10);thrust::device_vector d_output(10);thrust::scatter(thrust::device, d_values.begin(), d_values.end(), d_map.begin(), d_output.begin());// d_output is now {1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
#include#include #include ...// mark even indices with a 1; odd indices with a 0int values[10] = {1, 0, 1, 0, 1, 0, 1, 0, 1, 0};thrust::device_vector 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 rangeint map[10] = {0, 2, 4, 6, 8, 1, 3, 5, 7, 9};thrust::device_vector d_map(map, map + 10);thrust::device_vector d_output(10);thrust::gather(thrust::device, 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}