00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 #include <stdio.h>
00050 #include "lapacke.h"
00051 #include "lapacke_utils.h"
00052 #include "test_utils.h"
00053
00054 static void init_scalars_strrfs( char *uplo, char *trans, char *diag,
00055 lapack_int *n, lapack_int *nrhs,
00056 lapack_int *lda, lapack_int *ldb,
00057 lapack_int *ldx );
00058 static void init_a( lapack_int size, float *a );
00059 static void init_b( lapack_int size, float *b );
00060 static void init_x( lapack_int size, float *x );
00061 static void init_ferr( lapack_int size, float *ferr );
00062 static void init_berr( lapack_int size, float *berr );
00063 static void init_work( lapack_int size, float *work );
00064 static void init_iwork( lapack_int size, lapack_int *iwork );
00065 static int compare_strrfs( float *ferr, float *ferr_i, float *berr,
00066 float *berr_i, lapack_int info, lapack_int info_i,
00067 lapack_int nrhs );
00068
00069 int main(void)
00070 {
00071
00072 char uplo, uplo_i;
00073 char trans, trans_i;
00074 char diag, diag_i;
00075 lapack_int n, n_i;
00076 lapack_int nrhs, nrhs_i;
00077 lapack_int lda, lda_i;
00078 lapack_int lda_r;
00079 lapack_int ldb, ldb_i;
00080 lapack_int ldb_r;
00081 lapack_int ldx, ldx_i;
00082 lapack_int ldx_r;
00083 lapack_int info, info_i;
00084 lapack_int i;
00085 int failed;
00086
00087
00088 float *a = NULL, *a_i = NULL;
00089 float *b = NULL, *b_i = NULL;
00090 float *x = NULL, *x_i = NULL;
00091 float *ferr = NULL, *ferr_i = NULL;
00092 float *berr = NULL, *berr_i = NULL;
00093 float *work = NULL, *work_i = NULL;
00094 lapack_int *iwork = NULL, *iwork_i = NULL;
00095 float *ferr_save = NULL;
00096 float *berr_save = NULL;
00097 float *a_r = NULL;
00098 float *b_r = NULL;
00099 float *x_r = NULL;
00100
00101
00102 init_scalars_strrfs( &uplo, &trans, &diag, &n, &nrhs, &lda, &ldb, &ldx );
00103 lda_r = n+2;
00104 ldb_r = nrhs+2;
00105 ldx_r = nrhs+2;
00106 uplo_i = uplo;
00107 trans_i = trans;
00108 diag_i = diag;
00109 n_i = n;
00110 nrhs_i = nrhs;
00111 lda_i = lda;
00112 ldb_i = ldb;
00113 ldx_i = ldx;
00114
00115
00116 a = (float *)LAPACKE_malloc( lda*n * sizeof(float) );
00117 b = (float *)LAPACKE_malloc( ldb*nrhs * sizeof(float) );
00118 x = (float *)LAPACKE_malloc( ldx*nrhs * sizeof(float) );
00119 ferr = (float *)LAPACKE_malloc( nrhs * sizeof(float) );
00120 berr = (float *)LAPACKE_malloc( nrhs * sizeof(float) );
00121 work = (float *)LAPACKE_malloc( 3*n * sizeof(float) );
00122 iwork = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00123
00124
00125 a_i = (float *)LAPACKE_malloc( lda*n * sizeof(float) );
00126 b_i = (float *)LAPACKE_malloc( ldb*nrhs * sizeof(float) );
00127 x_i = (float *)LAPACKE_malloc( ldx*nrhs * sizeof(float) );
00128 ferr_i = (float *)LAPACKE_malloc( nrhs * sizeof(float) );
00129 berr_i = (float *)LAPACKE_malloc( nrhs * sizeof(float) );
00130 work_i = (float *)LAPACKE_malloc( 3*n * sizeof(float) );
00131 iwork_i = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00132
00133
00134 ferr_save = (float *)LAPACKE_malloc( nrhs * sizeof(float) );
00135 berr_save = (float *)LAPACKE_malloc( nrhs * sizeof(float) );
00136
00137
00138 a_r = (float *)LAPACKE_malloc( n*(n+2) * sizeof(float) );
00139 b_r = (float *)LAPACKE_malloc( n*(nrhs+2) * sizeof(float) );
00140 x_r = (float *)LAPACKE_malloc( n*(nrhs+2) * sizeof(float) );
00141
00142
00143 init_a( lda*n, a );
00144 init_b( ldb*nrhs, b );
00145 init_x( ldx*nrhs, x );
00146 init_ferr( nrhs, ferr );
00147 init_berr( nrhs, berr );
00148 init_work( 3*n, work );
00149 init_iwork( n, iwork );
00150
00151
00152 for( i = 0; i < nrhs; i++ ) {
00153 ferr_save[i] = ferr[i];
00154 }
00155 for( i = 0; i < nrhs; i++ ) {
00156 berr_save[i] = berr[i];
00157 }
00158
00159
00160 strrfs_( &uplo, &trans, &diag, &n, &nrhs, a, &lda, b, &ldb, x, &ldx, ferr,
00161 berr, work, iwork, &info );
00162
00163
00164
00165 for( i = 0; i < lda*n; i++ ) {
00166 a_i[i] = a[i];
00167 }
00168 for( i = 0; i < ldb*nrhs; i++ ) {
00169 b_i[i] = b[i];
00170 }
00171 for( i = 0; i < ldx*nrhs; i++ ) {
00172 x_i[i] = x[i];
00173 }
00174 for( i = 0; i < nrhs; i++ ) {
00175 ferr_i[i] = ferr_save[i];
00176 }
00177 for( i = 0; i < nrhs; i++ ) {
00178 berr_i[i] = berr_save[i];
00179 }
00180 for( i = 0; i < 3*n; i++ ) {
00181 work_i[i] = work[i];
00182 }
00183 for( i = 0; i < n; i++ ) {
00184 iwork_i[i] = iwork[i];
00185 }
00186 info_i = LAPACKE_strrfs_work( LAPACK_COL_MAJOR, uplo_i, trans_i, diag_i,
00187 n_i, nrhs_i, a_i, lda_i, b_i, ldb_i, x_i,
00188 ldx_i, ferr_i, berr_i, work_i, iwork_i );
00189
00190 failed = compare_strrfs( ferr, ferr_i, berr, berr_i, info, info_i, nrhs );
00191 if( failed == 0 ) {
00192 printf( "PASSED: column-major middle-level interface to strrfs\n" );
00193 } else {
00194 printf( "FAILED: column-major middle-level interface to strrfs\n" );
00195 }
00196
00197
00198
00199 for( i = 0; i < lda*n; i++ ) {
00200 a_i[i] = a[i];
00201 }
00202 for( i = 0; i < ldb*nrhs; i++ ) {
00203 b_i[i] = b[i];
00204 }
00205 for( i = 0; i < ldx*nrhs; i++ ) {
00206 x_i[i] = x[i];
00207 }
00208 for( i = 0; i < nrhs; i++ ) {
00209 ferr_i[i] = ferr_save[i];
00210 }
00211 for( i = 0; i < nrhs; i++ ) {
00212 berr_i[i] = berr_save[i];
00213 }
00214 for( i = 0; i < 3*n; i++ ) {
00215 work_i[i] = work[i];
00216 }
00217 for( i = 0; i < n; i++ ) {
00218 iwork_i[i] = iwork[i];
00219 }
00220 info_i = LAPACKE_strrfs( LAPACK_COL_MAJOR, uplo_i, trans_i, diag_i, n_i,
00221 nrhs_i, a_i, lda_i, b_i, ldb_i, x_i, ldx_i, ferr_i,
00222 berr_i );
00223
00224 failed = compare_strrfs( ferr, ferr_i, berr, berr_i, info, info_i, nrhs );
00225 if( failed == 0 ) {
00226 printf( "PASSED: column-major high-level interface to strrfs\n" );
00227 } else {
00228 printf( "FAILED: column-major high-level interface to strrfs\n" );
00229 }
00230
00231
00232
00233 for( i = 0; i < lda*n; i++ ) {
00234 a_i[i] = a[i];
00235 }
00236 for( i = 0; i < ldb*nrhs; i++ ) {
00237 b_i[i] = b[i];
00238 }
00239 for( i = 0; i < ldx*nrhs; i++ ) {
00240 x_i[i] = x[i];
00241 }
00242 for( i = 0; i < nrhs; i++ ) {
00243 ferr_i[i] = ferr_save[i];
00244 }
00245 for( i = 0; i < nrhs; i++ ) {
00246 berr_i[i] = berr_save[i];
00247 }
00248 for( i = 0; i < 3*n; i++ ) {
00249 work_i[i] = work[i];
00250 }
00251 for( i = 0; i < n; i++ ) {
00252 iwork_i[i] = iwork[i];
00253 }
00254
00255 LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00256 LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00257 LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, nrhs, x_i, ldx, x_r, nrhs+2 );
00258 info_i = LAPACKE_strrfs_work( LAPACK_ROW_MAJOR, uplo_i, trans_i, diag_i,
00259 n_i, nrhs_i, a_r, lda_r, b_r, ldb_r, x_r,
00260 ldx_r, ferr_i, berr_i, work_i, iwork_i );
00261
00262 failed = compare_strrfs( ferr, ferr_i, berr, berr_i, info, info_i, nrhs );
00263 if( failed == 0 ) {
00264 printf( "PASSED: row-major middle-level interface to strrfs\n" );
00265 } else {
00266 printf( "FAILED: row-major middle-level interface to strrfs\n" );
00267 }
00268
00269
00270
00271 for( i = 0; i < lda*n; i++ ) {
00272 a_i[i] = a[i];
00273 }
00274 for( i = 0; i < ldb*nrhs; i++ ) {
00275 b_i[i] = b[i];
00276 }
00277 for( i = 0; i < ldx*nrhs; i++ ) {
00278 x_i[i] = x[i];
00279 }
00280 for( i = 0; i < nrhs; i++ ) {
00281 ferr_i[i] = ferr_save[i];
00282 }
00283 for( i = 0; i < nrhs; i++ ) {
00284 berr_i[i] = berr_save[i];
00285 }
00286 for( i = 0; i < 3*n; i++ ) {
00287 work_i[i] = work[i];
00288 }
00289 for( i = 0; i < n; i++ ) {
00290 iwork_i[i] = iwork[i];
00291 }
00292
00293
00294 LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00295 LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00296 LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, nrhs, x_i, ldx, x_r, nrhs+2 );
00297 info_i = LAPACKE_strrfs( LAPACK_ROW_MAJOR, uplo_i, trans_i, diag_i, n_i,
00298 nrhs_i, a_r, lda_r, b_r, ldb_r, x_r, ldx_r, ferr_i,
00299 berr_i );
00300
00301 failed = compare_strrfs( ferr, ferr_i, berr, berr_i, info, info_i, nrhs );
00302 if( failed == 0 ) {
00303 printf( "PASSED: row-major high-level interface to strrfs\n" );
00304 } else {
00305 printf( "FAILED: row-major high-level interface to strrfs\n" );
00306 }
00307
00308
00309 if( a != NULL ) {
00310 LAPACKE_free( a );
00311 }
00312 if( a_i != NULL ) {
00313 LAPACKE_free( a_i );
00314 }
00315 if( a_r != NULL ) {
00316 LAPACKE_free( a_r );
00317 }
00318 if( b != NULL ) {
00319 LAPACKE_free( b );
00320 }
00321 if( b_i != NULL ) {
00322 LAPACKE_free( b_i );
00323 }
00324 if( b_r != NULL ) {
00325 LAPACKE_free( b_r );
00326 }
00327 if( x != NULL ) {
00328 LAPACKE_free( x );
00329 }
00330 if( x_i != NULL ) {
00331 LAPACKE_free( x_i );
00332 }
00333 if( x_r != NULL ) {
00334 LAPACKE_free( x_r );
00335 }
00336 if( ferr != NULL ) {
00337 LAPACKE_free( ferr );
00338 }
00339 if( ferr_i != NULL ) {
00340 LAPACKE_free( ferr_i );
00341 }
00342 if( ferr_save != NULL ) {
00343 LAPACKE_free( ferr_save );
00344 }
00345 if( berr != NULL ) {
00346 LAPACKE_free( berr );
00347 }
00348 if( berr_i != NULL ) {
00349 LAPACKE_free( berr_i );
00350 }
00351 if( berr_save != NULL ) {
00352 LAPACKE_free( berr_save );
00353 }
00354 if( work != NULL ) {
00355 LAPACKE_free( work );
00356 }
00357 if( work_i != NULL ) {
00358 LAPACKE_free( work_i );
00359 }
00360 if( iwork != NULL ) {
00361 LAPACKE_free( iwork );
00362 }
00363 if( iwork_i != NULL ) {
00364 LAPACKE_free( iwork_i );
00365 }
00366
00367 return 0;
00368 }
00369
00370
00371 static void init_scalars_strrfs( char *uplo, char *trans, char *diag,
00372 lapack_int *n, lapack_int *nrhs,
00373 lapack_int *lda, lapack_int *ldb,
00374 lapack_int *ldx )
00375 {
00376 *uplo = 'L';
00377 *trans = 'N';
00378 *diag = 'N';
00379 *n = 4;
00380 *nrhs = 2;
00381 *lda = 8;
00382 *ldb = 8;
00383 *ldx = 8;
00384
00385 return;
00386 }
00387
00388
00389 static void init_a( lapack_int size, float *a ) {
00390 lapack_int i;
00391 for( i = 0; i < size; i++ ) {
00392 a[i] = 0;
00393 }
00394 a[0] = 4.300000191e+000;
00395 a[8] = 0.000000000e+000;
00396 a[16] = 0.000000000e+000;
00397 a[24] = 0.000000000e+000;
00398 a[1] = -3.960000038e+000;
00399 a[9] = -4.869999886e+000;
00400 a[17] = 0.000000000e+000;
00401 a[25] = 0.000000000e+000;
00402 a[2] = 4.000000060e-001;
00403 a[10] = 3.100000024e-001;
00404 a[18] = -8.020000458e+000;
00405 a[26] = 0.000000000e+000;
00406 a[3] = -2.700000107e-001;
00407 a[11] = 7.000000030e-002;
00408 a[19] = -5.949999809e+000;
00409 a[27] = 1.199999973e-001;
00410 }
00411 static void init_b( lapack_int size, float *b ) {
00412 lapack_int i;
00413 for( i = 0; i < size; i++ ) {
00414 b[i] = 0;
00415 }
00416 b[0] = -1.289999962e+001;
00417 b[8] = -2.150000000e+001;
00418 b[1] = 1.675000000e+001;
00419 b[9] = 1.493000031e+001;
00420 b[2] = -1.754999924e+001;
00421 b[10] = 6.329999924e+000;
00422 b[3] = -1.103999996e+001;
00423 b[11] = 8.090000153e+000;
00424 }
00425 static void init_x( lapack_int size, float *x ) {
00426 lapack_int i;
00427 for( i = 0; i < size; i++ ) {
00428 x[i] = 0;
00429 }
00430 x[0] = -2.999999762e+000;
00431 x[8] = -5.000000000e+000;
00432 x[1] = -1.000000238e+000;
00433 x[9] = 9.999998212e-001;
00434 x[2] = 1.999999762e+000;
00435 x[10] = -1.000000000e+000;
00436 x[3] = 9.999911785e-001;
00437 x[11] = 6.000002861e+000;
00438 }
00439 static void init_ferr( lapack_int size, float *ferr ) {
00440 lapack_int i;
00441 for( i = 0; i < size; i++ ) {
00442 ferr[i] = 0;
00443 }
00444 }
00445 static void init_berr( lapack_int size, float *berr ) {
00446 lapack_int i;
00447 for( i = 0; i < size; i++ ) {
00448 berr[i] = 0;
00449 }
00450 }
00451 static void init_work( lapack_int size, float *work ) {
00452 lapack_int i;
00453 for( i = 0; i < size; i++ ) {
00454 work[i] = 0;
00455 }
00456 }
00457 static void init_iwork( lapack_int size, lapack_int *iwork ) {
00458 lapack_int i;
00459 for( i = 0; i < size; i++ ) {
00460 iwork[i] = 0;
00461 }
00462 }
00463
00464
00465
00466 static int compare_strrfs( float *ferr, float *ferr_i, float *berr,
00467 float *berr_i, lapack_int info, lapack_int info_i,
00468 lapack_int nrhs )
00469 {
00470 lapack_int i;
00471 int failed = 0;
00472 for( i = 0; i < nrhs; i++ ) {
00473 failed += compare_floats(ferr[i],ferr_i[i]);
00474 }
00475 for( i = 0; i < nrhs; i++ ) {
00476 failed += compare_floats(berr[i],berr_i[i]);
00477 }
00478 failed += (info == info_i) ? 0 : 1;
00479 if( info != 0 || info_i != 0 ) {
00480 printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00481 }
00482
00483 return failed;
00484 }