threefry_engine.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. //---------------------------------------------------------------------------//
  2. // Copyright (c) 2013 Muhammad Junaid Muzammil <mjunaidmuzammil@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://kylelutz.github.com/compute for more information.
  9. //---------------------------------------------------------------------------//
  10. #include <boost/compute/random/threefry_engine.hpp>
  11. #include <boost/compute/container/vector.hpp>
  12. #include <boost/compute/command_queue.hpp>
  13. #include <boost/compute/context.hpp>
  14. #include <boost/compute/device.hpp>
  15. #include <boost/compute/system.hpp>
  16. #include <iostream>
  17. int main()
  18. {
  19. using boost::compute::uint_;
  20. boost::compute::device device = boost::compute::system::default_device();
  21. boost::compute::context context(device);
  22. boost::compute::command_queue queue(context, device);
  23. boost::compute::threefry_engine<> rng(queue);
  24. boost::compute::vector<uint_> vector_ctr(20, context);
  25. uint32_t ctr[20];
  26. for(int i = 0; i < 10; i++) {
  27. ctr[i*2] = i;
  28. ctr[i*2+1] = 0;
  29. }
  30. boost::compute::copy(ctr, ctr+20, vector_ctr.begin(), queue);
  31. rng.generate(vector_ctr.begin(), vector_ctr.end(), queue);
  32. boost::compute::copy(vector_ctr.begin(), vector_ctr.end(), ctr, queue);
  33. for(int i = 0; i < 10; i++) {
  34. std::cout << std::hex << ctr[i*2] << " " << ctr[i*2+1] << std::endl;
  35. }
  36. return 0;
  37. }