Slide 6
Slide 6 text
Hello VexCL: vector sum
1 #include
2 #include
3 #include
4
5 int main() {
6 const size t n = 1024 ∗ 1024;
7
8 // Get compute devices supporting double precision:
9 vex :: Context ctx(vex :: Filter :: DoublePrecision );
10 if (!ctx) throw std:: runtime error (”No compute devices available”);
11
12 // Prepare input data, transfer it to the device(s):
13 std :: vector a(n, 1), b(n, 2), c(n);
14 vex :: vector A(ctx, a), B(ctx, b), C(ctx, n);
15
16 // Launch compute kernel:
17 C = A + B;
18
19 // Get result back to host:
20 vex :: copy(C, c);
21 std :: cout << c[42] << std::endl;
22 }