print_vector.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. #include <iostream>
  11. #include <vector>
  12. #include <boost/compute/system.hpp>
  13. #include <boost/compute/algorithm/copy.hpp>
  14. #include <boost/compute/algorithm/iota.hpp>
  15. #include <boost/compute/container/vector.hpp>
  16. namespace compute = boost::compute;
  17. // this example demonstrates how to print the values in a vector
  18. int main()
  19. {
  20. // get default device and setup context
  21. compute::device gpu = compute::system::default_device();
  22. compute::context context(gpu);
  23. compute::command_queue queue(context, gpu);
  24. std::cout << "device: " << gpu.name() << std::endl;
  25. // create vector on the device and fill with the sequence 1..10
  26. compute::vector<int> vector(10, context);
  27. compute::iota(vector.begin(), vector.end(), 1, queue);
  28. //[print_vector_example
  29. std::cout << "vector: [ ";
  30. boost::compute::copy(
  31. vector.begin(), vector.end(),
  32. std::ostream_iterator<int>(std::cout, ", "),
  33. queue
  34. );
  35. std::cout << "]" << std::endl;
  36. //]
  37. return 0;
  38. }