dsterf_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 * dsterf_1 is the test program for the C interface to LAPACK
00036 * routine dsterf
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_dsterf( lapack_int *n );
00055 static void init_d( lapack_int size, double *d );
00056 static void init_e( lapack_int size, double *e );
00057 static int compare_dsterf( double *d, double *d_i, double *e, double *e_i,
00058                            lapack_int info, lapack_int info_i, lapack_int n );
00059 
00060 int main(void)
00061 {
00062     /* Local scalars */
00063     lapack_int n, n_i;
00064     lapack_int info, info_i;
00065     lapack_int i;
00066     int failed;
00067 
00068     /* Local arrays */
00069     double *d = NULL, *d_i = NULL;
00070     double *e = NULL, *e_i = NULL;
00071     double *d_save = NULL;
00072     double *e_save = NULL;
00073 
00074     /* Iniitialize the scalar parameters */
00075     init_scalars_dsterf( &n );
00076     n_i = n;
00077 
00078     /* Allocate memory for the LAPACK routine arrays */
00079     d = (double *)LAPACKE_malloc( n * sizeof(double) );
00080     e = (double *)LAPACKE_malloc( (n-1) * sizeof(double) );
00081 
00082     /* Allocate memory for the C interface function arrays */
00083     d_i = (double *)LAPACKE_malloc( n * sizeof(double) );
00084     e_i = (double *)LAPACKE_malloc( (n-1) * sizeof(double) );
00085 
00086     /* Allocate memory for the backup arrays */
00087     d_save = (double *)LAPACKE_malloc( n * sizeof(double) );
00088     e_save = (double *)LAPACKE_malloc( (n-1) * sizeof(double) );
00089 
00090     /* Allocate memory for the row-major arrays */
00091 
00092     /* Initialize input arrays */
00093     init_d( n, d );
00094     init_e( (n-1), e );
00095 
00096     /* Backup the ouptut arrays */
00097     for( i = 0; i < n; i++ ) {
00098         d_save[i] = d[i];
00099     }
00100     for( i = 0; i < (n-1); i++ ) {
00101         e_save[i] = e[i];
00102     }
00103 
00104     /* Call the LAPACK routine */
00105     dsterf_( &n, d, e, &info );
00106 
00107     /* Initialize input data, call the column-major middle-level
00108      * interface to LAPACK routine and check the results */
00109     for( i = 0; i < n; i++ ) {
00110         d_i[i] = d_save[i];
00111     }
00112     for( i = 0; i < (n-1); i++ ) {
00113         e_i[i] = e_save[i];
00114     }
00115     info_i = LAPACKE_dsterf_work( n_i, d_i, e_i );
00116 
00117     failed = compare_dsterf( d, d_i, e, e_i, info, info_i, n );
00118     if( failed == 0 ) {
00119         printf( "PASSED: column-major middle-level interface to dsterf\n" );
00120     } else {
00121         printf( "FAILED: column-major middle-level interface to dsterf\n" );
00122     }
00123 
00124     /* Initialize input data, call the column-major high-level
00125      * interface to LAPACK routine and check the results */
00126     for( i = 0; i < n; i++ ) {
00127         d_i[i] = d_save[i];
00128     }
00129     for( i = 0; i < (n-1); i++ ) {
00130         e_i[i] = e_save[i];
00131     }
00132     info_i = LAPACKE_dsterf( n_i, d_i, e_i );
00133 
00134     failed = compare_dsterf( d, d_i, e, e_i, info, info_i, n );
00135     if( failed == 0 ) {
00136         printf( "PASSED: column-major high-level interface to dsterf\n" );
00137     } else {
00138         printf( "FAILED: column-major high-level interface to dsterf\n" );
00139     }
00140 
00141     failed = compare_dsterf( d, d_i, e, e_i, info, info_i, n );
00142     if( failed == 0 ) {
00143         printf( "PASSED: row-major middle-level interface to dsterf\n" );
00144     } else {
00145         printf( "FAILED: row-major middle-level interface to dsterf\n" );
00146     }
00147 
00148     failed = compare_dsterf( d, d_i, e, e_i, info, info_i, n );
00149     if( failed == 0 ) {
00150         printf( "PASSED: row-major high-level interface to dsterf\n" );
00151     } else {
00152         printf( "FAILED: row-major high-level interface to dsterf\n" );
00153     }
00154 
00155     /* Release memory */
00156     if( d != NULL ) {
00157         LAPACKE_free( d );
00158     }
00159     if( d_i != NULL ) {
00160         LAPACKE_free( d_i );
00161     }
00162     if( d_save != NULL ) {
00163         LAPACKE_free( d_save );
00164     }
00165     if( e != NULL ) {
00166         LAPACKE_free( e );
00167     }
00168     if( e_i != NULL ) {
00169         LAPACKE_free( e_i );
00170     }
00171     if( e_save != NULL ) {
00172         LAPACKE_free( e_save );
00173     }
00174 
00175     return 0;
00176 }
00177 
00178 /* Auxiliary function: dsterf scalar parameters initialization */
00179 static void init_scalars_dsterf( lapack_int *n )
00180 {
00181     *n = 4;
00182 
00183     return;
00184 }
00185 
00186 /* Auxiliary functions: dsterf array parameters initialization */
00187 static void init_d( lapack_int size, double *d ) {
00188     lapack_int i;
00189     for( i = 0; i < size; i++ ) {
00190         d[i] = 0;
00191     }
00192     d[0] = 5.76923076923076890e-002;
00193     d[1] = -1.12281732623795280e+000;
00194     d[2] = -2.27994375116573610e-002;
00195     d[3] = -3.65163806065562310e-001;
00196 }
00197 static void init_e( lapack_int size, double *e ) {
00198     lapack_int i;
00199     for( i = 0; i < size; i++ ) {
00200         e[i] = 0;
00201     }
00202     e[0] = -6.92063721827608340e-001;
00203     e[1] = -1.37737608436229640e+000;
00204     e[2] = 3.80464130611855360e-001;
00205 }
00206 
00207 /* Auxiliary function: C interface to dsterf results check */
00208 /* Return value: 0 - test is passed, non-zero - test is failed */
00209 static int compare_dsterf( double *d, double *d_i, double *e, double *e_i,
00210                            lapack_int info, lapack_int info_i, lapack_int n )
00211 {
00212     lapack_int i;
00213     int failed = 0;
00214     for( i = 0; i < n; i++ ) {
00215         failed += compare_doubles(d[i],d_i[i]);
00216     }
00217     for( i = 0; i < (n-1); i++ ) {
00218         failed += compare_doubles(e[i],e_i[i]);
00219     }
00220     failed += (info == info_i) ? 0 : 1;
00221     if( info != 0 || info_i != 0 ) {
00222         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00223     }
00224 
00225     return failed;
00226 }


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