zunmbr_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 * zunmbr_1 is the test program for the C interface to LAPACK
00036 * routine zunmbr
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_zunmbr( char *vect, char *side, char *trans,
00055                                  lapack_int *m, lapack_int *n, lapack_int *k,
00056                                  lapack_int *lda, lapack_int *ldc,
00057                                  lapack_int *lwork );
00058 static void init_a( lapack_int size, lapack_complex_double *a );
00059 static void init_tau( lapack_int size, lapack_complex_double *tau );
00060 static void init_c( lapack_int size, lapack_complex_double *c );
00061 static void init_work( lapack_int size, lapack_complex_double *work );
00062 static int compare_zunmbr( lapack_complex_double *c, lapack_complex_double *c_i,
00063                            lapack_int info, lapack_int info_i, lapack_int ldc,
00064                            lapack_int n );
00065 
00066 int main(void)
00067 {
00068     /* Local scalars */
00069     char vect, vect_i;
00070     char side, side_i;
00071     char trans, trans_i;
00072     lapack_int m, m_i;
00073     lapack_int n, n_i;
00074     lapack_int k, k_i;
00075     lapack_int lda, lda_i;
00076     lapack_int lda_r;
00077     lapack_int ldc, ldc_i;
00078     lapack_int ldc_r;
00079     lapack_int lwork, lwork_i;
00080     lapack_int info, info_i;
00081     /* Declare scalars */
00082     lapack_int nq;
00083     lapack_int r;
00084     lapack_int i;
00085     int failed;
00086 
00087     /* Local arrays */
00088     lapack_complex_double *a = NULL, *a_i = NULL;
00089     lapack_complex_double *tau = NULL, *tau_i = NULL;
00090     lapack_complex_double *c = NULL, *c_i = NULL;
00091     lapack_complex_double *work = NULL, *work_i = NULL;
00092     lapack_complex_double *c_save = NULL;
00093     lapack_complex_double *a_r = NULL;
00094     lapack_complex_double *c_r = NULL;
00095 
00096     /* Iniitialize the scalar parameters */
00097     init_scalars_zunmbr( &vect, &side, &trans, &m, &n, &k, &lda, &ldc, &lwork );
00098     nq = LAPACKE_lsame( side, 'l' ) ? m : n;
00099     r = LAPACKE_lsame( vect, 'q' ) ? nq : MIN(nq,k);
00100     lda_r = MIN(nq,k)+2;
00101     ldc_r = n+2;
00102     vect_i = vect;
00103     side_i = side;
00104     trans_i = trans;
00105     m_i = m;
00106     n_i = n;
00107     k_i = k;
00108     lda_i = lda;
00109     ldc_i = ldc;
00110     lwork_i = lwork;
00111 
00112     /* Allocate memory for the LAPACK routine arrays */
00113     a = (lapack_complex_double *)
00114         LAPACKE_malloc( (lda*(MIN(nq,k))) * sizeof(lapack_complex_double) );
00115     tau = (lapack_complex_double *)
00116         LAPACKE_malloc( MIN(nq,k) * sizeof(lapack_complex_double) );
00117     c = (lapack_complex_double *)
00118         LAPACKE_malloc( ldc*n * sizeof(lapack_complex_double) );
00119     work = (lapack_complex_double *)
00120         LAPACKE_malloc( lwork * sizeof(lapack_complex_double) );
00121 
00122     /* Allocate memory for the C interface function arrays */
00123     a_i = (lapack_complex_double *)
00124         LAPACKE_malloc( (lda*(MIN(nq,k))) * sizeof(lapack_complex_double) );
00125     tau_i = (lapack_complex_double *)
00126         LAPACKE_malloc( MIN(nq,k) * sizeof(lapack_complex_double) );
00127     c_i = (lapack_complex_double *)
00128         LAPACKE_malloc( ldc*n * sizeof(lapack_complex_double) );
00129     work_i = (lapack_complex_double *)
00130         LAPACKE_malloc( lwork * sizeof(lapack_complex_double) );
00131 
00132     /* Allocate memory for the backup arrays */
00133     c_save = (lapack_complex_double *)
00134         LAPACKE_malloc( ldc*n * sizeof(lapack_complex_double) );
00135 
00136     /* Allocate memory for the row-major arrays */
00137     a_r = (lapack_complex_double *)
00138         LAPACKE_malloc( (r*(MIN(nq,k)+2)) * sizeof(lapack_complex_double) );
00139     c_r = (lapack_complex_double *)
00140         LAPACKE_malloc( m*(n+2) * sizeof(lapack_complex_double) );
00141 
00142     /* Initialize input arrays */
00143     init_a( lda*(MIN(nq,k)), a );
00144     init_tau( (MIN(nq,k)), tau );
00145     init_c( ldc*n, c );
00146     init_work( lwork, work );
00147 
00148     /* Backup the ouptut arrays */
00149     for( i = 0; i < ldc*n; i++ ) {
00150         c_save[i] = c[i];
00151     }
00152 
00153     /* Call the LAPACK routine */
00154     zunmbr_( &vect, &side, &trans, &m, &n, &k, a, &lda, tau, c, &ldc, work,
00155              &lwork, &info );
00156 
00157     /* Initialize input data, call the column-major middle-level
00158      * interface to LAPACK routine and check the results */
00159     for( i = 0; i < lda*(MIN(nq,k)); i++ ) {
00160         a_i[i] = a[i];
00161     }
00162     for( i = 0; i < (MIN(nq,k)); i++ ) {
00163         tau_i[i] = tau[i];
00164     }
00165     for( i = 0; i < ldc*n; i++ ) {
00166         c_i[i] = c_save[i];
00167     }
00168     for( i = 0; i < lwork; i++ ) {
00169         work_i[i] = work[i];
00170     }
00171     info_i = LAPACKE_zunmbr_work( LAPACK_COL_MAJOR, vect_i, side_i, trans_i,
00172                                   m_i, n_i, k_i, a_i, lda_i, tau_i, c_i, ldc_i,
00173                                   work_i, lwork_i );
00174 
00175     failed = compare_zunmbr( c, c_i, info, info_i, ldc, n );
00176     if( failed == 0 ) {
00177         printf( "PASSED: column-major middle-level interface to zunmbr\n" );
00178     } else {
00179         printf( "FAILED: column-major middle-level interface to zunmbr\n" );
00180     }
00181 
00182     /* Initialize input data, call the column-major high-level
00183      * interface to LAPACK routine and check the results */
00184     for( i = 0; i < lda*(MIN(nq,k)); i++ ) {
00185         a_i[i] = a[i];
00186     }
00187     for( i = 0; i < (MIN(nq,k)); i++ ) {
00188         tau_i[i] = tau[i];
00189     }
00190     for( i = 0; i < ldc*n; i++ ) {
00191         c_i[i] = c_save[i];
00192     }
00193     for( i = 0; i < lwork; i++ ) {
00194         work_i[i] = work[i];
00195     }
00196     info_i = LAPACKE_zunmbr( LAPACK_COL_MAJOR, vect_i, side_i, trans_i, m_i,
00197                              n_i, k_i, a_i, lda_i, tau_i, c_i, ldc_i );
00198 
00199     failed = compare_zunmbr( c, c_i, info, info_i, ldc, n );
00200     if( failed == 0 ) {
00201         printf( "PASSED: column-major high-level interface to zunmbr\n" );
00202     } else {
00203         printf( "FAILED: column-major high-level interface to zunmbr\n" );
00204     }
00205 
00206     /* Initialize input data, call the row-major middle-level
00207      * interface to LAPACK routine and check the results */
00208     for( i = 0; i < lda*(MIN(nq,k)); i++ ) {
00209         a_i[i] = a[i];
00210     }
00211     for( i = 0; i < (MIN(nq,k)); i++ ) {
00212         tau_i[i] = tau[i];
00213     }
00214     for( i = 0; i < ldc*n; i++ ) {
00215         c_i[i] = c_save[i];
00216     }
00217     for( i = 0; i < lwork; i++ ) {
00218         work_i[i] = work[i];
00219     }
00220 
00221     LAPACKE_zge_trans( LAPACK_COL_MAJOR, r, MIN(nq, k ), a_i, lda, a_r, MIN(nq,
00222                        k)+2);
00223     LAPACKE_zge_trans( LAPACK_COL_MAJOR, m, n, c_i, ldc, c_r, n+2 );
00224     info_i = LAPACKE_zunmbr_work( LAPACK_ROW_MAJOR, vect_i, side_i, trans_i,
00225                                   m_i, n_i, k_i, a_r, lda_r, tau_i, c_r, ldc_r,
00226                                   work_i, lwork_i );
00227 
00228     LAPACKE_zge_trans( LAPACK_ROW_MAJOR, m, n, c_r, n+2, c_i, ldc );
00229 
00230     failed = compare_zunmbr( c, c_i, info, info_i, ldc, n );
00231     if( failed == 0 ) {
00232         printf( "PASSED: row-major middle-level interface to zunmbr\n" );
00233     } else {
00234         printf( "FAILED: row-major middle-level interface to zunmbr\n" );
00235     }
00236 
00237     /* Initialize input data, call the row-major high-level
00238      * interface to LAPACK routine and check the results */
00239     for( i = 0; i < lda*(MIN(nq,k)); i++ ) {
00240         a_i[i] = a[i];
00241     }
00242     for( i = 0; i < (MIN(nq,k)); i++ ) {
00243         tau_i[i] = tau[i];
00244     }
00245     for( i = 0; i < ldc*n; i++ ) {
00246         c_i[i] = c_save[i];
00247     }
00248     for( i = 0; i < lwork; i++ ) {
00249         work_i[i] = work[i];
00250     }
00251 
00252     /* Init row_major arrays */
00253     LAPACKE_zge_trans( LAPACK_COL_MAJOR, r, MIN(nq, k ), a_i, lda, a_r, MIN(nq,
00254                        k)+2);
00255     LAPACKE_zge_trans( LAPACK_COL_MAJOR, m, n, c_i, ldc, c_r, n+2 );
00256     info_i = LAPACKE_zunmbr( LAPACK_ROW_MAJOR, vect_i, side_i, trans_i, m_i,
00257                              n_i, k_i, a_r, lda_r, tau_i, c_r, ldc_r );
00258 
00259     LAPACKE_zge_trans( LAPACK_ROW_MAJOR, m, n, c_r, n+2, c_i, ldc );
00260 
00261     failed = compare_zunmbr( c, c_i, info, info_i, ldc, n );
00262     if( failed == 0 ) {
00263         printf( "PASSED: row-major high-level interface to zunmbr\n" );
00264     } else {
00265         printf( "FAILED: row-major high-level interface to zunmbr\n" );
00266     }
00267 
00268     /* Release memory */
00269     if( a != NULL ) {
00270         LAPACKE_free( a );
00271     }
00272     if( a_i != NULL ) {
00273         LAPACKE_free( a_i );
00274     }
00275     if( a_r != NULL ) {
00276         LAPACKE_free( a_r );
00277     }
00278     if( tau != NULL ) {
00279         LAPACKE_free( tau );
00280     }
00281     if( tau_i != NULL ) {
00282         LAPACKE_free( tau_i );
00283     }
00284     if( c != NULL ) {
00285         LAPACKE_free( c );
00286     }
00287     if( c_i != NULL ) {
00288         LAPACKE_free( c_i );
00289     }
00290     if( c_r != NULL ) {
00291         LAPACKE_free( c_r );
00292     }
00293     if( c_save != NULL ) {
00294         LAPACKE_free( c_save );
00295     }
00296     if( work != NULL ) {
00297         LAPACKE_free( work );
00298     }
00299     if( work_i != NULL ) {
00300         LAPACKE_free( work_i );
00301     }
00302 
00303     return 0;
00304 }
00305 
00306 /* Auxiliary function: zunmbr scalar parameters initialization */
00307 static void init_scalars_zunmbr( char *vect, char *side, char *trans,
00308                                  lapack_int *m, lapack_int *n, lapack_int *k,
00309                                  lapack_int *lda, lapack_int *ldc,
00310                                  lapack_int *lwork )
00311 {
00312     *vect = 'Q';
00313     *side = 'R';
00314     *trans = 'N';
00315     *m = 6;
00316     *n = 4;
00317     *k = 4;
00318     *lda = 8;
00319     *ldc = 8;
00320     *lwork = 1024;
00321 
00322     return;
00323 }
00324 
00325 /* Auxiliary functions: zunmbr array parameters initialization */
00326 static void init_a( lapack_int size, lapack_complex_double *a ) {
00327     lapack_int i;
00328     for( i = 0; i < size; i++ ) {
00329         a[i] = lapack_make_complex_double( 0.0, 0.0 );
00330     }
00331     a[0] = lapack_make_complex_double( -3.08700502105195800e+000,
00332                                        0.00000000000000000e+000 );
00333     a[8] = lapack_make_complex_double( 2.11257100745583950e+000,
00334                                        0.00000000000000000e+000 );
00335     a[16] = lapack_make_complex_double( 5.43341107944031730e-002,
00336                                         4.54311849677352220e-001 );
00337     a[24] = lapack_make_complex_double( 3.75743827925403060e-001,
00338                                         1.07008730409452330e-001 );
00339     a[1] = lapack_make_complex_double( 0.00000000000000000e+000,
00340                                        0.00000000000000000e+000 );
00341     a[9] = lapack_make_complex_double( -2.06603927667906810e+000,
00342                                        0.00000000000000000e+000 );
00343     a[17] = lapack_make_complex_double( -1.26281010665522380e+000,
00344                                         0.00000000000000000e+000 );
00345     a[25] = lapack_make_complex_double( 2.82771782873273430e-002,
00346                                         1.65005610304937070e-001 );
00347     a[2] = lapack_make_complex_double( 0.00000000000000000e+000,
00348                                        0.00000000000000000e+000 );
00349     a[10] = lapack_make_complex_double( -2.80478799113691670e-001,
00350                                         -4.12446107471391210e-001 );
00351     a[18] = lapack_make_complex_double( -1.87312889112571160e+000,
00352                                         0.00000000000000000e+000 );
00353     a[26] = lapack_make_complex_double( 1.61263387280039240e+000,
00354                                         0.00000000000000000e+000 );
00355     a[3] = lapack_make_complex_double( 0.00000000000000000e+000,
00356                                        0.00000000000000000e+000 );
00357     a[11] = lapack_make_complex_double( 2.10347237263873110e-001,
00358                                         -4.46076099427661470e-001 );
00359     a[19] = lapack_make_complex_double( -5.70841942484137550e-001,
00360                                         6.43744629522165630e-002 );
00361     a[27] = lapack_make_complex_double( -2.00218286620699090e+000,
00362                                         0.00000000000000000e+000 );
00363 }
00364 static void init_tau( lapack_int size, lapack_complex_double *tau ) {
00365     lapack_int i;
00366     for( i = 0; i < size; i++ ) {
00367         tau[i] = lapack_make_complex_double( 0.0, 0.0 );
00368     }
00369     tau[0] = lapack_make_complex_double( 0.00000000000000000e+000,
00370                                          0.00000000000000000e+000 );
00371     tau[1] = lapack_make_complex_double( 1.09819823812611190e+000,
00372                                          5.15816216039656440e-001 );
00373     tau[2] = lapack_make_complex_double( 1.45515808833705250e+000,
00374                                          -2.65922977495843870e-001 );
00375     tau[3] = lapack_make_complex_double( 1.98987975280288490e+000,
00376                                          -1.41908685396276930e-001 );
00377 }
00378 static void init_c( lapack_int size, lapack_complex_double *c ) {
00379     lapack_int i;
00380     for( i = 0; i < size; i++ ) {
00381         c[i] = lapack_make_complex_double( 0.0, 0.0 );
00382     }
00383     c[0] = lapack_make_complex_double( -3.10981029656006490e-001,
00384                                        2.62390243772255500e-001 );
00385     c[8] = lapack_make_complex_double( -3.17534144502360170e-001,
00386                                        4.83496706343327200e-001 );
00387     c[16] = lapack_make_complex_double( 4.96614318796456340e-001,
00388                                         -2.99683439908111190e-001 );
00389     c[24] = lapack_make_complex_double( -7.19581794453816310e-003,
00390                                         -3.71789321048053510e-001 );
00391     c[1] = lapack_make_complex_double( 3.17459801107173260e-001,
00392                                        -6.41398373665513440e-001 );
00393     c[9] = lapack_make_complex_double( -2.06186271838591340e-001,
00394                                        1.57696475525517740e-001 );
00395     c[17] = lapack_make_complex_double( -7.92590243451013750e-002,
00396                                         -3.09374948323355990e-001 );
00397     c[25] = lapack_make_complex_double( -2.81616606005113960e-002,
00398                                         -1.49146751526478600e-001 );
00399     c[2] = lapack_make_complex_double( -2.00841914986170850e-001,
00400                                        1.49011743376836450e-001 );
00401     c[10] = lapack_make_complex_double( 4.89188100959905730e-001,
00402                                         -9.00253506243144790e-002 );
00403     c[18] = lapack_make_complex_double( 3.57457076059659040e-002,
00404                                         -2.19038212535253160e-002 );
00405     c[26] = lapack_make_complex_double( 5.62461584914262350e-001,
00406                                         -7.09935540642336740e-002 );
00407     c[3] = lapack_make_complex_double( 1.19857271846585860e-001,
00408                                        -1.23096657572169240e-001 );
00409     c[11] = lapack_make_complex_double( 2.56601066116824760e-001,
00410                                         -3.05538478436464810e-001 );
00411     c[19] = lapack_make_complex_double( 4.48864600443415420e-001,
00412                                         -2.14082501679258070e-001 );
00413     c[27] = lapack_make_complex_double( -1.65130169153753950e-001,
00414                                         1.79976238026742870e-001 );
00415     c[4] = lapack_make_complex_double( -2.68869015223422270e-001,
00416                                        -1.65208672004753480e-001 );
00417     c[12] = lapack_make_complex_double( 1.69670826543481260e-001,
00418                                         -2.49070210545617840e-001 );
00419     c[20] = lapack_make_complex_double( -4.95609811295813220e-002,
00420                                         1.15754472307329690e-001 );
00421     c[28] = lapack_make_complex_double( -4.88520186437440000e-001,
00422                                         -4.54037797675943160e-001 );
00423     c[5] = lapack_make_complex_double( -3.49853658363007300e-001,
00424                                        9.07028003163352360e-002 );
00425     c[13] = lapack_make_complex_double( -4.91043340586379550e-002,
00426                                         -3.13335633697416240e-001 );
00427     c[21] = lapack_make_complex_double( -1.25647898922387340e-001,
00428                                         -5.29960507352611470e-001 );
00429     c[29] = lapack_make_complex_double( 1.03906587226856650e-001,
00430                                         4.49630621031451990e-002 );
00431 }
00432 static void init_work( lapack_int size, lapack_complex_double *work ) {
00433     lapack_int i;
00434     for( i = 0; i < size; i++ ) {
00435         work[i] = lapack_make_complex_double( 0.0, 0.0 );
00436     }
00437 }
00438 
00439 /* Auxiliary function: C interface to zunmbr results check */
00440 /* Return value: 0 - test is passed, non-zero - test is failed */
00441 static int compare_zunmbr( lapack_complex_double *c, lapack_complex_double *c_i,
00442                            lapack_int info, lapack_int info_i, lapack_int ldc,
00443                            lapack_int n )
00444 {
00445     lapack_int i;
00446     int failed = 0;
00447     for( i = 0; i < ldc*n; i++ ) {
00448         failed += compare_complex_doubles(c[i],c_i[i]);
00449     }
00450     failed += (info == info_i) ? 0 : 1;
00451     if( info != 0 || info_i != 0 ) {
00452         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00453     }
00454 
00455     return failed;
00456 }


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