-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex1_test.c
67 lines (56 loc) · 1.85 KB
/
ex1_test.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
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "ex1.h"
/* ***DON'T MODIFY THIS FILE! You should only need to modify simd.c!*** */
int main(int argc, char* argv[]) {
printf("Let's generate a randomized array.\n");
int vals[NUM_ELEMS];
long long int reference;
long long int simd;
long long int simdu;
for (unsigned int i = 0; i < NUM_ELEMS; i++) vals[i] = rand() % 256;
int success = 0;
printf("Starting randomized sum.\n");
clock_t start = clock();
reference = sum(vals);
clock_t end = clock();
printf("Sum: %lld\n\n", reference);
clock_t reft = end - start;
printf("Starting randomized unrolled sum.\n");
printf("Sum: %lld\n\n", sum_unrolled(vals));
printf("Starting randomized SIMD sum.\n");
start = clock();
simd = sum_simd(vals);
end = clock();
printf("Sum: %lld\n\n", simd);
clock_t simdt = end - start;
if (simd != reference) {
printf("Test Failed! SIMD sum %lld doesn't match reference sum %lld!\n\n", simd, reference);
success = 1;
}
if (reft <= simdt * 2) {
printf("Test Failed! SIMD sum provided less than 2X speedup.\n\n");
success = 1;
}
printf("Starting randomized SIMD unrolled sum.\n");
start = clock();
simdu = sum_simd_unrolled(vals);
end = clock();
printf("Sum: %lld\n\n", simdu);
clock_t simdut = end - start;
if (simdu != reference) {
printf("Test Failed! SIMD unrolled sum %lld doesn't match reference sum %lld!\n\n", simdu, reference);
success = 1;
}
if (simdt <= simdut) {
printf("Test Failed! SIMD unrolled function provided no speedup.\n\n");
success = 1;
}
if (!success) {
printf("All tests Passed! Correct values were produced, and speedups were achieved!\n\n");
return 0;
} else {
return 1;
}
}