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


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