forked from boostorg/compute
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperf_mersenne_twister.cpp
48 lines (38 loc) · 1.41 KB
/
perf_mersenne_twister.cpp
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//---------------------------------------------------------------------------//
// Copyright (c) 2013-2014 Kyle Lutz <[email protected]>
//
// Distributed under the Boost Software License, Version 1.0
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
//
// See http://kylelutz.github.com/compute for more information.
//---------------------------------------------------------------------------//
#include <algorithm>
#include <iostream>
#include <vector>
#include <boost/compute/system.hpp>
#include <boost/compute/container/vector.hpp>
#include <boost/compute/random/mersenne_twister_engine.hpp>
#include "perf.hpp"
namespace compute = boost::compute;
int main(int argc, char *argv[])
{
perf_parse_args(argc, argv);
std::cout << "size: " << PERF_N << std::endl;
// setup context and queue for the default device
compute::device device = compute::system::default_device();
compute::context context(device);
compute::command_queue queue(context, device);
// create vector on the device
compute::vector<unsigned int> vector(PERF_N, context);
// create mersenne twister engine
compute::mt19937 rng(queue);
// generate random numbers
perf_timer t;
t.start();
rng.generate(vector.begin(), vector.end(), queue);
queue.finish();
t.stop();
std::cout << "time: " << t.last_time() / 1e6 << " ms" << std::endl;
return 0;
}