ctbrfs_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 * ctbrfs_1 is the test program for the C interface to LAPACK
00036 * routine ctbrfs
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_ctbrfs( 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, lapack_complex_float *ab );
00059 static void init_b( lapack_int size, lapack_complex_float *b );
00060 static void init_x( lapack_int size, lapack_complex_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, lapack_complex_float *work );
00064 static void init_rwork( lapack_int size, float *rwork );
00065 static int compare_ctbrfs( float *ferr, float *ferr_i, float *berr,
00066                            float *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     lapack_complex_float *ab = NULL, *ab_i = NULL;
00090     lapack_complex_float *b = NULL, *b_i = NULL;
00091     lapack_complex_float *x = NULL, *x_i = NULL;
00092     float *ferr = NULL, *ferr_i = NULL;
00093     float *berr = NULL, *berr_i = NULL;
00094     lapack_complex_float *work = NULL, *work_i = NULL;
00095     float *rwork = NULL, *rwork_i = NULL;
00096     float *ferr_save = NULL;
00097     float *berr_save = NULL;
00098     lapack_complex_float *ab_r = NULL;
00099     lapack_complex_float *b_r = NULL;
00100     lapack_complex_float *x_r = NULL;
00101 
00102     /* Iniitialize the scalar parameters */
00103     init_scalars_ctbrfs( &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 = (lapack_complex_float *)
00120         LAPACKE_malloc( ldab*n * sizeof(lapack_complex_float) );
00121     b = (lapack_complex_float *)
00122         LAPACKE_malloc( ldb*nrhs * sizeof(lapack_complex_float) );
00123     x = (lapack_complex_float *)
00124         LAPACKE_malloc( ldx*nrhs * sizeof(lapack_complex_float) );
00125     ferr = (float *)LAPACKE_malloc( nrhs * sizeof(float) );
00126     berr = (float *)LAPACKE_malloc( nrhs * sizeof(float) );
00127     work = (lapack_complex_float *)
00128         LAPACKE_malloc( 2*n * sizeof(lapack_complex_float) );
00129     rwork = (float *)LAPACKE_malloc( n * sizeof(float) );
00130 
00131     /* Allocate memory for the C interface function arrays */
00132     ab_i = (lapack_complex_float *)
00133         LAPACKE_malloc( ldab*n * sizeof(lapack_complex_float) );
00134     b_i = (lapack_complex_float *)
00135         LAPACKE_malloc( ldb*nrhs * sizeof(lapack_complex_float) );
00136     x_i = (lapack_complex_float *)
00137         LAPACKE_malloc( ldx*nrhs * sizeof(lapack_complex_float) );
00138     ferr_i = (float *)LAPACKE_malloc( nrhs * sizeof(float) );
00139     berr_i = (float *)LAPACKE_malloc( nrhs * sizeof(float) );
00140     work_i = (lapack_complex_float *)
00141         LAPACKE_malloc( 2*n * sizeof(lapack_complex_float) );
00142     rwork_i = (float *)LAPACKE_malloc( n * sizeof(float) );
00143 
00144     /* Allocate memory for the backup arrays */
00145     ferr_save = (float *)LAPACKE_malloc( nrhs * sizeof(float) );
00146     berr_save = (float *)LAPACKE_malloc( nrhs * sizeof(float) );
00147 
00148     /* Allocate memory for the row-major arrays */
00149     ab_r = (lapack_complex_float *)
00150         LAPACKE_malloc( (kd+1)*(n+2) * sizeof(lapack_complex_float) );
00151     b_r = (lapack_complex_float *)
00152         LAPACKE_malloc( n*(nrhs+2) * sizeof(lapack_complex_float) );
00153     x_r = (lapack_complex_float *)
00154         LAPACKE_malloc( n*(nrhs+2) * sizeof(lapack_complex_float) );
00155 
00156     /* Initialize input arrays */
00157     init_ab( ldab*n, ab );
00158     init_b( ldb*nrhs, b );
00159     init_x( ldx*nrhs, x );
00160     init_ferr( nrhs, ferr );
00161     init_berr( nrhs, berr );
00162     init_work( 2*n, work );
00163     init_rwork( n, rwork );
00164 
00165     /* Backup the ouptut arrays */
00166     for( i = 0; i < nrhs; i++ ) {
00167         ferr_save[i] = ferr[i];
00168     }
00169     for( i = 0; i < nrhs; i++ ) {
00170         berr_save[i] = berr[i];
00171     }
00172 
00173     /* Call the LAPACK routine */
00174     ctbrfs_( &uplo, &trans, &diag, &n, &kd, &nrhs, ab, &ldab, b, &ldb, x, &ldx,
00175              ferr, berr, work, rwork, &info );
00176 
00177     /* Initialize input data, call the column-major middle-level
00178      * interface to LAPACK routine and check the results */
00179     for( i = 0; i < ldab*n; i++ ) {
00180         ab_i[i] = ab[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[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 < 2*n; i++ ) {
00195         work_i[i] = work[i];
00196     }
00197     for( i = 0; i < n; i++ ) {
00198         rwork_i[i] = rwork[i];
00199     }
00200     info_i = LAPACKE_ctbrfs_work( LAPACK_COL_MAJOR, uplo_i, trans_i, diag_i,
00201                                   n_i, kd_i, nrhs_i, ab_i, ldab_i, b_i, ldb_i,
00202                                   x_i, ldx_i, ferr_i, berr_i, work_i, rwork_i );
00203 
00204     failed = compare_ctbrfs( ferr, ferr_i, berr, berr_i, info, info_i, nrhs );
00205     if( failed == 0 ) {
00206         printf( "PASSED: column-major middle-level interface to ctbrfs\n" );
00207     } else {
00208         printf( "FAILED: column-major middle-level interface to ctbrfs\n" );
00209     }
00210 
00211     /* Initialize input data, call the column-major high-level
00212      * interface to LAPACK routine and check the results */
00213     for( i = 0; i < ldab*n; i++ ) {
00214         ab_i[i] = ab[i];
00215     }
00216     for( i = 0; i < ldb*nrhs; i++ ) {
00217         b_i[i] = b[i];
00218     }
00219     for( i = 0; i < ldx*nrhs; i++ ) {
00220         x_i[i] = x[i];
00221     }
00222     for( i = 0; i < nrhs; i++ ) {
00223         ferr_i[i] = ferr_save[i];
00224     }
00225     for( i = 0; i < nrhs; i++ ) {
00226         berr_i[i] = berr_save[i];
00227     }
00228     for( i = 0; i < 2*n; i++ ) {
00229         work_i[i] = work[i];
00230     }
00231     for( i = 0; i < n; i++ ) {
00232         rwork_i[i] = rwork[i];
00233     }
00234     info_i = LAPACKE_ctbrfs( LAPACK_COL_MAJOR, uplo_i, trans_i, diag_i, n_i,
00235                              kd_i, nrhs_i, ab_i, ldab_i, b_i, ldb_i, x_i, ldx_i,
00236                              ferr_i, berr_i );
00237 
00238     failed = compare_ctbrfs( ferr, ferr_i, berr, berr_i, info, info_i, nrhs );
00239     if( failed == 0 ) {
00240         printf( "PASSED: column-major high-level interface to ctbrfs\n" );
00241     } else {
00242         printf( "FAILED: column-major high-level interface to ctbrfs\n" );
00243     }
00244 
00245     /* Initialize input data, call the row-major middle-level
00246      * interface to LAPACK routine and check the results */
00247     for( i = 0; i < ldab*n; i++ ) {
00248         ab_i[i] = ab[i];
00249     }
00250     for( i = 0; i < ldb*nrhs; i++ ) {
00251         b_i[i] = b[i];
00252     }
00253     for( i = 0; i < ldx*nrhs; i++ ) {
00254         x_i[i] = x[i];
00255     }
00256     for( i = 0; i < nrhs; i++ ) {
00257         ferr_i[i] = ferr_save[i];
00258     }
00259     for( i = 0; i < nrhs; i++ ) {
00260         berr_i[i] = berr_save[i];
00261     }
00262     for( i = 0; i < 2*n; i++ ) {
00263         work_i[i] = work[i];
00264     }
00265     for( i = 0; i < n; i++ ) {
00266         rwork_i[i] = rwork[i];
00267     }
00268 
00269     LAPACKE_cge_trans( LAPACK_COL_MAJOR, kd+1, n, ab_i, ldab, ab_r, n+2 );
00270     LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00271     LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, nrhs, x_i, ldx, x_r, nrhs+2 );
00272     info_i = LAPACKE_ctbrfs_work( LAPACK_ROW_MAJOR, uplo_i, trans_i, diag_i,
00273                                   n_i, kd_i, nrhs_i, ab_r, ldab_r, b_r, ldb_r,
00274                                   x_r, ldx_r, ferr_i, berr_i, work_i, rwork_i );
00275 
00276     failed = compare_ctbrfs( ferr, ferr_i, berr, berr_i, info, info_i, nrhs );
00277     if( failed == 0 ) {
00278         printf( "PASSED: row-major middle-level interface to ctbrfs\n" );
00279     } else {
00280         printf( "FAILED: row-major middle-level interface to ctbrfs\n" );
00281     }
00282 
00283     /* Initialize input data, call the row-major high-level
00284      * interface to LAPACK routine and check the results */
00285     for( i = 0; i < ldab*n; i++ ) {
00286         ab_i[i] = ab[i];
00287     }
00288     for( i = 0; i < ldb*nrhs; i++ ) {
00289         b_i[i] = b[i];
00290     }
00291     for( i = 0; i < ldx*nrhs; i++ ) {
00292         x_i[i] = x[i];
00293     }
00294     for( i = 0; i < nrhs; i++ ) {
00295         ferr_i[i] = ferr_save[i];
00296     }
00297     for( i = 0; i < nrhs; i++ ) {
00298         berr_i[i] = berr_save[i];
00299     }
00300     for( i = 0; i < 2*n; i++ ) {
00301         work_i[i] = work[i];
00302     }
00303     for( i = 0; i < n; i++ ) {
00304         rwork_i[i] = rwork[i];
00305     }
00306 
00307     /* Init row_major arrays */
00308     LAPACKE_cge_trans( LAPACK_COL_MAJOR, kd+1, n, ab_i, ldab, ab_r, n+2 );
00309     LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00310     LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, nrhs, x_i, ldx, x_r, nrhs+2 );
00311     info_i = LAPACKE_ctbrfs( LAPACK_ROW_MAJOR, uplo_i, trans_i, diag_i, n_i,
00312                              kd_i, nrhs_i, ab_r, ldab_r, b_r, ldb_r, x_r, ldx_r,
00313                              ferr_i, berr_i );
00314 
00315     failed = compare_ctbrfs( ferr, ferr_i, berr, berr_i, info, info_i, nrhs );
00316     if( failed == 0 ) {
00317         printf( "PASSED: row-major high-level interface to ctbrfs\n" );
00318     } else {
00319         printf( "FAILED: row-major high-level interface to ctbrfs\n" );
00320     }
00321 
00322     /* Release memory */
00323     if( ab != NULL ) {
00324         LAPACKE_free( ab );
00325     }
00326     if( ab_i != NULL ) {
00327         LAPACKE_free( ab_i );
00328     }
00329     if( ab_r != NULL ) {
00330         LAPACKE_free( ab_r );
00331     }
00332     if( b != NULL ) {
00333         LAPACKE_free( b );
00334     }
00335     if( b_i != NULL ) {
00336         LAPACKE_free( b_i );
00337     }
00338     if( b_r != NULL ) {
00339         LAPACKE_free( b_r );
00340     }
00341     if( x != NULL ) {
00342         LAPACKE_free( x );
00343     }
00344     if( x_i != NULL ) {
00345         LAPACKE_free( x_i );
00346     }
00347     if( x_r != NULL ) {
00348         LAPACKE_free( x_r );
00349     }
00350     if( ferr != NULL ) {
00351         LAPACKE_free( ferr );
00352     }
00353     if( ferr_i != NULL ) {
00354         LAPACKE_free( ferr_i );
00355     }
00356     if( ferr_save != NULL ) {
00357         LAPACKE_free( ferr_save );
00358     }
00359     if( berr != NULL ) {
00360         LAPACKE_free( berr );
00361     }
00362     if( berr_i != NULL ) {
00363         LAPACKE_free( berr_i );
00364     }
00365     if( berr_save != NULL ) {
00366         LAPACKE_free( berr_save );
00367     }
00368     if( work != NULL ) {
00369         LAPACKE_free( work );
00370     }
00371     if( work_i != NULL ) {
00372         LAPACKE_free( work_i );
00373     }
00374     if( rwork != NULL ) {
00375         LAPACKE_free( rwork );
00376     }
00377     if( rwork_i != NULL ) {
00378         LAPACKE_free( rwork_i );
00379     }
00380 
00381     return 0;
00382 }
00383 
00384 /* Auxiliary function: ctbrfs scalar parameters initialization */
00385 static void init_scalars_ctbrfs( char *uplo, char *trans, char *diag,
00386                                  lapack_int *n, lapack_int *kd,
00387                                  lapack_int *nrhs, lapack_int *ldab,
00388                                  lapack_int *ldb, lapack_int *ldx )
00389 {
00390     *uplo = 'L';
00391     *trans = 'N';
00392     *diag = 'N';
00393     *n = 4;
00394     *kd = 2;
00395     *nrhs = 2;
00396     *ldab = 9;
00397     *ldb = 8;
00398     *ldx = 8;
00399 
00400     return;
00401 }
00402 
00403 /* Auxiliary functions: ctbrfs array parameters initialization */
00404 static void init_ab( lapack_int size, lapack_complex_float *ab ) {
00405     lapack_int i;
00406     for( i = 0; i < size; i++ ) {
00407         ab[i] = lapack_make_complex_float( 0.0f, 0.0f );
00408     }
00409     ab[0] = lapack_make_complex_float( -1.940000057e+000, 4.429999828e+000 );
00410     ab[9] = lapack_make_complex_float( 4.119999886e+000, -4.269999981e+000 );
00411     ab[18] = lapack_make_complex_float( 4.300000072e-001, -2.660000086e+000 );
00412     ab[27] = lapack_make_complex_float( 4.399999976e-001, 1.000000015e-001 );
00413     ab[1] = lapack_make_complex_float( -3.390000105e+000, 3.440000057e+000 );
00414     ab[10] = lapack_make_complex_float( -1.840000033e+000, 5.530000210e+000 );
00415     ab[19] = lapack_make_complex_float( 1.740000010e+000, -3.999999911e-002 );
00416     ab[28] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00417     ab[2] = lapack_make_complex_float( 1.620000005e+000, 3.680000067e+000 );
00418     ab[11] = lapack_make_complex_float( -2.769999981e+000, -1.929999948e+000 );
00419     ab[20] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00420     ab[29] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00421 }
00422 static void init_b( lapack_int size, lapack_complex_float *b ) {
00423     lapack_int i;
00424     for( i = 0; i < size; i++ ) {
00425         b[i] = lapack_make_complex_float( 0.0f, 0.0f );
00426     }
00427     b[0] = lapack_make_complex_float( -8.859999657e+000, -3.880000114e+000 );
00428     b[8] = lapack_make_complex_float( -2.409000015e+001, -5.269999981e+000 );
00429     b[1] = lapack_make_complex_float( -1.556999969e+001, -2.340999985e+001 );
00430     b[9] = lapack_make_complex_float( -5.797000122e+001, 8.140000343e+000 );
00431     b[2] = lapack_make_complex_float( -7.630000114e+000, 2.278000069e+001 );
00432     b[10] = lapack_make_complex_float( 1.909000015e+001, -2.951000023e+001 );
00433     b[3] = lapack_make_complex_float( -1.473999977e+001, -2.400000095e+000 );
00434     b[11] = lapack_make_complex_float( 1.917000008e+001, 2.132999992e+001 );
00435 }
00436 static void init_x( lapack_int size, lapack_complex_float *x ) {
00437     lapack_int i;
00438     for( i = 0; i < size; i++ ) {
00439         x[i] = lapack_make_complex_float( 0.0f, 0.0f );
00440     }
00441     x[0] = lapack_make_complex_float( 0.000000000e+000, 2.000000000e+000 );
00442     x[8] = lapack_make_complex_float( 1.000000119e+000, 5.000000000e+000 );
00443     x[1] = lapack_make_complex_float( 1.000000000e+000, -3.000000000e+000 );
00444     x[9] = lapack_make_complex_float( -7.000000000e+000, -1.999999642e+000 );
00445     x[2] = lapack_make_complex_float( -4.000000000e+000, -5.000000000e+000 );
00446     x[10] = lapack_make_complex_float( 2.999999285e+000, 4.000000000e+000 );
00447     x[3] = lapack_make_complex_float( 1.999999166e+000, -9.999992847e-001 );
00448     x[11] = lapack_make_complex_float( -5.999998093e+000, -8.999999046e+000 );
00449 }
00450 static void init_ferr( lapack_int size, float *ferr ) {
00451     lapack_int i;
00452     for( i = 0; i < size; i++ ) {
00453         ferr[i] = 0;
00454     }
00455 }
00456 static void init_berr( lapack_int size, float *berr ) {
00457     lapack_int i;
00458     for( i = 0; i < size; i++ ) {
00459         berr[i] = 0;
00460     }
00461 }
00462 static void init_work( lapack_int size, lapack_complex_float *work ) {
00463     lapack_int i;
00464     for( i = 0; i < size; i++ ) {
00465         work[i] = lapack_make_complex_float( 0.0f, 0.0f );
00466     }
00467 }
00468 static void init_rwork( lapack_int size, float *rwork ) {
00469     lapack_int i;
00470     for( i = 0; i < size; i++ ) {
00471         rwork[i] = 0;
00472     }
00473 }
00474 
00475 /* Auxiliary function: C interface to ctbrfs results check */
00476 /* Return value: 0 - test is passed, non-zero - test is failed */
00477 static int compare_ctbrfs( float *ferr, float *ferr_i, float *berr,
00478                            float *berr_i, lapack_int info, lapack_int info_i,
00479                            lapack_int nrhs )
00480 {
00481     lapack_int i;
00482     int failed = 0;
00483     for( i = 0; i < nrhs; i++ ) {
00484         failed += compare_floats(ferr[i],ferr_i[i]);
00485     }
00486     for( i = 0; i < nrhs; i++ ) {
00487         failed += compare_floats(berr[i],berr_i[i]);
00488     }
00489     failed += (info == info_i) ? 0 : 1;
00490     if( info != 0 || info_i != 0 ) {
00491         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00492     }
00493 
00494     return failed;
00495 }


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