forked from sysprog21/prefetcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculate.c
88 lines (73 loc) · 3.06 KB
/
calculate.c
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
/* original version */
FILE *output = fopen("local/output.txt", "w");
FILE *fp = fopen("local/NAIVE_TRANSPOSE.txt", "r");
int i = 0;
char stringA[20], stringB [20];
long int naive_transpose_sum_a = 0.0, naive_transpose_a;
for (i = 0; i < 20; i++) {
if (feof(fp)) {
printf("ERROR: You need 20 datum instead of %d\n", i);
printf("run 'make run' longer to get enough information\n\n");
exit(0);
}
fscanf(fp, "%s %s %ld \n", stringA, stringB , &naive_transpose_a);
naive_transpose_sum_a += naive_transpose_a;
}
fclose(fp);
fp = fopen("local/SSE_TRANSPOSE.txt", "r");
long int sse_transpose_sum_a = 0.0, sse_transpose_a;
for (i = 0; i < 20; i++) {
if (feof(fp)) {
printf("ERROR: You need 20 datum instead of %d\n", i);
printf("run 'make run' longer to get enough information\n\n");
exit(0);
}
fscanf(fp, "%s %s %ld \n", stringA, stringB , &sse_transpose_a);
sse_transpose_sum_a += sse_transpose_a;
}
fclose(fp);
fp = fopen("local/SSE_PREFETCH_TRANSPOSE.txt", "r");
long int sse_prefetch_transpose_sum_a = 0.0, sse_prefetch_transpose_a;
for (i = 0; i < 20; i++) {
if (feof(fp)) {
printf("ERROR: You need 20 datum instead of %d\n", i);
printf("run 'make run' longer to get enough information\n\n");
exit(0);
}
fscanf(fp, "%s %s %ld \n", stringA, stringB , &sse_prefetch_transpose_a);
sse_prefetch_transpose_sum_a += sse_prefetch_transpose_a;
}
fclose(fp);
fp = fopen("local/AVX_TRANSPOSE.txt", "r");
long int avx_transpose_sum_a = 0.0, avx_transpose_a;
for (i = 0; i < 20; i++) {
if (feof(fp)) {
printf("ERROR: You need 20 datum instead of %d\n", i);
printf("run 'make run' longer to get enough information\n\n");
exit(0);
}
fscanf(fp, "%s %s %ld \n", stringA, stringB , &avx_transpose_a);
avx_transpose_sum_a += avx_transpose_a;
}
fclose(fp);
fp = fopen("local/AVX_PREFETCH_TRANSPOSE.txt", "r");
long int avx_prefetch_transpose_sum_a = 0.0, avx_prefetch_transpose_a;
for (i = 0; i < 20; i++) {
if (feof(fp)) {
printf("ERROR: You need 20 datum instead of %d\n", i);
printf("run 'make run' longer to get enough information\n\n");
exit(0);
}
fscanf(fp, "%s %s %ld \n", stringA, stringB , &avx_prefetch_transpose_a);
avx_prefetch_transpose_sum_a += avx_prefetch_transpose_a;
}
fclose(fp);
fprintf(output, "time: %ld %ld %ld %ld %ld\n", naive_transpose_sum_a / 20, sse_transpose_sum_a / 20, sse_prefetch_transpose_sum_a / 20, avx_transpose_sum_a / 20, avx_prefetch_transpose_sum_a / 20);
printf("time: %ld %ld %ld %ld %ld\n", naive_transpose_sum_a / 20, sse_transpose_sum_a / 20, sse_prefetch_transpose_sum_a / 20,avx_transpose_sum_a / 20, avx_prefetch_transpose_sum_a / 20);
fclose(output);
return 0;
}