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


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