dgebak_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 * dgebak_1 is the test program for the C interface to LAPACK
00036 * routine dgebak
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_dgebak( char *job, char *side, lapack_int *n,
00055                                  lapack_int *ilo, lapack_int *ihi,
00056                                  lapack_int *m, lapack_int *ldv );
00057 static void init_scale( lapack_int size, double *scale );
00058 static void init_v( lapack_int size, double *v );
00059 static int compare_dgebak( double *v, double *v_i, lapack_int info,
00060                            lapack_int info_i, lapack_int ldv, lapack_int m );
00061 
00062 int main(void)
00063 {
00064     /* Local scalars */
00065     char job, job_i;
00066     char side, side_i;
00067     lapack_int n, n_i;
00068     lapack_int ilo, ilo_i;
00069     lapack_int ihi, ihi_i;
00070     lapack_int m, m_i;
00071     lapack_int ldv, ldv_i;
00072     lapack_int ldv_r;
00073     lapack_int info, info_i;
00074     lapack_int i;
00075     int failed;
00076 
00077     /* Local arrays */
00078     double *scale = NULL, *scale_i = NULL;
00079     double *v = NULL, *v_i = NULL;
00080     double *v_save = NULL;
00081     double *v_r = NULL;
00082 
00083     /* Iniitialize the scalar parameters */
00084     init_scalars_dgebak( &job, &side, &n, &ilo, &ihi, &m, &ldv );
00085     ldv_r = m+2;
00086     job_i = job;
00087     side_i = side;
00088     n_i = n;
00089     ilo_i = ilo;
00090     ihi_i = ihi;
00091     m_i = m;
00092     ldv_i = ldv;
00093 
00094     /* Allocate memory for the LAPACK routine arrays */
00095     scale = (double *)LAPACKE_malloc( n * sizeof(double) );
00096     v = (double *)LAPACKE_malloc( ldv*m * sizeof(double) );
00097 
00098     /* Allocate memory for the C interface function arrays */
00099     scale_i = (double *)LAPACKE_malloc( n * sizeof(double) );
00100     v_i = (double *)LAPACKE_malloc( ldv*m * sizeof(double) );
00101 
00102     /* Allocate memory for the backup arrays */
00103     v_save = (double *)LAPACKE_malloc( ldv*m * sizeof(double) );
00104 
00105     /* Allocate memory for the row-major arrays */
00106     v_r = (double *)LAPACKE_malloc( n*(m+2) * sizeof(double) );
00107 
00108     /* Initialize input arrays */
00109     init_scale( n, scale );
00110     init_v( ldv*m, v );
00111 
00112     /* Backup the ouptut arrays */
00113     for( i = 0; i < ldv*m; i++ ) {
00114         v_save[i] = v[i];
00115     }
00116 
00117     /* Call the LAPACK routine */
00118     dgebak_( &job, &side, &n, &ilo, &ihi, scale, &m, v, &ldv, &info );
00119 
00120     /* Initialize input data, call the column-major middle-level
00121      * interface to LAPACK routine and check the results */
00122     for( i = 0; i < n; i++ ) {
00123         scale_i[i] = scale[i];
00124     }
00125     for( i = 0; i < ldv*m; i++ ) {
00126         v_i[i] = v_save[i];
00127     }
00128     info_i = LAPACKE_dgebak_work( LAPACK_COL_MAJOR, job_i, side_i, n_i, ilo_i,
00129                                   ihi_i, scale_i, m_i, v_i, ldv_i );
00130 
00131     failed = compare_dgebak( v, v_i, info, info_i, ldv, m );
00132     if( failed == 0 ) {
00133         printf( "PASSED: column-major middle-level interface to dgebak\n" );
00134     } else {
00135         printf( "FAILED: column-major middle-level interface to dgebak\n" );
00136     }
00137 
00138     /* Initialize input data, call the column-major high-level
00139      * interface to LAPACK routine and check the results */
00140     for( i = 0; i < n; i++ ) {
00141         scale_i[i] = scale[i];
00142     }
00143     for( i = 0; i < ldv*m; i++ ) {
00144         v_i[i] = v_save[i];
00145     }
00146     info_i = LAPACKE_dgebak( LAPACK_COL_MAJOR, job_i, side_i, n_i, ilo_i, ihi_i,
00147                              scale_i, m_i, v_i, ldv_i );
00148 
00149     failed = compare_dgebak( v, v_i, info, info_i, ldv, m );
00150     if( failed == 0 ) {
00151         printf( "PASSED: column-major high-level interface to dgebak\n" );
00152     } else {
00153         printf( "FAILED: column-major high-level interface to dgebak\n" );
00154     }
00155 
00156     /* Initialize input data, call the row-major middle-level
00157      * interface to LAPACK routine and check the results */
00158     for( i = 0; i < n; i++ ) {
00159         scale_i[i] = scale[i];
00160     }
00161     for( i = 0; i < ldv*m; i++ ) {
00162         v_i[i] = v_save[i];
00163     }
00164 
00165     LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, m, v_i, ldv, v_r, m+2 );
00166     info_i = LAPACKE_dgebak_work( LAPACK_ROW_MAJOR, job_i, side_i, n_i, ilo_i,
00167                                   ihi_i, scale_i, m_i, v_r, ldv_r );
00168 
00169     LAPACKE_dge_trans( LAPACK_ROW_MAJOR, n, m, v_r, m+2, v_i, ldv );
00170 
00171     failed = compare_dgebak( v, v_i, info, info_i, ldv, m );
00172     if( failed == 0 ) {
00173         printf( "PASSED: row-major middle-level interface to dgebak\n" );
00174     } else {
00175         printf( "FAILED: row-major middle-level interface to dgebak\n" );
00176     }
00177 
00178     /* Initialize input data, call the row-major high-level
00179      * interface to LAPACK routine and check the results */
00180     for( i = 0; i < n; i++ ) {
00181         scale_i[i] = scale[i];
00182     }
00183     for( i = 0; i < ldv*m; i++ ) {
00184         v_i[i] = v_save[i];
00185     }
00186 
00187     /* Init row_major arrays */
00188     LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, m, v_i, ldv, v_r, m+2 );
00189     info_i = LAPACKE_dgebak( LAPACK_ROW_MAJOR, job_i, side_i, n_i, ilo_i, ihi_i,
00190                              scale_i, m_i, v_r, ldv_r );
00191 
00192     LAPACKE_dge_trans( LAPACK_ROW_MAJOR, n, m, v_r, m+2, v_i, ldv );
00193 
00194     failed = compare_dgebak( v, v_i, info, info_i, ldv, m );
00195     if( failed == 0 ) {
00196         printf( "PASSED: row-major high-level interface to dgebak\n" );
00197     } else {
00198         printf( "FAILED: row-major high-level interface to dgebak\n" );
00199     }
00200 
00201     /* Release memory */
00202     if( scale != NULL ) {
00203         LAPACKE_free( scale );
00204     }
00205     if( scale_i != NULL ) {
00206         LAPACKE_free( scale_i );
00207     }
00208     if( v != NULL ) {
00209         LAPACKE_free( v );
00210     }
00211     if( v_i != NULL ) {
00212         LAPACKE_free( v_i );
00213     }
00214     if( v_r != NULL ) {
00215         LAPACKE_free( v_r );
00216     }
00217     if( v_save != NULL ) {
00218         LAPACKE_free( v_save );
00219     }
00220 
00221     return 0;
00222 }
00223 
00224 /* Auxiliary function: dgebak scalar parameters initialization */
00225 static void init_scalars_dgebak( char *job, char *side, lapack_int *n,
00226                                  lapack_int *ilo, lapack_int *ihi,
00227                                  lapack_int *m, lapack_int *ldv )
00228 {
00229     *job = 'B';
00230     *side = 'R';
00231     *n = 4;
00232     *ilo = 2;
00233     *ihi = 4;
00234     *m = 4;
00235     *ldv = 8;
00236 
00237     return;
00238 }
00239 
00240 /* Auxiliary functions: dgebak array parameters initialization */
00241 static void init_scale( lapack_int size, double *scale ) {
00242     lapack_int i;
00243     for( i = 0; i < size; i++ ) {
00244         scale[i] = 0;
00245     }
00246     scale[0] = 3.00000000000000000e+000;
00247     scale[1] = 4.00000000000000000e+000;
00248     scale[2] = 4.00000000000000000e+000;
00249     scale[3] = 5.00000000000000000e-001;
00250 }
00251 static void init_v( lapack_int size, double *v ) {
00252     lapack_int i;
00253     for( i = 0; i < size; i++ ) {
00254         v[i] = 0;
00255     }
00256     v[0] = 1.00000000000000000e+000;  /* v[0,0] */
00257     v[8] = -2.15709029223295460e-001;  /* v[0,1] */
00258     v[16] = -1.00000000000000000e+000;  /* v[0,2] */
00259     v[24] = -1.00000000000000000e+000;  /* v[0,3] */
00260     v[1] = 0.00000000000000000e+000;  /* v[1,0] */
00261     v[9] = 1.00000000000000000e+000;  /* v[1,1] */
00262     v[17] = -4.95308301949082260e-001;  /* v[1,2] */
00263     v[25] = 1.71833107632870240e-001;  /* v[1,3] */
00264     v[2] = 0.00000000000000000e+000;  /* v[2,0] */
00265     v[10] = -4.91006373625574700e-001;  /* v[2,1] */
00266     v[18] = -2.92210843245896300e-001;  /* v[2,2] */
00267     v[26] = -9.53731439243778790e-001;  /* v[2,3] */
00268     v[3] = 0.00000000000000000e+000;  /* v[3,0] */
00269     v[11] = -8.75122446424736690e-001;  /* v[3,1] */
00270     v[19] = -2.61487853687739190e-001;  /* v[3,2] */
00271     v[27] = 4.72487441336102100e-001;  /* v[3,3] */
00272 }
00273 
00274 /* Auxiliary function: C interface to dgebak results check */
00275 /* Return value: 0 - test is passed, non-zero - test is failed */
00276 static int compare_dgebak( double *v, double *v_i, lapack_int info,
00277                            lapack_int info_i, lapack_int ldv, lapack_int m )
00278 {
00279     lapack_int i;
00280     int failed = 0;
00281     for( i = 0; i < ldv*m; i++ ) {
00282         failed += compare_doubles(v[i],v_i[i]);
00283     }
00284     failed += (info == info_i) ? 0 : 1;
00285     if( info != 0 || info_i != 0 ) {
00286         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00287     }
00288 
00289     return failed;
00290 }


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