cgehrd_3.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 * cgehrd_3 is the test program for the C interface to LAPACK
00036 * routine cgehrd
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_cgehrd( 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, lapack_complex_float *a );
00058 static void init_tau( lapack_int size, lapack_complex_float *tau );
00059 static void init_work( lapack_int size, lapack_complex_float *work );
00060 static int compare_cgehrd( lapack_complex_float *a, lapack_complex_float *a_i,
00061                            lapack_complex_float *tau,
00062                            lapack_complex_float *tau_i, lapack_int info,
00063                            lapack_int info_i, lapack_int lda, lapack_int n );
00064 
00065 int main(void)
00066 {
00067     /* Local scalars */
00068     lapack_int n, n_i;
00069     lapack_int ilo, ilo_i;
00070     lapack_int ihi, ihi_i;
00071     lapack_int lda, lda_i;
00072     lapack_int lda_r;
00073     lapack_int lwork, lwork_i;
00074     lapack_int info, info_i;
00075     lapack_int i;
00076     int failed;
00077 
00078     /* Local arrays */
00079     lapack_complex_float *a = NULL, *a_i = NULL;
00080     lapack_complex_float *tau = NULL, *tau_i = NULL;
00081     lapack_complex_float *work = NULL, *work_i = NULL;
00082     lapack_complex_float *a_save = NULL;
00083     lapack_complex_float *tau_save = NULL;
00084     lapack_complex_float *a_r = NULL;
00085 
00086     /* Iniitialize the scalar parameters */
00087     init_scalars_cgehrd( &n, &ilo, &ihi, &lda, &lwork );
00088     lda_r = n+2;
00089     n_i = n;
00090     ilo_i = ilo;
00091     ihi_i = ihi;
00092     lda_i = lda;
00093     lwork_i = lwork;
00094 
00095     /* Allocate memory for the LAPACK routine arrays */
00096     a = (lapack_complex_float *)
00097         LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00098     tau = (lapack_complex_float *)
00099         LAPACKE_malloc( (n-1) * sizeof(lapack_complex_float) );
00100     work = (lapack_complex_float *)
00101         LAPACKE_malloc( lwork * sizeof(lapack_complex_float) );
00102 
00103     /* Allocate memory for the C interface function arrays */
00104     a_i = (lapack_complex_float *)
00105         LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00106     tau_i = (lapack_complex_float *)
00107         LAPACKE_malloc( (n-1) * sizeof(lapack_complex_float) );
00108     work_i = (lapack_complex_float *)
00109         LAPACKE_malloc( lwork * sizeof(lapack_complex_float) );
00110 
00111     /* Allocate memory for the backup arrays */
00112     a_save = (lapack_complex_float *)
00113         LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00114     tau_save = (lapack_complex_float *)
00115         LAPACKE_malloc( (n-1) * sizeof(lapack_complex_float) );
00116 
00117     /* Allocate memory for the row-major arrays */
00118     a_r = (lapack_complex_float *)
00119         LAPACKE_malloc( n*(n+2) * sizeof(lapack_complex_float) );
00120 
00121     /* Initialize input arrays */
00122     init_a( lda*n, a );
00123     init_tau( (n-1), tau );
00124     init_work( lwork, work );
00125 
00126     /* Backup the ouptut arrays */
00127     for( i = 0; i < lda*n; i++ ) {
00128         a_save[i] = a[i];
00129     }
00130     for( i = 0; i < (n-1); i++ ) {
00131         tau_save[i] = tau[i];
00132     }
00133 
00134     /* Call the LAPACK routine */
00135     cgehrd_( &n, &ilo, &ihi, a, &lda, tau, work, &lwork, &info );
00136 
00137     /* Initialize input data, call the column-major middle-level
00138      * interface to LAPACK routine and check the results */
00139     for( i = 0; i < lda*n; i++ ) {
00140         a_i[i] = a_save[i];
00141     }
00142     for( i = 0; i < (n-1); i++ ) {
00143         tau_i[i] = tau_save[i];
00144     }
00145     for( i = 0; i < lwork; i++ ) {
00146         work_i[i] = work[i];
00147     }
00148     info_i = LAPACKE_cgehrd_work( LAPACK_COL_MAJOR, n_i, ilo_i, ihi_i, a_i,
00149                                   lda_i, tau_i, work_i, lwork_i );
00150 
00151     failed = compare_cgehrd( a, a_i, tau, tau_i, info, info_i, lda, n );
00152     if( failed == 0 ) {
00153         printf( "PASSED: column-major middle-level interface to cgehrd\n" );
00154     } else {
00155         printf( "FAILED: column-major middle-level interface to cgehrd\n" );
00156     }
00157 
00158     /* Initialize input data, call the column-major high-level
00159      * interface to LAPACK routine and check the results */
00160     for( i = 0; i < lda*n; i++ ) {
00161         a_i[i] = a_save[i];
00162     }
00163     for( i = 0; i < (n-1); i++ ) {
00164         tau_i[i] = tau_save[i];
00165     }
00166     for( i = 0; i < lwork; i++ ) {
00167         work_i[i] = work[i];
00168     }
00169     info_i = LAPACKE_cgehrd( LAPACK_COL_MAJOR, n_i, ilo_i, ihi_i, a_i, lda_i,
00170                              tau_i );
00171 
00172     failed = compare_cgehrd( a, a_i, tau, tau_i, info, info_i, lda, n );
00173     if( failed == 0 ) {
00174         printf( "PASSED: column-major high-level interface to cgehrd\n" );
00175     } else {
00176         printf( "FAILED: column-major high-level interface to cgehrd\n" );
00177     }
00178 
00179     /* Initialize input data, call the row-major middle-level
00180      * interface to LAPACK routine and check the results */
00181     for( i = 0; i < lda*n; i++ ) {
00182         a_i[i] = a_save[i];
00183     }
00184     for( i = 0; i < (n-1); i++ ) {
00185         tau_i[i] = tau_save[i];
00186     }
00187     for( i = 0; i < lwork; i++ ) {
00188         work_i[i] = work[i];
00189     }
00190 
00191     LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00192     info_i = LAPACKE_cgehrd_work( LAPACK_ROW_MAJOR, n_i, ilo_i, ihi_i, a_r,
00193                                   lda_r, tau_i, work_i, lwork_i );
00194 
00195     LAPACKE_cge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00196 
00197     failed = compare_cgehrd( a, a_i, tau, tau_i, info, info_i, lda, n );
00198     if( failed == 0 ) {
00199         printf( "PASSED: row-major middle-level interface to cgehrd\n" );
00200     } else {
00201         printf( "FAILED: row-major middle-level interface to cgehrd\n" );
00202     }
00203 
00204     /* Initialize input data, call the row-major high-level
00205      * interface to LAPACK routine and check the results */
00206     for( i = 0; i < lda*n; i++ ) {
00207         a_i[i] = a_save[i];
00208     }
00209     for( i = 0; i < (n-1); i++ ) {
00210         tau_i[i] = tau_save[i];
00211     }
00212     for( i = 0; i < lwork; i++ ) {
00213         work_i[i] = work[i];
00214     }
00215 
00216     /* Init row_major arrays */
00217     LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00218     info_i = LAPACKE_cgehrd( LAPACK_ROW_MAJOR, n_i, ilo_i, ihi_i, a_r, lda_r,
00219                              tau_i );
00220 
00221     LAPACKE_cge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00222 
00223     failed = compare_cgehrd( a, a_i, tau, tau_i, info, info_i, lda, n );
00224     if( failed == 0 ) {
00225         printf( "PASSED: row-major high-level interface to cgehrd\n" );
00226     } else {
00227         printf( "FAILED: row-major high-level interface to cgehrd\n" );
00228     }
00229 
00230     /* Release memory */
00231     if( a != NULL ) {
00232         LAPACKE_free( a );
00233     }
00234     if( a_i != NULL ) {
00235         LAPACKE_free( a_i );
00236     }
00237     if( a_r != NULL ) {
00238         LAPACKE_free( a_r );
00239     }
00240     if( a_save != NULL ) {
00241         LAPACKE_free( a_save );
00242     }
00243     if( tau != NULL ) {
00244         LAPACKE_free( tau );
00245     }
00246     if( tau_i != NULL ) {
00247         LAPACKE_free( tau_i );
00248     }
00249     if( tau_save != NULL ) {
00250         LAPACKE_free( tau_save );
00251     }
00252     if( work != NULL ) {
00253         LAPACKE_free( work );
00254     }
00255     if( work_i != NULL ) {
00256         LAPACKE_free( work_i );
00257     }
00258 
00259     return 0;
00260 }
00261 
00262 /* Auxiliary function: cgehrd scalar parameters initialization */
00263 static void init_scalars_cgehrd( lapack_int *n, lapack_int *ilo,
00264                                  lapack_int *ihi, lapack_int *lda,
00265                                  lapack_int *lwork )
00266 {
00267     *n = 4;
00268     *ilo = 1;
00269     *ihi = 4;
00270     *lda = 8;
00271     *lwork = 448;
00272 
00273     return;
00274 }
00275 
00276 /* Auxiliary functions: cgehrd array parameters initialization */
00277 static void init_a( lapack_int size, lapack_complex_float *a ) {
00278     lapack_int i;
00279     for( i = 0; i < size; i++ ) {
00280         a[i] = lapack_make_complex_float( 0.0f, 0.0f );
00281     }
00282     a[0] = lapack_make_complex_float( -3.970000029e+000, -5.039999962e+000 );
00283     a[8] = lapack_make_complex_float( -4.110000134e+000, 3.700000048e+000 );
00284     a[16] = lapack_make_complex_float( -3.400000036e-001, 1.009999990e+000 );
00285     a[24] = lapack_make_complex_float( 1.289999962e+000, -8.600000143e-001 );
00286     a[1] = lapack_make_complex_float( 3.400000036e-001, -1.500000000e+000 );
00287     a[9] = lapack_make_complex_float( 1.519999981e+000, -4.300000072e-001 );
00288     a[17] = lapack_make_complex_float( 1.879999995e+000, -5.380000114e+000 );
00289     a[25] = lapack_make_complex_float( 3.359999895e+000, 6.499999762e-001 );
00290     a[2] = lapack_make_complex_float( 3.309999943e+000, -3.849999905e+000 );
00291     a[10] = lapack_make_complex_float( 2.500000000e+000, 3.450000048e+000 );
00292     a[18] = lapack_make_complex_float( 8.799999952e-001, -1.080000043e+000 );
00293     a[26] = lapack_make_complex_float( 6.399999857e-001, -1.480000019e+000 );
00294     a[3] = lapack_make_complex_float( -1.100000024e+000, 8.199999928e-001 );
00295     a[11] = lapack_make_complex_float( 1.809999943e+000, -1.590000033e+000 );
00296     a[19] = lapack_make_complex_float( 3.250000000e+000, 1.330000043e+000 );
00297     a[27] = lapack_make_complex_float( 1.570000052e+000, -3.440000057e+000 );
00298 }
00299 static void init_tau( lapack_int size, lapack_complex_float *tau ) {
00300     lapack_int i;
00301     for( i = 0; i < size; i++ ) {
00302         tau[i] = lapack_make_complex_float( 0.0f, 0.0f );
00303     }
00304 }
00305 static void init_work( lapack_int size, lapack_complex_float *work ) {
00306     lapack_int i;
00307     for( i = 0; i < size; i++ ) {
00308         work[i] = lapack_make_complex_float( 0.0f, 0.0f );
00309     }
00310 }
00311 
00312 /* Auxiliary function: C interface to cgehrd results check */
00313 /* Return value: 0 - test is passed, non-zero - test is failed */
00314 static int compare_cgehrd( lapack_complex_float *a, lapack_complex_float *a_i,
00315                            lapack_complex_float *tau,
00316                            lapack_complex_float *tau_i, lapack_int info,
00317                            lapack_int info_i, lapack_int lda, lapack_int n )
00318 {
00319     lapack_int i;
00320     int failed = 0;
00321     for( i = 0; i < lda*n; i++ ) {
00322         failed += compare_complex_floats(a[i],a_i[i]);
00323     }
00324     for( i = 0; i < (n-1); i++ ) {
00325         failed += compare_complex_floats(tau[i],tau_i[i]);
00326     }
00327     failed += (info == info_i) ? 0 : 1;
00328     if( info != 0 || info_i != 0 ) {
00329         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00330     }
00331 
00332     return failed;
00333 }


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