dorghr_2.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 * dorghr_2 is the test program for the C interface to LAPACK
00036 * routine dorghr
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_dorghr( lapack_int *n, lapack_int *ilo,
00055                                  lapack_int *ihi, lapack_int *lda,
00056                                  lapack_int *lwork );
00057 static void init_a( lapack_int size, double *a );
00058 static void init_tau( lapack_int size, double *tau );
00059 static void init_work( lapack_int size, double *work );
00060 static int compare_dorghr( double *a, double *a_i, lapack_int info,
00061                            lapack_int info_i, lapack_int lda, lapack_int n );
00062 
00063 int main(void)
00064 {
00065     /* Local scalars */
00066     lapack_int n, n_i;
00067     lapack_int ilo, ilo_i;
00068     lapack_int ihi, ihi_i;
00069     lapack_int lda, lda_i;
00070     lapack_int lda_r;
00071     lapack_int lwork, lwork_i;
00072     lapack_int info, info_i;
00073     lapack_int i;
00074     int failed;
00075 
00076     /* Local arrays */
00077     double *a = NULL, *a_i = NULL;
00078     double *tau = NULL, *tau_i = NULL;
00079     double *work = NULL, *work_i = NULL;
00080     double *a_save = NULL;
00081     double *a_r = NULL;
00082 
00083     /* Iniitialize the scalar parameters */
00084     init_scalars_dorghr( &n, &ilo, &ihi, &lda, &lwork );
00085     lda_r = n+2;
00086     n_i = n;
00087     ilo_i = ilo;
00088     ihi_i = ihi;
00089     lda_i = lda;
00090     lwork_i = lwork;
00091 
00092     /* Allocate memory for the LAPACK routine arrays */
00093     a = (double *)LAPACKE_malloc( lda*n * sizeof(double) );
00094     tau = (double *)LAPACKE_malloc( (n-1) * sizeof(double) );
00095     work = (double *)LAPACKE_malloc( lwork * sizeof(double) );
00096 
00097     /* Allocate memory for the C interface function arrays */
00098     a_i = (double *)LAPACKE_malloc( lda*n * sizeof(double) );
00099     tau_i = (double *)LAPACKE_malloc( (n-1) * sizeof(double) );
00100     work_i = (double *)LAPACKE_malloc( lwork * sizeof(double) );
00101 
00102     /* Allocate memory for the backup arrays */
00103     a_save = (double *)LAPACKE_malloc( lda*n * sizeof(double) );
00104 
00105     /* Allocate memory for the row-major arrays */
00106     a_r = (double *)LAPACKE_malloc( n*(n+2) * sizeof(double) );
00107 
00108     /* Initialize input arrays */
00109     init_a( lda*n, a );
00110     init_tau( (n-1), tau );
00111     init_work( lwork, work );
00112 
00113     /* Backup the ouptut arrays */
00114     for( i = 0; i < lda*n; i++ ) {
00115         a_save[i] = a[i];
00116     }
00117 
00118     /* Call the LAPACK routine */
00119     dorghr_( &n, &ilo, &ihi, a, &lda, tau, work, &lwork, &info );
00120 
00121     /* Initialize input data, call the column-major middle-level
00122      * interface to LAPACK routine and check the results */
00123     for( i = 0; i < lda*n; i++ ) {
00124         a_i[i] = a_save[i];
00125     }
00126     for( i = 0; i < (n-1); i++ ) {
00127         tau_i[i] = tau[i];
00128     }
00129     for( i = 0; i < lwork; i++ ) {
00130         work_i[i] = work[i];
00131     }
00132     info_i = LAPACKE_dorghr_work( LAPACK_COL_MAJOR, n_i, ilo_i, ihi_i, a_i,
00133                                   lda_i, tau_i, work_i, lwork_i );
00134 
00135     failed = compare_dorghr( a, a_i, info, info_i, lda, n );
00136     if( failed == 0 ) {
00137         printf( "PASSED: column-major middle-level interface to dorghr\n" );
00138     } else {
00139         printf( "FAILED: column-major middle-level interface to dorghr\n" );
00140     }
00141 
00142     /* Initialize input data, call the column-major high-level
00143      * interface to LAPACK routine and check the results */
00144     for( i = 0; i < lda*n; i++ ) {
00145         a_i[i] = a_save[i];
00146     }
00147     for( i = 0; i < (n-1); i++ ) {
00148         tau_i[i] = tau[i];
00149     }
00150     for( i = 0; i < lwork; i++ ) {
00151         work_i[i] = work[i];
00152     }
00153     info_i = LAPACKE_dorghr( LAPACK_COL_MAJOR, n_i, ilo_i, ihi_i, a_i, lda_i,
00154                              tau_i );
00155 
00156     failed = compare_dorghr( a, a_i, info, info_i, lda, n );
00157     if( failed == 0 ) {
00158         printf( "PASSED: column-major high-level interface to dorghr\n" );
00159     } else {
00160         printf( "FAILED: column-major high-level interface to dorghr\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 < lda*n; i++ ) {
00166         a_i[i] = a_save[i];
00167     }
00168     for( i = 0; i < (n-1); i++ ) {
00169         tau_i[i] = tau[i];
00170     }
00171     for( i = 0; i < lwork; i++ ) {
00172         work_i[i] = work[i];
00173     }
00174 
00175     LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00176     info_i = LAPACKE_dorghr_work( LAPACK_ROW_MAJOR, n_i, ilo_i, ihi_i, a_r,
00177                                   lda_r, tau_i, work_i, lwork_i );
00178 
00179     LAPACKE_dge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00180 
00181     failed = compare_dorghr( a, a_i, info, info_i, lda, n );
00182     if( failed == 0 ) {
00183         printf( "PASSED: row-major middle-level interface to dorghr\n" );
00184     } else {
00185         printf( "FAILED: row-major middle-level interface to dorghr\n" );
00186     }
00187 
00188     /* Initialize input data, call the row-major high-level
00189      * interface to LAPACK routine and check the results */
00190     for( i = 0; i < lda*n; i++ ) {
00191         a_i[i] = a_save[i];
00192     }
00193     for( i = 0; i < (n-1); i++ ) {
00194         tau_i[i] = tau[i];
00195     }
00196     for( i = 0; i < lwork; i++ ) {
00197         work_i[i] = work[i];
00198     }
00199 
00200     /* Init row_major arrays */
00201     LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00202     info_i = LAPACKE_dorghr( LAPACK_ROW_MAJOR, n_i, ilo_i, ihi_i, a_r, lda_r,
00203                              tau_i );
00204 
00205     LAPACKE_dge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00206 
00207     failed = compare_dorghr( a, a_i, info, info_i, lda, n );
00208     if( failed == 0 ) {
00209         printf( "PASSED: row-major high-level interface to dorghr\n" );
00210     } else {
00211         printf( "FAILED: row-major high-level interface to dorghr\n" );
00212     }
00213 
00214     /* Release memory */
00215     if( a != NULL ) {
00216         LAPACKE_free( a );
00217     }
00218     if( a_i != NULL ) {
00219         LAPACKE_free( a_i );
00220     }
00221     if( a_r != NULL ) {
00222         LAPACKE_free( a_r );
00223     }
00224     if( a_save != NULL ) {
00225         LAPACKE_free( a_save );
00226     }
00227     if( tau != NULL ) {
00228         LAPACKE_free( tau );
00229     }
00230     if( tau_i != NULL ) {
00231         LAPACKE_free( tau_i );
00232     }
00233     if( work != NULL ) {
00234         LAPACKE_free( work );
00235     }
00236     if( work_i != NULL ) {
00237         LAPACKE_free( work_i );
00238     }
00239 
00240     return 0;
00241 }
00242 
00243 /* Auxiliary function: dorghr scalar parameters initialization */
00244 static void init_scalars_dorghr( lapack_int *n, lapack_int *ilo,
00245                                  lapack_int *ihi, lapack_int *lda,
00246                                  lapack_int *lwork )
00247 {
00248     *n = 4;
00249     *ilo = 1;
00250     *ihi = 4;
00251     *lda = 8;
00252     *lwork = 448;
00253 
00254     return;
00255 }
00256 
00257 /* Auxiliary functions: dorghr array parameters initialization */
00258 static void init_a( lapack_int size, double *a ) {
00259     lapack_int i;
00260     for( i = 0; i < size; i++ ) {
00261         a[i] = 0;
00262     }
00263     a[0] = 3.49999999999999980e-001;  /* a[0,0] */
00264     a[8] = -1.15952429620503390e-001;  /* a[0,1] */
00265     a[16] = -3.88601034323321160e-001;  /* a[0,2] */
00266     a[24] = -2.94184075347302120e-001;  /* a[0,3] */
00267     a[1] = -5.14003891035855980e-001;  /* a[1,0] */
00268     a[9] = 1.22486752460257420e-001;  /* a[1,1] */
00269     a[17] = 1.00359789682150170e-001;  /* a[1,2] */
00270     a[25] = 1.12561879970531830e-001;  /* a[1,3] */
00271     a[2] = -7.28472128292762870e-001;  /* a[2,0] */
00272     a[10] = 6.44263618527061930e-001;  /* a[2,1] */
00273     a[18] = -1.35700171757113630e-001;  /* a[2,2] */
00274     a[26] = -9.76816227049334410e-002;  /* a[2,3] */
00275     a[3] = 4.13904618348160720e-001;  /* a[3,0] */
00276     a[11] = -1.66544579490569860e-001;  /* a[3,1] */
00277     a[19] = 4.26244372207844720e-001;  /* a[3,2] */
00278     a[27] = 1.63213419296856090e-001;  /* a[3,3] */
00279 }
00280 static void init_tau( lapack_int size, double *tau ) {
00281     lapack_int i;
00282     for( i = 0; i < size; i++ ) {
00283         tau[i] = 0;
00284     }
00285     tau[0] = 1.17509595076921650e+000;
00286     tau[1] = 1.94602297213986320e+000;
00287     tau[2] = 0.00000000000000000e+000;
00288 }
00289 static void init_work( lapack_int size, double *work ) {
00290     lapack_int i;
00291     for( i = 0; i < size; i++ ) {
00292         work[i] = 0;
00293     }
00294 }
00295 
00296 /* Auxiliary function: C interface to dorghr results check */
00297 /* Return value: 0 - test is passed, non-zero - test is failed */
00298 static int compare_dorghr( double *a, double *a_i, lapack_int info,
00299                            lapack_int info_i, lapack_int lda, lapack_int n )
00300 {
00301     lapack_int i;
00302     int failed = 0;
00303     for( i = 0; i < lda*n; i++ ) {
00304         failed += compare_doubles(a[i],a_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:55:47