dgetrf_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 * dgetrf_1 is the test program for the C interface to LAPACK
00036 * routine dgetrf
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_dgetrf( lapack_int *m, lapack_int *n,
00055                                  lapack_int *lda );
00056 static void init_a( lapack_int size, double *a );
00057 static void init_ipiv( lapack_int size, lapack_int *ipiv );
00058 static int compare_dgetrf( double *a, double *a_i, lapack_int *ipiv,
00059                            lapack_int *ipiv_i, lapack_int info,
00060                            lapack_int info_i, lapack_int lda, lapack_int m,
00061                            lapack_int n );
00062 
00063 int main(void)
00064 {
00065     /* Local scalars */
00066     lapack_int m, m_i;
00067     lapack_int n, n_i;
00068     lapack_int lda, lda_i;
00069     lapack_int lda_r;
00070     lapack_int info, info_i;
00071     lapack_int i;
00072     int failed;
00073 
00074     /* Local arrays */
00075     double *a = NULL, *a_i = NULL;
00076     lapack_int *ipiv = NULL, *ipiv_i = NULL;
00077     double *a_save = NULL;
00078     lapack_int *ipiv_save = NULL;
00079     double *a_r = NULL;
00080 
00081     /* Iniitialize the scalar parameters */
00082     init_scalars_dgetrf( &m, &n, &lda );
00083     lda_r = n+2;
00084     m_i = m;
00085     n_i = n;
00086     lda_i = lda;
00087 
00088     /* Allocate memory for the LAPACK routine arrays */
00089     a = (double *)LAPACKE_malloc( lda*n * sizeof(double) );
00090     ipiv = (lapack_int *)LAPACKE_malloc( MIN(m,n) * sizeof(lapack_int) );
00091 
00092     /* Allocate memory for the C interface function arrays */
00093     a_i = (double *)LAPACKE_malloc( lda*n * sizeof(double) );
00094     ipiv_i = (lapack_int *)LAPACKE_malloc( MIN(m,n) * sizeof(lapack_int) );
00095 
00096     /* Allocate memory for the backup arrays */
00097     a_save = (double *)LAPACKE_malloc( lda*n * sizeof(double) );
00098     ipiv_save = (lapack_int *)LAPACKE_malloc( MIN(m,n) * sizeof(lapack_int) );
00099 
00100     /* Allocate memory for the row-major arrays */
00101     a_r = (double *)LAPACKE_malloc( m*(n+2) * sizeof(double) );
00102 
00103     /* Initialize input arrays */
00104     init_a( lda*n, a );
00105     init_ipiv( (MIN(m,n)), ipiv );
00106 
00107     /* Backup the ouptut arrays */
00108     for( i = 0; i < lda*n; i++ ) {
00109         a_save[i] = a[i];
00110     }
00111     for( i = 0; i < (MIN(m,n)); i++ ) {
00112         ipiv_save[i] = ipiv[i];
00113     }
00114 
00115     /* Call the LAPACK routine */
00116     dgetrf_( &m, &n, a, &lda, ipiv, &info );
00117 
00118     /* Initialize input data, call the column-major middle-level
00119      * interface to LAPACK routine and check the results */
00120     for( i = 0; i < lda*n; i++ ) {
00121         a_i[i] = a_save[i];
00122     }
00123     for( i = 0; i < (MIN(m,n)); i++ ) {
00124         ipiv_i[i] = ipiv_save[i];
00125     }
00126     info_i = LAPACKE_dgetrf_work( LAPACK_COL_MAJOR, m_i, n_i, a_i, lda_i,
00127                                   ipiv_i );
00128 
00129     failed = compare_dgetrf( a, a_i, ipiv, ipiv_i, info, info_i, lda, m, n );
00130     if( failed == 0 ) {
00131         printf( "PASSED: column-major middle-level interface to dgetrf\n" );
00132     } else {
00133         printf( "FAILED: column-major middle-level interface to dgetrf\n" );
00134     }
00135 
00136     /* Initialize input data, call the column-major high-level
00137      * interface to LAPACK routine and check the results */
00138     for( i = 0; i < lda*n; i++ ) {
00139         a_i[i] = a_save[i];
00140     }
00141     for( i = 0; i < (MIN(m,n)); i++ ) {
00142         ipiv_i[i] = ipiv_save[i];
00143     }
00144     info_i = LAPACKE_dgetrf( LAPACK_COL_MAJOR, m_i, n_i, a_i, lda_i, ipiv_i );
00145 
00146     failed = compare_dgetrf( a, a_i, ipiv, ipiv_i, info, info_i, lda, m, n );
00147     if( failed == 0 ) {
00148         printf( "PASSED: column-major high-level interface to dgetrf\n" );
00149     } else {
00150         printf( "FAILED: column-major high-level interface to dgetrf\n" );
00151     }
00152 
00153     /* Initialize input data, call the row-major middle-level
00154      * interface to LAPACK routine and check the results */
00155     for( i = 0; i < lda*n; i++ ) {
00156         a_i[i] = a_save[i];
00157     }
00158     for( i = 0; i < (MIN(m,n)); i++ ) {
00159         ipiv_i[i] = ipiv_save[i];
00160     }
00161 
00162     LAPACKE_dge_trans( LAPACK_COL_MAJOR, m, n, a_i, lda, a_r, n+2 );
00163     info_i = LAPACKE_dgetrf_work( LAPACK_ROW_MAJOR, m_i, n_i, a_r, lda_r,
00164                                   ipiv_i );
00165 
00166     LAPACKE_dge_trans( LAPACK_ROW_MAJOR, m, n, a_r, n+2, a_i, lda );
00167 
00168     failed = compare_dgetrf( a, a_i, ipiv, ipiv_i, info, info_i, lda, m, n );
00169     if( failed == 0 ) {
00170         printf( "PASSED: row-major middle-level interface to dgetrf\n" );
00171     } else {
00172         printf( "FAILED: row-major middle-level interface to dgetrf\n" );
00173     }
00174 
00175     /* Initialize input data, call the row-major high-level
00176      * interface to LAPACK routine and check the results */
00177     for( i = 0; i < lda*n; i++ ) {
00178         a_i[i] = a_save[i];
00179     }
00180     for( i = 0; i < (MIN(m,n)); i++ ) {
00181         ipiv_i[i] = ipiv_save[i];
00182     }
00183 
00184     /* Init row_major arrays */
00185     LAPACKE_dge_trans( LAPACK_COL_MAJOR, m, n, a_i, lda, a_r, n+2 );
00186     info_i = LAPACKE_dgetrf( LAPACK_ROW_MAJOR, m_i, n_i, a_r, lda_r, ipiv_i );
00187 
00188     LAPACKE_dge_trans( LAPACK_ROW_MAJOR, m, n, a_r, n+2, a_i, lda );
00189 
00190     failed = compare_dgetrf( a, a_i, ipiv, ipiv_i, info, info_i, lda, m, n );
00191     if( failed == 0 ) {
00192         printf( "PASSED: row-major high-level interface to dgetrf\n" );
00193     } else {
00194         printf( "FAILED: row-major high-level interface to dgetrf\n" );
00195     }
00196 
00197     /* Release memory */
00198     if( a != NULL ) {
00199         LAPACKE_free( a );
00200     }
00201     if( a_i != NULL ) {
00202         LAPACKE_free( a_i );
00203     }
00204     if( a_r != NULL ) {
00205         LAPACKE_free( a_r );
00206     }
00207     if( a_save != NULL ) {
00208         LAPACKE_free( a_save );
00209     }
00210     if( ipiv != NULL ) {
00211         LAPACKE_free( ipiv );
00212     }
00213     if( ipiv_i != NULL ) {
00214         LAPACKE_free( ipiv_i );
00215     }
00216     if( ipiv_save != NULL ) {
00217         LAPACKE_free( ipiv_save );
00218     }
00219 
00220     return 0;
00221 }
00222 
00223 /* Auxiliary function: dgetrf scalar parameters initialization */
00224 static void init_scalars_dgetrf( lapack_int *m, lapack_int *n, lapack_int *lda )
00225 {
00226     *m = 4;
00227     *n = 4;
00228     *lda = 8;
00229 
00230     return;
00231 }
00232 
00233 /* Auxiliary functions: dgetrf array parameters initialization */
00234 static void init_a( lapack_int size, double *a ) {
00235     lapack_int i;
00236     for( i = 0; i < size; i++ ) {
00237         a[i] = 0;
00238     }
00239     a[0] = 1.80000000000000000e+000;  /* a[0,0] */
00240     a[8] = 2.87999999999999990e+000;  /* a[0,1] */
00241     a[16] = 2.04999999999999980e+000;  /* a[0,2] */
00242     a[24] = -8.90000000000000010e-001;  /* a[0,3] */
00243     a[1] = 5.25000000000000000e+000;  /* a[1,0] */
00244     a[9] = -2.95000000000000020e+000;  /* a[1,1] */
00245     a[17] = -9.49999999999999960e-001;  /* a[1,2] */
00246     a[25] = -3.79999999999999980e+000;  /* a[1,3] */
00247     a[2] = 1.58000000000000010e+000;  /* a[2,0] */
00248     a[10] = -2.68999999999999990e+000;  /* a[2,1] */
00249     a[18] = -2.89999999999999990e+000;  /* a[2,2] */
00250     a[26] = -1.04000000000000000e+000;  /* a[2,3] */
00251     a[3] = -1.11000000000000010e+000;  /* a[3,0] */
00252     a[11] = -6.60000000000000030e-001;  /* a[3,1] */
00253     a[19] = -5.89999999999999970e-001;  /* a[3,2] */
00254     a[27] = 8.00000000000000040e-001;  /* a[3,3] */
00255 }
00256 static void init_ipiv( lapack_int size, lapack_int *ipiv ) {
00257     lapack_int i;
00258     for( i = 0; i < size; i++ ) {
00259         ipiv[i] = 0;
00260     }
00261 }
00262 
00263 /* Auxiliary function: C interface to dgetrf results check */
00264 /* Return value: 0 - test is passed, non-zero - test is failed */
00265 static int compare_dgetrf( double *a, double *a_i, lapack_int *ipiv,
00266                            lapack_int *ipiv_i, lapack_int info,
00267                            lapack_int info_i, lapack_int lda, lapack_int m,
00268                            lapack_int n )
00269 {
00270     lapack_int i;
00271     int failed = 0;
00272     for( i = 0; i < lda*n; i++ ) {
00273         failed += compare_doubles(a[i],a_i[i]);
00274     }
00275     for( i = 0; i < (MIN(m,n)); i++ ) {
00276         failed += (ipiv[i] == ipiv_i[i]) ? 0 : 1;
00277     }
00278     failed += (info == info_i) ? 0 : 1;
00279     if( info != 0 || info_i != 0 ) {
00280         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00281     }
00282 
00283     return failed;
00284 }


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