dgbtrs_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 * dgbtrs_1 is the test program for the C interface to LAPACK
00036 * routine dgbtrs
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_dgbtrs( char *trans, lapack_int *n, lapack_int *kl,
00055                                  lapack_int *ku, lapack_int *nrhs,
00056                                  lapack_int *ldab, lapack_int *ldb );
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_b( lapack_int size, double *b );
00060 static int compare_dgbtrs( double *b, double *b_i, lapack_int info,
00061                            lapack_int info_i, lapack_int ldb, lapack_int nrhs );
00062 
00063 int main(void)
00064 {
00065     /* Local scalars */
00066     char trans, trans_i;
00067     lapack_int n, n_i;
00068     lapack_int kl, kl_i;
00069     lapack_int ku, ku_i;
00070     lapack_int nrhs, nrhs_i;
00071     lapack_int ldab, ldab_i;
00072     lapack_int ldab_r;
00073     lapack_int ldb, ldb_i;
00074     lapack_int ldb_r;
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 *b = NULL, *b_i = NULL;
00083     double *b_save = NULL;
00084     double *ab_r = NULL;
00085     double *b_r = NULL;
00086 
00087     /* Iniitialize the scalar parameters */
00088     init_scalars_dgbtrs( &trans, &n, &kl, &ku, &nrhs, &ldab, &ldb );
00089     ldab_r = n+2;
00090     ldb_r = nrhs+2;
00091     trans_i = trans;
00092     n_i = n;
00093     kl_i = kl;
00094     ku_i = ku;
00095     nrhs_i = nrhs;
00096     ldab_i = ldab;
00097     ldb_i = ldb;
00098 
00099     /* Allocate memory for the LAPACK routine arrays */
00100     ab = (double *)LAPACKE_malloc( ldab*n * sizeof(double) );
00101     ipiv = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00102     b = (double *)LAPACKE_malloc( ldb*nrhs * sizeof(double) );
00103 
00104     /* Allocate memory for the C interface function arrays */
00105     ab_i = (double *)LAPACKE_malloc( ldab*n * sizeof(double) );
00106     ipiv_i = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00107     b_i = (double *)LAPACKE_malloc( ldb*nrhs * sizeof(double) );
00108 
00109     /* Allocate memory for the backup arrays */
00110     b_save = (double *)LAPACKE_malloc( ldb*nrhs * sizeof(double) );
00111 
00112     /* Allocate memory for the row-major arrays */
00113     ab_r = (double *)LAPACKE_malloc( ((2*kl+ku+1)*(n+2)) * sizeof(double) );
00114     b_r = (double *)LAPACKE_malloc( n*(nrhs+2) * sizeof(double) );
00115 
00116     /* Initialize input arrays */
00117     init_ab( ldab*n, ab );
00118     init_ipiv( n, ipiv );
00119     init_b( ldb*nrhs, b );
00120 
00121     /* Backup the ouptut arrays */
00122     for( i = 0; i < ldb*nrhs; i++ ) {
00123         b_save[i] = b[i];
00124     }
00125 
00126     /* Call the LAPACK routine */
00127     dgbtrs_( &trans, &n, &kl, &ku, &nrhs, ab, &ldab, ipiv, b, &ldb, &info );
00128 
00129     /* Initialize input data, call the column-major middle-level
00130      * interface to LAPACK routine and check the results */
00131     for( i = 0; i < ldab*n; i++ ) {
00132         ab_i[i] = ab[i];
00133     }
00134     for( i = 0; i < n; i++ ) {
00135         ipiv_i[i] = ipiv[i];
00136     }
00137     for( i = 0; i < ldb*nrhs; i++ ) {
00138         b_i[i] = b_save[i];
00139     }
00140     info_i = LAPACKE_dgbtrs_work( LAPACK_COL_MAJOR, trans_i, n_i, kl_i, ku_i,
00141                                   nrhs_i, ab_i, ldab_i, ipiv_i, b_i, ldb_i );
00142 
00143     failed = compare_dgbtrs( b, b_i, info, info_i, ldb, nrhs );
00144     if( failed == 0 ) {
00145         printf( "PASSED: column-major middle-level interface to dgbtrs\n" );
00146     } else {
00147         printf( "FAILED: column-major middle-level interface to dgbtrs\n" );
00148     }
00149 
00150     /* Initialize input data, call the column-major high-level
00151      * interface to LAPACK routine and check the results */
00152     for( i = 0; i < ldab*n; i++ ) {
00153         ab_i[i] = ab[i];
00154     }
00155     for( i = 0; i < n; i++ ) {
00156         ipiv_i[i] = ipiv[i];
00157     }
00158     for( i = 0; i < ldb*nrhs; i++ ) {
00159         b_i[i] = b_save[i];
00160     }
00161     info_i = LAPACKE_dgbtrs( LAPACK_COL_MAJOR, trans_i, n_i, kl_i, ku_i, nrhs_i,
00162                              ab_i, ldab_i, ipiv_i, b_i, ldb_i );
00163 
00164     failed = compare_dgbtrs( b, b_i, info, info_i, ldb, nrhs );
00165     if( failed == 0 ) {
00166         printf( "PASSED: column-major high-level interface to dgbtrs\n" );
00167     } else {
00168         printf( "FAILED: column-major high-level interface to dgbtrs\n" );
00169     }
00170 
00171     /* Initialize input data, call the row-major middle-level
00172      * interface to LAPACK routine and check the results */
00173     for( i = 0; i < ldab*n; i++ ) {
00174         ab_i[i] = ab[i];
00175     }
00176     for( i = 0; i < n; i++ ) {
00177         ipiv_i[i] = ipiv[i];
00178     }
00179     for( i = 0; i < ldb*nrhs; i++ ) {
00180         b_i[i] = b_save[i];
00181     }
00182 
00183     LAPACKE_dge_trans( LAPACK_COL_MAJOR, 2*kl+ku+1, n, ab_i, ldab, ab_r, n+2 );
00184     LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00185     info_i = LAPACKE_dgbtrs_work( LAPACK_ROW_MAJOR, trans_i, n_i, kl_i, ku_i,
00186                                   nrhs_i, ab_r, ldab_r, ipiv_i, b_r, ldb_r );
00187 
00188     LAPACKE_dge_trans( LAPACK_ROW_MAJOR, n, nrhs, b_r, nrhs+2, b_i, ldb );
00189 
00190     failed = compare_dgbtrs( b, b_i, info, info_i, ldb, nrhs );
00191     if( failed == 0 ) {
00192         printf( "PASSED: row-major middle-level interface to dgbtrs\n" );
00193     } else {
00194         printf( "FAILED: row-major middle-level interface to dgbtrs\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 < ldb*nrhs; i++ ) {
00206         b_i[i] = b_save[i];
00207     }
00208 
00209     /* Init row_major arrays */
00210     LAPACKE_dge_trans( LAPACK_COL_MAJOR, 2*kl+ku+1, n, ab_i, ldab, ab_r, n+2 );
00211     LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00212     info_i = LAPACKE_dgbtrs( LAPACK_ROW_MAJOR, trans_i, n_i, kl_i, ku_i, nrhs_i,
00213                              ab_r, ldab_r, ipiv_i, b_r, ldb_r );
00214 
00215     LAPACKE_dge_trans( LAPACK_ROW_MAJOR, n, nrhs, b_r, nrhs+2, b_i, ldb );
00216 
00217     failed = compare_dgbtrs( b, b_i, info, info_i, ldb, nrhs );
00218     if( failed == 0 ) {
00219         printf( "PASSED: row-major high-level interface to dgbtrs\n" );
00220     } else {
00221         printf( "FAILED: row-major high-level interface to dgbtrs\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( b != NULL ) {
00241         LAPACKE_free( b );
00242     }
00243     if( b_i != NULL ) {
00244         LAPACKE_free( b_i );
00245     }
00246     if( b_r != NULL ) {
00247         LAPACKE_free( b_r );
00248     }
00249     if( b_save != NULL ) {
00250         LAPACKE_free( b_save );
00251     }
00252 
00253     return 0;
00254 }
00255 
00256 /* Auxiliary function: dgbtrs scalar parameters initialization */
00257 static void init_scalars_dgbtrs( char *trans, lapack_int *n, lapack_int *kl,
00258                                  lapack_int *ku, lapack_int *nrhs,
00259                                  lapack_int *ldab, lapack_int *ldb )
00260 {
00261     *trans = 'N';
00262     *n = 4;
00263     *kl = 1;
00264     *ku = 2;
00265     *nrhs = 2;
00266     *ldab = 25;
00267     *ldb = 8;
00268 
00269     return;
00270 }
00271 
00272 /* Auxiliary functions: dgbtrs array parameters initialization */
00273 static void init_ab( lapack_int size, double *ab ) {
00274     lapack_int i;
00275     for( i = 0; i < size; i++ ) {
00276         ab[i] = 0;
00277     }
00278     ab[0] = 0.00000000000000000e+000;  /* ab[0,0] */
00279     ab[25] = 0.00000000000000000e+000;  /* ab[0,1] */
00280     ab[50] = 0.00000000000000000e+000;  /* ab[0,2] */
00281     ab[75] = -2.12999999999999990e+000;  /* ab[0,3] */
00282     ab[1] = 0.00000000000000000e+000;  /* ab[1,0] */
00283     ab[26] = 0.00000000000000000e+000;  /* ab[1,1] */
00284     ab[51] = -2.73000000000000000e+000;  /* ab[1,2] */
00285     ab[76] = 4.07000000000000030e+000;  /* ab[1,3] */
00286     ab[2] = 0.00000000000000000e+000;  /* ab[2,0] */
00287     ab[27] = 2.46000000000000000e+000;  /* ab[2,1] */
00288     ab[52] = 2.46000000000000000e+000;  /* ab[2,2] */
00289     ab[77] = -3.83914387088108940e+000;  /* ab[2,3] */
00290     ab[3] = -6.98000000000000040e+000;  /* ab[3,0] */
00291     ab[28] = 2.56000000000000010e+000;  /* ab[3,1] */
00292     ab[53] = -5.93293047098853950e+000;  /* ab[3,2] */
00293     ab[78] = -7.26906663992311850e-001;  /* ab[3,3] */
00294     ab[4] = 3.29512893982807990e-002;  /* ab[4,0] */
00295     ab[29] = 9.60523370343839610e-001;  /* ab[4,1] */
00296     ab[54] = 8.05672681211037410e-001;  /* ab[4,2] */
00297     ab[79] = 0.00000000000000000e+000;  /* ab[4,3] */
00298 }
00299 static void init_ipiv( lapack_int size, lapack_int *ipiv ) {
00300     lapack_int i;
00301     for( i = 0; i < size; i++ ) {
00302         ipiv[i] = 0;
00303     }
00304     ipiv[0] = 2;
00305     ipiv[1] = 3;
00306     ipiv[2] = 3;
00307     ipiv[3] = 4;
00308 }
00309 static void init_b( lapack_int size, double *b ) {
00310     lapack_int i;
00311     for( i = 0; i < size; i++ ) {
00312         b[i] = 0;
00313     }
00314     b[0] = 4.41999999999999990e+000;  /* b[0,0] */
00315     b[8] = -3.60099999999999980e+001;  /* b[0,1] */
00316     b[1] = 2.71299999999999990e+001;  /* b[1,0] */
00317     b[9] = -3.16700000000000020e+001;  /* b[1,1] */
00318     b[2] = -6.13999999999999970e+000;  /* b[2,0] */
00319     b[10] = -1.15999999999999990e+000;  /* b[2,1] */
00320     b[3] = 1.05000000000000000e+001;  /* b[3,0] */
00321     b[11] = -2.58200000000000000e+001;  /* b[3,1] */
00322 }
00323 
00324 /* Auxiliary function: C interface to dgbtrs results check */
00325 /* Return value: 0 - test is passed, non-zero - test is failed */
00326 static int compare_dgbtrs( double *b, double *b_i, lapack_int info,
00327                            lapack_int info_i, lapack_int ldb, lapack_int nrhs )
00328 {
00329     lapack_int i;
00330     int failed = 0;
00331     for( i = 0; i < ldb*nrhs; i++ ) {
00332         failed += compare_doubles(b[i],b_i[i]);
00333     }
00334     failed += (info == info_i) ? 0 : 1;
00335     if( info != 0 || info_i != 0 ) {
00336         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00337     }
00338 
00339     return failed;
00340 }


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