1 /*
2
3 Copyright (C) 2014, The University of Texas at Austin
4
5 This file is part of libflame and is available under the 3-Clause
6 BSD license, which can be found in the LICENSE file at the top-level
7 directory, or at http://opensource.org/licenses/BSD-3-Clause
8
9 */
10
11 #include "FLAME.h"
12
13
14 #define N_PARAM_COMBOS 12
15
16 #define FLA_ALG_REFERENCE 0
17 #define FLA_ALG_FRONT 1
18
19 char* pc_str[N_PARAM_COMBOS] = { "llh", "lln", "llt",
20 "luh", "lun", "lut",
21 "rlh", "rln", "rlt",
22 "ruh", "run", "rut" };
23
24 void time_Trsm(
25 int param_combo, int type, int n_repeats, int m, int n,
26 FLA_Obj A, FLA_Obj C, FLA_Obj C_ref,
27 double *dtime, double *diff, double *gflops );
28
29
main(int argc,char * argv[])30 int main(int argc, char *argv[])
31 {
32 int
33 datatype,
34 precision,
35 m_input, n_input,
36 m, n,
37 p_first, p_last, p_inc,
38 p,
39 n_repeats,
40 param_combo,
41 i,
42 n_param_combos = N_PARAM_COMBOS;
43
44 char *colors = "brkgmcbrkgmcbrkgmc";
45 char *ticks = "o+*xso+*xso+*xso+*xs";
46 char m_dim_desc[14];
47 char n_dim_desc[14];
48 char m_dim_tag[10];
49 char n_dim_tag[10];
50
51 double max_gflops=6.0;
52
53 double
54 dtime,
55 gflops,
56 diff;
57
58 FLA_Obj
59 A, C, C_ref;
60
61 FLA_Init( );
62
63
64 fprintf( stdout, "%c number of repeats:", '%' );
65 scanf( "%d", &n_repeats );
66 fprintf( stdout, "%c %d\n", '%', n_repeats );
67
68 fprintf( stdout, "%c enter problem size first, last, inc:", '%' );
69 scanf( "%d%d%d", &p_first, &p_last, &p_inc );
70 fprintf( stdout, "%c %d %d %d\n", '%', p_first, p_last, p_inc );
71
72 fprintf( stdout, "%c enter m n (-1 means bind to problem size): ", '%' );
73 scanf( "%d%d", &m_input, &n_input );
74 fprintf( stdout, "%c %d %d\n", '%', m_input, n_input );
75
76
77 fprintf( stdout, "\nclear all;\n\n" );
78
79
80 if ( m_input > 0 ) {
81 sprintf( m_dim_desc, "m = %d", m_input );
82 sprintf( m_dim_tag, "m%dc", m_input);
83 }
84 else if( m_input < -1 ) {
85 sprintf( m_dim_desc, "m = p/%d", -m_input );
86 sprintf( m_dim_tag, "m%dp", -m_input );
87 }
88 else if( m_input == -1 ) {
89 sprintf( m_dim_desc, "m = p" );
90 sprintf( m_dim_tag, "m%dp", 1 );
91 }
92 if ( n_input > 0 ) {
93 sprintf( n_dim_desc, "n = %d", n_input );
94 sprintf( n_dim_tag, "n%dc", n_input);
95 }
96 else if( n_input < -1 ) {
97 sprintf( n_dim_desc, "n = p/%d", -n_input );
98 sprintf( n_dim_tag, "n%dp", -n_input );
99 }
100 else if( n_input == -1 ) {
101 sprintf( n_dim_desc, "n = p" );
102 sprintf( n_dim_tag, "n%dp", 1 );
103 }
104
105 //precision = FLA_SINGLE_PRECISION;
106 precision = FLA_DOUBLE_PRECISION;
107
108 for ( p = p_first, i = 1; p <= p_last; p += p_inc, i += 1 )
109 {
110 m = m_input;
111 n = n_input;
112
113 if( m < 0 ) m = p / f2c_abs(m_input);
114 if( n < 0 ) n = p / f2c_abs(n_input);
115
116 for ( param_combo = 0; param_combo < n_param_combos; param_combo++ ){
117
118 // Determine datatype based on trans argument.
119 if ( pc_str[param_combo][2] == 'h' )
120 {
121 if ( precision == FLA_SINGLE_PRECISION )
122 datatype = FLA_COMPLEX;
123 else
124 datatype = FLA_DOUBLE_COMPLEX;
125 }
126 else
127 {
128 if ( precision == FLA_SINGLE_PRECISION )
129 datatype = FLA_FLOAT;
130 else
131 datatype = FLA_DOUBLE;
132 }
133
134 // If multiplying A on the left, A is m x m; ...on the right, A is n x n.
135 if ( pc_str[param_combo][0] == 'l' )
136 FLA_Obj_create( datatype, m, m, 0, 0, &A );
137 else
138 FLA_Obj_create( datatype, n, n, 0, 0, &A );
139
140 FLA_Obj_create( datatype, m, n, 0, 0, &C );
141 FLA_Obj_create( datatype, m, n, 0, 0, &C_ref );
142
143 if ( pc_str[param_combo][1] == 'l' )
144 {
145 FLA_Random_tri_matrix( FLA_LOWER_TRIANGULAR, FLA_NONUNIT_DIAG, A );
146 FLA_Random_matrix( C );
147 }
148 else
149 {
150 FLA_Random_tri_matrix( FLA_UPPER_TRIANGULAR, FLA_NONUNIT_DIAG, A );
151 FLA_Random_matrix( C );
152 }
153
154 fprintf( stdout, "data_trsm_%s( %d, 1:3 ) = [ %d ", pc_str[param_combo], i, p );
155 fflush( stdout );
156
157 time_Trsm( param_combo, FLA_ALG_REFERENCE, n_repeats, m, n,
158 A, C, C_ref, &dtime, &diff, &gflops );
159
160 fprintf( stdout, "%6.3lf %6.2le ", gflops, diff );
161 fflush( stdout );
162 /*
163 time_Trsm( param_combo, FLA_ALG_FRONT, n_repeats, m, n,
164 A, C, C_ref, &dtime, &diff, &gflops );
165
166 fprintf( stdout, "%6.3lf %6.2le ", gflops, diff );
167 fflush( stdout );
168 */
169
170 fprintf( stdout, " ]; \n" );
171 fflush( stdout );
172
173 FLA_Obj_free( &A );
174 FLA_Obj_free( &C );
175 FLA_Obj_free( &C_ref );
176 }
177
178 fprintf( stdout, "\n" );
179 }
180
181 /*
182 fprintf( stdout, "figure;\n" );
183
184 fprintf( stdout, "hold on;\n" );
185
186 for ( i = 0; i < n_param_combos; i++ ) {
187 fprintf( stdout, "plot( data_trsm_%s( :,1 ), data_trsm_%s( :, 2 ), '%c:%c' ); \n",
188 pc_str[i], pc_str[i], colors[ i ], ticks[ i ] );
189 fprintf( stdout, "plot( data_trsm_%s( :,1 ), data_trsm_%s( :, 4 ), '%c-.%c' ); \n",
190 pc_str[i], pc_str[i], colors[ i ], ticks[ i ] );
191 }
192
193 fprintf( stdout, "legend( ... \n" );
194
195 for ( i = 0; i < n_param_combos; i++ )
196 fprintf( stdout, "'ref\\_trsm\\_%s', 'fla\\_trsm\\_%s', ... \n", pc_str[i], pc_str[i] );
197
198 fprintf( stdout, "'Location', 'SouthEast' ); \n" );
199
200
201 fprintf( stdout, "xlabel( 'problem size p' );\n" );
202 fprintf( stdout, "ylabel( 'GFLOPS/sec.' );\n" );
203 fprintf( stdout, "axis( [ 0 %d 0 %.2f ] ); \n", p_last, max_gflops );
204 fprintf( stdout, "title( 'FLAME trsm front-end performance (%s, %s)' );\n",
205 m_dim_desc, n_dim_desc );
206 fprintf( stdout, "print -depsc trsm_front_%s_%s.eps\n", m_dim_tag, n_dim_tag );
207 fprintf( stdout, "hold off;\n");
208 fflush( stdout );
209 */
210
211 FLA_Finalize( );
212
213 return 0;
214 }
215
216