strtrs_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 * strtrs_1 is the test program for the C interface to LAPACK
00036 * routine strtrs
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_strtrs( char *uplo, char *trans, char *diag,
00055                                  lapack_int *n, lapack_int *nrhs,
00056                                  lapack_int *lda, lapack_int *ldb );
00057 static void init_a( lapack_int size, float *a );
00058 static void init_b( lapack_int size, float *b );
00059 static int compare_strtrs( float *b, float *b_i, lapack_int info,
00060                            lapack_int info_i, lapack_int ldb, lapack_int nrhs );
00061 
00062 int main(void)
00063 {
00064     /* Local scalars */
00065     char uplo, uplo_i;
00066     char trans, trans_i;
00067     char diag, diag_i;
00068     lapack_int n, n_i;
00069     lapack_int nrhs, nrhs_i;
00070     lapack_int lda, lda_i;
00071     lapack_int lda_r;
00072     lapack_int ldb, ldb_i;
00073     lapack_int ldb_r;
00074     lapack_int info, info_i;
00075     lapack_int i;
00076     int failed;
00077 
00078     /* Local arrays */
00079     float *a = NULL, *a_i = NULL;
00080     float *b = NULL, *b_i = NULL;
00081     float *b_save = NULL;
00082     float *a_r = NULL;
00083     float *b_r = NULL;
00084 
00085     /* Iniitialize the scalar parameters */
00086     init_scalars_strtrs( &uplo, &trans, &diag, &n, &nrhs, &lda, &ldb );
00087     lda_r = n+2;
00088     ldb_r = nrhs+2;
00089     uplo_i = uplo;
00090     trans_i = trans;
00091     diag_i = diag;
00092     n_i = n;
00093     nrhs_i = nrhs;
00094     lda_i = lda;
00095     ldb_i = ldb;
00096 
00097     /* Allocate memory for the LAPACK routine arrays */
00098     a = (float *)LAPACKE_malloc( lda*n * sizeof(float) );
00099     b = (float *)LAPACKE_malloc( ldb*nrhs * sizeof(float) );
00100 
00101     /* Allocate memory for the C interface function arrays */
00102     a_i = (float *)LAPACKE_malloc( lda*n * sizeof(float) );
00103     b_i = (float *)LAPACKE_malloc( ldb*nrhs * sizeof(float) );
00104 
00105     /* Allocate memory for the backup arrays */
00106     b_save = (float *)LAPACKE_malloc( ldb*nrhs * sizeof(float) );
00107 
00108     /* Allocate memory for the row-major arrays */
00109     a_r = (float *)LAPACKE_malloc( n*(n+2) * sizeof(float) );
00110     b_r = (float *)LAPACKE_malloc( n*(nrhs+2) * sizeof(float) );
00111 
00112     /* Initialize input arrays */
00113     init_a( lda*n, a );
00114     init_b( ldb*nrhs, b );
00115 
00116     /* Backup the ouptut arrays */
00117     for( i = 0; i < ldb*nrhs; i++ ) {
00118         b_save[i] = b[i];
00119     }
00120 
00121     /* Call the LAPACK routine */
00122     strtrs_( &uplo, &trans, &diag, &n, &nrhs, a, &lda, b, &ldb, &info );
00123 
00124     /* Initialize input data, call the column-major middle-level
00125      * interface to LAPACK routine and check the results */
00126     for( i = 0; i < lda*n; i++ ) {
00127         a_i[i] = a[i];
00128     }
00129     for( i = 0; i < ldb*nrhs; i++ ) {
00130         b_i[i] = b_save[i];
00131     }
00132     info_i = LAPACKE_strtrs_work( LAPACK_COL_MAJOR, uplo_i, trans_i, diag_i,
00133                                   n_i, nrhs_i, a_i, lda_i, b_i, ldb_i );
00134 
00135     failed = compare_strtrs( b, b_i, info, info_i, ldb, nrhs );
00136     if( failed == 0 ) {
00137         printf( "PASSED: column-major middle-level interface to strtrs\n" );
00138     } else {
00139         printf( "FAILED: column-major middle-level interface to strtrs\n" );
00140     }
00141 
00142     /* Initialize input data, call the column-major high-level
00143      * interface to LAPACK routine and check the results */
00144     for( i = 0; i < lda*n; i++ ) {
00145         a_i[i] = a[i];
00146     }
00147     for( i = 0; i < ldb*nrhs; i++ ) {
00148         b_i[i] = b_save[i];
00149     }
00150     info_i = LAPACKE_strtrs( LAPACK_COL_MAJOR, uplo_i, trans_i, diag_i, n_i,
00151                              nrhs_i, a_i, lda_i, b_i, ldb_i );
00152 
00153     failed = compare_strtrs( b, b_i, info, info_i, ldb, nrhs );
00154     if( failed == 0 ) {
00155         printf( "PASSED: column-major high-level interface to strtrs\n" );
00156     } else {
00157         printf( "FAILED: column-major high-level interface to strtrs\n" );
00158     }
00159 
00160     /* Initialize input data, call the row-major middle-level
00161      * interface to LAPACK routine and check the results */
00162     for( i = 0; i < lda*n; i++ ) {
00163         a_i[i] = a[i];
00164     }
00165     for( i = 0; i < ldb*nrhs; i++ ) {
00166         b_i[i] = b_save[i];
00167     }
00168 
00169     LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00170     LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00171     info_i = LAPACKE_strtrs_work( LAPACK_ROW_MAJOR, uplo_i, trans_i, diag_i,
00172                                   n_i, nrhs_i, a_r, lda_r, b_r, ldb_r );
00173 
00174     LAPACKE_sge_trans( LAPACK_ROW_MAJOR, n, nrhs, b_r, nrhs+2, b_i, ldb );
00175 
00176     failed = compare_strtrs( b, b_i, info, info_i, ldb, nrhs );
00177     if( failed == 0 ) {
00178         printf( "PASSED: row-major middle-level interface to strtrs\n" );
00179     } else {
00180         printf( "FAILED: row-major middle-level interface to strtrs\n" );
00181     }
00182 
00183     /* Initialize input data, call the row-major high-level
00184      * interface to LAPACK routine and check the results */
00185     for( i = 0; i < lda*n; i++ ) {
00186         a_i[i] = a[i];
00187     }
00188     for( i = 0; i < ldb*nrhs; i++ ) {
00189         b_i[i] = b_save[i];
00190     }
00191 
00192     /* Init row_major arrays */
00193     LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00194     LAPACKE_sge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00195     info_i = LAPACKE_strtrs( LAPACK_ROW_MAJOR, uplo_i, trans_i, diag_i, n_i,
00196                              nrhs_i, a_r, lda_r, b_r, ldb_r );
00197 
00198     LAPACKE_sge_trans( LAPACK_ROW_MAJOR, n, nrhs, b_r, nrhs+2, b_i, ldb );
00199 
00200     failed = compare_strtrs( b, b_i, info, info_i, ldb, nrhs );
00201     if( failed == 0 ) {
00202         printf( "PASSED: row-major high-level interface to strtrs\n" );
00203     } else {
00204         printf( "FAILED: row-major high-level interface to strtrs\n" );
00205     }
00206 
00207     /* Release memory */
00208     if( a != NULL ) {
00209         LAPACKE_free( a );
00210     }
00211     if( a_i != NULL ) {
00212         LAPACKE_free( a_i );
00213     }
00214     if( a_r != NULL ) {
00215         LAPACKE_free( a_r );
00216     }
00217     if( b != NULL ) {
00218         LAPACKE_free( b );
00219     }
00220     if( b_i != NULL ) {
00221         LAPACKE_free( b_i );
00222     }
00223     if( b_r != NULL ) {
00224         LAPACKE_free( b_r );
00225     }
00226     if( b_save != NULL ) {
00227         LAPACKE_free( b_save );
00228     }
00229 
00230     return 0;
00231 }
00232 
00233 /* Auxiliary function: strtrs scalar parameters initialization */
00234 static void init_scalars_strtrs( char *uplo, char *trans, char *diag,
00235                                  lapack_int *n, lapack_int *nrhs,
00236                                  lapack_int *lda, lapack_int *ldb )
00237 {
00238     *uplo = 'L';
00239     *trans = 'N';
00240     *diag = 'N';
00241     *n = 4;
00242     *nrhs = 2;
00243     *lda = 8;
00244     *ldb = 8;
00245 
00246     return;
00247 }
00248 
00249 /* Auxiliary functions: strtrs array parameters initialization */
00250 static void init_a( lapack_int size, float *a ) {
00251     lapack_int i;
00252     for( i = 0; i < size; i++ ) {
00253         a[i] = 0;
00254     }
00255     a[0] = 4.300000191e+000;  /* a[0,0] */
00256     a[8] = 0.000000000e+000;  /* a[0,1] */
00257     a[16] = 0.000000000e+000;  /* a[0,2] */
00258     a[24] = 0.000000000e+000;  /* a[0,3] */
00259     a[1] = -3.960000038e+000;  /* a[1,0] */
00260     a[9] = -4.869999886e+000;  /* a[1,1] */
00261     a[17] = 0.000000000e+000;  /* a[1,2] */
00262     a[25] = 0.000000000e+000;  /* a[1,3] */
00263     a[2] = 4.000000060e-001;  /* a[2,0] */
00264     a[10] = 3.100000024e-001;  /* a[2,1] */
00265     a[18] = -8.020000458e+000;  /* a[2,2] */
00266     a[26] = 0.000000000e+000;  /* a[2,3] */
00267     a[3] = -2.700000107e-001;  /* a[3,0] */
00268     a[11] = 7.000000030e-002;  /* a[3,1] */
00269     a[19] = -5.949999809e+000;  /* a[3,2] */
00270     a[27] = 1.199999973e-001;  /* a[3,3] */
00271 }
00272 static void init_b( lapack_int size, float *b ) {
00273     lapack_int i;
00274     for( i = 0; i < size; i++ ) {
00275         b[i] = 0;
00276     }
00277     b[0] = -1.289999962e+001;  /* b[0,0] */
00278     b[8] = -2.150000000e+001;  /* b[0,1] */
00279     b[1] = 1.675000000e+001;  /* b[1,0] */
00280     b[9] = 1.493000031e+001;  /* b[1,1] */
00281     b[2] = -1.754999924e+001;  /* b[2,0] */
00282     b[10] = 6.329999924e+000;  /* b[2,1] */
00283     b[3] = -1.103999996e+001;  /* b[3,0] */
00284     b[11] = 8.090000153e+000;  /* b[3,1] */
00285 }
00286 
00287 /* Auxiliary function: C interface to strtrs results check */
00288 /* Return value: 0 - test is passed, non-zero - test is failed */
00289 static int compare_strtrs( float *b, float *b_i, lapack_int info,
00290                            lapack_int info_i, lapack_int ldb, lapack_int nrhs )
00291 {
00292     lapack_int i;
00293     int failed = 0;
00294     for( i = 0; i < ldb*nrhs; i++ ) {
00295         failed += compare_floats(b[i],b_i[i]);
00296     }
00297     failed += (info == info_i) ? 0 : 1;
00298     if( info != 0 || info_i != 0 ) {
00299         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00300     }
00301 
00302     return failed;
00303 }


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