zgehrd_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 * zgehrd_2 is the test program for the C interface to LAPACK
00036 * routine zgehrd
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_zgehrd( 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_double *a );
00058 static void init_tau( lapack_int size, lapack_complex_double *tau );
00059 static void init_work( lapack_int size, lapack_complex_double *work );
00060 static int compare_zgehrd( lapack_complex_double *a, lapack_complex_double *a_i,
00061                            lapack_complex_double *tau,
00062                            lapack_complex_double *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_double *a = NULL, *a_i = NULL;
00080     lapack_complex_double *tau = NULL, *tau_i = NULL;
00081     lapack_complex_double *work = NULL, *work_i = NULL;
00082     lapack_complex_double *a_save = NULL;
00083     lapack_complex_double *tau_save = NULL;
00084     lapack_complex_double *a_r = NULL;
00085 
00086     /* Iniitialize the scalar parameters */
00087     init_scalars_zgehrd( &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_double *)
00097         LAPACKE_malloc( lda*n * sizeof(lapack_complex_double) );
00098     tau = (lapack_complex_double *)
00099         LAPACKE_malloc( (n-1) * sizeof(lapack_complex_double) );
00100     work = (lapack_complex_double *)
00101         LAPACKE_malloc( lwork * sizeof(lapack_complex_double) );
00102 
00103     /* Allocate memory for the C interface function arrays */
00104     a_i = (lapack_complex_double *)
00105         LAPACKE_malloc( lda*n * sizeof(lapack_complex_double) );
00106     tau_i = (lapack_complex_double *)
00107         LAPACKE_malloc( (n-1) * sizeof(lapack_complex_double) );
00108     work_i = (lapack_complex_double *)
00109         LAPACKE_malloc( lwork * sizeof(lapack_complex_double) );
00110 
00111     /* Allocate memory for the backup arrays */
00112     a_save = (lapack_complex_double *)
00113         LAPACKE_malloc( lda*n * sizeof(lapack_complex_double) );
00114     tau_save = (lapack_complex_double *)
00115         LAPACKE_malloc( (n-1) * sizeof(lapack_complex_double) );
00116 
00117     /* Allocate memory for the row-major arrays */
00118     a_r = (lapack_complex_double *)
00119         LAPACKE_malloc( n*(n+2) * sizeof(lapack_complex_double) );
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     zgehrd_( &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_zgehrd_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_zgehrd( a, a_i, tau, tau_i, info, info_i, lda, n );
00152     if( failed == 0 ) {
00153         printf( "PASSED: column-major middle-level interface to zgehrd\n" );
00154     } else {
00155         printf( "FAILED: column-major middle-level interface to zgehrd\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_zgehrd( LAPACK_COL_MAJOR, n_i, ilo_i, ihi_i, a_i, lda_i,
00170                              tau_i );
00171 
00172     failed = compare_zgehrd( a, a_i, tau, tau_i, info, info_i, lda, n );
00173     if( failed == 0 ) {
00174         printf( "PASSED: column-major high-level interface to zgehrd\n" );
00175     } else {
00176         printf( "FAILED: column-major high-level interface to zgehrd\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_zge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00192     info_i = LAPACKE_zgehrd_work( LAPACK_ROW_MAJOR, n_i, ilo_i, ihi_i, a_r,
00193                                   lda_r, tau_i, work_i, lwork_i );
00194 
00195     LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00196 
00197     failed = compare_zgehrd( a, a_i, tau, tau_i, info, info_i, lda, n );
00198     if( failed == 0 ) {
00199         printf( "PASSED: row-major middle-level interface to zgehrd\n" );
00200     } else {
00201         printf( "FAILED: row-major middle-level interface to zgehrd\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_zge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00218     info_i = LAPACKE_zgehrd( LAPACK_ROW_MAJOR, n_i, ilo_i, ihi_i, a_r, lda_r,
00219                              tau_i );
00220 
00221     LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00222 
00223     failed = compare_zgehrd( a, a_i, tau, tau_i, info, info_i, lda, n );
00224     if( failed == 0 ) {
00225         printf( "PASSED: row-major high-level interface to zgehrd\n" );
00226     } else {
00227         printf( "FAILED: row-major high-level interface to zgehrd\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: zgehrd scalar parameters initialization */
00263 static void init_scalars_zgehrd( 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 = 512;
00272 
00273     return;
00274 }
00275 
00276 /* Auxiliary functions: zgehrd array parameters initialization */
00277 static void init_a( lapack_int size, lapack_complex_double *a ) {
00278     lapack_int i;
00279     for( i = 0; i < size; i++ ) {
00280         a[i] = lapack_make_complex_double( 0.0, 0.0 );
00281     }
00282     a[0] = lapack_make_complex_double( -3.97000000000000020e+000,
00283                                        -5.04000000000000000e+000 );
00284     a[8] = lapack_make_complex_double( -4.11000000000000030e+000,
00285                                        3.70000000000000020e+000 );
00286     a[16] = lapack_make_complex_double( -3.40000000000000020e-001,
00287                                         1.01000000000000000e+000 );
00288     a[24] = lapack_make_complex_double( 1.29000000000000000e+000,
00289                                         -8.59999999999999990e-001 );
00290     a[1] = lapack_make_complex_double( 3.40000000000000020e-001,
00291                                        -1.50000000000000000e+000 );
00292     a[9] = lapack_make_complex_double( 1.52000000000000000e+000,
00293                                        -4.29999999999999990e-001 );
00294     a[17] = lapack_make_complex_double( 1.87999999999999990e+000,
00295                                         -5.37999999999999990e+000 );
00296     a[25] = lapack_make_complex_double( 3.35999999999999990e+000,
00297                                         6.50000000000000020e-001 );
00298     a[2] = lapack_make_complex_double( 3.31000000000000010e+000,
00299                                        -3.85000000000000010e+000 );
00300     a[10] = lapack_make_complex_double( 2.50000000000000000e+000,
00301                                         3.45000000000000020e+000 );
00302     a[18] = lapack_make_complex_double( 8.80000000000000000e-001,
00303                                         -1.08000000000000010e+000 );
00304     a[26] = lapack_make_complex_double( 6.40000000000000010e-001,
00305                                         -1.48000000000000000e+000 );
00306     a[3] = lapack_make_complex_double( -1.10000000000000010e+000,
00307                                        8.19999999999999950e-001 );
00308     a[11] = lapack_make_complex_double( 1.81000000000000010e+000,
00309                                         -1.59000000000000010e+000 );
00310     a[19] = lapack_make_complex_double( 3.25000000000000000e+000,
00311                                         1.33000000000000010e+000 );
00312     a[27] = lapack_make_complex_double( 1.57000000000000010e+000,
00313                                         -3.43999999999999990e+000 );
00314 }
00315 static void init_tau( lapack_int size, lapack_complex_double *tau ) {
00316     lapack_int i;
00317     for( i = 0; i < size; i++ ) {
00318         tau[i] = lapack_make_complex_double( 0.0, 0.0 );
00319     }
00320 }
00321 static void init_work( lapack_int size, lapack_complex_double *work ) {
00322     lapack_int i;
00323     for( i = 0; i < size; i++ ) {
00324         work[i] = lapack_make_complex_double( 0.0, 0.0 );
00325     }
00326 }
00327 
00328 /* Auxiliary function: C interface to zgehrd results check */
00329 /* Return value: 0 - test is passed, non-zero - test is failed */
00330 static int compare_zgehrd( lapack_complex_double *a, lapack_complex_double *a_i,
00331                            lapack_complex_double *tau,
00332                            lapack_complex_double *tau_i, lapack_int info,
00333                            lapack_int info_i, lapack_int lda, lapack_int n )
00334 {
00335     lapack_int i;
00336     int failed = 0;
00337     for( i = 0; i < lda*n; i++ ) {
00338         failed += compare_complex_doubles(a[i],a_i[i]);
00339     }
00340     for( i = 0; i < (n-1); i++ ) {
00341         failed += compare_complex_doubles(tau[i],tau_i[i]);
00342     }
00343     failed += (info == info_i) ? 0 : 1;
00344     if( info != 0 || info_i != 0 ) {
00345         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00346     }
00347 
00348     return failed;
00349 }


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