-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
75 lines (59 loc) · 2.09 KB
/
main.c
File metadata and controls
75 lines (59 loc) · 2.09 KB
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
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include "matrixUtil.h"
#include "naive.h"
#include "msrUtil.h"
#define N_INDEX 1
#define M1_INDEX 2
#define M2_INDEX 3
#define ANSWER_INDEX 4
#define DEBUG_INDEX 5
int main( int argc, char *argv[] )
{
int N, correct, debug, fd;
//double exetime;
//struct timeval start, end;
struct msr_batch_array read_batch, write_batch, zero_batch;
struct msr_batch_op start_op[ NUM_READ_MSRS ], stop_op[ NUM_READ_MSRS ], write_op[ NUM_WRITE_MSRS ], zero_op[ NUM_ZERO_MSRS ];
struct msr_deltas deltas[1];
N = atoi( argv[ N_INDEX ] );
double *a = ( double * ) malloc( N * N * sizeof( double ));
double *b = ( double * ) malloc( N * N * sizeof( double ));
double *c = ( double * ) malloc( N * N * sizeof( double ));
double *answer = ( double * ) malloc( N * N * sizeof( double ));
readMatrixFromFile( argv[ M1_INDEX ], a );
readMatrixFromFile( argv[ M2_INDEX ], b );
readMatrixFromFile( argv[ ANSWER_INDEX ], answer );
debug = ( argc > 5 ) ? atoi( argv[ DEBUG_INDEX ] ) : 0 ;
// msr setup
fd = open_msr_fd();
write_batch.numops = NUM_WRITE_MSRS;
write_batch.ops = write_op;
read_batch.numops = NUM_READ_MSRS;
read_batch.ops = start_op;
zero_batch.numops = NUM_ZERO_MSRS;
zero_batch.ops = zero_op;
write_perf_count_off( fd, 1, &write_batch );
zero_counter( fd, 1, &zero_batch );
write_perf_count_on( fd, 1, &write_batch );
read_msrs( fd, 1, &read_batch );
//gettimeofday( &start, NULL );
naiveMultiply( N, a, b, c );
//gettimeofday( &end, NULL );
write_perf_count_off( fd, 1, &write_batch );
read_batch.ops = stop_op;
read_msrs( fd, 1, &read_batch );
get_msrdata( 1, start_op, stop_op, deltas );
print_msrdelta( 1, deltas );
//print_debug( 1, start_op, stop_op );
correct = checkAnswer( N, c, answer, debug );
// printf( "Answer is (%d): %s\n", correct, (correct? "correct" : "incorrect") );
//exetime = ( end.tv_sec * 1000000 + end.tv_usec ) - ( start.tv_sec * 1000000 + start.tv_usec );
// printf( "Execution time is %.0f microseconds\n", exetime );
free( a );
free( b );
free( c );
free( answer );
return 0;
}