File: constant_iterator.cu

package info (click to toggle)
rocthrust 5.7.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 12,520 kB
  • sloc: cpp: 59,115; ansic: 34,558; python: 1,474; sh: 332; xml: 200; makefile: 114
file content (29 lines) | stat: -rw-r--r-- 721 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <thrust/iterator/constant_iterator.h>
#include <thrust/transform.h>
#include <thrust/functional.h>
#include <thrust/device_vector.h>
#include <thrust/copy.h> 
#include <iterator>
#include <iostream>

int main(void)
{
    thrust::device_vector<int> data(4);
    data[0] = 3;
    data[1] = 7;
    data[2] = 2;
    data[3] = 5;

    // add 10 to all values in data
    thrust::transform(data.begin(), data.end(),
                      thrust::constant_iterator<int>(10),
                      data.begin(),
                      thrust::plus<int>());

    // data is now [13, 17, 12, 15]

    // print result
    thrust::copy(data.begin(), data.end(), std::ostream_iterator<int>(std::cout, "\n"));

    return 0;
}