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


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