]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/compute/example/host_sort.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / compute / example / host_sort.cpp
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
3 //
4 // Distributed under the Boost Software License, Version 1.0
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
7 //
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
10
11 #include <iostream>
12 #include <vector>
13
14 #include <boost/spirit/include/karma.hpp>
15
16 #include <boost/compute/system.hpp>
17 #include <boost/compute/algorithm/sort.hpp>
18
19 namespace compute = boost::compute;
20 namespace karma = boost::spirit::karma;
21
22 int rand_int()
23 {
24 return rand() % 100;
25 }
26
27 // this example demonstrates how to sort a std::vector of ints on the GPU
28 int main()
29 {
30 // get default device and setup context
31 compute::device gpu = compute::system::default_device();
32 compute::context context(gpu);
33 compute::command_queue queue(context, gpu);
34 std::cout << "device: " << gpu.name() << std::endl;
35
36 // create vector of random values on the host
37 std::vector<int> vector(8);
38 std::generate(vector.begin(), vector.end(), rand_int);
39
40 // print input vector
41 std::cout << "input: [ "
42 << karma::format(karma::int_ % ", ", vector)
43 << " ]"
44 << std::endl;
45
46 // sort vector
47 compute::sort(vector.begin(), vector.end(), queue);
48
49 // print sorted vector
50 std::cout << "output: [ "
51 << karma::format(karma::int_ % ", ", vector)
52 << " ]"
53 << std::endl;
54
55 return 0;
56 }