cgbcon_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 * cgbcon_1 is the test program for the C interface to LAPACK
00036 * routine cgbcon
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_cgbcon( char *norm, lapack_int *n, lapack_int *kl,
00055                                  lapack_int *ku, lapack_int *ldab,
00056                                  float *anorm );
00057 static void init_ab( lapack_int size, lapack_complex_float *ab );
00058 static void init_ipiv( lapack_int size, lapack_int *ipiv );
00059 static void init_work( lapack_int size, lapack_complex_float *work );
00060 static void init_rwork( lapack_int size, float *rwork );
00061 static int compare_cgbcon( float rcond, float 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     float anorm, anorm_i;
00074     float rcond, rcond_i;
00075     lapack_int info, info_i;
00076     lapack_int i;
00077     int failed;
00078 
00079     /* Local arrays */
00080     lapack_complex_float *ab = NULL, *ab_i = NULL;
00081     lapack_int *ipiv = NULL, *ipiv_i = NULL;
00082     lapack_complex_float *work = NULL, *work_i = NULL;
00083     float *rwork = NULL, *rwork_i = NULL;
00084     lapack_complex_float *ab_r = NULL;
00085 
00086     /* Iniitialize the scalar parameters */
00087     init_scalars_cgbcon( &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 = (lapack_complex_float *)
00098         LAPACKE_malloc( ldab*n * sizeof(lapack_complex_float) );
00099     ipiv = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00100     work = (lapack_complex_float *)
00101         LAPACKE_malloc( 2*n * sizeof(lapack_complex_float) );
00102     rwork = (float *)LAPACKE_malloc( n * sizeof(float) );
00103 
00104     /* Allocate memory for the C interface function arrays */
00105     ab_i = (lapack_complex_float *)
00106         LAPACKE_malloc( ldab*n * sizeof(lapack_complex_float) );
00107     ipiv_i = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00108     work_i = (lapack_complex_float *)
00109         LAPACKE_malloc( 2*n * sizeof(lapack_complex_float) );
00110     rwork_i = (float *)LAPACKE_malloc( n * sizeof(float) );
00111 
00112     /* Allocate memory for the row-major arrays */
00113     ab_r = (lapack_complex_float *)
00114         LAPACKE_malloc( ((2*kl+ku+1)*(n+2)) * sizeof(lapack_complex_float) );
00115 
00116     /* Initialize input arrays */
00117     init_ab( ldab*n, ab );
00118     init_ipiv( n, ipiv );
00119     init_work( 2*n, work );
00120     init_rwork( n, rwork );
00121 
00122     /* Call the LAPACK routine */
00123     cgbcon_( &norm, &n, &kl, &ku, ab, &ldab, ipiv, &anorm, &rcond, work, rwork,
00124              &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[i];
00130     }
00131     for( i = 0; i < n; i++ ) {
00132         ipiv_i[i] = ipiv[i];
00133     }
00134     for( i = 0; i < 2*n; i++ ) {
00135         work_i[i] = work[i];
00136     }
00137     for( i = 0; i < n; i++ ) {
00138         rwork_i[i] = rwork[i];
00139     }
00140     info_i = LAPACKE_cgbcon_work( LAPACK_COL_MAJOR, norm_i, n_i, kl_i, ku_i,
00141                                   ab_i, ldab_i, ipiv_i, anorm_i, &rcond_i,
00142                                   work_i, rwork_i );
00143 
00144     failed = compare_cgbcon( rcond, rcond_i, info, info_i );
00145     if( failed == 0 ) {
00146         printf( "PASSED: column-major middle-level interface to cgbcon\n" );
00147     } else {
00148         printf( "FAILED: column-major middle-level interface to cgbcon\n" );
00149     }
00150 
00151     /* Initialize input data, call the column-major high-level
00152      * interface to LAPACK routine and check the results */
00153     for( i = 0; i < ldab*n; i++ ) {
00154         ab_i[i] = ab[i];
00155     }
00156     for( i = 0; i < n; i++ ) {
00157         ipiv_i[i] = ipiv[i];
00158     }
00159     for( i = 0; i < 2*n; i++ ) {
00160         work_i[i] = work[i];
00161     }
00162     for( i = 0; i < n; i++ ) {
00163         rwork_i[i] = rwork[i];
00164     }
00165     info_i = LAPACKE_cgbcon( LAPACK_COL_MAJOR, norm_i, n_i, kl_i, ku_i, ab_i,
00166                              ldab_i, ipiv_i, anorm_i, &rcond_i );
00167 
00168     failed = compare_cgbcon( rcond, rcond_i, info, info_i );
00169     if( failed == 0 ) {
00170         printf( "PASSED: column-major high-level interface to cgbcon\n" );
00171     } else {
00172         printf( "FAILED: column-major high-level interface to cgbcon\n" );
00173     }
00174 
00175     /* Initialize input data, call the row-major middle-level
00176      * interface to LAPACK routine and check the results */
00177     for( i = 0; i < ldab*n; i++ ) {
00178         ab_i[i] = ab[i];
00179     }
00180     for( i = 0; i < n; i++ ) {
00181         ipiv_i[i] = ipiv[i];
00182     }
00183     for( i = 0; i < 2*n; i++ ) {
00184         work_i[i] = work[i];
00185     }
00186     for( i = 0; i < n; i++ ) {
00187         rwork_i[i] = rwork[i];
00188     }
00189 
00190     LAPACKE_cge_trans( LAPACK_COL_MAJOR, 2*kl+ku+1, n, ab_i, ldab, ab_r, n+2 );
00191     info_i = LAPACKE_cgbcon_work( LAPACK_ROW_MAJOR, norm_i, n_i, kl_i, ku_i,
00192                                   ab_r, ldab_r, ipiv_i, anorm_i, &rcond_i,
00193                                   work_i, rwork_i );
00194 
00195     failed = compare_cgbcon( rcond, rcond_i, info, info_i );
00196     if( failed == 0 ) {
00197         printf( "PASSED: row-major middle-level interface to cgbcon\n" );
00198     } else {
00199         printf( "FAILED: row-major middle-level interface to cgbcon\n" );
00200     }
00201 
00202     /* Initialize input data, call the row-major high-level
00203      * interface to LAPACK routine and check the results */
00204     for( i = 0; i < ldab*n; i++ ) {
00205         ab_i[i] = ab[i];
00206     }
00207     for( i = 0; i < n; i++ ) {
00208         ipiv_i[i] = ipiv[i];
00209     }
00210     for( i = 0; i < 2*n; i++ ) {
00211         work_i[i] = work[i];
00212     }
00213     for( i = 0; i < n; i++ ) {
00214         rwork_i[i] = rwork[i];
00215     }
00216 
00217     /* Init row_major arrays */
00218     LAPACKE_cge_trans( LAPACK_COL_MAJOR, 2*kl+ku+1, n, ab_i, ldab, ab_r, n+2 );
00219     info_i = LAPACKE_cgbcon( LAPACK_ROW_MAJOR, norm_i, n_i, kl_i, ku_i, ab_r,
00220                              ldab_r, ipiv_i, anorm_i, &rcond_i );
00221 
00222     failed = compare_cgbcon( rcond, rcond_i, info, info_i );
00223     if( failed == 0 ) {
00224         printf( "PASSED: row-major high-level interface to cgbcon\n" );
00225     } else {
00226         printf( "FAILED: row-major high-level interface to cgbcon\n" );
00227     }
00228 
00229     /* Release memory */
00230     if( ab != NULL ) {
00231         LAPACKE_free( ab );
00232     }
00233     if( ab_i != NULL ) {
00234         LAPACKE_free( ab_i );
00235     }
00236     if( ab_r != NULL ) {
00237         LAPACKE_free( ab_r );
00238     }
00239     if( ipiv != NULL ) {
00240         LAPACKE_free( ipiv );
00241     }
00242     if( ipiv_i != NULL ) {
00243         LAPACKE_free( ipiv_i );
00244     }
00245     if( work != NULL ) {
00246         LAPACKE_free( work );
00247     }
00248     if( work_i != NULL ) {
00249         LAPACKE_free( work_i );
00250     }
00251     if( rwork != NULL ) {
00252         LAPACKE_free( rwork );
00253     }
00254     if( rwork_i != NULL ) {
00255         LAPACKE_free( rwork_i );
00256     }
00257 
00258     return 0;
00259 }
00260 
00261 /* Auxiliary function: cgbcon scalar parameters initialization */
00262 static void init_scalars_cgbcon( char *norm, lapack_int *n, lapack_int *kl,
00263                                  lapack_int *ku, lapack_int *ldab,
00264                                  float *anorm )
00265 {
00266     *norm = '1';
00267     *n = 4;
00268     *kl = 1;
00269     *ku = 2;
00270     *ldab = 25;
00271     *anorm = 1.547935009e+001;
00272 
00273     return;
00274 }
00275 
00276 /* Auxiliary functions: cgbcon array parameters initialization */
00277 static void init_ab( lapack_int size, lapack_complex_float *ab ) {
00278     lapack_int i;
00279     for( i = 0; i < size; i++ ) {
00280         ab[i] = lapack_make_complex_float( 0.0f, 0.0f );
00281     }
00282     ab[0] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00283     ab[25] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00284     ab[50] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00285     ab[75] = lapack_make_complex_float( 5.899999738e-001, -4.799999893e-001 );
00286     ab[1] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00287     ab[26] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00288     ab[51] = lapack_make_complex_float( -3.990000010e+000, 4.010000229e+000 );
00289     ab[76] = lapack_make_complex_float( 3.329999924e+000, -1.039999962e+000 );
00290     ab[2] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00291     ab[27] = lapack_make_complex_float( -1.480000019e+000, -1.750000000e+000 );
00292     ab[52] = lapack_make_complex_float( -1.059999943e+000, 1.940000057e+000 );
00293     ab[77] = lapack_make_complex_float( -1.769209266e+000, -1.858747363e+000 );
00294     ab[3] = lapack_make_complex_float( 0.000000000e+000, 6.300000191e+000 );
00295     ab[28] = lapack_make_complex_float( -7.699999809e-001, 2.829999924e+000 );
00296     ab[53] = lapack_make_complex_float( 4.930266857e+000, -3.008563757e+000 );
00297     ab[78] = lapack_make_complex_float( 4.337749183e-001, 1.232528687e-001 );
00298     ab[4] = lapack_make_complex_float( 3.587301373e-001, 2.619047463e-001 );
00299     ab[29] = lapack_make_complex_float( 2.314260751e-001, 6.357648969e-001 );
00300     ab[54] = lapack_make_complex_float( 7.604227066e-001, 2.429442555e-001 );
00301     ab[79] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00302 }
00303 static void init_ipiv( lapack_int size, lapack_int *ipiv ) {
00304     lapack_int i;
00305     for( i = 0; i < size; i++ ) {
00306         ipiv[i] = 0;
00307     }
00308     ipiv[0] = 2;
00309     ipiv[1] = 3;
00310     ipiv[2] = 3;
00311     ipiv[3] = 4;
00312 }
00313 static void init_work( lapack_int size, lapack_complex_float *work ) {
00314     lapack_int i;
00315     for( i = 0; i < size; i++ ) {
00316         work[i] = lapack_make_complex_float( 0.0f, 0.0f );
00317     }
00318 }
00319 static void init_rwork( lapack_int size, float *rwork ) {
00320     lapack_int i;
00321     for( i = 0; i < size; i++ ) {
00322         rwork[i] = 0;
00323     }
00324 }
00325 
00326 /* Auxiliary function: C interface to cgbcon results check */
00327 /* Return value: 0 - test is passed, non-zero - test is failed */
00328 static int compare_cgbcon( float rcond, float rcond_i, lapack_int info,
00329                            lapack_int info_i )
00330 {
00331     int failed = 0;
00332     failed += compare_floats(rcond,rcond_i);
00333     failed += (info == info_i) ? 0 : 1;
00334     if( info != 0 || info_i != 0 ) {
00335         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00336     }
00337 
00338     return failed;
00339 }


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