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 <algorithm> 12 #include <iostream> 13 #include <numeric> 14 #include <vector> 15 16 #include <boost/compute/system.hpp> 17 18 #include "perf.hpp" 19 rand_int()20int rand_int() 21 { 22 return static_cast<int>((rand() / double(RAND_MAX)) * 25.0); 23 } 24 main(int argc,char * argv[])25int main(int argc, char *argv[]) 26 { 27 using boost::compute::int_; 28 29 perf_parse_args(argc, argv); 30 31 std::cout << "size: " << PERF_N << std::endl; 32 33 // create vector of random numbers on the host 34 std::vector<int_> v(PERF_N); 35 std::vector<int_> r(PERF_N); 36 37 perf_timer t; 38 for(size_t trial = 0; trial < PERF_TRIALS; trial++){ 39 std::generate(v.begin(), v.end(), rand_int); 40 t.start(); 41 std::partial_sum( 42 v.begin(), 43 v.end(), 44 r.begin() 45 ); 46 t.stop(); 47 } 48 std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl; 49 50 return 0; 51 } 52