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