dtbrfs_1.c
Go to the documentation of this file.
00001 /*****************************************************************************
00002   Copyright (c) 2010, Intel Corp.
00003   All rights reserved.
00004 
00005   Redistribution and use in source and binary forms, with or without
00006   modification, are permitted provided that the following conditions are met:
00007 
00008     * Redistributions of source code must retain the above copyright notice,
00009       this list of conditions and the following disclaimer.
00010     * Redistributions in binary form must reproduce the above copyright
00011       notice, this list of conditions and the following disclaimer in the
00012       documentation and/or other materials provided with the distribution.
00013     * Neither the name of Intel Corporation nor the names of its contributors
00014       may be used to endorse or promote products derived from this software
00015       without specific prior written permission.
00016 
00017   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
00027   THE POSSIBILITY OF SUCH DAMAGE.
00028 *****************************************************************************/
00029 /*  Contents: test routine for C interface to LAPACK
00030 *   Author: Intel Corporation
00031 *   Created in March, 2010
00032 *
00033 * Purpose
00034 *
00035 * dtbrfs_1 is the test program for the C interface to LAPACK
00036 * routine dtbrfs
00037 * The program doesn't require an input, the input data is hardcoded in the
00038 * test program.
00039 * The program tests the C interface in the four combinations:
00040 *   1) column-major layout, middle-level interface
00041 *   2) column-major layout, high-level interface
00042 *   3) row-major layout, middle-level interface
00043 *   4) row-major layout, high-level interface
00044 * The output of the C interface function is compared to those obtained from
00045 * the corresponiding LAPACK routine with the same input data, and the
00046 * comparison diagnostics is then printed on the standard output having PASSED
00047 * keyword if the test is passed, and FAILED keyword if the test isn't passed.
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_dtbrfs( char *uplo, char *trans, char *diag,
00055                                  lapack_int *n, lapack_int *kd,
00056                                  lapack_int *nrhs, lapack_int *ldab,
00057                                  lapack_int *ldb, lapack_int *ldx );
00058 static void init_ab( lapack_int size, double *ab );
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_dtbrfs( 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     /* Local scalars */
00072     char uplo, uplo_i;
00073     char trans, trans_i;
00074     char diag, diag_i;
00075     lapack_int n, n_i;
00076     lapack_int kd, kd_i;
00077     lapack_int nrhs, nrhs_i;
00078     lapack_int ldab, ldab_i;
00079     lapack_int ldab_r;
00080     lapack_int ldb, ldb_i;
00081     lapack_int ldb_r;
00082     lapack_int ldx, ldx_i;
00083     lapack_int ldx_r;
00084     lapack_int info, info_i;
00085     lapack_int i;
00086     int failed;
00087 
00088     /* Local arrays */
00089     double *ab = NULL, *ab_i = NULL;
00090     double *b = NULL, *b_i = NULL;
00091     double *x = NULL, *x_i = NULL;
00092     double *ferr = NULL, *ferr_i = NULL;
00093     double *berr = NULL, *berr_i = NULL;
00094     double *work = NULL, *work_i = NULL;
00095     lapack_int *iwork = NULL, *iwork_i = NULL;
00096     double *ferr_save = NULL;
00097     double *berr_save = NULL;
00098     double *ab_r = NULL;
00099     double *b_r = NULL;
00100     double *x_r = NULL;
00101 
00102     /* Iniitialize the scalar parameters */
00103     init_scalars_dtbrfs( &uplo, &trans, &diag, &n, &kd, &nrhs, &ldab, &ldb,
00104                          &ldx );
00105     ldab_r = n+2;
00106     ldb_r = nrhs+2;
00107     ldx_r = nrhs+2;
00108     uplo_i = uplo;
00109     trans_i = trans;
00110     diag_i = diag;
00111     n_i = n;
00112     kd_i = kd;
00113     nrhs_i = nrhs;
00114     ldab_i = ldab;
00115     ldb_i = ldb;
00116     ldx_i = ldx;
00117 
00118     /* Allocate memory for the LAPACK routine arrays */
00119     ab = (double *)LAPACKE_malloc( ldab*n * sizeof(double) );
00120     b = (double *)LAPACKE_malloc( ldb*nrhs * sizeof(double) );
00121     x = (double *)LAPACKE_malloc( ldx*nrhs * sizeof(double) );
00122     ferr = (double *)LAPACKE_malloc( nrhs * sizeof(double) );
00123     berr = (double *)LAPACKE_malloc( nrhs * sizeof(double) );
00124     work = (double *)LAPACKE_malloc( 3*n * sizeof(double) );
00125     iwork = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00126 
00127     /* Allocate memory for the C interface function arrays */
00128     ab_i = (double *)LAPACKE_malloc( ldab*n * sizeof(double) );
00129     b_i = (double *)LAPACKE_malloc( ldb*nrhs * sizeof(double) );
00130     x_i = (double *)LAPACKE_malloc( ldx*nrhs * sizeof(double) );
00131     ferr_i = (double *)LAPACKE_malloc( nrhs * sizeof(double) );
00132     berr_i = (double *)LAPACKE_malloc( nrhs * sizeof(double) );
00133     work_i = (double *)LAPACKE_malloc( 3*n * sizeof(double) );
00134     iwork_i = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00135 
00136     /* Allocate memory for the backup arrays */
00137     ferr_save = (double *)LAPACKE_malloc( nrhs * sizeof(double) );
00138     berr_save = (double *)LAPACKE_malloc( nrhs * sizeof(double) );
00139 
00140     /* Allocate memory for the row-major arrays */
00141     ab_r = (double *)LAPACKE_malloc( (kd+1)*(n+2) * sizeof(double) );
00142     b_r = (double *)LAPACKE_malloc( n*(nrhs+2) * sizeof(double) );
00143     x_r = (double *)LAPACKE_malloc( n*(nrhs+2) * sizeof(double) );
00144 
00145     /* Initialize input arrays */
00146     init_ab( ldab*n, ab );
00147     init_b( ldb*nrhs, b );
00148     init_x( ldx*nrhs, x );
00149     init_ferr( nrhs, ferr );
00150     init_berr( nrhs, berr );
00151     init_work( 3*n, work );
00152     init_iwork( n, iwork );
00153 
00154     /* Backup the ouptut arrays */
00155     for( i = 0; i < nrhs; i++ ) {
00156         ferr_save[i] = ferr[i];
00157     }
00158     for( i = 0; i < nrhs; i++ ) {
00159         berr_save[i] = berr[i];
00160     }
00161 
00162     /* Call the LAPACK routine */
00163     dtbrfs_( &uplo, &trans, &diag, &n, &kd, &nrhs, ab, &ldab, b, &ldb, x, &ldx,
00164              ferr, berr, work, iwork, &info );
00165 
00166     /* Initialize input data, call the column-major middle-level
00167      * interface to LAPACK routine and check the results */
00168     for( i = 0; i < ldab*n; i++ ) {
00169         ab_i[i] = ab[i];
00170     }
00171     for( i = 0; i < ldb*nrhs; i++ ) {
00172         b_i[i] = b[i];
00173     }
00174     for( i = 0; i < ldx*nrhs; i++ ) {
00175         x_i[i] = x[i];
00176     }
00177     for( i = 0; i < nrhs; i++ ) {
00178         ferr_i[i] = ferr_save[i];
00179     }
00180     for( i = 0; i < nrhs; i++ ) {
00181         berr_i[i] = berr_save[i];
00182     }
00183     for( i = 0; i < 3*n; i++ ) {
00184         work_i[i] = work[i];
00185     }
00186     for( i = 0; i < n; i++ ) {
00187         iwork_i[i] = iwork[i];
00188     }
00189     info_i = LAPACKE_dtbrfs_work( LAPACK_COL_MAJOR, uplo_i, trans_i, diag_i,
00190                                   n_i, kd_i, nrhs_i, ab_i, ldab_i, b_i, ldb_i,
00191                                   x_i, ldx_i, ferr_i, berr_i, work_i, iwork_i );
00192 
00193     failed = compare_dtbrfs( ferr, ferr_i, berr, berr_i, info, info_i, nrhs );
00194     if( failed == 0 ) {
00195         printf( "PASSED: column-major middle-level interface to dtbrfs\n" );
00196     } else {
00197         printf( "FAILED: column-major middle-level interface to dtbrfs\n" );
00198     }
00199 
00200     /* Initialize input data, call the column-major high-level
00201      * interface to LAPACK routine and check the results */
00202     for( i = 0; i < ldab*n; i++ ) {
00203         ab_i[i] = ab[i];
00204     }
00205     for( i = 0; i < ldb*nrhs; i++ ) {
00206         b_i[i] = b[i];
00207     }
00208     for( i = 0; i < ldx*nrhs; i++ ) {
00209         x_i[i] = x[i];
00210     }
00211     for( i = 0; i < nrhs; i++ ) {
00212         ferr_i[i] = ferr_save[i];
00213     }
00214     for( i = 0; i < nrhs; i++ ) {
00215         berr_i[i] = berr_save[i];
00216     }
00217     for( i = 0; i < 3*n; i++ ) {
00218         work_i[i] = work[i];
00219     }
00220     for( i = 0; i < n; i++ ) {
00221         iwork_i[i] = iwork[i];
00222     }
00223     info_i = LAPACKE_dtbrfs( LAPACK_COL_MAJOR, uplo_i, trans_i, diag_i, n_i,
00224                              kd_i, nrhs_i, ab_i, ldab_i, b_i, ldb_i, x_i, ldx_i,
00225                              ferr_i, berr_i );
00226 
00227     failed = compare_dtbrfs( ferr, ferr_i, berr, berr_i, info, info_i, nrhs );
00228     if( failed == 0 ) {
00229         printf( "PASSED: column-major high-level interface to dtbrfs\n" );
00230     } else {
00231         printf( "FAILED: column-major high-level interface to dtbrfs\n" );
00232     }
00233 
00234     /* Initialize input data, call the row-major middle-level
00235      * interface to LAPACK routine and check the results */
00236     for( i = 0; i < ldab*n; i++ ) {
00237         ab_i[i] = ab[i];
00238     }
00239     for( i = 0; i < ldb*nrhs; i++ ) {
00240         b_i[i] = b[i];
00241     }
00242     for( i = 0; i < ldx*nrhs; i++ ) {
00243         x_i[i] = x[i];
00244     }
00245     for( i = 0; i < nrhs; i++ ) {
00246         ferr_i[i] = ferr_save[i];
00247     }
00248     for( i = 0; i < nrhs; i++ ) {
00249         berr_i[i] = berr_save[i];
00250     }
00251     for( i = 0; i < 3*n; i++ ) {
00252         work_i[i] = work[i];
00253     }
00254     for( i = 0; i < n; i++ ) {
00255         iwork_i[i] = iwork[i];
00256     }
00257 
00258     LAPACKE_dge_trans( LAPACK_COL_MAJOR, kd+1, n, ab_i, ldab, ab_r, n+2 );
00259     LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00260     LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, nrhs, x_i, ldx, x_r, nrhs+2 );
00261     info_i = LAPACKE_dtbrfs_work( LAPACK_ROW_MAJOR, uplo_i, trans_i, diag_i,
00262                                   n_i, kd_i, nrhs_i, ab_r, ldab_r, b_r, ldb_r,
00263                                   x_r, ldx_r, ferr_i, berr_i, work_i, iwork_i );
00264 
00265     failed = compare_dtbrfs( ferr, ferr_i, berr, berr_i, info, info_i, nrhs );
00266     if( failed == 0 ) {
00267         printf( "PASSED: row-major middle-level interface to dtbrfs\n" );
00268     } else {
00269         printf( "FAILED: row-major middle-level interface to dtbrfs\n" );
00270     }
00271 
00272     /* Initialize input data, call the row-major high-level
00273      * interface to LAPACK routine and check the results */
00274     for( i = 0; i < ldab*n; i++ ) {
00275         ab_i[i] = ab[i];
00276     }
00277     for( i = 0; i < ldb*nrhs; i++ ) {
00278         b_i[i] = b[i];
00279     }
00280     for( i = 0; i < ldx*nrhs; i++ ) {
00281         x_i[i] = x[i];
00282     }
00283     for( i = 0; i < nrhs; i++ ) {
00284         ferr_i[i] = ferr_save[i];
00285     }
00286     for( i = 0; i < nrhs; i++ ) {
00287         berr_i[i] = berr_save[i];
00288     }
00289     for( i = 0; i < 3*n; i++ ) {
00290         work_i[i] = work[i];
00291     }
00292     for( i = 0; i < n; i++ ) {
00293         iwork_i[i] = iwork[i];
00294     }
00295 
00296     /* Init row_major arrays */
00297     LAPACKE_dge_trans( LAPACK_COL_MAJOR, kd+1, n, ab_i, ldab, ab_r, n+2 );
00298     LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00299     LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, nrhs, x_i, ldx, x_r, nrhs+2 );
00300     info_i = LAPACKE_dtbrfs( LAPACK_ROW_MAJOR, uplo_i, trans_i, diag_i, n_i,
00301                              kd_i, nrhs_i, ab_r, ldab_r, b_r, ldb_r, x_r, ldx_r,
00302                              ferr_i, berr_i );
00303 
00304     failed = compare_dtbrfs( ferr, ferr_i, berr, berr_i, info, info_i, nrhs );
00305     if( failed == 0 ) {
00306         printf( "PASSED: row-major high-level interface to dtbrfs\n" );
00307     } else {
00308         printf( "FAILED: row-major high-level interface to dtbrfs\n" );
00309     }
00310 
00311     /* Release memory */
00312     if( ab != NULL ) {
00313         LAPACKE_free( ab );
00314     }
00315     if( ab_i != NULL ) {
00316         LAPACKE_free( ab_i );
00317     }
00318     if( ab_r != NULL ) {
00319         LAPACKE_free( ab_r );
00320     }
00321     if( b != NULL ) {
00322         LAPACKE_free( b );
00323     }
00324     if( b_i != NULL ) {
00325         LAPACKE_free( b_i );
00326     }
00327     if( b_r != NULL ) {
00328         LAPACKE_free( b_r );
00329     }
00330     if( x != NULL ) {
00331         LAPACKE_free( x );
00332     }
00333     if( x_i != NULL ) {
00334         LAPACKE_free( x_i );
00335     }
00336     if( x_r != NULL ) {
00337         LAPACKE_free( x_r );
00338     }
00339     if( ferr != NULL ) {
00340         LAPACKE_free( ferr );
00341     }
00342     if( ferr_i != NULL ) {
00343         LAPACKE_free( ferr_i );
00344     }
00345     if( ferr_save != NULL ) {
00346         LAPACKE_free( ferr_save );
00347     }
00348     if( berr != NULL ) {
00349         LAPACKE_free( berr );
00350     }
00351     if( berr_i != NULL ) {
00352         LAPACKE_free( berr_i );
00353     }
00354     if( berr_save != NULL ) {
00355         LAPACKE_free( berr_save );
00356     }
00357     if( work != NULL ) {
00358         LAPACKE_free( work );
00359     }
00360     if( work_i != NULL ) {
00361         LAPACKE_free( work_i );
00362     }
00363     if( iwork != NULL ) {
00364         LAPACKE_free( iwork );
00365     }
00366     if( iwork_i != NULL ) {
00367         LAPACKE_free( iwork_i );
00368     }
00369 
00370     return 0;
00371 }
00372 
00373 /* Auxiliary function: dtbrfs scalar parameters initialization */
00374 static void init_scalars_dtbrfs( char *uplo, char *trans, char *diag,
00375                                  lapack_int *n, lapack_int *kd,
00376                                  lapack_int *nrhs, lapack_int *ldab,
00377                                  lapack_int *ldb, lapack_int *ldx )
00378 {
00379     *uplo = 'L';
00380     *trans = 'N';
00381     *diag = 'N';
00382     *n = 4;
00383     *kd = 1;
00384     *nrhs = 2;
00385     *ldab = 9;
00386     *ldb = 8;
00387     *ldx = 8;
00388 
00389     return;
00390 }
00391 
00392 /* Auxiliary functions: dtbrfs array parameters initialization */
00393 static void init_ab( lapack_int size, double *ab ) {
00394     lapack_int i;
00395     for( i = 0; i < size; i++ ) {
00396         ab[i] = 0;
00397     }
00398     ab[0] = -4.16000000000000010e+000;  /* ab[0,0] */
00399     ab[9] = 4.78000000000000020e+000;  /* ab[0,1] */
00400     ab[18] = 6.32000000000000030e+000;  /* ab[0,2] */
00401     ab[27] = 1.60000000000000000e-001;  /* ab[0,3] */
00402     ab[1] = -2.25000000000000000e+000;  /* ab[1,0] */
00403     ab[10] = 5.86000000000000030e+000;  /* ab[1,1] */
00404     ab[19] = -4.82000000000000030e+000;  /* ab[1,2] */
00405     ab[28] = 0.00000000000000000e+000;  /* ab[1,3] */
00406 }
00407 static void init_b( lapack_int size, double *b ) {
00408     lapack_int i;
00409     for( i = 0; i < size; i++ ) {
00410         b[i] = 0;
00411     }
00412     b[0] = -1.66400000000000010e+001;  /* b[0,0] */
00413     b[8] = -4.16000000000000010e+000;  /* b[0,1] */
00414     b[1] = -1.37799999999999990e+001;  /* b[1,0] */
00415     b[9] = -1.65900000000000000e+001;  /* b[1,1] */
00416     b[2] = 1.31000000000000000e+001;  /* b[2,0] */
00417     b[10] = -4.94000000000000040e+000;  /* b[2,1] */
00418     b[3] = -1.41400000000000010e+001;  /* b[3,0] */
00419     b[11] = -9.96000000000000090e+000;  /* b[3,1] */
00420 }
00421 static void init_x( lapack_int size, double *x ) {
00422     lapack_int i;
00423     for( i = 0; i < size; i++ ) {
00424         x[i] = 0;
00425     }
00426     x[0] = 4.00000000000000000e+000;  /* x[0,0] */
00427     x[8] = 1.00000000000000000e+000;  /* x[0,1] */
00428     x[1] = -9.99999999999999780e-001;  /* x[1,0] */
00429     x[9] = -3.00000000000000000e+000;  /* x[1,1] */
00430     x[2] = 3.00000000000000000e+000;  /* x[2,0] */
00431     x[10] = 2.00000000000000000e+000;  /* x[2,1] */
00432     x[3] = 2.00000000000000180e+000;  /* x[3,0] */
00433     x[11] = -2.00000000000000180e+000;  /* x[3,1] */
00434 }
00435 static void init_ferr( lapack_int size, double *ferr ) {
00436     lapack_int i;
00437     for( i = 0; i < size; i++ ) {
00438         ferr[i] = 0;
00439     }
00440 }
00441 static void init_berr( lapack_int size, double *berr ) {
00442     lapack_int i;
00443     for( i = 0; i < size; i++ ) {
00444         berr[i] = 0;
00445     }
00446 }
00447 static void init_work( lapack_int size, double *work ) {
00448     lapack_int i;
00449     for( i = 0; i < size; i++ ) {
00450         work[i] = 0;
00451     }
00452 }
00453 static void init_iwork( lapack_int size, lapack_int *iwork ) {
00454     lapack_int i;
00455     for( i = 0; i < size; i++ ) {
00456         iwork[i] = 0;
00457     }
00458 }
00459 
00460 /* Auxiliary function: C interface to dtbrfs results check */
00461 /* Return value: 0 - test is passed, non-zero - test is failed */
00462 static int compare_dtbrfs( double *ferr, double *ferr_i, double *berr,
00463                            double *berr_i, lapack_int info, lapack_int info_i,
00464                            lapack_int nrhs )
00465 {
00466     lapack_int i;
00467     int failed = 0;
00468     for( i = 0; i < nrhs; i++ ) {
00469         failed += compare_doubles(ferr[i],ferr_i[i]);
00470     }
00471     for( i = 0; i < nrhs; i++ ) {
00472         failed += compare_doubles(berr[i],berr_i[i]);
00473     }
00474     failed += (info == info_i) ? 0 : 1;
00475     if( info != 0 || info_i != 0 ) {
00476         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00477     }
00478 
00479     return failed;
00480 }


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:55:49