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_ztrrfs( 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, lapack_complex_double *a );
00059 static void init_b( lapack_int size, lapack_complex_double *b );
00060 static void init_x( lapack_int size, lapack_complex_double *x );
00061 static void init_ferr( lapack_int size, double *ferr );
00062 static void init_berr( lapack_int size, double *berr );
00063 static void init_work( lapack_int size, lapack_complex_double *work );
00064 static void init_rwork( lapack_int size, double *rwork );
00065 static int compare_ztrrfs( double *ferr, double *ferr_i, double *berr,
00066 double *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 lapack_complex_double *a = NULL, *a_i = NULL;
00089 lapack_complex_double *b = NULL, *b_i = NULL;
00090 lapack_complex_double *x = NULL, *x_i = NULL;
00091 double *ferr = NULL, *ferr_i = NULL;
00092 double *berr = NULL, *berr_i = NULL;
00093 lapack_complex_double *work = NULL, *work_i = NULL;
00094 double *rwork = NULL, *rwork_i = NULL;
00095 double *ferr_save = NULL;
00096 double *berr_save = NULL;
00097 lapack_complex_double *a_r = NULL;
00098 lapack_complex_double *b_r = NULL;
00099 lapack_complex_double *x_r = NULL;
00100
00101
00102 init_scalars_ztrrfs( &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 = (lapack_complex_double *)
00117 LAPACKE_malloc( lda*n * sizeof(lapack_complex_double) );
00118 b = (lapack_complex_double *)
00119 LAPACKE_malloc( ldb*nrhs * sizeof(lapack_complex_double) );
00120 x = (lapack_complex_double *)
00121 LAPACKE_malloc( ldx*nrhs * sizeof(lapack_complex_double) );
00122 ferr = (double *)LAPACKE_malloc( nrhs * sizeof(double) );
00123 berr = (double *)LAPACKE_malloc( nrhs * sizeof(double) );
00124 work = (lapack_complex_double *)
00125 LAPACKE_malloc( 2*n * sizeof(lapack_complex_double) );
00126 rwork = (double *)LAPACKE_malloc( n * sizeof(double) );
00127
00128
00129 a_i = (lapack_complex_double *)
00130 LAPACKE_malloc( lda*n * sizeof(lapack_complex_double) );
00131 b_i = (lapack_complex_double *)
00132 LAPACKE_malloc( ldb*nrhs * sizeof(lapack_complex_double) );
00133 x_i = (lapack_complex_double *)
00134 LAPACKE_malloc( ldx*nrhs * sizeof(lapack_complex_double) );
00135 ferr_i = (double *)LAPACKE_malloc( nrhs * sizeof(double) );
00136 berr_i = (double *)LAPACKE_malloc( nrhs * sizeof(double) );
00137 work_i = (lapack_complex_double *)
00138 LAPACKE_malloc( 2*n * sizeof(lapack_complex_double) );
00139 rwork_i = (double *)LAPACKE_malloc( n * sizeof(double) );
00140
00141
00142 ferr_save = (double *)LAPACKE_malloc( nrhs * sizeof(double) );
00143 berr_save = (double *)LAPACKE_malloc( nrhs * sizeof(double) );
00144
00145
00146 a_r = (lapack_complex_double *)
00147 LAPACKE_malloc( n*(n+2) * sizeof(lapack_complex_double) );
00148 b_r = (lapack_complex_double *)
00149 LAPACKE_malloc( n*(nrhs+2) * sizeof(lapack_complex_double) );
00150 x_r = (lapack_complex_double *)
00151 LAPACKE_malloc( n*(nrhs+2) * sizeof(lapack_complex_double) );
00152
00153
00154 init_a( lda*n, a );
00155 init_b( ldb*nrhs, b );
00156 init_x( ldx*nrhs, x );
00157 init_ferr( nrhs, ferr );
00158 init_berr( nrhs, berr );
00159 init_work( 2*n, work );
00160 init_rwork( n, rwork );
00161
00162
00163 for( i = 0; i < nrhs; i++ ) {
00164 ferr_save[i] = ferr[i];
00165 }
00166 for( i = 0; i < nrhs; i++ ) {
00167 berr_save[i] = berr[i];
00168 }
00169
00170
00171 ztrrfs_( &uplo, &trans, &diag, &n, &nrhs, a, &lda, b, &ldb, x, &ldx, ferr,
00172 berr, work, rwork, &info );
00173
00174
00175
00176 for( i = 0; i < lda*n; i++ ) {
00177 a_i[i] = a[i];
00178 }
00179 for( i = 0; i < ldb*nrhs; i++ ) {
00180 b_i[i] = b[i];
00181 }
00182 for( i = 0; i < ldx*nrhs; i++ ) {
00183 x_i[i] = x[i];
00184 }
00185 for( i = 0; i < nrhs; i++ ) {
00186 ferr_i[i] = ferr_save[i];
00187 }
00188 for( i = 0; i < nrhs; i++ ) {
00189 berr_i[i] = berr_save[i];
00190 }
00191 for( i = 0; i < 2*n; i++ ) {
00192 work_i[i] = work[i];
00193 }
00194 for( i = 0; i < n; i++ ) {
00195 rwork_i[i] = rwork[i];
00196 }
00197 info_i = LAPACKE_ztrrfs_work( LAPACK_COL_MAJOR, uplo_i, trans_i, diag_i,
00198 n_i, nrhs_i, a_i, lda_i, b_i, ldb_i, x_i,
00199 ldx_i, ferr_i, berr_i, work_i, rwork_i );
00200
00201 failed = compare_ztrrfs( ferr, ferr_i, berr, berr_i, info, info_i, nrhs );
00202 if( failed == 0 ) {
00203 printf( "PASSED: column-major middle-level interface to ztrrfs\n" );
00204 } else {
00205 printf( "FAILED: column-major middle-level interface to ztrrfs\n" );
00206 }
00207
00208
00209
00210 for( i = 0; i < lda*n; i++ ) {
00211 a_i[i] = a[i];
00212 }
00213 for( i = 0; i < ldb*nrhs; i++ ) {
00214 b_i[i] = b[i];
00215 }
00216 for( i = 0; i < ldx*nrhs; i++ ) {
00217 x_i[i] = x[i];
00218 }
00219 for( i = 0; i < nrhs; i++ ) {
00220 ferr_i[i] = ferr_save[i];
00221 }
00222 for( i = 0; i < nrhs; i++ ) {
00223 berr_i[i] = berr_save[i];
00224 }
00225 for( i = 0; i < 2*n; i++ ) {
00226 work_i[i] = work[i];
00227 }
00228 for( i = 0; i < n; i++ ) {
00229 rwork_i[i] = rwork[i];
00230 }
00231 info_i = LAPACKE_ztrrfs( LAPACK_COL_MAJOR, uplo_i, trans_i, diag_i, n_i,
00232 nrhs_i, a_i, lda_i, b_i, ldb_i, x_i, ldx_i, ferr_i,
00233 berr_i );
00234
00235 failed = compare_ztrrfs( ferr, ferr_i, berr, berr_i, info, info_i, nrhs );
00236 if( failed == 0 ) {
00237 printf( "PASSED: column-major high-level interface to ztrrfs\n" );
00238 } else {
00239 printf( "FAILED: column-major high-level interface to ztrrfs\n" );
00240 }
00241
00242
00243
00244 for( i = 0; i < lda*n; i++ ) {
00245 a_i[i] = a[i];
00246 }
00247 for( i = 0; i < ldb*nrhs; i++ ) {
00248 b_i[i] = b[i];
00249 }
00250 for( i = 0; i < ldx*nrhs; i++ ) {
00251 x_i[i] = x[i];
00252 }
00253 for( i = 0; i < nrhs; i++ ) {
00254 ferr_i[i] = ferr_save[i];
00255 }
00256 for( i = 0; i < nrhs; i++ ) {
00257 berr_i[i] = berr_save[i];
00258 }
00259 for( i = 0; i < 2*n; i++ ) {
00260 work_i[i] = work[i];
00261 }
00262 for( i = 0; i < n; i++ ) {
00263 rwork_i[i] = rwork[i];
00264 }
00265
00266 LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00267 LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00268 LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, nrhs, x_i, ldx, x_r, nrhs+2 );
00269 info_i = LAPACKE_ztrrfs_work( LAPACK_ROW_MAJOR, uplo_i, trans_i, diag_i,
00270 n_i, nrhs_i, a_r, lda_r, b_r, ldb_r, x_r,
00271 ldx_r, ferr_i, berr_i, work_i, rwork_i );
00272
00273 failed = compare_ztrrfs( ferr, ferr_i, berr, berr_i, info, info_i, nrhs );
00274 if( failed == 0 ) {
00275 printf( "PASSED: row-major middle-level interface to ztrrfs\n" );
00276 } else {
00277 printf( "FAILED: row-major middle-level interface to ztrrfs\n" );
00278 }
00279
00280
00281
00282 for( i = 0; i < lda*n; i++ ) {
00283 a_i[i] = a[i];
00284 }
00285 for( i = 0; i < ldb*nrhs; i++ ) {
00286 b_i[i] = b[i];
00287 }
00288 for( i = 0; i < ldx*nrhs; i++ ) {
00289 x_i[i] = x[i];
00290 }
00291 for( i = 0; i < nrhs; i++ ) {
00292 ferr_i[i] = ferr_save[i];
00293 }
00294 for( i = 0; i < nrhs; i++ ) {
00295 berr_i[i] = berr_save[i];
00296 }
00297 for( i = 0; i < 2*n; i++ ) {
00298 work_i[i] = work[i];
00299 }
00300 for( i = 0; i < n; i++ ) {
00301 rwork_i[i] = rwork[i];
00302 }
00303
00304
00305 LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00306 LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00307 LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, nrhs, x_i, ldx, x_r, nrhs+2 );
00308 info_i = LAPACKE_ztrrfs( LAPACK_ROW_MAJOR, uplo_i, trans_i, diag_i, n_i,
00309 nrhs_i, a_r, lda_r, b_r, ldb_r, x_r, ldx_r, ferr_i,
00310 berr_i );
00311
00312 failed = compare_ztrrfs( ferr, ferr_i, berr, berr_i, info, info_i, nrhs );
00313 if( failed == 0 ) {
00314 printf( "PASSED: row-major high-level interface to ztrrfs\n" );
00315 } else {
00316 printf( "FAILED: row-major high-level interface to ztrrfs\n" );
00317 }
00318
00319
00320 if( a != NULL ) {
00321 LAPACKE_free( a );
00322 }
00323 if( a_i != NULL ) {
00324 LAPACKE_free( a_i );
00325 }
00326 if( a_r != NULL ) {
00327 LAPACKE_free( a_r );
00328 }
00329 if( b != NULL ) {
00330 LAPACKE_free( b );
00331 }
00332 if( b_i != NULL ) {
00333 LAPACKE_free( b_i );
00334 }
00335 if( b_r != NULL ) {
00336 LAPACKE_free( b_r );
00337 }
00338 if( x != NULL ) {
00339 LAPACKE_free( x );
00340 }
00341 if( x_i != NULL ) {
00342 LAPACKE_free( x_i );
00343 }
00344 if( x_r != NULL ) {
00345 LAPACKE_free( x_r );
00346 }
00347 if( ferr != NULL ) {
00348 LAPACKE_free( ferr );
00349 }
00350 if( ferr_i != NULL ) {
00351 LAPACKE_free( ferr_i );
00352 }
00353 if( ferr_save != NULL ) {
00354 LAPACKE_free( ferr_save );
00355 }
00356 if( berr != NULL ) {
00357 LAPACKE_free( berr );
00358 }
00359 if( berr_i != NULL ) {
00360 LAPACKE_free( berr_i );
00361 }
00362 if( berr_save != NULL ) {
00363 LAPACKE_free( berr_save );
00364 }
00365 if( work != NULL ) {
00366 LAPACKE_free( work );
00367 }
00368 if( work_i != NULL ) {
00369 LAPACKE_free( work_i );
00370 }
00371 if( rwork != NULL ) {
00372 LAPACKE_free( rwork );
00373 }
00374 if( rwork_i != NULL ) {
00375 LAPACKE_free( rwork_i );
00376 }
00377
00378 return 0;
00379 }
00380
00381
00382 static void init_scalars_ztrrfs( char *uplo, char *trans, char *diag,
00383 lapack_int *n, lapack_int *nrhs,
00384 lapack_int *lda, lapack_int *ldb,
00385 lapack_int *ldx )
00386 {
00387 *uplo = 'L';
00388 *trans = 'N';
00389 *diag = 'N';
00390 *n = 4;
00391 *nrhs = 2;
00392 *lda = 8;
00393 *ldb = 8;
00394 *ldx = 8;
00395
00396 return;
00397 }
00398
00399
00400 static void init_a( lapack_int size, lapack_complex_double *a ) {
00401 lapack_int i;
00402 for( i = 0; i < size; i++ ) {
00403 a[i] = lapack_make_complex_double( 0.0, 0.0 );
00404 }
00405 a[0] = lapack_make_complex_double( 4.78000000000000020e+000,
00406 4.55999999999999960e+000 );
00407 a[8] = lapack_make_complex_double( 0.00000000000000000e+000,
00408 0.00000000000000000e+000 );
00409 a[16] = lapack_make_complex_double( 0.00000000000000000e+000,
00410 0.00000000000000000e+000 );
00411 a[24] = lapack_make_complex_double( 0.00000000000000000e+000,
00412 0.00000000000000000e+000 );
00413 a[1] = lapack_make_complex_double( 2.00000000000000000e+000,
00414 -2.99999999999999990e-001 );
00415 a[9] = lapack_make_complex_double( -4.11000000000000030e+000,
00416 1.25000000000000000e+000 );
00417 a[17] = lapack_make_complex_double( 0.00000000000000000e+000,
00418 0.00000000000000000e+000 );
00419 a[25] = lapack_make_complex_double( 0.00000000000000000e+000,
00420 0.00000000000000000e+000 );
00421 a[2] = lapack_make_complex_double( 2.89000000000000010e+000,
00422 -1.34000000000000010e+000 );
00423 a[10] = lapack_make_complex_double( 2.35999999999999990e+000,
00424 -4.25000000000000000e+000 );
00425 a[18] = lapack_make_complex_double( 4.15000000000000040e+000,
00426 8.00000000000000040e-001 );
00427 a[26] = lapack_make_complex_double( 0.00000000000000000e+000,
00428 0.00000000000000000e+000 );
00429 a[3] = lapack_make_complex_double( -1.88999999999999990e+000,
00430 1.14999999999999990e+000 );
00431 a[11] = lapack_make_complex_double( 4.00000000000000010e-002,
00432 -3.68999999999999990e+000 );
00433 a[19] = lapack_make_complex_double( -2.00000000000000000e-002,
00434 4.60000000000000020e-001 );
00435 a[27] = lapack_make_complex_double( 3.30000000000000020e-001,
00436 -2.60000000000000010e-001 );
00437 }
00438 static void init_b( lapack_int size, lapack_complex_double *b ) {
00439 lapack_int i;
00440 for( i = 0; i < size; i++ ) {
00441 b[i] = lapack_make_complex_double( 0.0, 0.0 );
00442 }
00443 b[0] = lapack_make_complex_double( -1.47799999999999990e+001,
00444 -3.23599999999999990e+001 );
00445 b[8] = lapack_make_complex_double( -1.80200000000000000e+001,
00446 2.84600000000000010e+001 );
00447 b[1] = lapack_make_complex_double( 2.98000000000000000e+000,
00448 -2.14000000000000010e+000 );
00449 b[9] = lapack_make_complex_double( 1.42200000000000010e+001,
00450 1.54200000000000000e+001 );
00451 b[2] = lapack_make_complex_double( -2.09600000000000010e+001,
00452 1.70599999999999990e+001 );
00453 b[10] = lapack_make_complex_double( 5.62000000000000010e+000,
00454 3.58900000000000010e+001 );
00455 b[3] = lapack_make_complex_double( 9.53999999999999910e+000,
00456 9.91000000000000010e+000 );
00457 b[11] = lapack_make_complex_double( -1.64600000000000010e+001,
00458 -1.73000000000000000e+000 );
00459 }
00460 static void init_x( lapack_int size, lapack_complex_double *x ) {
00461 lapack_int i;
00462 for( i = 0; i < size; i++ ) {
00463 x[i] = lapack_make_complex_double( 0.0, 0.0 );
00464 }
00465 x[0] = lapack_make_complex_double( -5.00000000000000000e+000,
00466 -2.00000000000000040e+000 );
00467 x[8] = lapack_make_complex_double( 1.00000000000000000e+000,
00468 5.00000000000000000e+000 );
00469 x[1] = lapack_make_complex_double( -2.99999999999999960e+000,
00470 -1.00000000000000000e+000 );
00471 x[9] = lapack_make_complex_double( -1.99999999999999960e+000,
00472 -2.00000000000000000e+000 );
00473 x[2] = lapack_make_complex_double( 1.99999999999999980e+000,
00474 1.00000000000000000e+000 );
00475 x[10] = lapack_make_complex_double( 2.99999999999999960e+000,
00476 4.00000000000000000e+000 );
00477 x[3] = lapack_make_complex_double( 4.00000000000000000e+000,
00478 2.99999999999999820e+000 );
00479 x[11] = lapack_make_complex_double( 3.99999999999999690e+000,
00480 -2.99999999999999910e+000 );
00481 }
00482 static void init_ferr( lapack_int size, double *ferr ) {
00483 lapack_int i;
00484 for( i = 0; i < size; i++ ) {
00485 ferr[i] = 0;
00486 }
00487 }
00488 static void init_berr( lapack_int size, double *berr ) {
00489 lapack_int i;
00490 for( i = 0; i < size; i++ ) {
00491 berr[i] = 0;
00492 }
00493 }
00494 static void init_work( lapack_int size, lapack_complex_double *work ) {
00495 lapack_int i;
00496 for( i = 0; i < size; i++ ) {
00497 work[i] = lapack_make_complex_double( 0.0, 0.0 );
00498 }
00499 }
00500 static void init_rwork( lapack_int size, double *rwork ) {
00501 lapack_int i;
00502 for( i = 0; i < size; i++ ) {
00503 rwork[i] = 0;
00504 }
00505 }
00506
00507
00508
00509 static int compare_ztrrfs( double *ferr, double *ferr_i, double *berr,
00510 double *berr_i, lapack_int info, lapack_int info_i,
00511 lapack_int nrhs )
00512 {
00513 lapack_int i;
00514 int failed = 0;
00515 for( i = 0; i < nrhs; i++ ) {
00516 failed += compare_doubles(ferr[i],ferr_i[i]);
00517 }
00518 for( i = 0; i < nrhs; i++ ) {
00519 failed += compare_doubles(berr[i],berr_i[i]);
00520 }
00521 failed += (info == info_i) ? 0 : 1;
00522 if( info != 0 || info_i != 0 ) {
00523 printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00524 }
00525
00526 return failed;
00527 }