-
Notifications
You must be signed in to change notification settings - Fork 2
/
acc.cpp
50 lines (43 loc) · 1.03 KB
/
acc.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
49
50
/**
* Copyright 2020 RICOS Co. Ltd.
*
* This file is a part of ricosjp/allgebra, distributed under Apache-2.0 License
* https://github.com/ricosjp/allgebra
*/
#include <cstdlib> // atoi, malloc
#include <iostream>
int main(int argc, char **argv) {
int size = 0;
if (argc == 2) {
size = std::atoi(argv[1]);
} else {
std::cout << "error, $1 is vector size" << std::endl;
return 1;
}
double *x = (double *)malloc(sizeof(double) * size);
double *y = (double *)malloc(sizeof(double) * size);
for (int i = 0; i < size; i++) {
x[i] = 1.0;
y[i] = 2.0;
}
double dot = 0.0;
#pragma acc data copy(x [0:size], y [0:size])
{
#pragma acc kernels
{
#pragma acc loop reduction(+ : dot)
for (int i = 0; i < size; i++) {
dot += x[i] * y[i];
}
}
}
if (dot != 2.0 * size) {
std::cout << "dot = " << dot << std::endl;
std::cout << "error!" << std::endl;
return 1;
} else {
std::cout << "dot = " << dot << std::endl;
std::cout << "Pass!" << std::endl;
return 0;
}
}