-
Notifications
You must be signed in to change notification settings - Fork 367
/
Copy pathmain.cpp
58 lines (44 loc) · 1.51 KB
/
main.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
57
58
#include <iostream>
#include <cstdlib>
#include <chrono>
#include "matoperation.hpp"
using namespace std;
#define TIME_START start=std::chrono::steady_clock::now();
#define TIME_END(NAME) end=std::chrono::steady_clock::now(); \
duration=std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count();\
cout<<(NAME)<<": result="<<result \
<<", duration = "<<duration<<"ms"<<endl;
int main(int argc, char ** argv)
{
size_t nSize = 200000000;
float * p1 = new float[nSize](); //the memory is not aligned
float * p2 = new float[nSize](); //the memory is not aligned
// // 256bits aligned, C++17 standard
// float * p1 = static_cast<float*>(aligned_alloc(256, nSize*sizeof(float)));
// float * p2 = static_cast<float*>(aligned_alloc(256, nSize*sizeof(float)));
float result = 0.0f;
p1[2] = 2.3f;
p2[2] = 3.0f;
p1[nSize-1] = 2.0f;
p2[nSize-1] = 1.1f;
auto start = std::chrono::steady_clock::now();
auto end = std::chrono::steady_clock::now();
auto duration = 0L;
result = dotproduct(p1, p2, nSize);
result = dotproduct(p1, p2, nSize);
TIME_START
result = dotproduct(p1, p2, nSize);
TIME_END("normal")
TIME_START
result = dotproduct_unloop(p1, p2, nSize);
TIME_END("unloop")
TIME_START
result = dotproduct_neon(p1, p2, nSize);
TIME_END("SIMD")
TIME_START
result = dotproduct_neon_omp(p1, p2, nSize);
TIME_END("SIMD+OpenMP")
delete []p1;
delete []p2;
return 0;
}