-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathSaxpyLoop.java
More file actions
31 lines (26 loc) · 801 Bytes
/
Copy pathSaxpyLoop.java
File metadata and controls
31 lines (26 loc) · 801 Bytes
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
public class SaxpyLoop {
public static void main(String []args) {
int N = 1 << 26;
float XVAL = (float)(10 * Math.random());
float YVAL = (float)(10 * Math.random());
float AVAL = (float)(10 * Math.random());
float[] x = new float[N];
float[] y = new float[N];
System.out.println("N: " + N);
for (int i=0; i<N; i++) {
x[i] = XVAL;
y[i] = YVAL;
}
double startTime = System.nanoTime();
for (int i=0; i<N; i++) {
y[i] += AVAL * x[i];
}
double endTime = System.nanoTime();
System.out.println("Elapsed: " + (endTime - startTime) / 1000000.0 + " ms");
float error = 0;
for (int i=0; i<N; i++) {
error += Math.abs(y[i] - (YVAL + AVAL * XVAL));
}
System.out.println("Error: " + error);
}
}