sorgbr_4.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 * sorgbr_4 is the test program for the C interface to LAPACK
00036 * routine sorgbr
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_sorgbr( char *vect, lapack_int *m, lapack_int *n,
00055                                  lapack_int *k, lapack_int *lda,
00056                                  lapack_int *lwork );
00057 static void init_a( lapack_int size, float *a );
00058 static void init_tau( lapack_int size, float *tau );
00059 static void init_work( lapack_int size, float *work );
00060 static int compare_sorgbr( float *a, float *a_i, lapack_int info,
00061                            lapack_int info_i, lapack_int lda, lapack_int n );
00062 
00063 int main(void)
00064 {
00065     /* Local scalars */
00066     char vect, vect_i;
00067     lapack_int m, m_i;
00068     lapack_int n, n_i;
00069     lapack_int k, k_i;
00070     lapack_int lda, lda_i;
00071     lapack_int lda_r;
00072     lapack_int lwork, lwork_i;
00073     lapack_int info, info_i;
00074     lapack_int i;
00075     int failed;
00076 
00077     /* Local arrays */
00078     float *a = NULL, *a_i = NULL;
00079     float *tau = NULL, *tau_i = NULL;
00080     float *work = NULL, *work_i = NULL;
00081     float *a_save = NULL;
00082     float *a_r = NULL;
00083 
00084     /* Iniitialize the scalar parameters */
00085     init_scalars_sorgbr( &vect, &m, &n, &k, &lda, &lwork );
00086     lda_r = n+2;
00087     vect_i = vect;
00088     m_i = m;
00089     n_i = n;
00090     k_i = k;
00091     lda_i = lda;
00092     lwork_i = lwork;
00093 
00094     /* Allocate memory for the LAPACK routine arrays */
00095     a = (float *)LAPACKE_malloc( lda*n * sizeof(float) );
00096     tau = (float *)LAPACKE_malloc( MIN(m,k) * sizeof(float) );
00097     work = (float *)LAPACKE_malloc( lwork * sizeof(float) );
00098 
00099     /* Allocate memory for the C interface function arrays */
00100     a_i = (float *)LAPACKE_malloc( lda*n * sizeof(float) );
00101     tau_i = (float *)LAPACKE_malloc( MIN(m,k) * sizeof(float) );
00102     work_i = (float *)LAPACKE_malloc( lwork * sizeof(float) );
00103 
00104     /* Allocate memory for the backup arrays */
00105     a_save = (float *)LAPACKE_malloc( lda*n * sizeof(float) );
00106 
00107     /* Allocate memory for the row-major arrays */
00108     a_r = (float *)LAPACKE_malloc( m*(n+2) * sizeof(float) );
00109 
00110     /* Initialize input arrays */
00111     init_a( lda*n, a );
00112     init_tau( (MIN(m,k)), tau );
00113     init_work( lwork, work );
00114 
00115     /* Backup the ouptut arrays */
00116     for( i = 0; i < lda*n; i++ ) {
00117         a_save[i] = a[i];
00118     }
00119 
00120     /* Call the LAPACK routine */
00121     sorgbr_( &vect, &m, &n, &k, a, &lda, tau, work, &lwork, &info );
00122 
00123     /* Initialize input data, call the column-major middle-level
00124      * interface to LAPACK routine and check the results */
00125     for( i = 0; i < lda*n; i++ ) {
00126         a_i[i] = a_save[i];
00127     }
00128     for( i = 0; i < (MIN(m,k)); i++ ) {
00129         tau_i[i] = tau[i];
00130     }
00131     for( i = 0; i < lwork; i++ ) {
00132         work_i[i] = work[i];
00133     }
00134     info_i = LAPACKE_sorgbr_work( LAPACK_COL_MAJOR, vect_i, m_i, n_i, k_i, a_i,
00135                                   lda_i, tau_i, work_i, lwork_i );
00136 
00137     failed = compare_sorgbr( a, a_i, info, info_i, lda, n );
00138     if( failed == 0 ) {
00139         printf( "PASSED: column-major middle-level interface to sorgbr\n" );
00140     } else {
00141         printf( "FAILED: column-major middle-level interface to sorgbr\n" );
00142     }
00143 
00144     /* Initialize input data, call the column-major high-level
00145      * interface to LAPACK routine and check the results */
00146     for( i = 0; i < lda*n; i++ ) {
00147         a_i[i] = a_save[i];
00148     }
00149     for( i = 0; i < (MIN(m,k)); i++ ) {
00150         tau_i[i] = tau[i];
00151     }
00152     for( i = 0; i < lwork; i++ ) {
00153         work_i[i] = work[i];
00154     }
00155     info_i = LAPACKE_sorgbr( LAPACK_COL_MAJOR, vect_i, m_i, n_i, k_i, a_i,
00156                              lda_i, tau_i );
00157 
00158     failed = compare_sorgbr( a, a_i, info, info_i, lda, n );
00159     if( failed == 0 ) {
00160         printf( "PASSED: column-major high-level interface to sorgbr\n" );
00161     } else {
00162         printf( "FAILED: column-major high-level interface to sorgbr\n" );
00163     }
00164 
00165     /* Initialize input data, call the row-major middle-level
00166      * interface to LAPACK routine and check the results */
00167     for( i = 0; i < lda*n; i++ ) {
00168         a_i[i] = a_save[i];
00169     }
00170     for( i = 0; i < (MIN(m,k)); i++ ) {
00171         tau_i[i] = tau[i];
00172     }
00173     for( i = 0; i < lwork; i++ ) {
00174         work_i[i] = work[i];
00175     }
00176 
00177     LAPACKE_sge_trans( LAPACK_COL_MAJOR, m, n, a_i, lda, a_r, n+2 );
00178     info_i = LAPACKE_sorgbr_work( LAPACK_ROW_MAJOR, vect_i, m_i, n_i, k_i, a_r,
00179                                   lda_r, tau_i, work_i, lwork_i );
00180 
00181     LAPACKE_sge_trans( LAPACK_ROW_MAJOR, m, n, a_r, n+2, a_i, lda );
00182 
00183     failed = compare_sorgbr( a, a_i, info, info_i, lda, n );
00184     if( failed == 0 ) {
00185         printf( "PASSED: row-major middle-level interface to sorgbr\n" );
00186     } else {
00187         printf( "FAILED: row-major middle-level interface to sorgbr\n" );
00188     }
00189 
00190     /* Initialize input data, call the row-major high-level
00191      * interface to LAPACK routine and check the results */
00192     for( i = 0; i < lda*n; i++ ) {
00193         a_i[i] = a_save[i];
00194     }
00195     for( i = 0; i < (MIN(m,k)); i++ ) {
00196         tau_i[i] = tau[i];
00197     }
00198     for( i = 0; i < lwork; i++ ) {
00199         work_i[i] = work[i];
00200     }
00201 
00202     /* Init row_major arrays */
00203     LAPACKE_sge_trans( LAPACK_COL_MAJOR, m, n, a_i, lda, a_r, n+2 );
00204     info_i = LAPACKE_sorgbr( LAPACK_ROW_MAJOR, vect_i, m_i, n_i, k_i, a_r,
00205                              lda_r, tau_i );
00206 
00207     LAPACKE_sge_trans( LAPACK_ROW_MAJOR, m, n, a_r, n+2, a_i, lda );
00208 
00209     failed = compare_sorgbr( a, a_i, info, info_i, lda, n );
00210     if( failed == 0 ) {
00211         printf( "PASSED: row-major high-level interface to sorgbr\n" );
00212     } else {
00213         printf( "FAILED: row-major high-level interface to sorgbr\n" );
00214     }
00215 
00216     /* Release memory */
00217     if( a != NULL ) {
00218         LAPACKE_free( a );
00219     }
00220     if( a_i != NULL ) {
00221         LAPACKE_free( a_i );
00222     }
00223     if( a_r != NULL ) {
00224         LAPACKE_free( a_r );
00225     }
00226     if( a_save != NULL ) {
00227         LAPACKE_free( a_save );
00228     }
00229     if( tau != NULL ) {
00230         LAPACKE_free( tau );
00231     }
00232     if( tau_i != NULL ) {
00233         LAPACKE_free( tau_i );
00234     }
00235     if( work != NULL ) {
00236         LAPACKE_free( work );
00237     }
00238     if( work_i != NULL ) {
00239         LAPACKE_free( work_i );
00240     }
00241 
00242     return 0;
00243 }
00244 
00245 /* Auxiliary function: sorgbr scalar parameters initialization */
00246 static void init_scalars_sorgbr( char *vect, lapack_int *m, lapack_int *n,
00247                                  lapack_int *k, lapack_int *lda,
00248                                  lapack_int *lwork )
00249 {
00250     *vect = 'Q';
00251     *m = 4;
00252     *n = 4;
00253     *k = 6;
00254     *lda = 8;
00255     *lwork = 1024;
00256 
00257     return;
00258 }
00259 
00260 /* Auxiliary functions: sorgbr array parameters initialization */
00261 static void init_a( lapack_int size, float *a ) {
00262     lapack_int i;
00263     for( i = 0; i < size; i++ ) {
00264         a[i] = 0;
00265     }
00266     a[0] = 7.629240036e+000;  /* a[0,0] */
00267     a[8] = 2.793948948e-001;  /* a[0,1] */
00268     a[16] = 4.690052271e-001;  /* a[0,2] */
00269     a[24] = 7.691755891e-001;  /* a[0,3] */
00270     a[1] = -1.485074878e+000;  /* a[1,0] */
00271     a[9] = -6.241923332e+000;  /* a[1,1] */
00272     a[17] = -1.694165729e-002;  /* a[1,2] */
00273     a[25] = -3.829033673e-002;  /* a[1,3] */
00274     a[2] = 6.361265481e-002;  /* a[2,0] */
00275     a[10] = 6.107655168e-001;  /* a[2,1] */
00276     a[18] = 5.780192375e+000;  /* a[2,2] */
00277     a[26] = 8.222252131e-002;  /* a[2,3] */
00278     a[3] = 9.195886254e-001;  /* a[3,0] */
00279     a[11] = -6.674073171e-003;  /* a[3,1] */
00280     a[19] = -1.900582910e+000;  /* a[3,2] */
00281     a[27] = 6.101348877e+000;  /* a[3,3] */
00282 }
00283 static void init_tau( lapack_int size, float *tau ) {
00284     lapack_int i;
00285     for( i = 0; i < size; i++ ) {
00286         tau[i] = 0;
00287     }
00288     tau[0] = 1.081262231e+000;
00289     tau[1] = 1.999910951e+000;
00290     tau[2] = 0.000000000e+000;
00291     tau[3] = 0.000000000e+000;
00292 }
00293 static void init_work( lapack_int size, float *work ) {
00294     lapack_int i;
00295     for( i = 0; i < size; i++ ) {
00296         work[i] = 0;
00297     }
00298 }
00299 
00300 /* Auxiliary function: C interface to sorgbr results check */
00301 /* Return value: 0 - test is passed, non-zero - test is failed */
00302 static int compare_sorgbr( float *a, float *a_i, lapack_int info,
00303                            lapack_int info_i, lapack_int lda, lapack_int n )
00304 {
00305     lapack_int i;
00306     int failed = 0;
00307     for( i = 0; i < lda*n; i++ ) {
00308         failed += compare_floats(a[i],a_i[i]);
00309     }
00310     failed += (info == info_i) ? 0 : 1;
00311     if( info != 0 || info_i != 0 ) {
00312         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00313     }
00314 
00315     return failed;
00316 }


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