cgbtrf_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 * cgbtrf_1 is the test program for the C interface to LAPACK
00036 * routine cgbtrf
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_cgbtrf( lapack_int *m, lapack_int *n, lapack_int *kl,
00055                                  lapack_int *ku, lapack_int *ldab );
00056 static void init_ab( lapack_int size, lapack_complex_float *ab );
00057 static void init_ipiv( lapack_int size, lapack_int *ipiv );
00058 static int compare_cgbtrf( lapack_complex_float *ab, lapack_complex_float *ab_i,
00059                            lapack_int *ipiv, lapack_int *ipiv_i,
00060                            lapack_int info, lapack_int info_i, lapack_int ldab,
00061                            lapack_int m, 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     lapack_complex_float *ab = NULL, *ab_i = NULL;
00078     lapack_int *ipiv = NULL, *ipiv_i = NULL;
00079     lapack_complex_float *ab_save = NULL;
00080     lapack_int *ipiv_save = NULL;
00081     lapack_complex_float *ab_r = NULL;
00082 
00083     /* Iniitialize the scalar parameters */
00084     init_scalars_cgbtrf( &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 = (lapack_complex_float *)
00094         LAPACKE_malloc( ldab*n * sizeof(lapack_complex_float) );
00095     ipiv = (lapack_int *)LAPACKE_malloc( MIN(m,n) * sizeof(lapack_int) );
00096 
00097     /* Allocate memory for the C interface function arrays */
00098     ab_i = (lapack_complex_float *)
00099         LAPACKE_malloc( ldab*n * sizeof(lapack_complex_float) );
00100     ipiv_i = (lapack_int *)LAPACKE_malloc( MIN(m,n) * sizeof(lapack_int) );
00101 
00102     /* Allocate memory for the backup arrays */
00103     ab_save = (lapack_complex_float *)
00104         LAPACKE_malloc( ldab*n * sizeof(lapack_complex_float) );
00105     ipiv_save = (lapack_int *)LAPACKE_malloc( MIN(m,n) * sizeof(lapack_int) );
00106 
00107     /* Allocate memory for the row-major arrays */
00108     ab_r = (lapack_complex_float *)
00109         LAPACKE_malloc( ((2*kl+ku+1)*(n+2)) * sizeof(lapack_complex_float) );
00110 
00111     /* Initialize input arrays */
00112     init_ab( ldab*n, ab );
00113     init_ipiv( (MIN(m,n)), ipiv );
00114 
00115     /* Backup the ouptut arrays */
00116     for( i = 0; i < ldab*n; i++ ) {
00117         ab_save[i] = ab[i];
00118     }
00119     for( i = 0; i < (MIN(m,n)); i++ ) {
00120         ipiv_save[i] = ipiv[i];
00121     }
00122 
00123     /* Call the LAPACK routine */
00124     cgbtrf_( &m, &n, &kl, &ku, ab, &ldab, ipiv, &info );
00125 
00126     /* Initialize input data, call the column-major middle-level
00127      * interface to LAPACK routine and check the results */
00128     for( i = 0; i < ldab*n; i++ ) {
00129         ab_i[i] = ab_save[i];
00130     }
00131     for( i = 0; i < (MIN(m,n)); i++ ) {
00132         ipiv_i[i] = ipiv_save[i];
00133     }
00134     info_i = LAPACKE_cgbtrf_work( LAPACK_COL_MAJOR, m_i, n_i, kl_i, ku_i, ab_i,
00135                                   ldab_i, ipiv_i );
00136 
00137     failed = compare_cgbtrf( ab, ab_i, ipiv, ipiv_i, info, info_i, ldab, m, n );
00138     if( failed == 0 ) {
00139         printf( "PASSED: column-major middle-level interface to cgbtrf\n" );
00140     } else {
00141         printf( "FAILED: column-major middle-level interface to cgbtrf\n" );
00142     }
00143 
00144     /* Initialize input data, call the column-major high-level
00145      * interface to LAPACK routine and check the results */
00146     for( i = 0; i < ldab*n; i++ ) {
00147         ab_i[i] = ab_save[i];
00148     }
00149     for( i = 0; i < (MIN(m,n)); i++ ) {
00150         ipiv_i[i] = ipiv_save[i];
00151     }
00152     info_i = LAPACKE_cgbtrf( LAPACK_COL_MAJOR, m_i, n_i, kl_i, ku_i, ab_i,
00153                              ldab_i, ipiv_i );
00154 
00155     failed = compare_cgbtrf( ab, ab_i, ipiv, ipiv_i, info, info_i, ldab, m, n );
00156     if( failed == 0 ) {
00157         printf( "PASSED: column-major high-level interface to cgbtrf\n" );
00158     } else {
00159         printf( "FAILED: column-major high-level interface to cgbtrf\n" );
00160     }
00161 
00162     /* Initialize input data, call the row-major middle-level
00163      * interface to LAPACK routine and check the results */
00164     for( i = 0; i < ldab*n; i++ ) {
00165         ab_i[i] = ab_save[i];
00166     }
00167     for( i = 0; i < (MIN(m,n)); i++ ) {
00168         ipiv_i[i] = ipiv_save[i];
00169     }
00170 
00171     LAPACKE_cge_trans( LAPACK_COL_MAJOR, 2*kl+ku+1, n, ab_i, ldab, ab_r, n+2 );
00172     info_i = LAPACKE_cgbtrf_work( LAPACK_ROW_MAJOR, m_i, n_i, kl_i, ku_i, ab_r,
00173                                   ldab_r, ipiv_i );
00174 
00175     LAPACKE_cge_trans( LAPACK_ROW_MAJOR, 2*kl+ku+1, n, ab_r, n+2, ab_i, ldab );
00176 
00177     failed = compare_cgbtrf( ab, ab_i, ipiv, ipiv_i, info, info_i, ldab, m, n );
00178     if( failed == 0 ) {
00179         printf( "PASSED: row-major middle-level interface to cgbtrf\n" );
00180     } else {
00181         printf( "FAILED: row-major middle-level interface to cgbtrf\n" );
00182     }
00183 
00184     /* Initialize input data, call the row-major high-level
00185      * interface to LAPACK routine and check the results */
00186     for( i = 0; i < ldab*n; i++ ) {
00187         ab_i[i] = ab_save[i];
00188     }
00189     for( i = 0; i < (MIN(m,n)); i++ ) {
00190         ipiv_i[i] = ipiv_save[i];
00191     }
00192 
00193     /* Init row_major arrays */
00194     LAPACKE_cge_trans( LAPACK_COL_MAJOR, 2*kl+ku+1, n, ab_i, ldab, ab_r, n+2 );
00195     info_i = LAPACKE_cgbtrf( LAPACK_ROW_MAJOR, m_i, n_i, kl_i, ku_i, ab_r,
00196                              ldab_r, ipiv_i );
00197 
00198     LAPACKE_cge_trans( LAPACK_ROW_MAJOR, 2*kl+ku+1, n, ab_r, n+2, ab_i, ldab );
00199 
00200     failed = compare_cgbtrf( ab, ab_i, ipiv, ipiv_i, info, info_i, ldab, m, n );
00201     if( failed == 0 ) {
00202         printf( "PASSED: row-major high-level interface to cgbtrf\n" );
00203     } else {
00204         printf( "FAILED: row-major high-level interface to cgbtrf\n" );
00205     }
00206 
00207     /* Release memory */
00208     if( ab != NULL ) {
00209         LAPACKE_free( ab );
00210     }
00211     if( ab_i != NULL ) {
00212         LAPACKE_free( ab_i );
00213     }
00214     if( ab_r != NULL ) {
00215         LAPACKE_free( ab_r );
00216     }
00217     if( ab_save != NULL ) {
00218         LAPACKE_free( ab_save );
00219     }
00220     if( ipiv != NULL ) {
00221         LAPACKE_free( ipiv );
00222     }
00223     if( ipiv_i != NULL ) {
00224         LAPACKE_free( ipiv_i );
00225     }
00226     if( ipiv_save != NULL ) {
00227         LAPACKE_free( ipiv_save );
00228     }
00229 
00230     return 0;
00231 }
00232 
00233 /* Auxiliary function: cgbtrf scalar parameters initialization */
00234 static void init_scalars_cgbtrf( lapack_int *m, lapack_int *n, lapack_int *kl,
00235                                  lapack_int *ku, lapack_int *ldab )
00236 {
00237     *m = 4;
00238     *n = 4;
00239     *kl = 1;
00240     *ku = 2;
00241     *ldab = 25;
00242 
00243     return;
00244 }
00245 
00246 /* Auxiliary functions: cgbtrf array parameters initialization */
00247 static void init_ab( lapack_int size, lapack_complex_float *ab ) {
00248     lapack_int i;
00249     for( i = 0; i < size; i++ ) {
00250         ab[i] = lapack_make_complex_float( 0.0f, 0.0f );
00251     }
00252     ab[0] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00253     ab[25] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00254     ab[50] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00255     ab[75] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00256     ab[1] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00257     ab[26] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00258     ab[51] = lapack_make_complex_float( 9.700000286e-001, -2.839999914e+000 );
00259     ab[76] = lapack_make_complex_float( 5.899999738e-001, -4.799999893e-001 );
00260     ab[2] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00261     ab[27] = lapack_make_complex_float( -2.049999952e+000, -8.500000238e-001 );
00262     ab[52] = lapack_make_complex_float( -3.990000010e+000, 4.010000229e+000 );
00263     ab[77] = lapack_make_complex_float( 3.329999924e+000, -1.039999962e+000 );
00264     ab[3] = lapack_make_complex_float( -1.649999976e+000, 2.259999990e+000 );
00265     ab[28] = lapack_make_complex_float( -1.480000019e+000, -1.750000000e+000 );
00266     ab[53] = lapack_make_complex_float( -1.059999943e+000, 1.940000057e+000 );
00267     ab[78] = lapack_make_complex_float( -4.600000083e-001, -1.720000029e+000 );
00268     ab[4] = lapack_make_complex_float( 0.000000000e+000, 6.300000191e+000 );
00269     ab[29] = lapack_make_complex_float( -7.699999809e-001, 2.829999924e+000 );
00270     ab[54] = lapack_make_complex_float( 4.480000019e+000, -1.090000033e+000 );
00271     ab[79] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00272 }
00273 static void init_ipiv( lapack_int size, lapack_int *ipiv ) {
00274     lapack_int i;
00275     for( i = 0; i < size; i++ ) {
00276         ipiv[i] = 0;
00277     }
00278 }
00279 
00280 /* Auxiliary function: C interface to cgbtrf results check */
00281 /* Return value: 0 - test is passed, non-zero - test is failed */
00282 static int compare_cgbtrf( lapack_complex_float *ab, lapack_complex_float *ab_i,
00283                            lapack_int *ipiv, lapack_int *ipiv_i,
00284                            lapack_int info, lapack_int info_i, lapack_int ldab,
00285                            lapack_int m, lapack_int n )
00286 {
00287     lapack_int i;
00288     int failed = 0;
00289     for( i = 0; i < ldab*n; i++ ) {
00290         failed += compare_complex_floats(ab[i],ab_i[i]);
00291     }
00292     for( i = 0; i < (MIN(m,n)); i++ ) {
00293         failed += (ipiv[i] == ipiv_i[i]) ? 0 : 1;
00294     }
00295     failed += (info == info_i) ? 0 : 1;
00296     if( info != 0 || info_i != 0 ) {
00297         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00298     }
00299 
00300     return failed;
00301 }


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