34 lines
806 B
Plaintext
34 lines
806 B
Plaintext
|
|
#include <thrust/copy.h>
|
||
|
|
#include <thrust/device_vector.h>
|
||
|
|
#include <thrust/fill.h>
|
||
|
|
#include <thrust/host_vector.h>
|
||
|
|
#include <thrust/sequence.h>
|
||
|
|
|
||
|
|
#include <iostream>
|
||
|
|
|
||
|
|
int main()
|
||
|
|
{
|
||
|
|
// initialize all ten integers of a device_vector to 1
|
||
|
|
thrust::device_vector<int> D(10, 1);
|
||
|
|
|
||
|
|
// set the first seven elements of a vector to 9
|
||
|
|
thrust::fill(D.begin(), D.begin() + 7, 9);
|
||
|
|
|
||
|
|
// initialize a host_vector with the first five elements of D
|
||
|
|
thrust::host_vector<int> H(D.begin(), D.begin() + 5);
|
||
|
|
|
||
|
|
// set the elements of H to 0, 1, 2, 3, ...
|
||
|
|
thrust::sequence(H.begin(), H.end());
|
||
|
|
|
||
|
|
// copy all of H back to the beginning of D
|
||
|
|
thrust::copy(H.begin(), H.end(), D.begin());
|
||
|
|
|
||
|
|
// print D
|
||
|
|
for (size_t i = 0; i < D.size(); i++)
|
||
|
|
{
|
||
|
|
std::cout << "D[" << i << "] = " << D[i] << '\n';
|
||
|
|
}
|
||
|
|
|
||
|
|
return 0;
|
||
|
|
}
|