-
Notifications
You must be signed in to change notification settings - Fork 0
/
minitest_daub8.c
159 lines (134 loc) · 5.21 KB
/
minitest_daub8.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/* This file is part of pawt.
*
* Calling program for the 2D Daubechies D8 transform dda8mt2.
*
* Copyright 2018 LIPN, CNRS UMR 7030, Université Paris 13,
* Sorbonne-Paris-Cité. All rights reserved.
* Author: see AUTHORS
* Licence: GPL-3.0, see COPYING for details.
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef WITHPAPI
#include <papi.h>
#endif
#include "matrices.h"
/* If PAPI does not work (indicates 0 counters):
echo 0 > /proc/sys/kernel/perf_event_paranoid
*/
#define NUMRUN 1
#define DEFAULTM 8
#define DEFAULTN 8
void DDA8MT( double* restrict A, double* restrict B, double* restrict W, int M, int N, int lda, int ldb );
#ifndef WITHPAPI
extern __inline__ long long rdtsc(void) {
long long a, d;
__asm__ volatile ("rdtsc" : "=a" (a), "=d" (d));
return (d<<32) | a;
}
#endif
int main( int argc, char** argv ){
int M, N;
double* mat;
double* work;
double* wor2;
double cond = 1e10;
#ifdef DEBUG_BASARAB
double basarab[64] = {0.1206, 0.6438, 0.0623, 0.4903, 0.3061, 0.8164, 0.9972, 0.4246 ,
0.7675, 0.8468, 0.1681, 0.4045, 0.3025, 0.7730, 0.3156, 0.8355,
0.3103, 0.4922, 0.0378, 0.6989, 0.1704, 0.4167, 0.1199, 0.2274 ,
0.3527, 0.1086, 0.8734, 0.9629, 0.5332, 0.4056, 0.8503, 0.1604 ,
0.7382, 0.8833, 0.3093, 0.4463, 0.0403, 0.9273, 0.7538, 0.5861,
0.7008, 0.9463, 0.4652, 0.3890, 0.4388, 0.3014, 0.8448, 0.0802,
0.6985, 0.4762, 0.1508, 0.5055, 0.8133, 0.1878, 0.3805, 0.5890,
0.6836, 0.0463, 0.0702, 0.4994, 0.2996, 0.6929, 0.0510, 0.6763 };
double solution[64] = { 1.219168 , 0.482832 , 1.111272 , 1.119340 , -0.581676 , -0.357569 , -0.187398 , -0.228104 ,
0.604543 , 1.379706 , 0.964038 , 0.769794 , -0.099787 , -0.306024 , 0.295851 , 0.050487 ,
1.641438 , 0.799625 , 1.008289, 0.941142 , -0.240047 , -0.076741 , 0.556083 , -0.028614 ,
0.592649 , 0.714927 , 0.938438 , 1.046255 , -0.420245 , 0.021793 , -0.318054 , 0.312924 ,
-0.068692 , -0.272928 , -0.310585, -0.387884, -0.354573, -0.060916 , -0.307149 , -0.028895,
0.217629 , -0.315991 , 0.205230 , 0.341722 , -0.145144 , -0.453236 , -0.240130 , -0.048585 ,
0.025795 , 0.149668 , -0.104576 , 0.057637 , -0.072589 , 0.536268 , -0.003323 , -0.039721 ,
-0.219055 , -0.030570, 0.253523 , -0.053564, -0.018347 , -0.115078 , 0.631844 , -0.475752 };
#endif
#ifdef WITHPAPI
#define NUM_EVENTS 3
int i, rc;
// int events[NUM_EVENTS] = { PAPI_TOT_CYC, PAPI_L2_DCM, PAPI_L3_TCM };
int events[NUM_EVENTS] = { PAPI_TOT_CYC, PAPI_L2_LDM, PAPI_L2_STM };
long long values[NUM_EVENTS] = {0, 0, 0};
int num_hwcntrs = 0;
if ((num_hwcntrs = PAPI_num_counters()) <= PAPI_OK) {
printf( "Not enough counters: %d available\n", num_hwcntrs );
return EXIT_FAILURE;
}
#else
long long t_start, t_end;
int i;
#endif
if( argc < 3 ) {
M = DEFAULTM;
N = DEFAULTN;
} else {
M = atoi( argv[1] );
N = atoi( argv[2] );
}
#ifndef DEBUG_BASARAB
mat = (double*) malloc( M*N*sizeof( double));
#endif
work = (double*) malloc( M*N*sizeof( double));
wor2 = (double*) malloc( M*N*sizeof( double));
memset( wor2, 0, M*N*sizeof( double ) );
/* Ill-conditionned matrix */
// dillrandom( mat, M, N, N, cond, work, wor2 );
#ifndef DEBUG_BASARAB
drandom( mat, M, N );
#else
mat = &(basarab[0]);
#endif
//identity( mat, M, N );
// printmatrixOctave( mat, M, N );
// printmatrixOctave( basarab, M, N );
//printmatrix( mat, M, N );
#ifdef WITHPAPI
rc = PAPI_start_counters( events, NUM_EVENTS );
if( rc != PAPI_OK ){
PAPI_perror( "Error starting the counters" );
}
#else
t_start = rdtsc();
#endif
/* Daub4 transform */
for( i = 0 ; i < NUMRUN ; i++ ) {
DDA8MT( mat, work, wor2, M, N, N, N );
// printmatrixOctave( work, M, N );
// printmatrix( work, M, N );
}
#ifdef DEBUG_BASARAB
// printmatrixOctave( mat, M, N );
printmatrixOctave( wor2, M, N );
printmatrixOctave( work, M, N );
// printmatrixOctave( solution, M, N );
#endif
#ifdef WITHPAPI
PAPI_stop_counters( values, NUM_EVENTS );
// printf( "# M \t N \t PAPI_TOT_CYC \t PAPI_L2_DCM \t PAPI_L3_TCM \t PAPI_L1_LDM \t PAPI_L1_STM\n" );
printf( "# M \t N \t PAPI_TOT_CYC \t PAPI_L1_LDM \t PAPI_L1_STM\n" );
printf( "%d \t %d \t %lld \t %lld \t %lld \n", M, N, values[0] / NUMRUN, values[1] / NUMRUN , values[2] / NUMRUN );
#else
t_end = rdtsc();
printf( "# M \t N \t time \n" );
printf( "%d \t %d \t %lld \n", M, N, (t_end - t_start ) / NUMRUN );
#endif
#ifndef DEBUG_BASARAB
free( mat );
#endif
free( work );
free( wor2 );
return EXIT_SUCCESS;
}