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


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