zpbtrs_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 * zpbtrs_1 is the test program for the C interface to LAPACK
00036 * routine zpbtrs
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_zpbtrs( 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, lapack_complex_double *ab );
00058 static void init_b( lapack_int size, lapack_complex_double *b );
00059 static int compare_zpbtrs( lapack_complex_double *b, lapack_complex_double *b_i,
00060                            lapack_int info, lapack_int info_i, lapack_int ldb,
00061                            lapack_int nrhs );
00062 
00063 int main(void)
00064 {
00065     /* Local scalars */
00066     char uplo, uplo_i;
00067     lapack_int n, n_i;
00068     lapack_int kd, kd_i;
00069     lapack_int nrhs, nrhs_i;
00070     lapack_int ldab, ldab_i;
00071     lapack_int ldab_r;
00072     lapack_int ldb, ldb_i;
00073     lapack_int ldb_r;
00074     lapack_int info, info_i;
00075     lapack_int i;
00076     int failed;
00077 
00078     /* Local arrays */
00079     lapack_complex_double *ab = NULL, *ab_i = NULL;
00080     lapack_complex_double *b = NULL, *b_i = NULL;
00081     lapack_complex_double *b_save = NULL;
00082     lapack_complex_double *ab_r = NULL;
00083     lapack_complex_double *b_r = NULL;
00084 
00085     /* Iniitialize the scalar parameters */
00086     init_scalars_zpbtrs( &uplo, &n, &kd, &nrhs, &ldab, &ldb );
00087     ldab_r = n+2;
00088     ldb_r = nrhs+2;
00089     uplo_i = uplo;
00090     n_i = n;
00091     kd_i = kd;
00092     nrhs_i = nrhs;
00093     ldab_i = ldab;
00094     ldb_i = ldb;
00095 
00096     /* Allocate memory for the LAPACK routine arrays */
00097     ab = (lapack_complex_double *)
00098         LAPACKE_malloc( ldab*n * sizeof(lapack_complex_double) );
00099     b = (lapack_complex_double *)
00100         LAPACKE_malloc( ldb*nrhs * sizeof(lapack_complex_double) );
00101 
00102     /* Allocate memory for the C interface function arrays */
00103     ab_i = (lapack_complex_double *)
00104         LAPACKE_malloc( ldab*n * sizeof(lapack_complex_double) );
00105     b_i = (lapack_complex_double *)
00106         LAPACKE_malloc( ldb*nrhs * sizeof(lapack_complex_double) );
00107 
00108     /* Allocate memory for the backup arrays */
00109     b_save = (lapack_complex_double *)
00110         LAPACKE_malloc( ldb*nrhs * sizeof(lapack_complex_double) );
00111 
00112     /* Allocate memory for the row-major arrays */
00113     ab_r = (lapack_complex_double *)
00114         LAPACKE_malloc( (kd+1)*(n+2) * sizeof(lapack_complex_double) );
00115     b_r = (lapack_complex_double *)
00116         LAPACKE_malloc( n*(nrhs+2) * sizeof(lapack_complex_double) );
00117 
00118     /* Initialize input arrays */
00119     init_ab( ldab*n, ab );
00120     init_b( ldb*nrhs, b );
00121 
00122     /* Backup the ouptut arrays */
00123     for( i = 0; i < ldb*nrhs; i++ ) {
00124         b_save[i] = b[i];
00125     }
00126 
00127     /* Call the LAPACK routine */
00128     zpbtrs_( &uplo, &n, &kd, &nrhs, ab, &ldab, b, &ldb, &info );
00129 
00130     /* Initialize input data, call the column-major middle-level
00131      * interface to LAPACK routine and check the results */
00132     for( i = 0; i < ldab*n; i++ ) {
00133         ab_i[i] = ab[i];
00134     }
00135     for( i = 0; i < ldb*nrhs; i++ ) {
00136         b_i[i] = b_save[i];
00137     }
00138     info_i = LAPACKE_zpbtrs_work( LAPACK_COL_MAJOR, uplo_i, n_i, kd_i, nrhs_i,
00139                                   ab_i, ldab_i, b_i, ldb_i );
00140 
00141     failed = compare_zpbtrs( b, b_i, info, info_i, ldb, nrhs );
00142     if( failed == 0 ) {
00143         printf( "PASSED: column-major middle-level interface to zpbtrs\n" );
00144     } else {
00145         printf( "FAILED: column-major middle-level interface to zpbtrs\n" );
00146     }
00147 
00148     /* Initialize input data, call the column-major high-level
00149      * interface to LAPACK routine and check the results */
00150     for( i = 0; i < ldab*n; i++ ) {
00151         ab_i[i] = ab[i];
00152     }
00153     for( i = 0; i < ldb*nrhs; i++ ) {
00154         b_i[i] = b_save[i];
00155     }
00156     info_i = LAPACKE_zpbtrs( LAPACK_COL_MAJOR, uplo_i, n_i, kd_i, nrhs_i, ab_i,
00157                              ldab_i, b_i, ldb_i );
00158 
00159     failed = compare_zpbtrs( b, b_i, info, info_i, ldb, nrhs );
00160     if( failed == 0 ) {
00161         printf( "PASSED: column-major high-level interface to zpbtrs\n" );
00162     } else {
00163         printf( "FAILED: column-major high-level interface to zpbtrs\n" );
00164     }
00165 
00166     /* Initialize input data, call the row-major middle-level
00167      * interface to LAPACK routine and check the results */
00168     for( i = 0; i < ldab*n; i++ ) {
00169         ab_i[i] = ab[i];
00170     }
00171     for( i = 0; i < ldb*nrhs; i++ ) {
00172         b_i[i] = b_save[i];
00173     }
00174 
00175     LAPACKE_zge_trans( LAPACK_COL_MAJOR, kd+1, n, ab_i, ldab, ab_r, n+2 );
00176     LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00177     info_i = LAPACKE_zpbtrs_work( LAPACK_ROW_MAJOR, uplo_i, n_i, kd_i, nrhs_i,
00178                                   ab_r, ldab_r, b_r, ldb_r );
00179 
00180     LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, nrhs, b_r, nrhs+2, b_i, ldb );
00181 
00182     failed = compare_zpbtrs( b, b_i, info, info_i, ldb, nrhs );
00183     if( failed == 0 ) {
00184         printf( "PASSED: row-major middle-level interface to zpbtrs\n" );
00185     } else {
00186         printf( "FAILED: row-major middle-level interface to zpbtrs\n" );
00187     }
00188 
00189     /* Initialize input data, call the row-major high-level
00190      * interface to LAPACK routine and check the results */
00191     for( i = 0; i < ldab*n; i++ ) {
00192         ab_i[i] = ab[i];
00193     }
00194     for( i = 0; i < ldb*nrhs; i++ ) {
00195         b_i[i] = b_save[i];
00196     }
00197 
00198     /* Init row_major arrays */
00199     LAPACKE_zge_trans( LAPACK_COL_MAJOR, kd+1, n, ab_i, ldab, ab_r, n+2 );
00200     LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00201     info_i = LAPACKE_zpbtrs( LAPACK_ROW_MAJOR, uplo_i, n_i, kd_i, nrhs_i, ab_r,
00202                              ldab_r, b_r, ldb_r );
00203 
00204     LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, nrhs, b_r, nrhs+2, b_i, ldb );
00205 
00206     failed = compare_zpbtrs( b, b_i, info, info_i, ldb, nrhs );
00207     if( failed == 0 ) {
00208         printf( "PASSED: row-major high-level interface to zpbtrs\n" );
00209     } else {
00210         printf( "FAILED: row-major high-level interface to zpbtrs\n" );
00211     }
00212 
00213     /* Release memory */
00214     if( ab != NULL ) {
00215         LAPACKE_free( ab );
00216     }
00217     if( ab_i != NULL ) {
00218         LAPACKE_free( ab_i );
00219     }
00220     if( ab_r != NULL ) {
00221         LAPACKE_free( ab_r );
00222     }
00223     if( b != NULL ) {
00224         LAPACKE_free( b );
00225     }
00226     if( b_i != NULL ) {
00227         LAPACKE_free( b_i );
00228     }
00229     if( b_r != NULL ) {
00230         LAPACKE_free( b_r );
00231     }
00232     if( b_save != NULL ) {
00233         LAPACKE_free( b_save );
00234     }
00235 
00236     return 0;
00237 }
00238 
00239 /* Auxiliary function: zpbtrs scalar parameters initialization */
00240 static void init_scalars_zpbtrs( char *uplo, lapack_int *n, lapack_int *kd,
00241                                  lapack_int *nrhs, lapack_int *ldab,
00242                                  lapack_int *ldb )
00243 {
00244     *uplo = 'L';
00245     *n = 4;
00246     *kd = 1;
00247     *nrhs = 2;
00248     *ldab = 9;
00249     *ldb = 8;
00250 
00251     return;
00252 }
00253 
00254 /* Auxiliary functions: zpbtrs array parameters initialization */
00255 static void init_ab( lapack_int size, lapack_complex_double *ab ) {
00256     lapack_int i;
00257     for( i = 0; i < size; i++ ) {
00258         ab[i] = lapack_make_complex_double( 0.0, 0.0 );
00259     }
00260     ab[0] = lapack_make_complex_double( 3.06431068920891250e+000,
00261                                         0.00000000000000000e+000 );
00262     ab[9] = lapack_make_complex_double( 1.11671395318950690e+000,
00263                                         0.00000000000000000e+000 );
00264     ab[18] = lapack_make_complex_double( 1.60663555873113610e+000,
00265                                          0.00000000000000000e+000 );
00266     ab[27] = lapack_make_complex_double( 4.28915067402645010e-001,
00267                                          0.00000000000000000e+000 );
00268     ab[1] = lapack_make_complex_double( 3.52444679909012350e-001,
00269                                         5.64564163187584510e-001 );
00270     ab[10] = lapack_make_complex_double( -3.58193787099676180e-002,
00271                                          -2.59690495647265210e-001 );
00272     ab[19] = lapack_make_complex_double( -2.05398167746655840e-001,
00273                                          -1.39421786591669420e+000 );
00274     ab[28] = lapack_make_complex_double( 0.00000000000000000e+000,
00275                                          0.00000000000000000e+000 );
00276 }
00277 static void init_b( lapack_int size, lapack_complex_double *b ) {
00278     lapack_int i;
00279     for( i = 0; i < size; i++ ) {
00280         b[i] = lapack_make_complex_double( 0.0, 0.0 );
00281     }
00282     b[0] = lapack_make_complex_double( -1.24200000000000000e+001,
00283                                        6.84200000000000020e+001 );
00284     b[8] = lapack_make_complex_double( 5.42999999999999970e+001,
00285                                        -5.65600000000000020e+001 );
00286     b[1] = lapack_make_complex_double( -9.92999999999999970e+000,
00287                                        8.80000000000000000e-001 );
00288     b[9] = lapack_make_complex_double( 1.83200000000000000e+001,
00289                                        4.75999999999999980e+000 );
00290     b[2] = lapack_make_complex_double( -2.73000000000000010e+001,
00291                                        -1.00000000000000000e-002 );
00292     b[10] = lapack_make_complex_double( -4.40000000000000040e+000,
00293                                         9.97000000000000060e+000 );
00294     b[3] = lapack_make_complex_double( 5.30999999999999960e+000,
00295                                        2.36299999999999990e+001 );
00296     b[11] = lapack_make_complex_double( 9.42999999999999970e+000,
00297                                         1.40999999999999990e+000 );
00298 }
00299 
00300 /* Auxiliary function: C interface to zpbtrs results check */
00301 /* Return value: 0 - test is passed, non-zero - test is failed */
00302 static int compare_zpbtrs( lapack_complex_double *b, lapack_complex_double *b_i,
00303                            lapack_int info, lapack_int info_i, lapack_int ldb,
00304                            lapack_int nrhs )
00305 {
00306     lapack_int i;
00307     int failed = 0;
00308     for( i = 0; i < ldb*nrhs; i++ ) {
00309         failed += compare_complex_doubles(b[i],b_i[i]);
00310     }
00311     failed += (info == info_i) ? 0 : 1;
00312     if( info != 0 || info_i != 0 ) {
00313         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00314     }
00315 
00316     return failed;
00317 }


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