-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparallel2,2.cpp
More file actions
34 lines (33 loc) · 966 Bytes
/
Copy pathparallel2,2.cpp
File metadata and controls
34 lines (33 loc) · 966 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
32
33
34
#include<iostream>
#include<windows.h>
using namespace std;
int a[1001][1101];
int b[1101];
int sum;
inline int recursion(int n) {
if (n == 1) return b[1];
for (int i = 1; i <= n / 2; i++) {
b[i] += b[n - i + 1];
}
recursion(n / 2);
}
int ans = 0;
int main()
{
LARGE_INTEGER head, tail, freq; // timers
QueryPerformanceFrequency(&freq);
QueryPerformanceCounter(&head);
int n = 128; //此处的n为数据规模;
for (int k = 1; k <= 5; k++) {
sum = 0;
for (int i = 1; i <= n; i++) b[i] = i;
ans = recursion(n);
}
cout << "the result is " << ans << endl;
QueryPerformanceCounter(&tail);
int second_time = (double)(tail.QuadPart - head.QuadPart) * 1.00 / (double)(freq.QuadPart);
int micro_time = (double)(tail.QuadPart - head.QuadPart) / (double)(freq.QuadPart) * 1e6;
cout << "The total time of the project is :" << second_time << " s and " << micro_time << " ms" << endl;
system("pause");
return 0;
}