spbtrs_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 * spbtrs_1 is the test program for the C interface to LAPACK
00036 * routine spbtrs
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_spbtrs( char *uplo, lapack_int *n, lapack_int *kd,
00055                                  lapack_int *nrhs, lapack_int *ldab,
00056                                  lapack_int *ldb );
00057 static void init_ab( lapack_int size, float *ab );
00058 static void init_b( lapack_int size, float *b );
00059 static int compare_spbtrs( float *b, float *b_i, lapack_int info,
00060                            lapack_int info_i, lapack_int ldb, lapack_int nrhs );
00061 
00062 int main(void)
00063 {
00064     /* Local scalars */
00065     char uplo, uplo_i;
00066     lapack_int n, n_i;
00067     lapack_int kd, kd_i;
00068     lapack_int nrhs, nrhs_i;
00069     lapack_int ldab, ldab_i;
00070     lapack_int ldab_r;
00071     lapack_int ldb, ldb_i;
00072     lapack_int ldb_r;
00073     lapack_int info, info_i;
00074     lapack_int i;
00075     int failed;
00076 
00077     /* Local arrays */
00078     float *ab = NULL, *ab_i = NULL;
00079     float *b = NULL, *b_i = NULL;
00080     float *b_save = NULL;
00081     float *ab_r = NULL;
00082     float *b_r = NULL;
00083 
00084     /* Iniitialize the scalar parameters */
00085     init_scalars_spbtrs( &uplo, &n, &kd, &nrhs, &ldab, &ldb );
00086     ldab_r = n+2;
00087     ldb_r = nrhs+2;
00088     uplo_i = uplo;
00089     n_i = n;
00090     kd_i = kd;
00091     nrhs_i = nrhs;
00092     ldab_i = ldab;
00093     ldb_i = ldb;
00094 
00095     /* Allocate memory for the LAPACK routine arrays */
00096     ab = (float *)LAPACKE_malloc( ldab*n * sizeof(float) );
00097     b = (float *)LAPACKE_malloc( ldb*nrhs * sizeof(float) );
00098 
00099     /* Allocate memory for the C interface function arrays */
00100     ab_i = (float *)LAPACKE_malloc( ldab*n * sizeof(float) );
00101     b_i = (float *)LAPACKE_malloc( ldb*nrhs * sizeof(float) );
00102 
00103     /* Allocate memory for the backup arrays */
00104     b_save = (float *)LAPACKE_malloc( ldb*nrhs * sizeof(float) );
00105 
00106     /* Allocate memory for the row-major arrays */
00107     ab_r = (float *)LAPACKE_malloc( (kd+1)*(n+2) * sizeof(float) );
00108     b_r = (float *)LAPACKE_malloc( n*(nrhs+2) * sizeof(float) );
00109 
00110     /* Initialize input arrays */
00111     init_ab( ldab*n, ab );
00112     init_b( ldb*nrhs, b );
00113 
00114     /* Backup the ouptut arrays */
00115     for( i = 0; i < ldb*nrhs; i++ ) {
00116         b_save[i] = b[i];
00117     }
00118 
00119     /* Call the LAPACK routine */
00120     spbtrs_( &uplo, &n, &kd, &nrhs, ab, &ldab, b, &ldb, &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[i];
00126     }
00127     for( i = 0; i < ldb*nrhs; i++ ) {
00128         b_i[i] = b_save[i];
00129     }
00130     info_i = LAPACKE_spbtrs_work( LAPACK_COL_MAJOR, uplo_i, n_i, kd_i, nrhs_i,
00131                                   ab_i, ldab_i, b_i, ldb_i );
00132 
00133     failed = compare_spbtrs( b, b_i, info, info_i, ldb, nrhs );
00134     if( failed == 0 ) {
00135         printf( "PASSED: column-major middle-level interface to spbtrs\n" );
00136     } else {
00137         printf( "FAILED: column-major middle-level interface to spbtrs\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[i];
00144     }
00145     for( i = 0; i < ldb*nrhs; i++ ) {
00146         b_i[i] = b_save[i];
00147     }
00148     info_i = LAPACKE_spbtrs( LAPACK_COL_MAJOR, uplo_i, n_i, kd_i, nrhs_i, ab_i,
00149                              ldab_i, b_i, ldb_i );
00150 
00151     failed = compare_spbtrs( b, b_i, info, info_i, ldb, nrhs );
00152     if( failed == 0 ) {
00153         printf( "PASSED: column-major high-level interface to spbtrs\n" );
00154     } else {
00155         printf( "FAILED: column-major high-level interface to spbtrs\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[i];
00162     }
00163     for( i = 0; i < ldb*nrhs; i++ ) {
00164         b_i[i] = b_save[i];
00165     }
00166 
00167     LAPACKE_sge_trans( LAPACK_COL_MAJOR, kd+1, n, ab_i, ldab, ab_r, n+2 );
00168     LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00169     info_i = LAPACKE_spbtrs_work( LAPACK_ROW_MAJOR, uplo_i, n_i, kd_i, nrhs_i,
00170                                   ab_r, ldab_r, b_r, ldb_r );
00171 
00172     LAPACKE_sge_trans( LAPACK_ROW_MAJOR, n, nrhs, b_r, nrhs+2, b_i, ldb );
00173 
00174     failed = compare_spbtrs( b, b_i, info, info_i, ldb, nrhs );
00175     if( failed == 0 ) {
00176         printf( "PASSED: row-major middle-level interface to spbtrs\n" );
00177     } else {
00178         printf( "FAILED: row-major middle-level interface to spbtrs\n" );
00179     }
00180 
00181     /* Initialize input data, call the row-major high-level
00182      * interface to LAPACK routine and check the results */
00183     for( i = 0; i < ldab*n; i++ ) {
00184         ab_i[i] = ab[i];
00185     }
00186     for( i = 0; i < ldb*nrhs; i++ ) {
00187         b_i[i] = b_save[i];
00188     }
00189 
00190     /* Init row_major arrays */
00191     LAPACKE_sge_trans( LAPACK_COL_MAJOR, kd+1, n, ab_i, ldab, ab_r, n+2 );
00192     LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00193     info_i = LAPACKE_spbtrs( LAPACK_ROW_MAJOR, uplo_i, n_i, kd_i, nrhs_i, ab_r,
00194                              ldab_r, b_r, ldb_r );
00195 
00196     LAPACKE_sge_trans( LAPACK_ROW_MAJOR, n, nrhs, b_r, nrhs+2, b_i, ldb );
00197 
00198     failed = compare_spbtrs( b, b_i, info, info_i, ldb, nrhs );
00199     if( failed == 0 ) {
00200         printf( "PASSED: row-major high-level interface to spbtrs\n" );
00201     } else {
00202         printf( "FAILED: row-major high-level interface to spbtrs\n" );
00203     }
00204 
00205     /* Release memory */
00206     if( ab != NULL ) {
00207         LAPACKE_free( ab );
00208     }
00209     if( ab_i != NULL ) {
00210         LAPACKE_free( ab_i );
00211     }
00212     if( ab_r != NULL ) {
00213         LAPACKE_free( ab_r );
00214     }
00215     if( b != NULL ) {
00216         LAPACKE_free( b );
00217     }
00218     if( b_i != NULL ) {
00219         LAPACKE_free( b_i );
00220     }
00221     if( b_r != NULL ) {
00222         LAPACKE_free( b_r );
00223     }
00224     if( b_save != NULL ) {
00225         LAPACKE_free( b_save );
00226     }
00227 
00228     return 0;
00229 }
00230 
00231 /* Auxiliary function: spbtrs scalar parameters initialization */
00232 static void init_scalars_spbtrs( char *uplo, lapack_int *n, lapack_int *kd,
00233                                  lapack_int *nrhs, lapack_int *ldab,
00234                                  lapack_int *ldb )
00235 {
00236     *uplo = 'L';
00237     *n = 4;
00238     *kd = 1;
00239     *nrhs = 2;
00240     *ldab = 9;
00241     *ldb = 8;
00242 
00243     return;
00244 }
00245 
00246 /* Auxiliary functions: spbtrs array parameters initialization */
00247 static void init_ab( lapack_int size, float *ab ) {
00248     lapack_int i;
00249     for( i = 0; i < size; i++ ) {
00250         ab[i] = 0;
00251     }
00252     ab[0] = 2.343074799e+000;  /* ab[0,0] */
00253     ab[9] = 2.078877211e+000;  /* ab[0,1] */
00254     ab[18] = 1.130612254e+000;  /* ab[0,2] */
00255     ab[27] = 1.146524668e+000;  /* ab[0,3] */
00256     ab[1] = 1.143796206e+000;  /* ab[1,0] */
00257     ab[10] = -1.149659038e+000;  /* ab[1,1] */
00258     ab[19] = -1.963537931e+000;  /* ab[1,2] */
00259     ab[28] = 0.000000000e+000;  /* ab[1,3] */
00260 }
00261 static void init_b( lapack_int size, float *b ) {
00262     lapack_int i;
00263     for( i = 0; i < size; i++ ) {
00264         b[i] = 0;
00265     }
00266     b[0] = 2.209000015e+001;  /* b[0,0] */
00267     b[8] = 5.099999905e+000;  /* b[0,1] */
00268     b[1] = 9.310000420e+000;  /* b[1,0] */
00269     b[9] = 3.080999947e+001;  /* b[1,1] */
00270     b[2] = -5.239999771e+000;  /* b[2,0] */
00271     b[10] = -2.581999969e+001;  /* b[2,1] */
00272     b[3] = 1.182999992e+001;  /* b[3,0] */
00273     b[11] = 2.289999962e+001;  /* b[3,1] */
00274 }
00275 
00276 /* Auxiliary function: C interface to spbtrs results check */
00277 /* Return value: 0 - test is passed, non-zero - test is failed */
00278 static int compare_spbtrs( float *b, float *b_i, lapack_int info,
00279                            lapack_int info_i, lapack_int ldb, lapack_int nrhs )
00280 {
00281     lapack_int i;
00282     int failed = 0;
00283     for( i = 0; i < ldb*nrhs; i++ ) {
00284         failed += compare_floats(b[i],b_i[i]);
00285     }
00286     failed += (info == info_i) ? 0 : 1;
00287     if( info != 0 || info_i != 0 ) {
00288         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00289     }
00290 
00291     return failed;
00292 }


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:56:12