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_sporfs( char *uplo, lapack_int *n, lapack_int *nrhs,
00055 lapack_int *lda, lapack_int *ldaf,
00056 lapack_int *ldb, lapack_int *ldx );
00057 static void init_a( lapack_int size, float *a );
00058 static void init_af( lapack_int size, float *af );
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_sporfs( float *x, float *x_i, float *ferr, float *ferr_i,
00066 float *berr, float *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 lda, lda_i;
00076 lapack_int lda_r;
00077 lapack_int ldaf, ldaf_i;
00078 lapack_int ldaf_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 *af = NULL, *af_i = NULL;
00090 float *b = NULL, *b_i = NULL;
00091 float *x = NULL, *x_i = NULL;
00092 float *ferr = NULL, *ferr_i = NULL;
00093 float *berr = NULL, *berr_i = NULL;
00094 float *work = NULL, *work_i = NULL;
00095 lapack_int *iwork = NULL, *iwork_i = NULL;
00096 float *x_save = NULL;
00097 float *ferr_save = NULL;
00098 float *berr_save = NULL;
00099 float *a_r = NULL;
00100 float *af_r = NULL;
00101 float *b_r = NULL;
00102 float *x_r = NULL;
00103
00104
00105 init_scalars_sporfs( &uplo, &n, &nrhs, &lda, &ldaf, &ldb, &ldx );
00106 lda_r = n+2;
00107 ldaf_r = n+2;
00108 ldb_r = nrhs+2;
00109 ldx_r = nrhs+2;
00110 uplo_i = uplo;
00111 n_i = n;
00112 nrhs_i = nrhs;
00113 lda_i = lda;
00114 ldaf_i = ldaf;
00115 ldb_i = ldb;
00116 ldx_i = ldx;
00117
00118
00119 a = (float *)LAPACKE_malloc( lda*n * sizeof(float) );
00120 af = (float *)LAPACKE_malloc( ldaf*n * sizeof(float) );
00121 b = (float *)LAPACKE_malloc( ldb*nrhs * sizeof(float) );
00122 x = (float *)LAPACKE_malloc( ldx*nrhs * sizeof(float) );
00123 ferr = (float *)LAPACKE_malloc( nrhs * sizeof(float) );
00124 berr = (float *)LAPACKE_malloc( nrhs * sizeof(float) );
00125 work = (float *)LAPACKE_malloc( 3*n * sizeof(float) );
00126 iwork = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00127
00128
00129 a_i = (float *)LAPACKE_malloc( lda*n * sizeof(float) );
00130 af_i = (float *)LAPACKE_malloc( ldaf*n * sizeof(float) );
00131 b_i = (float *)LAPACKE_malloc( ldb*nrhs * sizeof(float) );
00132 x_i = (float *)LAPACKE_malloc( ldx*nrhs * sizeof(float) );
00133 ferr_i = (float *)LAPACKE_malloc( nrhs * sizeof(float) );
00134 berr_i = (float *)LAPACKE_malloc( nrhs * sizeof(float) );
00135 work_i = (float *)LAPACKE_malloc( 3*n * sizeof(float) );
00136 iwork_i = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00137
00138
00139 x_save = (float *)LAPACKE_malloc( ldx*nrhs * sizeof(float) );
00140 ferr_save = (float *)LAPACKE_malloc( nrhs * sizeof(float) );
00141 berr_save = (float *)LAPACKE_malloc( nrhs * sizeof(float) );
00142
00143
00144 a_r = (float *)LAPACKE_malloc( n*(n+2) * sizeof(float) );
00145 af_r = (float *)LAPACKE_malloc( n*(n+2) * sizeof(float) );
00146 b_r = (float *)LAPACKE_malloc( n*(nrhs+2) * sizeof(float) );
00147 x_r = (float *)LAPACKE_malloc( n*(nrhs+2) * sizeof(float) );
00148
00149
00150 init_a( lda*n, a );
00151 init_af( ldaf*n, af );
00152 init_b( ldb*nrhs, b );
00153 init_x( ldx*nrhs, x );
00154 init_ferr( nrhs, ferr );
00155 init_berr( nrhs, berr );
00156 init_work( 3*n, work );
00157 init_iwork( n, iwork );
00158
00159
00160 for( i = 0; i < ldx*nrhs; i++ ) {
00161 x_save[i] = x[i];
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 sporfs_( &uplo, &n, &nrhs, a, &lda, af, &ldaf, b, &ldb, x, &ldx, ferr, berr,
00172 work, iwork, &info );
00173
00174
00175
00176 for( i = 0; i < lda*n; i++ ) {
00177 a_i[i] = a[i];
00178 }
00179 for( i = 0; i < ldaf*n; i++ ) {
00180 af_i[i] = af[i];
00181 }
00182 for( i = 0; i < ldb*nrhs; i++ ) {
00183 b_i[i] = b[i];
00184 }
00185 for( i = 0; i < ldx*nrhs; i++ ) {
00186 x_i[i] = x_save[i];
00187 }
00188 for( i = 0; i < nrhs; i++ ) {
00189 ferr_i[i] = ferr_save[i];
00190 }
00191 for( i = 0; i < nrhs; i++ ) {
00192 berr_i[i] = berr_save[i];
00193 }
00194 for( i = 0; i < 3*n; i++ ) {
00195 work_i[i] = work[i];
00196 }
00197 for( i = 0; i < n; i++ ) {
00198 iwork_i[i] = iwork[i];
00199 }
00200 info_i = LAPACKE_sporfs_work( LAPACK_COL_MAJOR, uplo_i, n_i, nrhs_i, a_i,
00201 lda_i, af_i, ldaf_i, b_i, ldb_i, x_i, ldx_i,
00202 ferr_i, berr_i, work_i, iwork_i );
00203
00204 failed = compare_sporfs( x, x_i, ferr, ferr_i, berr, berr_i, info, info_i,
00205 ldx, nrhs );
00206 if( failed == 0 ) {
00207 printf( "PASSED: column-major middle-level interface to sporfs\n" );
00208 } else {
00209 printf( "FAILED: column-major middle-level interface to sporfs\n" );
00210 }
00211
00212
00213
00214 for( i = 0; i < lda*n; i++ ) {
00215 a_i[i] = a[i];
00216 }
00217 for( i = 0; i < ldaf*n; i++ ) {
00218 af_i[i] = af[i];
00219 }
00220 for( i = 0; i < ldb*nrhs; i++ ) {
00221 b_i[i] = b[i];
00222 }
00223 for( i = 0; i < ldx*nrhs; i++ ) {
00224 x_i[i] = x_save[i];
00225 }
00226 for( i = 0; i < nrhs; i++ ) {
00227 ferr_i[i] = ferr_save[i];
00228 }
00229 for( i = 0; i < nrhs; i++ ) {
00230 berr_i[i] = berr_save[i];
00231 }
00232 for( i = 0; i < 3*n; i++ ) {
00233 work_i[i] = work[i];
00234 }
00235 for( i = 0; i < n; i++ ) {
00236 iwork_i[i] = iwork[i];
00237 }
00238 info_i = LAPACKE_sporfs( LAPACK_COL_MAJOR, uplo_i, n_i, nrhs_i, a_i, lda_i,
00239 af_i, ldaf_i, b_i, ldb_i, x_i, ldx_i, ferr_i,
00240 berr_i );
00241
00242 failed = compare_sporfs( x, x_i, ferr, ferr_i, berr, berr_i, info, info_i,
00243 ldx, nrhs );
00244 if( failed == 0 ) {
00245 printf( "PASSED: column-major high-level interface to sporfs\n" );
00246 } else {
00247 printf( "FAILED: column-major high-level interface to sporfs\n" );
00248 }
00249
00250
00251
00252 for( i = 0; i < lda*n; i++ ) {
00253 a_i[i] = a[i];
00254 }
00255 for( i = 0; i < ldaf*n; i++ ) {
00256 af_i[i] = af[i];
00257 }
00258 for( i = 0; i < ldb*nrhs; i++ ) {
00259 b_i[i] = b[i];
00260 }
00261 for( i = 0; i < ldx*nrhs; i++ ) {
00262 x_i[i] = x_save[i];
00263 }
00264 for( i = 0; i < nrhs; i++ ) {
00265 ferr_i[i] = ferr_save[i];
00266 }
00267 for( i = 0; i < nrhs; i++ ) {
00268 berr_i[i] = berr_save[i];
00269 }
00270 for( i = 0; i < 3*n; i++ ) {
00271 work_i[i] = work[i];
00272 }
00273 for( i = 0; i < n; i++ ) {
00274 iwork_i[i] = iwork[i];
00275 }
00276
00277 LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00278 LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, n, af_i, ldaf, af_r, n+2 );
00279 LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00280 LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, nrhs, x_i, ldx, x_r, nrhs+2 );
00281 info_i = LAPACKE_sporfs_work( LAPACK_ROW_MAJOR, uplo_i, n_i, nrhs_i, a_r,
00282 lda_r, af_r, ldaf_r, b_r, ldb_r, x_r, ldx_r,
00283 ferr_i, berr_i, work_i, iwork_i );
00284
00285 LAPACKE_sge_trans( LAPACK_ROW_MAJOR, n, nrhs, x_r, nrhs+2, x_i, ldx );
00286
00287 failed = compare_sporfs( x, x_i, ferr, ferr_i, berr, berr_i, info, info_i,
00288 ldx, nrhs );
00289 if( failed == 0 ) {
00290 printf( "PASSED: row-major middle-level interface to sporfs\n" );
00291 } else {
00292 printf( "FAILED: row-major middle-level interface to sporfs\n" );
00293 }
00294
00295
00296
00297 for( i = 0; i < lda*n; i++ ) {
00298 a_i[i] = a[i];
00299 }
00300 for( i = 0; i < ldaf*n; i++ ) {
00301 af_i[i] = af[i];
00302 }
00303 for( i = 0; i < ldb*nrhs; i++ ) {
00304 b_i[i] = b[i];
00305 }
00306 for( i = 0; i < ldx*nrhs; i++ ) {
00307 x_i[i] = x_save[i];
00308 }
00309 for( i = 0; i < nrhs; i++ ) {
00310 ferr_i[i] = ferr_save[i];
00311 }
00312 for( i = 0; i < nrhs; i++ ) {
00313 berr_i[i] = berr_save[i];
00314 }
00315 for( i = 0; i < 3*n; i++ ) {
00316 work_i[i] = work[i];
00317 }
00318 for( i = 0; i < n; i++ ) {
00319 iwork_i[i] = iwork[i];
00320 }
00321
00322
00323 LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00324 LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, n, af_i, ldaf, af_r, n+2 );
00325 LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00326 LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, nrhs, x_i, ldx, x_r, nrhs+2 );
00327 info_i = LAPACKE_sporfs( LAPACK_ROW_MAJOR, uplo_i, n_i, nrhs_i, a_r, lda_r,
00328 af_r, ldaf_r, b_r, ldb_r, x_r, ldx_r, ferr_i,
00329 berr_i );
00330
00331 LAPACKE_sge_trans( LAPACK_ROW_MAJOR, n, nrhs, x_r, nrhs+2, x_i, ldx );
00332
00333 failed = compare_sporfs( x, x_i, ferr, ferr_i, berr, berr_i, info, info_i,
00334 ldx, nrhs );
00335 if( failed == 0 ) {
00336 printf( "PASSED: row-major high-level interface to sporfs\n" );
00337 } else {
00338 printf( "FAILED: row-major high-level interface to sporfs\n" );
00339 }
00340
00341
00342 if( a != NULL ) {
00343 LAPACKE_free( a );
00344 }
00345 if( a_i != NULL ) {
00346 LAPACKE_free( a_i );
00347 }
00348 if( a_r != NULL ) {
00349 LAPACKE_free( a_r );
00350 }
00351 if( af != NULL ) {
00352 LAPACKE_free( af );
00353 }
00354 if( af_i != NULL ) {
00355 LAPACKE_free( af_i );
00356 }
00357 if( af_r != NULL ) {
00358 LAPACKE_free( af_r );
00359 }
00360 if( b != NULL ) {
00361 LAPACKE_free( b );
00362 }
00363 if( b_i != NULL ) {
00364 LAPACKE_free( b_i );
00365 }
00366 if( b_r != NULL ) {
00367 LAPACKE_free( b_r );
00368 }
00369 if( x != NULL ) {
00370 LAPACKE_free( x );
00371 }
00372 if( x_i != NULL ) {
00373 LAPACKE_free( x_i );
00374 }
00375 if( x_r != NULL ) {
00376 LAPACKE_free( x_r );
00377 }
00378 if( x_save != NULL ) {
00379 LAPACKE_free( x_save );
00380 }
00381 if( ferr != NULL ) {
00382 LAPACKE_free( ferr );
00383 }
00384 if( ferr_i != NULL ) {
00385 LAPACKE_free( ferr_i );
00386 }
00387 if( ferr_save != NULL ) {
00388 LAPACKE_free( ferr_save );
00389 }
00390 if( berr != NULL ) {
00391 LAPACKE_free( berr );
00392 }
00393 if( berr_i != NULL ) {
00394 LAPACKE_free( berr_i );
00395 }
00396 if( berr_save != NULL ) {
00397 LAPACKE_free( berr_save );
00398 }
00399 if( work != NULL ) {
00400 LAPACKE_free( work );
00401 }
00402 if( work_i != NULL ) {
00403 LAPACKE_free( work_i );
00404 }
00405 if( iwork != NULL ) {
00406 LAPACKE_free( iwork );
00407 }
00408 if( iwork_i != NULL ) {
00409 LAPACKE_free( iwork_i );
00410 }
00411
00412 return 0;
00413 }
00414
00415
00416 static void init_scalars_sporfs( char *uplo, lapack_int *n, lapack_int *nrhs,
00417 lapack_int *lda, lapack_int *ldaf,
00418 lapack_int *ldb, lapack_int *ldx )
00419 {
00420 *uplo = 'L';
00421 *n = 4;
00422 *nrhs = 2;
00423 *lda = 8;
00424 *ldaf = 8;
00425 *ldb = 8;
00426 *ldx = 8;
00427
00428 return;
00429 }
00430
00431
00432 static void init_a( lapack_int size, float *a ) {
00433 lapack_int i;
00434 for( i = 0; i < size; i++ ) {
00435 a[i] = 0;
00436 }
00437 a[0] = 4.159999847e+000;
00438 a[8] = 0.000000000e+000;
00439 a[16] = 0.000000000e+000;
00440 a[24] = 0.000000000e+000;
00441 a[1] = -3.119999886e+000;
00442 a[9] = 5.030000210e+000;
00443 a[17] = 0.000000000e+000;
00444 a[25] = 0.000000000e+000;
00445 a[2] = 5.600000024e-001;
00446 a[10] = -8.299999833e-001;
00447 a[18] = 7.599999905e-001;
00448 a[26] = 0.000000000e+000;
00449 a[3] = -1.000000015e-001;
00450 a[11] = 1.179999948e+000;
00451 a[19] = 3.400000036e-001;
00452 a[27] = 1.179999948e+000;
00453 }
00454 static void init_af( lapack_int size, float *af ) {
00455 lapack_int i;
00456 for( i = 0; i < size; i++ ) {
00457 af[i] = 0;
00458 }
00459 af[0] = 2.039607763e+000;
00460 af[8] = 0.000000000e+000;
00461 af[16] = 0.000000000e+000;
00462 af[24] = 0.000000000e+000;
00463 af[1] = -1.529705763e+000;
00464 af[9] = 1.640122056e+000;
00465 af[17] = 0.000000000e+000;
00466 af[25] = 0.000000000e+000;
00467 af[2] = 2.745625973e-001;
00468 af[10] = -2.499813884e-001;
00469 af[18] = 7.887488008e-001;
00470 af[26] = 0.000000000e+000;
00471 af[3] = -4.902903363e-002;
00472 af[11] = 6.737302542e-001;
00473 af[19] = 6.616575122e-001;
00474 af[27] = 5.346896052e-001;
00475 }
00476 static void init_b( lapack_int size, float *b ) {
00477 lapack_int i;
00478 for( i = 0; i < size; i++ ) {
00479 b[i] = 0;
00480 }
00481 b[0] = 8.699999809e+000;
00482 b[8] = 8.300000191e+000;
00483 b[1] = -1.335000038e+001;
00484 b[9] = 2.130000114e+000;
00485 b[2] = 1.889999986e+000;
00486 b[10] = 1.610000014e+000;
00487 b[3] = -4.139999866e+000;
00488 b[11] = 5.000000000e+000;
00489 }
00490 static void init_x( lapack_int size, float *x ) {
00491 lapack_int i;
00492 for( i = 0; i < size; i++ ) {
00493 x[i] = 0;
00494 }
00495 x[0] = 1.000000119e+000;
00496 x[8] = 3.999998093e+000;
00497 x[1] = -9.999998808e-001;
00498 x[9] = 2.999996424e+000;
00499 x[2] = 2.000000477e+000;
00500 x[10] = 1.999995232e+000;
00501 x[3] = -3.000000477e+000;
00502 x[11] = 1.000004888e+000;
00503 }
00504 static void init_ferr( lapack_int size, float *ferr ) {
00505 lapack_int i;
00506 for( i = 0; i < size; i++ ) {
00507 ferr[i] = 0;
00508 }
00509 }
00510 static void init_berr( lapack_int size, float *berr ) {
00511 lapack_int i;
00512 for( i = 0; i < size; i++ ) {
00513 berr[i] = 0;
00514 }
00515 }
00516 static void init_work( lapack_int size, float *work ) {
00517 lapack_int i;
00518 for( i = 0; i < size; i++ ) {
00519 work[i] = 0;
00520 }
00521 }
00522 static void init_iwork( lapack_int size, lapack_int *iwork ) {
00523 lapack_int i;
00524 for( i = 0; i < size; i++ ) {
00525 iwork[i] = 0;
00526 }
00527 }
00528
00529
00530
00531 static int compare_sporfs( float *x, float *x_i, float *ferr, float *ferr_i,
00532 float *berr, float *berr_i, lapack_int info,
00533 lapack_int info_i, lapack_int ldx, lapack_int nrhs )
00534 {
00535 lapack_int i;
00536 int failed = 0;
00537 for( i = 0; i < ldx*nrhs; i++ ) {
00538 failed += compare_floats(x[i],x_i[i]);
00539 }
00540 for( i = 0; i < nrhs; i++ ) {
00541 failed += compare_floats(ferr[i],ferr_i[i]);
00542 }
00543 for( i = 0; i < nrhs; i++ ) {
00544 failed += compare_floats(berr[i],berr_i[i]);
00545 }
00546 failed += (info == info_i) ? 0 : 1;
00547 if( info != 0 || info_i != 0 ) {
00548 printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00549 }
00550
00551 return failed;
00552 }