-
Notifications
You must be signed in to change notification settings - Fork 1
/
dot.cpp
56 lines (47 loc) · 826 Bytes
/
dot.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
51
52
53
54
55
56
//
//
//
#include "cstdio"
using namespace std;
//template <class T>
typedef float T;
T dot(T const *A, T const *B, size_t N)
{
//#pragma ivdep
//#pragma simd
T s = 0;
for(size_t i = 0 ; i != N ; ++i) {
s += A[i] * B[i];
}
return s;
}
// template<class T>
T *one(size_t n)
{
T *data = new T[n];
data += n;
while(n--)
*--data = (T)1;
return data;
}
#include "timer.h"
int main()
{
{
int N = 1000000;
float *A = one(N);
float *B = one(N);
Timer t;
t.start();
auto r = dot(A, B, N);
t.stop();
printf("dot = %g\n", (double)r);
printf("Elapsed: %g sec.\n", t.elapsed());
}
}
// Local Variables:
// mode: c++
// c-basic-offset: 4
// tab-width: 4
// indent-tabs-mode: nil
// End: