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_dsprfs( char *uplo, lapack_int *n, lapack_int *nrhs,
00055 lapack_int *ldb, lapack_int *ldx );
00056 static void init_ap( lapack_int size, double *ap );
00057 static void init_afp( lapack_int size, double *afp );
00058 static void init_ipiv( lapack_int size, lapack_int *ipiv );
00059 static void init_b( lapack_int size, double *b );
00060 static void init_x( lapack_int size, 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, double *work );
00064 static void init_iwork( lapack_int size, lapack_int *iwork );
00065 static int compare_dsprfs( double *x, double *x_i, double *ferr, double *ferr_i,
00066 double *berr, double *berr_i, lapack_int info,
00067 lapack_int info_i, lapack_int ldx, lapack_int nrhs );
00068
00069 int main(void)
00070 {
00071
00072 char uplo, uplo_i;
00073 lapack_int n, n_i;
00074 lapack_int nrhs, nrhs_i;
00075 lapack_int ldb, ldb_i;
00076 lapack_int ldb_r;
00077 lapack_int ldx, ldx_i;
00078 lapack_int ldx_r;
00079 lapack_int info, info_i;
00080 lapack_int i;
00081 int failed;
00082
00083
00084 double *ap = NULL, *ap_i = NULL;
00085 double *afp = NULL, *afp_i = NULL;
00086 lapack_int *ipiv = NULL, *ipiv_i = NULL;
00087 double *b = NULL, *b_i = NULL;
00088 double *x = NULL, *x_i = NULL;
00089 double *ferr = NULL, *ferr_i = NULL;
00090 double *berr = NULL, *berr_i = NULL;
00091 double *work = NULL, *work_i = NULL;
00092 lapack_int *iwork = NULL, *iwork_i = NULL;
00093 double *x_save = NULL;
00094 double *ferr_save = NULL;
00095 double *berr_save = NULL;
00096 double *ap_r = NULL;
00097 double *afp_r = NULL;
00098 double *b_r = NULL;
00099 double *x_r = NULL;
00100
00101
00102 init_scalars_dsprfs( &uplo, &n, &nrhs, &ldb, &ldx );
00103 ldb_r = nrhs+2;
00104 ldx_r = nrhs+2;
00105 uplo_i = uplo;
00106 n_i = n;
00107 nrhs_i = nrhs;
00108 ldb_i = ldb;
00109 ldx_i = ldx;
00110
00111
00112 ap = (double *)LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(double) );
00113 afp = (double *)LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(double) );
00114 ipiv = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00115 b = (double *)LAPACKE_malloc( ldb*nrhs * sizeof(double) );
00116 x = (double *)LAPACKE_malloc( ldx*nrhs * sizeof(double) );
00117 ferr = (double *)LAPACKE_malloc( nrhs * sizeof(double) );
00118 berr = (double *)LAPACKE_malloc( nrhs * sizeof(double) );
00119 work = (double *)LAPACKE_malloc( 3*n * sizeof(double) );
00120 iwork = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00121
00122
00123 ap_i = (double *)LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(double) );
00124 afp_i = (double *)LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(double) );
00125 ipiv_i = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00126 b_i = (double *)LAPACKE_malloc( ldb*nrhs * sizeof(double) );
00127 x_i = (double *)LAPACKE_malloc( ldx*nrhs * sizeof(double) );
00128 ferr_i = (double *)LAPACKE_malloc( nrhs * sizeof(double) );
00129 berr_i = (double *)LAPACKE_malloc( nrhs * sizeof(double) );
00130 work_i = (double *)LAPACKE_malloc( 3*n * sizeof(double) );
00131 iwork_i = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00132
00133
00134 x_save = (double *)LAPACKE_malloc( ldx*nrhs * sizeof(double) );
00135 ferr_save = (double *)LAPACKE_malloc( nrhs * sizeof(double) );
00136 berr_save = (double *)LAPACKE_malloc( nrhs * sizeof(double) );
00137
00138
00139 ap_r = (double *)LAPACKE_malloc( n*(n+1)/2 * sizeof(double) );
00140 afp_r = (double *)LAPACKE_malloc( n*(n+1)/2 * sizeof(double) );
00141 b_r = (double *)LAPACKE_malloc( n*(nrhs+2) * sizeof(double) );
00142 x_r = (double *)LAPACKE_malloc( n*(nrhs+2) * sizeof(double) );
00143
00144
00145 init_ap( (n*(n+1)/2), ap );
00146 init_afp( (n*(n+1)/2), afp );
00147 init_ipiv( n, ipiv );
00148 init_b( ldb*nrhs, b );
00149 init_x( ldx*nrhs, x );
00150 init_ferr( nrhs, ferr );
00151 init_berr( nrhs, berr );
00152 init_work( 3*n, work );
00153 init_iwork( n, iwork );
00154
00155
00156 for( i = 0; i < ldx*nrhs; i++ ) {
00157 x_save[i] = x[i];
00158 }
00159 for( i = 0; i < nrhs; i++ ) {
00160 ferr_save[i] = ferr[i];
00161 }
00162 for( i = 0; i < nrhs; i++ ) {
00163 berr_save[i] = berr[i];
00164 }
00165
00166
00167 dsprfs_( &uplo, &n, &nrhs, ap, afp, ipiv, b, &ldb, x, &ldx, ferr, berr,
00168 work, iwork, &info );
00169
00170
00171
00172 for( i = 0; i < (n*(n+1)/2); i++ ) {
00173 ap_i[i] = ap[i];
00174 }
00175 for( i = 0; i < (n*(n+1)/2); i++ ) {
00176 afp_i[i] = afp[i];
00177 }
00178 for( i = 0; i < n; i++ ) {
00179 ipiv_i[i] = ipiv[i];
00180 }
00181 for( i = 0; i < ldb*nrhs; i++ ) {
00182 b_i[i] = b[i];
00183 }
00184 for( i = 0; i < ldx*nrhs; i++ ) {
00185 x_i[i] = x_save[i];
00186 }
00187 for( i = 0; i < nrhs; i++ ) {
00188 ferr_i[i] = ferr_save[i];
00189 }
00190 for( i = 0; i < nrhs; i++ ) {
00191 berr_i[i] = berr_save[i];
00192 }
00193 for( i = 0; i < 3*n; i++ ) {
00194 work_i[i] = work[i];
00195 }
00196 for( i = 0; i < n; i++ ) {
00197 iwork_i[i] = iwork[i];
00198 }
00199 info_i = LAPACKE_dsprfs_work( LAPACK_COL_MAJOR, uplo_i, n_i, nrhs_i, ap_i,
00200 afp_i, ipiv_i, b_i, ldb_i, x_i, ldx_i, ferr_i,
00201 berr_i, work_i, iwork_i );
00202
00203 failed = compare_dsprfs( x, x_i, ferr, ferr_i, berr, berr_i, info, info_i,
00204 ldx, nrhs );
00205 if( failed == 0 ) {
00206 printf( "PASSED: column-major middle-level interface to dsprfs\n" );
00207 } else {
00208 printf( "FAILED: column-major middle-level interface to dsprfs\n" );
00209 }
00210
00211
00212
00213 for( i = 0; i < (n*(n+1)/2); i++ ) {
00214 ap_i[i] = ap[i];
00215 }
00216 for( i = 0; i < (n*(n+1)/2); i++ ) {
00217 afp_i[i] = afp[i];
00218 }
00219 for( i = 0; i < n; i++ ) {
00220 ipiv_i[i] = ipiv[i];
00221 }
00222 for( i = 0; i < ldb*nrhs; i++ ) {
00223 b_i[i] = b[i];
00224 }
00225 for( i = 0; i < ldx*nrhs; i++ ) {
00226 x_i[i] = x_save[i];
00227 }
00228 for( i = 0; i < nrhs; i++ ) {
00229 ferr_i[i] = ferr_save[i];
00230 }
00231 for( i = 0; i < nrhs; i++ ) {
00232 berr_i[i] = berr_save[i];
00233 }
00234 for( i = 0; i < 3*n; i++ ) {
00235 work_i[i] = work[i];
00236 }
00237 for( i = 0; i < n; i++ ) {
00238 iwork_i[i] = iwork[i];
00239 }
00240 info_i = LAPACKE_dsprfs( LAPACK_COL_MAJOR, uplo_i, n_i, nrhs_i, ap_i, afp_i,
00241 ipiv_i, b_i, ldb_i, x_i, ldx_i, ferr_i, berr_i );
00242
00243 failed = compare_dsprfs( x, x_i, ferr, ferr_i, berr, berr_i, info, info_i,
00244 ldx, nrhs );
00245 if( failed == 0 ) {
00246 printf( "PASSED: column-major high-level interface to dsprfs\n" );
00247 } else {
00248 printf( "FAILED: column-major high-level interface to dsprfs\n" );
00249 }
00250
00251
00252
00253 for( i = 0; i < (n*(n+1)/2); i++ ) {
00254 ap_i[i] = ap[i];
00255 }
00256 for( i = 0; i < (n*(n+1)/2); i++ ) {
00257 afp_i[i] = afp[i];
00258 }
00259 for( i = 0; i < n; i++ ) {
00260 ipiv_i[i] = ipiv[i];
00261 }
00262 for( i = 0; i < ldb*nrhs; i++ ) {
00263 b_i[i] = b[i];
00264 }
00265 for( i = 0; i < ldx*nrhs; i++ ) {
00266 x_i[i] = x_save[i];
00267 }
00268 for( i = 0; i < nrhs; i++ ) {
00269 ferr_i[i] = ferr_save[i];
00270 }
00271 for( i = 0; i < nrhs; i++ ) {
00272 berr_i[i] = berr_save[i];
00273 }
00274 for( i = 0; i < 3*n; i++ ) {
00275 work_i[i] = work[i];
00276 }
00277 for( i = 0; i < n; i++ ) {
00278 iwork_i[i] = iwork[i];
00279 }
00280
00281 LAPACKE_dpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00282 LAPACKE_dpp_trans( LAPACK_COL_MAJOR, uplo, n, afp_i, afp_r );
00283 LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00284 LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, nrhs, x_i, ldx, x_r, nrhs+2 );
00285 info_i = LAPACKE_dsprfs_work( LAPACK_ROW_MAJOR, uplo_i, n_i, nrhs_i, ap_r,
00286 afp_r, ipiv_i, b_r, ldb_r, x_r, ldx_r, ferr_i,
00287 berr_i, work_i, iwork_i );
00288
00289 LAPACKE_dge_trans( LAPACK_ROW_MAJOR, n, nrhs, x_r, nrhs+2, x_i, ldx );
00290
00291 failed = compare_dsprfs( x, x_i, ferr, ferr_i, berr, berr_i, info, info_i,
00292 ldx, nrhs );
00293 if( failed == 0 ) {
00294 printf( "PASSED: row-major middle-level interface to dsprfs\n" );
00295 } else {
00296 printf( "FAILED: row-major middle-level interface to dsprfs\n" );
00297 }
00298
00299
00300
00301 for( i = 0; i < (n*(n+1)/2); i++ ) {
00302 ap_i[i] = ap[i];
00303 }
00304 for( i = 0; i < (n*(n+1)/2); i++ ) {
00305 afp_i[i] = afp[i];
00306 }
00307 for( i = 0; i < n; i++ ) {
00308 ipiv_i[i] = ipiv[i];
00309 }
00310 for( i = 0; i < ldb*nrhs; i++ ) {
00311 b_i[i] = b[i];
00312 }
00313 for( i = 0; i < ldx*nrhs; i++ ) {
00314 x_i[i] = x_save[i];
00315 }
00316 for( i = 0; i < nrhs; i++ ) {
00317 ferr_i[i] = ferr_save[i];
00318 }
00319 for( i = 0; i < nrhs; i++ ) {
00320 berr_i[i] = berr_save[i];
00321 }
00322 for( i = 0; i < 3*n; i++ ) {
00323 work_i[i] = work[i];
00324 }
00325 for( i = 0; i < n; i++ ) {
00326 iwork_i[i] = iwork[i];
00327 }
00328
00329
00330 LAPACKE_dpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00331 LAPACKE_dpp_trans( LAPACK_COL_MAJOR, uplo, n, afp_i, afp_r );
00332 LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00333 LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, nrhs, x_i, ldx, x_r, nrhs+2 );
00334 info_i = LAPACKE_dsprfs( LAPACK_ROW_MAJOR, uplo_i, n_i, nrhs_i, ap_r, afp_r,
00335 ipiv_i, b_r, ldb_r, x_r, ldx_r, ferr_i, berr_i );
00336
00337 LAPACKE_dge_trans( LAPACK_ROW_MAJOR, n, nrhs, x_r, nrhs+2, x_i, ldx );
00338
00339 failed = compare_dsprfs( x, x_i, ferr, ferr_i, berr, berr_i, info, info_i,
00340 ldx, nrhs );
00341 if( failed == 0 ) {
00342 printf( "PASSED: row-major high-level interface to dsprfs\n" );
00343 } else {
00344 printf( "FAILED: row-major high-level interface to dsprfs\n" );
00345 }
00346
00347
00348 if( ap != NULL ) {
00349 LAPACKE_free( ap );
00350 }
00351 if( ap_i != NULL ) {
00352 LAPACKE_free( ap_i );
00353 }
00354 if( ap_r != NULL ) {
00355 LAPACKE_free( ap_r );
00356 }
00357 if( afp != NULL ) {
00358 LAPACKE_free( afp );
00359 }
00360 if( afp_i != NULL ) {
00361 LAPACKE_free( afp_i );
00362 }
00363 if( afp_r != NULL ) {
00364 LAPACKE_free( afp_r );
00365 }
00366 if( ipiv != NULL ) {
00367 LAPACKE_free( ipiv );
00368 }
00369 if( ipiv_i != NULL ) {
00370 LAPACKE_free( ipiv_i );
00371 }
00372 if( b != NULL ) {
00373 LAPACKE_free( b );
00374 }
00375 if( b_i != NULL ) {
00376 LAPACKE_free( b_i );
00377 }
00378 if( b_r != NULL ) {
00379 LAPACKE_free( b_r );
00380 }
00381 if( x != NULL ) {
00382 LAPACKE_free( x );
00383 }
00384 if( x_i != NULL ) {
00385 LAPACKE_free( x_i );
00386 }
00387 if( x_r != NULL ) {
00388 LAPACKE_free( x_r );
00389 }
00390 if( x_save != NULL ) {
00391 LAPACKE_free( x_save );
00392 }
00393 if( ferr != NULL ) {
00394 LAPACKE_free( ferr );
00395 }
00396 if( ferr_i != NULL ) {
00397 LAPACKE_free( ferr_i );
00398 }
00399 if( ferr_save != NULL ) {
00400 LAPACKE_free( ferr_save );
00401 }
00402 if( berr != NULL ) {
00403 LAPACKE_free( berr );
00404 }
00405 if( berr_i != NULL ) {
00406 LAPACKE_free( berr_i );
00407 }
00408 if( berr_save != NULL ) {
00409 LAPACKE_free( berr_save );
00410 }
00411 if( work != NULL ) {
00412 LAPACKE_free( work );
00413 }
00414 if( work_i != NULL ) {
00415 LAPACKE_free( work_i );
00416 }
00417 if( iwork != NULL ) {
00418 LAPACKE_free( iwork );
00419 }
00420 if( iwork_i != NULL ) {
00421 LAPACKE_free( iwork_i );
00422 }
00423
00424 return 0;
00425 }
00426
00427
00428 static void init_scalars_dsprfs( char *uplo, lapack_int *n, lapack_int *nrhs,
00429 lapack_int *ldb, lapack_int *ldx )
00430 {
00431 *uplo = 'L';
00432 *n = 4;
00433 *nrhs = 2;
00434 *ldb = 8;
00435 *ldx = 8;
00436
00437 return;
00438 }
00439
00440
00441 static void init_ap( lapack_int size, double *ap ) {
00442 lapack_int i;
00443 for( i = 0; i < size; i++ ) {
00444 ap[i] = 0;
00445 }
00446 ap[0] = 2.06999999999999980e+000;
00447 ap[1] = 3.87000000000000010e+000;
00448 ap[2] = 4.20000000000000020e+000;
00449 ap[3] = -1.14999999999999990e+000;
00450 ap[4] = -2.09999999999999990e-001;
00451 ap[5] = 1.87000000000000010e+000;
00452 ap[6] = 6.30000000000000000e-001;
00453 ap[7] = 1.14999999999999990e+000;
00454 ap[8] = 2.06000000000000010e+000;
00455 ap[9] = -1.81000000000000010e+000;
00456 }
00457 static void init_afp( lapack_int size, double *afp ) {
00458 lapack_int i;
00459 for( i = 0; i < size; i++ ) {
00460 afp[i] = 0;
00461 }
00462 afp[0] = 2.06999999999999980e+000;
00463 afp[1] = 4.20000000000000020e+000;
00464 afp[2] = 2.23041384055834070e-001;
00465 afp[3] = 6.53658376748910360e-001;
00466 afp[4] = 1.14999999999999990e+000;
00467 afp[5] = 8.11501032143910230e-001;
00468 afp[6] = -5.95969723778629450e-001;
00469 afp[7] = -2.59067708640519000e+000;
00470 afp[8] = 3.03084679550618070e-001;
00471 afp[9] = 4.07385198134887610e-001;
00472 }
00473 static void init_ipiv( lapack_int size, lapack_int *ipiv ) {
00474 lapack_int i;
00475 for( i = 0; i < size; i++ ) {
00476 ipiv[i] = 0;
00477 }
00478 ipiv[0] = -3;
00479 ipiv[1] = -3;
00480 ipiv[2] = 3;
00481 ipiv[3] = 4;
00482 }
00483 static void init_b( lapack_int size, double *b ) {
00484 lapack_int i;
00485 for( i = 0; i < size; i++ ) {
00486 b[i] = 0;
00487 }
00488 b[0] = -9.50000000000000000e+000;
00489 b[8] = 2.78500000000000010e+001;
00490 b[1] = -8.38000000000000080e+000;
00491 b[9] = 9.90000000000000040e+000;
00492 b[2] = -6.07000000000000030e+000;
00493 b[10] = 1.92500000000000000e+001;
00494 b[3] = -9.59999999999999960e-001;
00495 b[11] = 3.93000000000000020e+000;
00496 }
00497 static void init_x( lapack_int size, double *x ) {
00498 lapack_int i;
00499 for( i = 0; i < size; i++ ) {
00500 x[i] = 0;
00501 }
00502 x[0] = -4.00000000000000710e+000;
00503 x[8] = 1.00000000000000440e+000;
00504 x[1] = -1.00000000000000270e+000;
00505 x[9] = 4.00000000000000180e+000;
00506 x[2] = 2.00000000000000800e+000;
00507 x[10] = 2.99999999999999470e+000;
00508 x[3] = 5.00000000000001240e+000;
00509 x[11] = 1.99999999999999200e+000;
00510 }
00511 static void init_ferr( lapack_int size, double *ferr ) {
00512 lapack_int i;
00513 for( i = 0; i < size; i++ ) {
00514 ferr[i] = 0;
00515 }
00516 }
00517 static void init_berr( lapack_int size, double *berr ) {
00518 lapack_int i;
00519 for( i = 0; i < size; i++ ) {
00520 berr[i] = 0;
00521 }
00522 }
00523 static void init_work( lapack_int size, double *work ) {
00524 lapack_int i;
00525 for( i = 0; i < size; i++ ) {
00526 work[i] = 0;
00527 }
00528 }
00529 static void init_iwork( lapack_int size, lapack_int *iwork ) {
00530 lapack_int i;
00531 for( i = 0; i < size; i++ ) {
00532 iwork[i] = 0;
00533 }
00534 }
00535
00536
00537
00538 static int compare_dsprfs( double *x, double *x_i, double *ferr, double *ferr_i,
00539 double *berr, double *berr_i, lapack_int info,
00540 lapack_int info_i, lapack_int ldx, lapack_int nrhs )
00541 {
00542 lapack_int i;
00543 int failed = 0;
00544 for( i = 0; i < ldx*nrhs; i++ ) {
00545 failed += compare_doubles(x[i],x_i[i]);
00546 }
00547 for( i = 0; i < nrhs; i++ ) {
00548 failed += compare_doubles(ferr[i],ferr_i[i]);
00549 }
00550 for( i = 0; i < nrhs; i++ ) {
00551 failed += compare_doubles(berr[i],berr_i[i]);
00552 }
00553 failed += (info == info_i) ? 0 : 1;
00554 if( info != 0 || info_i != 0 ) {
00555 printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00556 }
00557
00558 return failed;
00559 }