ddemidov / vexcl
1
#define BOOST_TEST_MODULE Sort
2
#include <boost/thread.hpp>
3
#include <boost/test/unit_test.hpp>
4
#include <boost/ptr_container/ptr_vector.hpp>
5
#include <vexcl/vector.hpp>
6
#include <vexcl/reductor.hpp>
7
#include "context_setup.hpp"
8

9 6
BOOST_AUTO_TEST_CASE(threads)
10
{
11
    const size_t n = 1024 * 1024;
12

13
    auto run = [n](vex::backend::command_queue queue, cl_long *s) {
14 6
        std::vector<vex::backend::command_queue> q(1, queue);
15 6
        vex::vector<int> x(q, n);
16 6
        x = 1;
17 6
        vex::Reductor<cl_long, vex::SUM> sum(q);
18 6
        *s = sum(x);
19 6
    };
20

21 6
    boost::ptr_vector< boost::thread > threads;
22 6
    std::vector< cl_long       > results(ctx.size(), 0);
23

24 6
    for(unsigned d = 0; d < ctx.size(); ++d) {
25 6
        threads.push_back( new boost::thread(run, ctx.queue(d), &results[d]) );
26
    }
27

28 6
    cl_long sum = 0;
29 6
    for(unsigned d = 0; d < ctx.size(); ++d) {
30 6
        threads[d].join();
31 6
        sum += results[d];
32
    }
33

34 6
    BOOST_CHECK_EQUAL(sum, n * ctx.size());
35
}
36

37 6
BOOST_AUTO_TEST_SUITE_END()

Read our documentation on viewing source code .

Loading