]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/compute/example/longest_vector.cpp
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
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
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
14 #include <boost/compute/algorithm/max_element.hpp>
15 #include <boost/compute/container/vector.hpp>
16 #include <boost/compute/functional/geometry.hpp>
17 #include <boost/compute/iterator/transform_iterator.hpp>
18 #include <boost/compute/types/fundamental.hpp>
20 namespace compute
= boost::compute
;
22 // this example shows how to use the max_element() algorithm along with
23 // a transform_iterator and the length() function to find the longest
24 // 4-component vector in an array of vectors
27 using compute::float4_
;
30 float data
[] = { 1.0f
, 2.0f
, 3.0f
, 0.0f
,
31 4.0f
, 5.0f
, 6.0f
, 0.0f
,
32 7.0f
, 8.0f
, 9.0f
, 0.0f
,
33 0.0f
, 0.0f
, 0.0f
, 0.0f
};
35 // create device vector with the vector data
36 compute::vector
<float4_
> vector(
37 reinterpret_cast<float4_
*>(data
),
38 reinterpret_cast<float4_
*>(data
) + 4
41 // find the longest vector
42 compute::vector
<float4_
>::const_iterator iter
=
44 compute::make_transform_iterator(
45 vector
.begin(), compute::length
<float4_
>()
47 compute::make_transform_iterator(
48 vector
.end(), compute::length
<float4_
>()
52 // print the index of the longest vector
53 std::cout
<< "longest vector index: "
54 << std::distance(vector
.begin(), iter
)