dtrrfs_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 * dtrrfs_1 is the test program for the C interface to LAPACK
00036 * routine dtrrfs
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_dtrrfs( char *uplo, char *trans, char *diag,
00055                                  lapack_int *n, lapack_int *nrhs,
00056                                  lapack_int *lda, lapack_int *ldb,
00057                                  lapack_int *ldx );
00058 static void init_a( lapack_int size, double *a );
00059 static void init_b( lapack_int size, double *b );
00060 static void init_x( lapack_int size, double *x );
00061 static void init_ferr( lapack_int size, double *ferr );
00062 static void init_berr( lapack_int size, double *berr );
00063 static void init_work( lapack_int size, double *work );
00064 static void init_iwork( lapack_int size, lapack_int *iwork );
00065 static int compare_dtrrfs( double *ferr, double *ferr_i, double *berr,
00066                            double *berr_i, lapack_int info, lapack_int info_i,
00067                            lapack_int nrhs );
00068 
00069 int main(void)
00070 {
00071     /* Local scalars */
00072     char uplo, uplo_i;
00073     char trans, trans_i;
00074     char diag, diag_i;
00075     lapack_int n, n_i;
00076     lapack_int nrhs, nrhs_i;
00077     lapack_int lda, lda_i;
00078     lapack_int lda_r;
00079     lapack_int ldb, ldb_i;
00080     lapack_int ldb_r;
00081     lapack_int ldx, ldx_i;
00082     lapack_int ldx_r;
00083     lapack_int info, info_i;
00084     lapack_int i;
00085     int failed;
00086 
00087     /* Local arrays */
00088     double *a = NULL, *a_i = NULL;
00089     double *b = NULL, *b_i = NULL;
00090     double *x = NULL, *x_i = NULL;
00091     double *ferr = NULL, *ferr_i = NULL;
00092     double *berr = NULL, *berr_i = NULL;
00093     double *work = NULL, *work_i = NULL;
00094     lapack_int *iwork = NULL, *iwork_i = NULL;
00095     double *ferr_save = NULL;
00096     double *berr_save = NULL;
00097     double *a_r = NULL;
00098     double *b_r = NULL;
00099     double *x_r = NULL;
00100 
00101     /* Iniitialize the scalar parameters */
00102     init_scalars_dtrrfs( &uplo, &trans, &diag, &n, &nrhs, &lda, &ldb, &ldx );
00103     lda_r = n+2;
00104     ldb_r = nrhs+2;
00105     ldx_r = nrhs+2;
00106     uplo_i = uplo;
00107     trans_i = trans;
00108     diag_i = diag;
00109     n_i = n;
00110     nrhs_i = nrhs;
00111     lda_i = lda;
00112     ldb_i = ldb;
00113     ldx_i = ldx;
00114 
00115     /* Allocate memory for the LAPACK routine arrays */
00116     a = (double *)LAPACKE_malloc( lda*n * sizeof(double) );
00117     b = (double *)LAPACKE_malloc( ldb*nrhs * sizeof(double) );
00118     x = (double *)LAPACKE_malloc( ldx*nrhs * sizeof(double) );
00119     ferr = (double *)LAPACKE_malloc( nrhs * sizeof(double) );
00120     berr = (double *)LAPACKE_malloc( nrhs * sizeof(double) );
00121     work = (double *)LAPACKE_malloc( 3*n * sizeof(double) );
00122     iwork = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00123 
00124     /* Allocate memory for the C interface function arrays */
00125     a_i = (double *)LAPACKE_malloc( lda*n * sizeof(double) );
00126     b_i = (double *)LAPACKE_malloc( ldb*nrhs * sizeof(double) );
00127     x_i = (double *)LAPACKE_malloc( ldx*nrhs * sizeof(double) );
00128     ferr_i = (double *)LAPACKE_malloc( nrhs * sizeof(double) );
00129     berr_i = (double *)LAPACKE_malloc( nrhs * sizeof(double) );
00130     work_i = (double *)LAPACKE_malloc( 3*n * sizeof(double) );
00131     iwork_i = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00132 
00133     /* Allocate memory for the backup arrays */
00134     ferr_save = (double *)LAPACKE_malloc( nrhs * sizeof(double) );
00135     berr_save = (double *)LAPACKE_malloc( nrhs * sizeof(double) );
00136 
00137     /* Allocate memory for the row-major arrays */
00138     a_r = (double *)LAPACKE_malloc( n*(n+2) * sizeof(double) );
00139     b_r = (double *)LAPACKE_malloc( n*(nrhs+2) * sizeof(double) );
00140     x_r = (double *)LAPACKE_malloc( n*(nrhs+2) * sizeof(double) );
00141 
00142     /* Initialize input arrays */
00143     init_a( lda*n, a );
00144     init_b( ldb*nrhs, b );
00145     init_x( ldx*nrhs, x );
00146     init_ferr( nrhs, ferr );
00147     init_berr( nrhs, berr );
00148     init_work( 3*n, work );
00149     init_iwork( n, iwork );
00150 
00151     /* Backup the ouptut arrays */
00152     for( i = 0; i < nrhs; i++ ) {
00153         ferr_save[i] = ferr[i];
00154     }
00155     for( i = 0; i < nrhs; i++ ) {
00156         berr_save[i] = berr[i];
00157     }
00158 
00159     /* Call the LAPACK routine */
00160     dtrrfs_( &uplo, &trans, &diag, &n, &nrhs, a, &lda, b, &ldb, x, &ldx, ferr,
00161              berr, work, iwork, &info );
00162 
00163     /* Initialize input data, call the column-major middle-level
00164      * interface to LAPACK routine and check the results */
00165     for( i = 0; i < lda*n; i++ ) {
00166         a_i[i] = a[i];
00167     }
00168     for( i = 0; i < ldb*nrhs; i++ ) {
00169         b_i[i] = b[i];
00170     }
00171     for( i = 0; i < ldx*nrhs; i++ ) {
00172         x_i[i] = x[i];
00173     }
00174     for( i = 0; i < nrhs; i++ ) {
00175         ferr_i[i] = ferr_save[i];
00176     }
00177     for( i = 0; i < nrhs; i++ ) {
00178         berr_i[i] = berr_save[i];
00179     }
00180     for( i = 0; i < 3*n; i++ ) {
00181         work_i[i] = work[i];
00182     }
00183     for( i = 0; i < n; i++ ) {
00184         iwork_i[i] = iwork[i];
00185     }
00186     info_i = LAPACKE_dtrrfs_work( LAPACK_COL_MAJOR, uplo_i, trans_i, diag_i,
00187                                   n_i, nrhs_i, a_i, lda_i, b_i, ldb_i, x_i,
00188                                   ldx_i, ferr_i, berr_i, work_i, iwork_i );
00189 
00190     failed = compare_dtrrfs( ferr, ferr_i, berr, berr_i, info, info_i, nrhs );
00191     if( failed == 0 ) {
00192         printf( "PASSED: column-major middle-level interface to dtrrfs\n" );
00193     } else {
00194         printf( "FAILED: column-major middle-level interface to dtrrfs\n" );
00195     }
00196 
00197     /* Initialize input data, call the column-major high-level
00198      * interface to LAPACK routine and check the results */
00199     for( i = 0; i < lda*n; i++ ) {
00200         a_i[i] = a[i];
00201     }
00202     for( i = 0; i < ldb*nrhs; i++ ) {
00203         b_i[i] = b[i];
00204     }
00205     for( i = 0; i < ldx*nrhs; i++ ) {
00206         x_i[i] = x[i];
00207     }
00208     for( i = 0; i < nrhs; i++ ) {
00209         ferr_i[i] = ferr_save[i];
00210     }
00211     for( i = 0; i < nrhs; i++ ) {
00212         berr_i[i] = berr_save[i];
00213     }
00214     for( i = 0; i < 3*n; i++ ) {
00215         work_i[i] = work[i];
00216     }
00217     for( i = 0; i < n; i++ ) {
00218         iwork_i[i] = iwork[i];
00219     }
00220     info_i = LAPACKE_dtrrfs( LAPACK_COL_MAJOR, uplo_i, trans_i, diag_i, n_i,
00221                              nrhs_i, a_i, lda_i, b_i, ldb_i, x_i, ldx_i, ferr_i,
00222                              berr_i );
00223 
00224     failed = compare_dtrrfs( ferr, ferr_i, berr, berr_i, info, info_i, nrhs );
00225     if( failed == 0 ) {
00226         printf( "PASSED: column-major high-level interface to dtrrfs\n" );
00227     } else {
00228         printf( "FAILED: column-major high-level interface to dtrrfs\n" );
00229     }
00230 
00231     /* Initialize input data, call the row-major middle-level
00232      * interface to LAPACK routine and check the results */
00233     for( i = 0; i < lda*n; i++ ) {
00234         a_i[i] = a[i];
00235     }
00236     for( i = 0; i < ldb*nrhs; i++ ) {
00237         b_i[i] = b[i];
00238     }
00239     for( i = 0; i < ldx*nrhs; i++ ) {
00240         x_i[i] = x[i];
00241     }
00242     for( i = 0; i < nrhs; i++ ) {
00243         ferr_i[i] = ferr_save[i];
00244     }
00245     for( i = 0; i < nrhs; i++ ) {
00246         berr_i[i] = berr_save[i];
00247     }
00248     for( i = 0; i < 3*n; i++ ) {
00249         work_i[i] = work[i];
00250     }
00251     for( i = 0; i < n; i++ ) {
00252         iwork_i[i] = iwork[i];
00253     }
00254 
00255     LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00256     LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00257     LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, nrhs, x_i, ldx, x_r, nrhs+2 );
00258     info_i = LAPACKE_dtrrfs_work( LAPACK_ROW_MAJOR, uplo_i, trans_i, diag_i,
00259                                   n_i, nrhs_i, a_r, lda_r, b_r, ldb_r, x_r,
00260                                   ldx_r, ferr_i, berr_i, work_i, iwork_i );
00261 
00262     failed = compare_dtrrfs( ferr, ferr_i, berr, berr_i, info, info_i, nrhs );
00263     if( failed == 0 ) {
00264         printf( "PASSED: row-major middle-level interface to dtrrfs\n" );
00265     } else {
00266         printf( "FAILED: row-major middle-level interface to dtrrfs\n" );
00267     }
00268 
00269     /* Initialize input data, call the row-major high-level
00270      * interface to LAPACK routine and check the results */
00271     for( i = 0; i < lda*n; i++ ) {
00272         a_i[i] = a[i];
00273     }
00274     for( i = 0; i < ldb*nrhs; i++ ) {
00275         b_i[i] = b[i];
00276     }
00277     for( i = 0; i < ldx*nrhs; i++ ) {
00278         x_i[i] = x[i];
00279     }
00280     for( i = 0; i < nrhs; i++ ) {
00281         ferr_i[i] = ferr_save[i];
00282     }
00283     for( i = 0; i < nrhs; i++ ) {
00284         berr_i[i] = berr_save[i];
00285     }
00286     for( i = 0; i < 3*n; i++ ) {
00287         work_i[i] = work[i];
00288     }
00289     for( i = 0; i < n; i++ ) {
00290         iwork_i[i] = iwork[i];
00291     }
00292 
00293     /* Init row_major arrays */
00294     LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00295     LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00296     LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, nrhs, x_i, ldx, x_r, nrhs+2 );
00297     info_i = LAPACKE_dtrrfs( LAPACK_ROW_MAJOR, uplo_i, trans_i, diag_i, n_i,
00298                              nrhs_i, a_r, lda_r, b_r, ldb_r, x_r, ldx_r, ferr_i,
00299                              berr_i );
00300 
00301     failed = compare_dtrrfs( ferr, ferr_i, berr, berr_i, info, info_i, nrhs );
00302     if( failed == 0 ) {
00303         printf( "PASSED: row-major high-level interface to dtrrfs\n" );
00304     } else {
00305         printf( "FAILED: row-major high-level interface to dtrrfs\n" );
00306     }
00307 
00308     /* Release memory */
00309     if( a != NULL ) {
00310         LAPACKE_free( a );
00311     }
00312     if( a_i != NULL ) {
00313         LAPACKE_free( a_i );
00314     }
00315     if( a_r != NULL ) {
00316         LAPACKE_free( a_r );
00317     }
00318     if( b != NULL ) {
00319         LAPACKE_free( b );
00320     }
00321     if( b_i != NULL ) {
00322         LAPACKE_free( b_i );
00323     }
00324     if( b_r != NULL ) {
00325         LAPACKE_free( b_r );
00326     }
00327     if( x != NULL ) {
00328         LAPACKE_free( x );
00329     }
00330     if( x_i != NULL ) {
00331         LAPACKE_free( x_i );
00332     }
00333     if( x_r != NULL ) {
00334         LAPACKE_free( x_r );
00335     }
00336     if( ferr != NULL ) {
00337         LAPACKE_free( ferr );
00338     }
00339     if( ferr_i != NULL ) {
00340         LAPACKE_free( ferr_i );
00341     }
00342     if( ferr_save != NULL ) {
00343         LAPACKE_free( ferr_save );
00344     }
00345     if( berr != NULL ) {
00346         LAPACKE_free( berr );
00347     }
00348     if( berr_i != NULL ) {
00349         LAPACKE_free( berr_i );
00350     }
00351     if( berr_save != NULL ) {
00352         LAPACKE_free( berr_save );
00353     }
00354     if( work != NULL ) {
00355         LAPACKE_free( work );
00356     }
00357     if( work_i != NULL ) {
00358         LAPACKE_free( work_i );
00359     }
00360     if( iwork != NULL ) {
00361         LAPACKE_free( iwork );
00362     }
00363     if( iwork_i != NULL ) {
00364         LAPACKE_free( iwork_i );
00365     }
00366 
00367     return 0;
00368 }
00369 
00370 /* Auxiliary function: dtrrfs scalar parameters initialization */
00371 static void init_scalars_dtrrfs( char *uplo, char *trans, char *diag,
00372                                  lapack_int *n, lapack_int *nrhs,
00373                                  lapack_int *lda, lapack_int *ldb,
00374                                  lapack_int *ldx )
00375 {
00376     *uplo = 'L';
00377     *trans = 'N';
00378     *diag = 'N';
00379     *n = 4;
00380     *nrhs = 2;
00381     *lda = 8;
00382     *ldb = 8;
00383     *ldx = 8;
00384 
00385     return;
00386 }
00387 
00388 /* Auxiliary functions: dtrrfs array parameters initialization */
00389 static void init_a( lapack_int size, double *a ) {
00390     lapack_int i;
00391     for( i = 0; i < size; i++ ) {
00392         a[i] = 0;
00393     }
00394     a[0] = 4.29999999999999980e+000;  /* a[0,0] */
00395     a[8] = 0.00000000000000000e+000;  /* a[0,1] */
00396     a[16] = 0.00000000000000000e+000;  /* a[0,2] */
00397     a[24] = 0.00000000000000000e+000;  /* a[0,3] */
00398     a[1] = -3.96000000000000000e+000;  /* a[1,0] */
00399     a[9] = -4.87000000000000010e+000;  /* a[1,1] */
00400     a[17] = 0.00000000000000000e+000;  /* a[1,2] */
00401     a[25] = 0.00000000000000000e+000;  /* a[1,3] */
00402     a[2] = 4.00000000000000020e-001;  /* a[2,0] */
00403     a[10] = 3.10000000000000000e-001;  /* a[2,1] */
00404     a[18] = -8.01999999999999960e+000;  /* a[2,2] */
00405     a[26] = 0.00000000000000000e+000;  /* a[2,3] */
00406     a[3] = -2.70000000000000020e-001;  /* a[3,0] */
00407     a[11] = 7.00000000000000070e-002;  /* a[3,1] */
00408     a[19] = -5.95000000000000020e+000;  /* a[3,2] */
00409     a[27] = 1.20000000000000000e-001;  /* a[3,3] */
00410 }
00411 static void init_b( lapack_int size, double *b ) {
00412     lapack_int i;
00413     for( i = 0; i < size; i++ ) {
00414         b[i] = 0;
00415     }
00416     b[0] = -1.29000000000000000e+001;  /* b[0,0] */
00417     b[8] = -2.15000000000000000e+001;  /* b[0,1] */
00418     b[1] = 1.67500000000000000e+001;  /* b[1,0] */
00419     b[9] = 1.49300000000000000e+001;  /* b[1,1] */
00420     b[2] = -1.75500000000000010e+001;  /* b[2,0] */
00421     b[10] = 6.33000000000000010e+000;  /* b[2,1] */
00422     b[3] = -1.10399999999999990e+001;  /* b[3,0] */
00423     b[11] = 8.08999999999999990e+000;  /* b[3,1] */
00424 }
00425 static void init_x( lapack_int size, double *x ) {
00426     lapack_int i;
00427     for( i = 0; i < size; i++ ) {
00428         x[i] = 0;
00429     }
00430     x[0] = -3.00000000000000000e+000;  /* x[0,0] */
00431     x[8] = -5.00000000000000000e+000;  /* x[0,1] */
00432     x[1] = -1.00000000000000020e+000;  /* x[1,0] */
00433     x[9] = 1.00000000000000020e+000;  /* x[1,1] */
00434     x[2] = 2.00000000000000040e+000;  /* x[2,0] */
00435     x[10] = -1.00000000000000000e+000;  /* x[2,1] */
00436     x[3] = 1.00000000000002310e+000;  /* x[3,0] */
00437     x[11] = 5.99999999999999820e+000;  /* x[3,1] */
00438 }
00439 static void init_ferr( lapack_int size, double *ferr ) {
00440     lapack_int i;
00441     for( i = 0; i < size; i++ ) {
00442         ferr[i] = 0;
00443     }
00444 }
00445 static void init_berr( lapack_int size, double *berr ) {
00446     lapack_int i;
00447     for( i = 0; i < size; i++ ) {
00448         berr[i] = 0;
00449     }
00450 }
00451 static void init_work( lapack_int size, double *work ) {
00452     lapack_int i;
00453     for( i = 0; i < size; i++ ) {
00454         work[i] = 0;
00455     }
00456 }
00457 static void init_iwork( lapack_int size, lapack_int *iwork ) {
00458     lapack_int i;
00459     for( i = 0; i < size; i++ ) {
00460         iwork[i] = 0;
00461     }
00462 }
00463 
00464 /* Auxiliary function: C interface to dtrrfs results check */
00465 /* Return value: 0 - test is passed, non-zero - test is failed */
00466 static int compare_dtrrfs( double *ferr, double *ferr_i, double *berr,
00467                            double *berr_i, lapack_int info, lapack_int info_i,
00468                            lapack_int nrhs )
00469 {
00470     lapack_int i;
00471     int failed = 0;
00472     for( i = 0; i < nrhs; i++ ) {
00473         failed += compare_doubles(ferr[i],ferr_i[i]);
00474     }
00475     for( i = 0; i < nrhs; i++ ) {
00476         failed += compare_doubles(berr[i],berr_i[i]);
00477     }
00478     failed += (info == info_i) ? 0 : 1;
00479     if( info != 0 || info_i != 0 ) {
00480         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00481     }
00482 
00483     return failed;
00484 }


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