-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
45 lines (39 loc) · 916 Bytes
/
test.cpp
File metadata and controls
45 lines (39 loc) · 916 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
35
36
37
38
39
40
41
42
43
44
#include <stdio.h>
#include <time.h>
#include <assert.h>
#include <random>
#include "matrix_mul.hpp"
void initialize(int **A, int **B, int **C, int n) {
printf("step 1\n");
*A = new int[n*n];
*B = new int[n*n];
*C = new int[n*n];
printf("step 2\n");
for (int i = 0; i < n; ++i){
for (int j = 0; j < n; ++j){
(*A)[index(i,j,n)] = 1;
(*B)[index(i,j,n)] = 1;
}
}
}
void verify(int *C, int n) {
assert(C[index(n/2,n/2,n)] == n);
srand (100);
for (int k = 0; k < 100; ++k) {
int i = rand()%n, j = rand()%n;
assert(C[index(i,j,n)] == n);
}
}
int main() {
int *A, *B, *C;
int n = 2048;
initialize(&A, &B, &C, n);
printf("step 3\n");
clock_t begin = clock();
multiply(A, B, C, n);
clock_t end = clock();
verify(C, n);
double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
printf("Elpased time %f seconds.\n", elapsed_secs);
return 0;
}