zunmtr_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 * zunmtr_1 is the test program for the C interface to LAPACK
00036 * routine zunmtr
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_zunmtr( char *side, char *uplo, char *trans,
00055                                  lapack_int *m, lapack_int *n, lapack_int *lda,
00056                                  lapack_int *ldc, 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_c( lapack_int size, lapack_complex_double *c );
00060 static void init_work( lapack_int size, lapack_complex_double *work );
00061 static int compare_zunmtr( lapack_complex_double *c, lapack_complex_double *c_i,
00062                            lapack_int info, lapack_int info_i, lapack_int ldc,
00063                            lapack_int n );
00064 
00065 int main(void)
00066 {
00067     /* Local scalars */
00068     char side, side_i;
00069     char uplo, uplo_i;
00070     char trans, trans_i;
00071     lapack_int m, m_i;
00072     lapack_int n, n_i;
00073     lapack_int lda, lda_i;
00074     lapack_int lda_r;
00075     lapack_int ldc, ldc_i;
00076     lapack_int ldc_r;
00077     lapack_int lwork, lwork_i;
00078     lapack_int info, info_i;
00079     /* Declare scalars */
00080     lapack_int r;
00081     lapack_int i;
00082     int failed;
00083 
00084     /* Local arrays */
00085     lapack_complex_double *a = NULL, *a_i = NULL;
00086     lapack_complex_double *tau = NULL, *tau_i = NULL;
00087     lapack_complex_double *c = NULL, *c_i = NULL;
00088     lapack_complex_double *work = NULL, *work_i = NULL;
00089     lapack_complex_double *c_save = NULL;
00090     lapack_complex_double *a_r = NULL;
00091     lapack_complex_double *c_r = NULL;
00092 
00093     /* Iniitialize the scalar parameters */
00094     init_scalars_zunmtr( &side, &uplo, &trans, &m, &n, &lda, &ldc, &lwork );
00095     r = LAPACKE_lsame( side, 'l' ) ? m : n;
00096     lda_r = r+2;
00097     ldc_r = n+2;
00098     side_i = side;
00099     uplo_i = uplo;
00100     trans_i = trans;
00101     m_i = m;
00102     n_i = n;
00103     lda_i = lda;
00104     ldc_i = ldc;
00105     lwork_i = lwork;
00106 
00107     /* Allocate memory for the LAPACK routine arrays */
00108     a = (lapack_complex_double *)
00109         LAPACKE_malloc( lda*m * sizeof(lapack_complex_double) );
00110     tau = (lapack_complex_double *)
00111         LAPACKE_malloc( (m-1) * sizeof(lapack_complex_double) );
00112     c = (lapack_complex_double *)
00113         LAPACKE_malloc( ldc*n * sizeof(lapack_complex_double) );
00114     work = (lapack_complex_double *)
00115         LAPACKE_malloc( lwork * sizeof(lapack_complex_double) );
00116 
00117     /* Allocate memory for the C interface function arrays */
00118     a_i = (lapack_complex_double *)
00119         LAPACKE_malloc( lda*m * sizeof(lapack_complex_double) );
00120     tau_i = (lapack_complex_double *)
00121         LAPACKE_malloc( (m-1) * sizeof(lapack_complex_double) );
00122     c_i = (lapack_complex_double *)
00123         LAPACKE_malloc( ldc*n * sizeof(lapack_complex_double) );
00124     work_i = (lapack_complex_double *)
00125         LAPACKE_malloc( lwork * sizeof(lapack_complex_double) );
00126 
00127     /* Allocate memory for the backup arrays */
00128     c_save = (lapack_complex_double *)
00129         LAPACKE_malloc( ldc*n * sizeof(lapack_complex_double) );
00130 
00131     /* Allocate memory for the row-major arrays */
00132     a_r = (lapack_complex_double *)
00133         LAPACKE_malloc( r*(r+2) * sizeof(lapack_complex_double) );
00134     c_r = (lapack_complex_double *)
00135         LAPACKE_malloc( m*(n+2) * sizeof(lapack_complex_double) );
00136 
00137     /* Initialize input arrays */
00138     init_a( lda*m, a );
00139     init_tau( (m-1), tau );
00140     init_c( ldc*n, c );
00141     init_work( lwork, work );
00142 
00143     /* Backup the ouptut arrays */
00144     for( i = 0; i < ldc*n; i++ ) {
00145         c_save[i] = c[i];
00146     }
00147 
00148     /* Call the LAPACK routine */
00149     zunmtr_( &side, &uplo, &trans, &m, &n, a, &lda, tau, c, &ldc, work, &lwork,
00150              &info );
00151 
00152     /* Initialize input data, call the column-major middle-level
00153      * interface to LAPACK routine and check the results */
00154     for( i = 0; i < lda*m; i++ ) {
00155         a_i[i] = a[i];
00156     }
00157     for( i = 0; i < (m-1); i++ ) {
00158         tau_i[i] = tau[i];
00159     }
00160     for( i = 0; i < ldc*n; i++ ) {
00161         c_i[i] = c_save[i];
00162     }
00163     for( i = 0; i < lwork; i++ ) {
00164         work_i[i] = work[i];
00165     }
00166     info_i = LAPACKE_zunmtr_work( LAPACK_COL_MAJOR, side_i, uplo_i, trans_i,
00167                                   m_i, n_i, a_i, lda_i, tau_i, c_i, ldc_i,
00168                                   work_i, lwork_i );
00169 
00170     failed = compare_zunmtr( c, c_i, info, info_i, ldc, n );
00171     if( failed == 0 ) {
00172         printf( "PASSED: column-major middle-level interface to zunmtr\n" );
00173     } else {
00174         printf( "FAILED: column-major middle-level interface to zunmtr\n" );
00175     }
00176 
00177     /* Initialize input data, call the column-major high-level
00178      * interface to LAPACK routine and check the results */
00179     for( i = 0; i < lda*m; i++ ) {
00180         a_i[i] = a[i];
00181     }
00182     for( i = 0; i < (m-1); i++ ) {
00183         tau_i[i] = tau[i];
00184     }
00185     for( i = 0; i < ldc*n; i++ ) {
00186         c_i[i] = c_save[i];
00187     }
00188     for( i = 0; i < lwork; i++ ) {
00189         work_i[i] = work[i];
00190     }
00191     info_i = LAPACKE_zunmtr( LAPACK_COL_MAJOR, side_i, uplo_i, trans_i, m_i,
00192                              n_i, a_i, lda_i, tau_i, c_i, ldc_i );
00193 
00194     failed = compare_zunmtr( c, c_i, info, info_i, ldc, n );
00195     if( failed == 0 ) {
00196         printf( "PASSED: column-major high-level interface to zunmtr\n" );
00197     } else {
00198         printf( "FAILED: column-major high-level interface to zunmtr\n" );
00199     }
00200 
00201     /* Initialize input data, call the row-major middle-level
00202      * interface to LAPACK routine and check the results */
00203     for( i = 0; i < lda*m; i++ ) {
00204         a_i[i] = a[i];
00205     }
00206     for( i = 0; i < (m-1); i++ ) {
00207         tau_i[i] = tau[i];
00208     }
00209     for( i = 0; i < ldc*n; i++ ) {
00210         c_i[i] = c_save[i];
00211     }
00212     for( i = 0; i < lwork; i++ ) {
00213         work_i[i] = work[i];
00214     }
00215 
00216     LAPACKE_zge_trans( LAPACK_COL_MAJOR, r, r, a_i, lda, a_r, r+2 );
00217     LAPACKE_zge_trans( LAPACK_COL_MAJOR, m, n, c_i, ldc, c_r, n+2 );
00218     info_i = LAPACKE_zunmtr_work( LAPACK_ROW_MAJOR, side_i, uplo_i, trans_i,
00219                                   m_i, n_i, a_r, lda_r, tau_i, c_r, ldc_r,
00220                                   work_i, lwork_i );
00221 
00222     LAPACKE_zge_trans( LAPACK_ROW_MAJOR, m, n, c_r, n+2, c_i, ldc );
00223 
00224     failed = compare_zunmtr( c, c_i, info, info_i, ldc, n );
00225     if( failed == 0 ) {
00226         printf( "PASSED: row-major middle-level interface to zunmtr\n" );
00227     } else {
00228         printf( "FAILED: row-major middle-level interface to zunmtr\n" );
00229     }
00230 
00231     /* Initialize input data, call the row-major high-level
00232      * interface to LAPACK routine and check the results */
00233     for( i = 0; i < lda*m; i++ ) {
00234         a_i[i] = a[i];
00235     }
00236     for( i = 0; i < (m-1); i++ ) {
00237         tau_i[i] = tau[i];
00238     }
00239     for( i = 0; i < ldc*n; i++ ) {
00240         c_i[i] = c_save[i];
00241     }
00242     for( i = 0; i < lwork; i++ ) {
00243         work_i[i] = work[i];
00244     }
00245 
00246     /* Init row_major arrays */
00247     LAPACKE_zge_trans( LAPACK_COL_MAJOR, r, r, a_i, lda, a_r, r+2 );
00248     LAPACKE_zge_trans( LAPACK_COL_MAJOR, m, n, c_i, ldc, c_r, n+2 );
00249     info_i = LAPACKE_zunmtr( LAPACK_ROW_MAJOR, side_i, uplo_i, trans_i, m_i,
00250                              n_i, a_r, lda_r, tau_i, c_r, ldc_r );
00251 
00252     LAPACKE_zge_trans( LAPACK_ROW_MAJOR, m, n, c_r, n+2, c_i, ldc );
00253 
00254     failed = compare_zunmtr( c, c_i, info, info_i, ldc, n );
00255     if( failed == 0 ) {
00256         printf( "PASSED: row-major high-level interface to zunmtr\n" );
00257     } else {
00258         printf( "FAILED: row-major high-level interface to zunmtr\n" );
00259     }
00260 
00261     /* Release memory */
00262     if( a != NULL ) {
00263         LAPACKE_free( a );
00264     }
00265     if( a_i != NULL ) {
00266         LAPACKE_free( a_i );
00267     }
00268     if( a_r != NULL ) {
00269         LAPACKE_free( a_r );
00270     }
00271     if( tau != NULL ) {
00272         LAPACKE_free( tau );
00273     }
00274     if( tau_i != NULL ) {
00275         LAPACKE_free( tau_i );
00276     }
00277     if( c != NULL ) {
00278         LAPACKE_free( c );
00279     }
00280     if( c_i != NULL ) {
00281         LAPACKE_free( c_i );
00282     }
00283     if( c_r != NULL ) {
00284         LAPACKE_free( c_r );
00285     }
00286     if( c_save != NULL ) {
00287         LAPACKE_free( c_save );
00288     }
00289     if( work != NULL ) {
00290         LAPACKE_free( work );
00291     }
00292     if( work_i != NULL ) {
00293         LAPACKE_free( work_i );
00294     }
00295 
00296     return 0;
00297 }
00298 
00299 /* Auxiliary function: zunmtr scalar parameters initialization */
00300 static void init_scalars_zunmtr( char *side, char *uplo, char *trans,
00301                                  lapack_int *m, lapack_int *n, lapack_int *lda,
00302                                  lapack_int *ldc, lapack_int *lwork )
00303 {
00304     *side = 'L';
00305     *uplo = 'L';
00306     *trans = 'N';
00307     *m = 4;
00308     *n = 2;
00309     *lda = 8;
00310     *ldc = 8;
00311     *lwork = 512;
00312 
00313     return;
00314 }
00315 
00316 /* Auxiliary functions: zunmtr array parameters initialization */
00317 static void init_a( lapack_int size, lapack_complex_double *a ) {
00318     lapack_int i;
00319     for( i = 0; i < size; i++ ) {
00320         a[i] = lapack_make_complex_double( 0.0, 0.0 );
00321     }
00322     a[0] = lapack_make_complex_double( -2.27999999999999980e+000,
00323                                        0.00000000000000000e+000 );
00324     a[8] = lapack_make_complex_double( 0.00000000000000000e+000,
00325                                        0.00000000000000000e+000 );
00326     a[16] = lapack_make_complex_double( 0.00000000000000000e+000,
00327                                         0.00000000000000000e+000 );
00328     a[24] = lapack_make_complex_double( 0.00000000000000000e+000,
00329                                         0.00000000000000000e+000 );
00330     a[1] = lapack_make_complex_double( -4.33845594653212970e+000,
00331                                        0.00000000000000000e+000 );
00332     a[9] = lapack_make_complex_double( -1.28456981649329280e-001,
00333                                        0.00000000000000000e+000 );
00334     a[17] = lapack_make_complex_double( 0.00000000000000000e+000,
00335                                         0.00000000000000000e+000 );
00336     a[25] = lapack_make_complex_double( 0.00000000000000000e+000,
00337                                         0.00000000000000000e+000 );
00338     a[2] = lapack_make_complex_double( 3.27860676092192380e-001,
00339                                        -1.25122609226443690e-001 );
00340     a[10] = lapack_make_complex_double( -2.02259457862261720e+000,
00341                                         0.00000000000000000e+000 );
00342     a[18] = lapack_make_complex_double( -1.66593253752407190e-001,
00343                                         0.00000000000000000e+000 );
00344     a[26] = lapack_make_complex_double( 0.00000000000000000e+000,
00345                                         0.00000000000000000e+000 );
00346     a[3] = lapack_make_complex_double( -1.41256563750694670e-001,
00347                                        -3.66636483973957040e-001 );
00348     a[11] = lapack_make_complex_double( -3.08321908008089010e-001,
00349                                         1.76322636472677850e-001 );
00350     a[19] = lapack_make_complex_double( -1.80232297833873440e+000,
00351                                         0.00000000000000000e+000 );
00352     a[27] = lapack_make_complex_double( -1.92494976459826360e+000,
00353                                         0.00000000000000000e+000 );
00354 }
00355 static void init_tau( lapack_int size, lapack_complex_double *tau ) {
00356     lapack_int i;
00357     for( i = 0; i < size; i++ ) {
00358         tau[i] = lapack_make_complex_double( 0.0, 0.0 );
00359     }
00360     tau[0] = lapack_make_complex_double( 1.41028421676675380e+000,
00361                                          4.67908404514893240e-001 );
00362     tau[1] = lapack_make_complex_double( 1.30242036943477490e+000,
00363                                          7.85332074252958030e-001 );
00364     tau[2] = lapack_make_complex_double( 1.09397371592308160e+000,
00365                                          -9.95574678623159850e-001 );
00366 }
00367 static void init_c( lapack_int size, lapack_complex_double *c ) {
00368     lapack_int i;
00369     for( i = 0; i < size; i++ ) {
00370         c[i] = lapack_make_complex_double( 0.0, 0.0 );
00371     }
00372     c[0] = lapack_make_complex_double( 7.29894574391705130e-001,
00373                                        0.00000000000000000e+000 );
00374     c[8] = lapack_make_complex_double( -2.59544973387760720e-001,
00375                                        0.00000000000000000e+000 );
00376     c[1] = lapack_make_complex_double( 6.25877780555793130e-001,
00377                                        0.00000000000000000e+000 );
00378     c[9] = lapack_make_complex_double( -4.32549625865536950e-002,
00379                                        0.00000000000000000e+000 );
00380     c[2] = lapack_make_complex_double( 2.51344947364408430e-001,
00381                                        0.00000000000000000e+000 );
00382     c[10] = lapack_make_complex_double( 4.95247410182067920e-001,
00383                                         0.00000000000000000e+000 );
00384     c[3] = lapack_make_complex_double( 1.11160386444491490e-001,
00385                                        0.00000000000000000e+000 );
00386     c[11] = lapack_make_complex_double( 8.27946506550234270e-001,
00387                                         0.00000000000000000e+000 );
00388 }
00389 static void init_work( lapack_int size, lapack_complex_double *work ) {
00390     lapack_int i;
00391     for( i = 0; i < size; i++ ) {
00392         work[i] = lapack_make_complex_double( 0.0, 0.0 );
00393     }
00394 }
00395 
00396 /* Auxiliary function: C interface to zunmtr results check */
00397 /* Return value: 0 - test is passed, non-zero - test is failed */
00398 static int compare_zunmtr( lapack_complex_double *c, lapack_complex_double *c_i,
00399                            lapack_int info, lapack_int info_i, lapack_int ldc,
00400                            lapack_int n )
00401 {
00402     lapack_int i;
00403     int failed = 0;
00404     for( i = 0; i < ldc*n; i++ ) {
00405         failed += compare_complex_doubles(c[i],c_i[i]);
00406     }
00407     failed += (info == info_i) ? 0 : 1;
00408     if( info != 0 || info_i != 0 ) {
00409         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00410     }
00411 
00412     return failed;
00413 }


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