dpotrf_6.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 * dpotrf_6 is the test program for the C interface to LAPACK
00036 * routine dpotrf
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_dpotrf( char *uplo, lapack_int *n, lapack_int *lda );
00055 static void init_a( lapack_int size, double *a );
00056 static int compare_dpotrf( double *a, double *a_i, lapack_int info,
00057                            lapack_int info_i, lapack_int lda, lapack_int n );
00058 
00059 int main(void)
00060 {
00061     /* Local scalars */
00062     char uplo, uplo_i;
00063     lapack_int n, n_i;
00064     lapack_int lda, lda_i;
00065     lapack_int lda_r;
00066     lapack_int info, info_i;
00067     lapack_int i;
00068     int failed;
00069 
00070     /* Local arrays */
00071     double *a = NULL, *a_i = NULL;
00072     double *a_save = NULL;
00073     double *a_r = NULL;
00074 
00075     /* Iniitialize the scalar parameters */
00076     init_scalars_dpotrf( &uplo, &n, &lda );
00077     lda_r = n+2;
00078     uplo_i = uplo;
00079     n_i = n;
00080     lda_i = lda;
00081 
00082     /* Allocate memory for the LAPACK routine arrays */
00083     a = (double *)LAPACKE_malloc( lda*n * sizeof(double) );
00084 
00085     /* Allocate memory for the C interface function arrays */
00086     a_i = (double *)LAPACKE_malloc( lda*n * sizeof(double) );
00087 
00088     /* Allocate memory for the backup arrays */
00089     a_save = (double *)LAPACKE_malloc( lda*n * sizeof(double) );
00090 
00091     /* Allocate memory for the row-major arrays */
00092     a_r = (double *)LAPACKE_malloc( n*(n+2) * sizeof(double) );
00093 
00094     /* Initialize input arrays */
00095     init_a( lda*n, a );
00096 
00097     /* Backup the ouptut arrays */
00098     for( i = 0; i < lda*n; i++ ) {
00099         a_save[i] = a[i];
00100     }
00101 
00102     /* Call the LAPACK routine */
00103     dpotrf_( &uplo, &n, a, &lda, &info );
00104 
00105     /* Initialize input data, call the column-major middle-level
00106      * interface to LAPACK routine and check the results */
00107     for( i = 0; i < lda*n; i++ ) {
00108         a_i[i] = a_save[i];
00109     }
00110     info_i = LAPACKE_dpotrf_work( LAPACK_COL_MAJOR, uplo_i, n_i, a_i, lda_i );
00111 
00112     failed = compare_dpotrf( a, a_i, info, info_i, lda, n );
00113     if( failed == 0 ) {
00114         printf( "PASSED: column-major middle-level interface to dpotrf\n" );
00115     } else {
00116         printf( "FAILED: column-major middle-level interface to dpotrf\n" );
00117     }
00118 
00119     /* Initialize input data, call the column-major high-level
00120      * interface to LAPACK routine and check the results */
00121     for( i = 0; i < lda*n; i++ ) {
00122         a_i[i] = a_save[i];
00123     }
00124     info_i = LAPACKE_dpotrf( LAPACK_COL_MAJOR, uplo_i, n_i, a_i, lda_i );
00125 
00126     failed = compare_dpotrf( a, a_i, info, info_i, lda, n );
00127     if( failed == 0 ) {
00128         printf( "PASSED: column-major high-level interface to dpotrf\n" );
00129     } else {
00130         printf( "FAILED: column-major high-level interface to dpotrf\n" );
00131     }
00132 
00133     /* Initialize input data, call the row-major middle-level
00134      * interface to LAPACK routine and check the results */
00135     for( i = 0; i < lda*n; i++ ) {
00136         a_i[i] = a_save[i];
00137     }
00138 
00139     LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00140     info_i = LAPACKE_dpotrf_work( LAPACK_ROW_MAJOR, uplo_i, n_i, a_r, lda_r );
00141 
00142     LAPACKE_dge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00143 
00144     failed = compare_dpotrf( a, a_i, info, info_i, lda, n );
00145     if( failed == 0 ) {
00146         printf( "PASSED: row-major middle-level interface to dpotrf\n" );
00147     } else {
00148         printf( "FAILED: row-major middle-level interface to dpotrf\n" );
00149     }
00150 
00151     /* Initialize input data, call the row-major high-level
00152      * interface to LAPACK routine and check the results */
00153     for( i = 0; i < lda*n; i++ ) {
00154         a_i[i] = a_save[i];
00155     }
00156 
00157     /* Init row_major arrays */
00158     LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00159     info_i = LAPACKE_dpotrf( LAPACK_ROW_MAJOR, uplo_i, n_i, a_r, lda_r );
00160 
00161     LAPACKE_dge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00162 
00163     failed = compare_dpotrf( a, a_i, info, info_i, lda, n );
00164     if( failed == 0 ) {
00165         printf( "PASSED: row-major high-level interface to dpotrf\n" );
00166     } else {
00167         printf( "FAILED: row-major high-level interface to dpotrf\n" );
00168     }
00169 
00170     /* Release memory */
00171     if( a != NULL ) {
00172         LAPACKE_free( a );
00173     }
00174     if( a_i != NULL ) {
00175         LAPACKE_free( a_i );
00176     }
00177     if( a_r != NULL ) {
00178         LAPACKE_free( a_r );
00179     }
00180     if( a_save != NULL ) {
00181         LAPACKE_free( a_save );
00182     }
00183 
00184     return 0;
00185 }
00186 
00187 /* Auxiliary function: dpotrf scalar parameters initialization */
00188 static void init_scalars_dpotrf( char *uplo, lapack_int *n, lapack_int *lda )
00189 {
00190     *uplo = 'L';
00191     *n = 4;
00192     *lda = 8;
00193 
00194     return;
00195 }
00196 
00197 /* Auxiliary functions: dpotrf array parameters initialization */
00198 static void init_a( lapack_int size, double *a ) {
00199     lapack_int i;
00200     for( i = 0; i < size; i++ ) {
00201         a[i] = 0;
00202     }
00203     a[0] = 4.16000000000000010e+000;  /* a[0,0] */
00204     a[8] = 0.00000000000000000e+000;  /* a[0,1] */
00205     a[16] = 0.00000000000000000e+000;  /* a[0,2] */
00206     a[24] = 0.00000000000000000e+000;  /* a[0,3] */
00207     a[1] = -3.12000000000000010e+000;  /* a[1,0] */
00208     a[9] = 5.03000000000000020e+000;  /* a[1,1] */
00209     a[17] = 0.00000000000000000e+000;  /* a[1,2] */
00210     a[25] = 0.00000000000000000e+000;  /* a[1,3] */
00211     a[2] = 5.60000000000000050e-001;  /* a[2,0] */
00212     a[10] = -8.29999999999999960e-001;  /* a[2,1] */
00213     a[18] = 7.60000000000000010e-001;  /* a[2,2] */
00214     a[26] = 0.00000000000000000e+000;  /* a[2,3] */
00215     a[3] = -1.00000000000000010e-001;  /* a[3,0] */
00216     a[11] = 1.09000000000000010e+000;  /* a[3,1] */
00217     a[19] = 3.40000000000000020e-001;  /* a[3,2] */
00218     a[27] = 1.17999999999999990e+000;  /* a[3,3] */
00219 }
00220 
00221 /* Auxiliary function: C interface to dpotrf results check */
00222 /* Return value: 0 - test is passed, non-zero - test is failed */
00223 static int compare_dpotrf( double *a, double *a_i, lapack_int info,
00224                            lapack_int info_i, lapack_int lda, lapack_int n )
00225 {
00226     lapack_int i;
00227     int failed = 0;
00228     for( i = 0; i < lda*n; i++ ) {
00229         failed += compare_doubles(a[i],a_i[i]);
00230     }
00231     failed += (info == info_i) ? 0 : 1;
00232     if( info != 0 || info_i != 0 ) {
00233         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00234     }
00235 
00236     return failed;
00237 }


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