dgbcon_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 * dgbcon_1 is the test program for the C interface to LAPACK
00036 * routine dgbcon
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_dgbcon( char *norm, lapack_int *n, lapack_int *kl,
00055                                  lapack_int *ku, lapack_int *ldab,
00056                                  double *anorm );
00057 static void init_ab( lapack_int size, double *ab );
00058 static void init_ipiv( lapack_int size, lapack_int *ipiv );
00059 static void init_work( lapack_int size, double *work );
00060 static void init_iwork( lapack_int size, lapack_int *iwork );
00061 static int compare_dgbcon( double rcond, double rcond_i, lapack_int info,
00062                            lapack_int info_i );
00063 
00064 int main(void)
00065 {
00066     /* Local scalars */
00067     char norm, norm_i;
00068     lapack_int n, n_i;
00069     lapack_int kl, kl_i;
00070     lapack_int ku, ku_i;
00071     lapack_int ldab, ldab_i;
00072     lapack_int ldab_r;
00073     double anorm, anorm_i;
00074     double rcond, rcond_i;
00075     lapack_int info, info_i;
00076     lapack_int i;
00077     int failed;
00078 
00079     /* Local arrays */
00080     double *ab = NULL, *ab_i = NULL;
00081     lapack_int *ipiv = NULL, *ipiv_i = NULL;
00082     double *work = NULL, *work_i = NULL;
00083     lapack_int *iwork = NULL, *iwork_i = NULL;
00084     double *ab_r = NULL;
00085 
00086     /* Iniitialize the scalar parameters */
00087     init_scalars_dgbcon( &norm, &n, &kl, &ku, &ldab, &anorm );
00088     ldab_r = n+2;
00089     norm_i = norm;
00090     n_i = n;
00091     kl_i = kl;
00092     ku_i = ku;
00093     ldab_i = ldab;
00094     anorm_i = anorm;
00095 
00096     /* Allocate memory for the LAPACK routine arrays */
00097     ab = (double *)LAPACKE_malloc( ldab*n * sizeof(double) );
00098     ipiv = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00099     work = (double *)LAPACKE_malloc( 3*n * sizeof(double) );
00100     iwork = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00101 
00102     /* Allocate memory for the C interface function arrays */
00103     ab_i = (double *)LAPACKE_malloc( ldab*n * sizeof(double) );
00104     ipiv_i = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00105     work_i = (double *)LAPACKE_malloc( 3*n * sizeof(double) );
00106     iwork_i = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00107 
00108     /* Allocate memory for the row-major arrays */
00109     ab_r = (double *)LAPACKE_malloc( ((2*kl+ku+1)*(n+2)) * sizeof(double) );
00110 
00111     /* Initialize input arrays */
00112     init_ab( ldab*n, ab );
00113     init_ipiv( n, ipiv );
00114     init_work( 3*n, work );
00115     init_iwork( n, iwork );
00116 
00117     /* Call the LAPACK routine */
00118     dgbcon_( &norm, &n, &kl, &ku, ab, &ldab, ipiv, &anorm, &rcond, work, iwork,
00119              &info );
00120 
00121     /* Initialize input data, call the column-major middle-level
00122      * interface to LAPACK routine and check the results */
00123     for( i = 0; i < ldab*n; i++ ) {
00124         ab_i[i] = ab[i];
00125     }
00126     for( i = 0; i < n; i++ ) {
00127         ipiv_i[i] = ipiv[i];
00128     }
00129     for( i = 0; i < 3*n; i++ ) {
00130         work_i[i] = work[i];
00131     }
00132     for( i = 0; i < n; i++ ) {
00133         iwork_i[i] = iwork[i];
00134     }
00135     info_i = LAPACKE_dgbcon_work( LAPACK_COL_MAJOR, norm_i, n_i, kl_i, ku_i,
00136                                   ab_i, ldab_i, ipiv_i, anorm_i, &rcond_i,
00137                                   work_i, iwork_i );
00138 
00139     failed = compare_dgbcon( rcond, rcond_i, info, info_i );
00140     if( failed == 0 ) {
00141         printf( "PASSED: column-major middle-level interface to dgbcon\n" );
00142     } else {
00143         printf( "FAILED: column-major middle-level interface to dgbcon\n" );
00144     }
00145 
00146     /* Initialize input data, call the column-major high-level
00147      * interface to LAPACK routine and check the results */
00148     for( i = 0; i < ldab*n; i++ ) {
00149         ab_i[i] = ab[i];
00150     }
00151     for( i = 0; i < n; i++ ) {
00152         ipiv_i[i] = ipiv[i];
00153     }
00154     for( i = 0; i < 3*n; i++ ) {
00155         work_i[i] = work[i];
00156     }
00157     for( i = 0; i < n; i++ ) {
00158         iwork_i[i] = iwork[i];
00159     }
00160     info_i = LAPACKE_dgbcon( LAPACK_COL_MAJOR, norm_i, n_i, kl_i, ku_i, ab_i,
00161                              ldab_i, ipiv_i, anorm_i, &rcond_i );
00162 
00163     failed = compare_dgbcon( rcond, rcond_i, info, info_i );
00164     if( failed == 0 ) {
00165         printf( "PASSED: column-major high-level interface to dgbcon\n" );
00166     } else {
00167         printf( "FAILED: column-major high-level interface to dgbcon\n" );
00168     }
00169 
00170     /* Initialize input data, call the row-major middle-level
00171      * interface to LAPACK routine and check the results */
00172     for( i = 0; i < ldab*n; i++ ) {
00173         ab_i[i] = ab[i];
00174     }
00175     for( i = 0; i < n; i++ ) {
00176         ipiv_i[i] = ipiv[i];
00177     }
00178     for( i = 0; i < 3*n; i++ ) {
00179         work_i[i] = work[i];
00180     }
00181     for( i = 0; i < n; i++ ) {
00182         iwork_i[i] = iwork[i];
00183     }
00184 
00185     LAPACKE_dge_trans( LAPACK_COL_MAJOR, 2*kl+ku+1, n, ab_i, ldab, ab_r, n+2 );
00186     info_i = LAPACKE_dgbcon_work( LAPACK_ROW_MAJOR, norm_i, n_i, kl_i, ku_i,
00187                                   ab_r, ldab_r, ipiv_i, anorm_i, &rcond_i,
00188                                   work_i, iwork_i );
00189 
00190     failed = compare_dgbcon( rcond, rcond_i, info, info_i );
00191     if( failed == 0 ) {
00192         printf( "PASSED: row-major middle-level interface to dgbcon\n" );
00193     } else {
00194         printf( "FAILED: row-major middle-level interface to dgbcon\n" );
00195     }
00196 
00197     /* Initialize input data, call the row-major high-level
00198      * interface to LAPACK routine and check the results */
00199     for( i = 0; i < ldab*n; i++ ) {
00200         ab_i[i] = ab[i];
00201     }
00202     for( i = 0; i < n; i++ ) {
00203         ipiv_i[i] = ipiv[i];
00204     }
00205     for( i = 0; i < 3*n; i++ ) {
00206         work_i[i] = work[i];
00207     }
00208     for( i = 0; i < n; i++ ) {
00209         iwork_i[i] = iwork[i];
00210     }
00211 
00212     /* Init row_major arrays */
00213     LAPACKE_dge_trans( LAPACK_COL_MAJOR, 2*kl+ku+1, n, ab_i, ldab, ab_r, n+2 );
00214     info_i = LAPACKE_dgbcon( LAPACK_ROW_MAJOR, norm_i, n_i, kl_i, ku_i, ab_r,
00215                              ldab_r, ipiv_i, anorm_i, &rcond_i );
00216 
00217     failed = compare_dgbcon( rcond, rcond_i, info, info_i );
00218     if( failed == 0 ) {
00219         printf( "PASSED: row-major high-level interface to dgbcon\n" );
00220     } else {
00221         printf( "FAILED: row-major high-level interface to dgbcon\n" );
00222     }
00223 
00224     /* Release memory */
00225     if( ab != NULL ) {
00226         LAPACKE_free( ab );
00227     }
00228     if( ab_i != NULL ) {
00229         LAPACKE_free( ab_i );
00230     }
00231     if( ab_r != NULL ) {
00232         LAPACKE_free( ab_r );
00233     }
00234     if( ipiv != NULL ) {
00235         LAPACKE_free( ipiv );
00236     }
00237     if( ipiv_i != NULL ) {
00238         LAPACKE_free( ipiv_i );
00239     }
00240     if( work != NULL ) {
00241         LAPACKE_free( work );
00242     }
00243     if( work_i != NULL ) {
00244         LAPACKE_free( work_i );
00245     }
00246     if( iwork != NULL ) {
00247         LAPACKE_free( iwork );
00248     }
00249     if( iwork_i != NULL ) {
00250         LAPACKE_free( iwork_i );
00251     }
00252 
00253     return 0;
00254 }
00255 
00256 /* Auxiliary function: dgbcon scalar parameters initialization */
00257 static void init_scalars_dgbcon( char *norm, lapack_int *n, lapack_int *kl,
00258                                  lapack_int *ku, lapack_int *ldab,
00259                                  double *anorm )
00260 {
00261     *norm = '1';
00262     *n = 4;
00263     *kl = 1;
00264     *ku = 2;
00265     *ldab = 25;
00266     *anorm = 1.36300000000000030e+001;
00267 
00268     return;
00269 }
00270 
00271 /* Auxiliary functions: dgbcon array parameters initialization */
00272 static void init_ab( lapack_int size, double *ab ) {
00273     lapack_int i;
00274     for( i = 0; i < size; i++ ) {
00275         ab[i] = 0;
00276     }
00277     ab[0] = 0.00000000000000000e+000;  /* ab[0,0] */
00278     ab[25] = 0.00000000000000000e+000;  /* ab[0,1] */
00279     ab[50] = 0.00000000000000000e+000;  /* ab[0,2] */
00280     ab[75] = -2.12999999999999990e+000;  /* ab[0,3] */
00281     ab[1] = 0.00000000000000000e+000;  /* ab[1,0] */
00282     ab[26] = 0.00000000000000000e+000;  /* ab[1,1] */
00283     ab[51] = -2.73000000000000000e+000;  /* ab[1,2] */
00284     ab[76] = 4.07000000000000030e+000;  /* ab[1,3] */
00285     ab[2] = 0.00000000000000000e+000;  /* ab[2,0] */
00286     ab[27] = 2.46000000000000000e+000;  /* ab[2,1] */
00287     ab[52] = 2.46000000000000000e+000;  /* ab[2,2] */
00288     ab[77] = -3.83914387088108940e+000;  /* ab[2,3] */
00289     ab[3] = -6.98000000000000040e+000;  /* ab[3,0] */
00290     ab[28] = 2.56000000000000010e+000;  /* ab[3,1] */
00291     ab[53] = -5.93293047098853950e+000;  /* ab[3,2] */
00292     ab[78] = -7.26906663992311850e-001;  /* ab[3,3] */
00293     ab[4] = 3.29512893982807990e-002;  /* ab[4,0] */
00294     ab[29] = 9.60523370343839610e-001;  /* ab[4,1] */
00295     ab[54] = 8.05672681211037410e-001;  /* ab[4,2] */
00296     ab[79] = 0.00000000000000000e+000;  /* ab[4,3] */
00297 }
00298 static void init_ipiv( lapack_int size, lapack_int *ipiv ) {
00299     lapack_int i;
00300     for( i = 0; i < size; i++ ) {
00301         ipiv[i] = 0;
00302     }
00303     ipiv[0] = 2;
00304     ipiv[1] = 3;
00305     ipiv[2] = 3;
00306     ipiv[3] = 4;
00307 }
00308 static void init_work( lapack_int size, double *work ) {
00309     lapack_int i;
00310     for( i = 0; i < size; i++ ) {
00311         work[i] = 0;
00312     }
00313 }
00314 static void init_iwork( lapack_int size, lapack_int *iwork ) {
00315     lapack_int i;
00316     for( i = 0; i < size; i++ ) {
00317         iwork[i] = 0;
00318     }
00319 }
00320 
00321 /* Auxiliary function: C interface to dgbcon results check */
00322 /* Return value: 0 - test is passed, non-zero - test is failed */
00323 static int compare_dgbcon( double rcond, double rcond_i, lapack_int info,
00324                            lapack_int info_i )
00325 {
00326     int failed = 0;
00327     failed += compare_doubles(rcond,rcond_i);
00328     failed += (info == info_i) ? 0 : 1;
00329     if( info != 0 || info_i != 0 ) {
00330         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00331     }
00332 
00333     return failed;
00334 }


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