cunmbr_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 * cunmbr_2 is the test program for the C interface to LAPACK
00036 * routine cunmbr
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_cunmbr( 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_float *a );
00059 static void init_tau( lapack_int size, lapack_complex_float *tau );
00060 static void init_c( lapack_int size, lapack_complex_float *c );
00061 static void init_work( lapack_int size, lapack_complex_float *work );
00062 static int compare_cunmbr( lapack_complex_float *c, lapack_complex_float *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_float *a = NULL, *a_i = NULL;
00089     lapack_complex_float *tau = NULL, *tau_i = NULL;
00090     lapack_complex_float *c = NULL, *c_i = NULL;
00091     lapack_complex_float *work = NULL, *work_i = NULL;
00092     lapack_complex_float *c_save = NULL;
00093     lapack_complex_float *a_r = NULL;
00094     lapack_complex_float *c_r = NULL;
00095 
00096     /* Iniitialize the scalar parameters */
00097     init_scalars_cunmbr( &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_float *)
00114         LAPACKE_malloc( (lda*(MIN(nq,k))) * sizeof(lapack_complex_float) );
00115     tau = (lapack_complex_float *)
00116         LAPACKE_malloc( MIN(nq,k) * sizeof(lapack_complex_float) );
00117     c = (lapack_complex_float *)
00118         LAPACKE_malloc( ldc*n * sizeof(lapack_complex_float) );
00119     work = (lapack_complex_float *)
00120         LAPACKE_malloc( lwork * sizeof(lapack_complex_float) );
00121 
00122     /* Allocate memory for the C interface function arrays */
00123     a_i = (lapack_complex_float *)
00124         LAPACKE_malloc( (lda*(MIN(nq,k))) * sizeof(lapack_complex_float) );
00125     tau_i = (lapack_complex_float *)
00126         LAPACKE_malloc( MIN(nq,k) * sizeof(lapack_complex_float) );
00127     c_i = (lapack_complex_float *)
00128         LAPACKE_malloc( ldc*n * sizeof(lapack_complex_float) );
00129     work_i = (lapack_complex_float *)
00130         LAPACKE_malloc( lwork * sizeof(lapack_complex_float) );
00131 
00132     /* Allocate memory for the backup arrays */
00133     c_save = (lapack_complex_float *)
00134         LAPACKE_malloc( ldc*n * sizeof(lapack_complex_float) );
00135 
00136     /* Allocate memory for the row-major arrays */
00137     a_r = (lapack_complex_float *)
00138         LAPACKE_malloc( (r*(MIN(nq,k)+2)) * sizeof(lapack_complex_float) );
00139     c_r = (lapack_complex_float *)
00140         LAPACKE_malloc( m*(n+2) * sizeof(lapack_complex_float) );
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     cunmbr_( &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_cunmbr_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_cunmbr( c, c_i, info, info_i, ldc, n );
00176     if( failed == 0 ) {
00177         printf( "PASSED: column-major middle-level interface to cunmbr\n" );
00178     } else {
00179         printf( "FAILED: column-major middle-level interface to cunmbr\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_cunmbr( 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_cunmbr( c, c_i, info, info_i, ldc, n );
00200     if( failed == 0 ) {
00201         printf( "PASSED: column-major high-level interface to cunmbr\n" );
00202     } else {
00203         printf( "FAILED: column-major high-level interface to cunmbr\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_cge_trans( LAPACK_COL_MAJOR, r, MIN(nq, k ), a_i, lda, a_r, MIN(nq,
00222                        k)+2);
00223     LAPACKE_cge_trans( LAPACK_COL_MAJOR, m, n, c_i, ldc, c_r, n+2 );
00224     info_i = LAPACKE_cunmbr_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_cge_trans( LAPACK_ROW_MAJOR, m, n, c_r, n+2, c_i, ldc );
00229 
00230     failed = compare_cunmbr( c, c_i, info, info_i, ldc, n );
00231     if( failed == 0 ) {
00232         printf( "PASSED: row-major middle-level interface to cunmbr\n" );
00233     } else {
00234         printf( "FAILED: row-major middle-level interface to cunmbr\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_cge_trans( LAPACK_COL_MAJOR, r, MIN(nq, k ), a_i, lda, a_r, MIN(nq,
00254                        k)+2);
00255     LAPACKE_cge_trans( LAPACK_COL_MAJOR, m, n, c_i, ldc, c_r, n+2 );
00256     info_i = LAPACKE_cunmbr( 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_cge_trans( LAPACK_ROW_MAJOR, m, n, c_r, n+2, c_i, ldc );
00260 
00261     failed = compare_cunmbr( c, c_i, info, info_i, ldc, n );
00262     if( failed == 0 ) {
00263         printf( "PASSED: row-major high-level interface to cunmbr\n" );
00264     } else {
00265         printf( "FAILED: row-major high-level interface to cunmbr\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: cunmbr scalar parameters initialization */
00307 static void init_scalars_cunmbr( 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 = 'P';
00313     *side = 'L';
00314     *trans = 'C';
00315     *m = 3;
00316     *n = 4;
00317     *k = 3;
00318     *lda = 8;
00319     *ldc = 8;
00320     *lwork = 1024;
00321 
00322     return;
00323 }
00324 
00325 /* Auxiliary functions: cunmbr array parameters initialization */
00326 static void init_a( lapack_int size, lapack_complex_float *a ) {
00327     lapack_int i;
00328     for( i = 0; i < size; i++ ) {
00329         a[i] = lapack_make_complex_float( 0.0f, 0.0f );
00330     }
00331     a[0] = lapack_make_complex_float( 2.761475801e+000, 0.000000000e+000 );
00332     a[8] = lapack_make_complex_float( -9.499514103e-001, 0.000000000e+000 );
00333     a[16] = lapack_make_complex_float( 7.651669532e-002, -2.179353982e-001 );
00334     a[1] = lapack_make_complex_float( -1.645794213e-001, -2.483377308e-001 );
00335     a[9] = lapack_make_complex_float( 1.629762888e+000, 0.000000000e+000 );
00336     a[17] = lapack_make_complex_float( -1.018280864e+000, 0.000000000e+000 );
00337     a[2] = lapack_make_complex_float( -2.072303614e-004, 1.368010789e-001 );
00338     a[10] = lapack_make_complex_float( 2.649169862e-001, -2.632617950e-001 );
00339     a[18] = lapack_make_complex_float( -1.327486753e+000, 0.000000000e+000 );
00340 }
00341 static void init_tau( lapack_int size, lapack_complex_float *tau ) {
00342     lapack_int i;
00343     for( i = 0; i < size; i++ ) {
00344         tau[i] = lapack_make_complex_float( 0.0f, 0.0f );
00345     }
00346     tau[0] = lapack_make_complex_float( 1.688534141e+000, 5.957157016e-001 );
00347     tau[1] = lapack_make_complex_float( 1.935088515e+000, 3.544141948e-001 );
00348     tau[2] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00349 }
00350 static void init_c( lapack_int size, lapack_complex_float *c ) {
00351     lapack_int i;
00352     for( i = 0; i < size; i++ ) {
00353         c[i] = lapack_make_complex_float( 0.0f, 0.0f );
00354     }
00355     c[0] = lapack_make_complex_float( -1.258138418e-001, 1.617605835e-001 );
00356     c[8] = lapack_make_complex_float( -2.246674895e-001, 3.864280879e-001 );
00357     c[16] = lapack_make_complex_float( 3.459879458e-001, 2.156807780e-001 );
00358     c[24] = lapack_make_complex_float( -7.099492550e-001, -2.965611219e-001 );
00359     c[1] = lapack_make_complex_float( -1.163461953e-001, -6.379657388e-001 );
00360     c[9] = lapack_make_complex_float( -3.240494728e-001, 4.271534085e-001 );
00361     c[17] = lapack_make_complex_float( -1.995496750e-001, -5.008659363e-001 );
00362     c[25] = lapack_make_complex_float( -3.233429790e-002, -1.620414853e-002 );
00363     c[2] = lapack_make_complex_float( -4.606565833e-001, 1.090034544e-001 );
00364     c[10] = lapack_make_complex_float( 2.170982510e-001, -4.061889052e-001 );
00365     c[18] = lapack_make_complex_float( 2.733075619e-001, -6.106228232e-001 );
00366     c[26] = lapack_make_complex_float( -9.940487146e-002, -3.261196911e-001 );
00367 }
00368 static void init_work( lapack_int size, lapack_complex_float *work ) {
00369     lapack_int i;
00370     for( i = 0; i < size; i++ ) {
00371         work[i] = lapack_make_complex_float( 0.0f, 0.0f );
00372     }
00373 }
00374 
00375 /* Auxiliary function: C interface to cunmbr results check */
00376 /* Return value: 0 - test is passed, non-zero - test is failed */
00377 static int compare_cunmbr( lapack_complex_float *c, lapack_complex_float *c_i,
00378                            lapack_int info, lapack_int info_i, lapack_int ldc,
00379                            lapack_int n )
00380 {
00381     lapack_int i;
00382     int failed = 0;
00383     for( i = 0; i < ldc*n; i++ ) {
00384         failed += compare_complex_floats(c[i],c_i[i]);
00385     }
00386     failed += (info == info_i) ? 0 : 1;
00387     if( info != 0 || info_i != 0 ) {
00388         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00389     }
00390 
00391     return failed;
00392 }


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