sstebz_3.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 * sstebz_3 is the test program for the C interface to LAPACK
00036 * routine sstebz
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_sstebz( char *range, char *order, lapack_int *n,
00055                                  float *vl, float *vu, lapack_int *il,
00056                                  lapack_int *iu, float *abstol );
00057 static void init_d( lapack_int size, float *d );
00058 static void init_e( lapack_int size, float *e );
00059 static void init_w( lapack_int size, float *w );
00060 static void init_iblock( lapack_int size, lapack_int *iblock );
00061 static void init_isplit( lapack_int size, lapack_int *isplit );
00062 static void init_work( lapack_int size, float *work );
00063 static void init_iwork( lapack_int size, lapack_int *iwork );
00064 static int compare_sstebz( lapack_int m, lapack_int m_i, lapack_int nsplit,
00065                            lapack_int nsplit_i, float *w, float *w_i,
00066                            lapack_int *iblock, lapack_int *iblock_i,
00067                            lapack_int *isplit, lapack_int *isplit_i,
00068                            lapack_int info, lapack_int info_i, lapack_int n );
00069 
00070 int main(void)
00071 {
00072     /* Local scalars */
00073     char range, range_i;
00074     char order, order_i;
00075     lapack_int n, n_i;
00076     float vl, vl_i;
00077     float vu, vu_i;
00078     lapack_int il, il_i;
00079     lapack_int iu, iu_i;
00080     float abstol, abstol_i;
00081     lapack_int m, m_i;
00082     lapack_int nsplit, nsplit_i;
00083     lapack_int info, info_i;
00084     lapack_int i;
00085     int failed;
00086 
00087     /* Local arrays */
00088     float *d = NULL, *d_i = NULL;
00089     float *e = NULL, *e_i = NULL;
00090     float *w = NULL, *w_i = NULL;
00091     lapack_int *iblock = NULL, *iblock_i = NULL;
00092     lapack_int *isplit = NULL, *isplit_i = NULL;
00093     float *work = NULL, *work_i = NULL;
00094     lapack_int *iwork = NULL, *iwork_i = NULL;
00095     float *w_save = NULL;
00096     lapack_int *iblock_save = NULL;
00097     lapack_int *isplit_save = NULL;
00098 
00099     /* Iniitialize the scalar parameters */
00100     init_scalars_sstebz( &range, &order, &n, &vl, &vu, &il, &iu, &abstol );
00101     range_i = range;
00102     order_i = order;
00103     n_i = n;
00104     vl_i = vl;
00105     vu_i = vu;
00106     il_i = il;
00107     iu_i = iu;
00108     abstol_i = abstol;
00109 
00110     /* Allocate memory for the LAPACK routine arrays */
00111     d = (float *)LAPACKE_malloc( n * sizeof(float) );
00112     e = (float *)LAPACKE_malloc( (n-1) * sizeof(float) );
00113     w = (float *)LAPACKE_malloc( n * sizeof(float) );
00114     iblock = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00115     isplit = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00116     work = (float *)LAPACKE_malloc( 4*n * sizeof(float) );
00117     iwork = (lapack_int *)LAPACKE_malloc( 3*n * sizeof(lapack_int) );
00118 
00119     /* Allocate memory for the C interface function arrays */
00120     d_i = (float *)LAPACKE_malloc( n * sizeof(float) );
00121     e_i = (float *)LAPACKE_malloc( (n-1) * sizeof(float) );
00122     w_i = (float *)LAPACKE_malloc( n * sizeof(float) );
00123     iblock_i = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00124     isplit_i = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00125     work_i = (float *)LAPACKE_malloc( 4*n * sizeof(float) );
00126     iwork_i = (lapack_int *)LAPACKE_malloc( 3*n * sizeof(lapack_int) );
00127 
00128     /* Allocate memory for the backup arrays */
00129     w_save = (float *)LAPACKE_malloc( n * sizeof(float) );
00130     iblock_save = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00131     isplit_save = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00132 
00133     /* Allocate memory for the row-major arrays */
00134 
00135     /* Initialize input arrays */
00136     init_d( n, d );
00137     init_e( (n-1), e );
00138     init_w( n, w );
00139     init_iblock( n, iblock );
00140     init_isplit( n, isplit );
00141     init_work( 4*n, work );
00142     init_iwork( 3*n, iwork );
00143 
00144     /* Backup the ouptut arrays */
00145     for( i = 0; i < n; i++ ) {
00146         w_save[i] = w[i];
00147     }
00148     for( i = 0; i < n; i++ ) {
00149         iblock_save[i] = iblock[i];
00150     }
00151     for( i = 0; i < n; i++ ) {
00152         isplit_save[i] = isplit[i];
00153     }
00154 
00155     /* Call the LAPACK routine */
00156     sstebz_( &range, &order, &n, &vl, &vu, &il, &iu, &abstol, d, e, &m, &nsplit,
00157              w, iblock, isplit, work, iwork, &info );
00158 
00159     /* Initialize input data, call the column-major middle-level
00160      * interface to LAPACK routine and check the results */
00161     for( i = 0; i < n; i++ ) {
00162         d_i[i] = d[i];
00163     }
00164     for( i = 0; i < (n-1); i++ ) {
00165         e_i[i] = e[i];
00166     }
00167     for( i = 0; i < n; i++ ) {
00168         w_i[i] = w_save[i];
00169     }
00170     for( i = 0; i < n; i++ ) {
00171         iblock_i[i] = iblock_save[i];
00172     }
00173     for( i = 0; i < n; i++ ) {
00174         isplit_i[i] = isplit_save[i];
00175     }
00176     for( i = 0; i < 4*n; i++ ) {
00177         work_i[i] = work[i];
00178     }
00179     for( i = 0; i < 3*n; i++ ) {
00180         iwork_i[i] = iwork[i];
00181     }
00182     info_i = LAPACKE_sstebz_work( range_i, order_i, n_i, vl_i, vu_i, il_i, iu_i,
00183                                   abstol_i, d_i, e_i, &m_i, &nsplit_i, w_i,
00184                                   iblock_i, isplit_i, work_i, iwork_i );
00185 
00186     failed = compare_sstebz( m, m_i, nsplit, nsplit_i, w, w_i, iblock, iblock_i,
00187                              isplit, isplit_i, info, info_i, n );
00188     if( failed == 0 ) {
00189         printf( "PASSED: column-major middle-level interface to sstebz\n" );
00190     } else {
00191         printf( "FAILED: column-major middle-level interface to sstebz\n" );
00192     }
00193 
00194     /* Initialize input data, call the column-major high-level
00195      * interface to LAPACK routine and check the results */
00196     for( i = 0; i < n; i++ ) {
00197         d_i[i] = d[i];
00198     }
00199     for( i = 0; i < (n-1); i++ ) {
00200         e_i[i] = e[i];
00201     }
00202     for( i = 0; i < n; i++ ) {
00203         w_i[i] = w_save[i];
00204     }
00205     for( i = 0; i < n; i++ ) {
00206         iblock_i[i] = iblock_save[i];
00207     }
00208     for( i = 0; i < n; i++ ) {
00209         isplit_i[i] = isplit_save[i];
00210     }
00211     for( i = 0; i < 4*n; i++ ) {
00212         work_i[i] = work[i];
00213     }
00214     for( i = 0; i < 3*n; i++ ) {
00215         iwork_i[i] = iwork[i];
00216     }
00217     info_i = LAPACKE_sstebz( range_i, order_i, n_i, vl_i, vu_i, il_i, iu_i,
00218                              abstol_i, d_i, e_i, &m_i, &nsplit_i, w_i, iblock_i,
00219                              isplit_i );
00220 
00221     failed = compare_sstebz( m, m_i, nsplit, nsplit_i, w, w_i, iblock, iblock_i,
00222                              isplit, isplit_i, info, info_i, n );
00223     if( failed == 0 ) {
00224         printf( "PASSED: column-major high-level interface to sstebz\n" );
00225     } else {
00226         printf( "FAILED: column-major high-level interface to sstebz\n" );
00227     }
00228 
00229     failed = compare_sstebz( m, m_i, nsplit, nsplit_i, w, w_i, iblock, iblock_i,
00230                              isplit, isplit_i, info, info_i, n );
00231     if( failed == 0 ) {
00232         printf( "PASSED: row-major middle-level interface to sstebz\n" );
00233     } else {
00234         printf( "FAILED: row-major middle-level interface to sstebz\n" );
00235     }
00236 
00237     failed = compare_sstebz( m, m_i, nsplit, nsplit_i, w, w_i, iblock, iblock_i,
00238                              isplit, isplit_i, info, info_i, n );
00239     if( failed == 0 ) {
00240         printf( "PASSED: row-major high-level interface to sstebz\n" );
00241     } else {
00242         printf( "FAILED: row-major high-level interface to sstebz\n" );
00243     }
00244 
00245     /* Release memory */
00246     if( d != NULL ) {
00247         LAPACKE_free( d );
00248     }
00249     if( d_i != NULL ) {
00250         LAPACKE_free( d_i );
00251     }
00252     if( e != NULL ) {
00253         LAPACKE_free( e );
00254     }
00255     if( e_i != NULL ) {
00256         LAPACKE_free( e_i );
00257     }
00258     if( w != NULL ) {
00259         LAPACKE_free( w );
00260     }
00261     if( w_i != NULL ) {
00262         LAPACKE_free( w_i );
00263     }
00264     if( w_save != NULL ) {
00265         LAPACKE_free( w_save );
00266     }
00267     if( iblock != NULL ) {
00268         LAPACKE_free( iblock );
00269     }
00270     if( iblock_i != NULL ) {
00271         LAPACKE_free( iblock_i );
00272     }
00273     if( iblock_save != NULL ) {
00274         LAPACKE_free( iblock_save );
00275     }
00276     if( isplit != NULL ) {
00277         LAPACKE_free( isplit );
00278     }
00279     if( isplit_i != NULL ) {
00280         LAPACKE_free( isplit_i );
00281     }
00282     if( isplit_save != NULL ) {
00283         LAPACKE_free( isplit_save );
00284     }
00285     if( work != NULL ) {
00286         LAPACKE_free( work );
00287     }
00288     if( work_i != NULL ) {
00289         LAPACKE_free( work_i );
00290     }
00291     if( iwork != NULL ) {
00292         LAPACKE_free( iwork );
00293     }
00294     if( iwork_i != NULL ) {
00295         LAPACKE_free( iwork_i );
00296     }
00297 
00298     return 0;
00299 }
00300 
00301 /* Auxiliary function: sstebz scalar parameters initialization */
00302 static void init_scalars_sstebz( char *range, char *order, lapack_int *n,
00303                                  float *vl, float *vu, lapack_int *il,
00304                                  lapack_int *iu, float *abstol )
00305 {
00306     *range = 'I';
00307     *order = 'B';
00308     *n = 4;
00309     *vl = 0.000000000e+000;
00310     *vu = 0.000000000e+000;
00311     *il = 1;
00312     *iu = 2;
00313     *abstol = 0.000000000e+000;
00314 
00315     return;
00316 }
00317 
00318 /* Auxiliary functions: sstebz array parameters initialization */
00319 static void init_d( lapack_int size, float *d ) {
00320     lapack_int i;
00321     for( i = 0; i < size; i++ ) {
00322         d[i] = 0;
00323     }
00324     d[0] = 2.069999933e+000;
00325     d[1] = 1.474093199e+000;
00326     d[2] = -6.491593122e-001;
00327     d[3] = -1.694934368e+000;
00328 }
00329 static void init_e( lapack_int size, float *e ) {
00330     lapack_int i;
00331     for( i = 0; i < size; i++ ) {
00332         e[i] = 0;
00333     }
00334     e[0] = -5.825753212e+000;
00335     e[1] = 2.624044895e+000;
00336     e[2] = 9.162727594e-001;
00337 }
00338 static void init_w( lapack_int size, float *w ) {
00339     lapack_int i;
00340     for( i = 0; i < size; i++ ) {
00341         w[i] = 0;
00342     }
00343 }
00344 static void init_iblock( lapack_int size, lapack_int *iblock ) {
00345     lapack_int i;
00346     for( i = 0; i < size; i++ ) {
00347         iblock[i] = 0;
00348     }
00349 }
00350 static void init_isplit( lapack_int size, lapack_int *isplit ) {
00351     lapack_int i;
00352     for( i = 0; i < size; i++ ) {
00353         isplit[i] = 0;
00354     }
00355 }
00356 static void init_work( lapack_int size, float *work ) {
00357     lapack_int i;
00358     for( i = 0; i < size; i++ ) {
00359         work[i] = 0;
00360     }
00361 }
00362 static void init_iwork( lapack_int size, lapack_int *iwork ) {
00363     lapack_int i;
00364     for( i = 0; i < size; i++ ) {
00365         iwork[i] = 0;
00366     }
00367 }
00368 
00369 /* Auxiliary function: C interface to sstebz results check */
00370 /* Return value: 0 - test is passed, non-zero - test is failed */
00371 static int compare_sstebz( lapack_int m, lapack_int m_i, lapack_int nsplit,
00372                            lapack_int nsplit_i, float *w, float *w_i,
00373                            lapack_int *iblock, lapack_int *iblock_i,
00374                            lapack_int *isplit, lapack_int *isplit_i,
00375                            lapack_int info, lapack_int info_i, lapack_int n )
00376 {
00377     lapack_int i;
00378     int failed = 0;
00379     failed += (m == m_i) ? 0 : 1;
00380     failed += (nsplit == nsplit_i) ? 0 : 1;
00381     for( i = 0; i < n; i++ ) {
00382         failed += compare_floats(w[i],w_i[i]);
00383     }
00384     for( i = 0; i < n; i++ ) {
00385         failed += (iblock[i] == iblock_i[i]) ? 0 : 1;
00386     }
00387     for( i = 0; i < n; i++ ) {
00388         failed += (isplit[i] == isplit_i[i]) ? 0 : 1;
00389     }
00390     failed += (info == info_i) ? 0 : 1;
00391     if( info != 0 || info_i != 0 ) {
00392         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00393     }
00394 
00395     return failed;
00396 }


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