dsptrd_3.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 * dsptrd_3 is the test program for the C interface to LAPACK
00036 * routine dsptrd
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_dsptrd( char *uplo, lapack_int *n );
00055 static void init_ap( lapack_int size, double *ap );
00056 static void init_d( lapack_int size, double *d );
00057 static void init_e( lapack_int size, double *e );
00058 static void init_tau( lapack_int size, double *tau );
00059 static int compare_dsptrd( double *ap, double *ap_i, double *d, double *d_i,
00060                            double *e, double *e_i, double *tau, double *tau_i,
00061                            lapack_int info, lapack_int info_i, lapack_int n );
00062 
00063 int main(void)
00064 {
00065     /* Local scalars */
00066     char uplo, uplo_i;
00067     lapack_int n, n_i;
00068     lapack_int info, info_i;
00069     lapack_int i;
00070     int failed;
00071 
00072     /* Local arrays */
00073     double *ap = NULL, *ap_i = NULL;
00074     double *d = NULL, *d_i = NULL;
00075     double *e = NULL, *e_i = NULL;
00076     double *tau = NULL, *tau_i = NULL;
00077     double *ap_save = NULL;
00078     double *d_save = NULL;
00079     double *e_save = NULL;
00080     double *tau_save = NULL;
00081     double *ap_r = NULL;
00082 
00083     /* Iniitialize the scalar parameters */
00084     init_scalars_dsptrd( &uplo, &n );
00085     uplo_i = uplo;
00086     n_i = n;
00087 
00088     /* Allocate memory for the LAPACK routine arrays */
00089     ap = (double *)LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(double) );
00090     d = (double *)LAPACKE_malloc( n * sizeof(double) );
00091     e = (double *)LAPACKE_malloc( (n-1) * sizeof(double) );
00092     tau = (double *)LAPACKE_malloc( (n-1) * sizeof(double) );
00093 
00094     /* Allocate memory for the C interface function arrays */
00095     ap_i = (double *)LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(double) );
00096     d_i = (double *)LAPACKE_malloc( n * sizeof(double) );
00097     e_i = (double *)LAPACKE_malloc( (n-1) * sizeof(double) );
00098     tau_i = (double *)LAPACKE_malloc( (n-1) * sizeof(double) );
00099 
00100     /* Allocate memory for the backup arrays */
00101     ap_save = (double *)LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(double) );
00102     d_save = (double *)LAPACKE_malloc( n * sizeof(double) );
00103     e_save = (double *)LAPACKE_malloc( (n-1) * sizeof(double) );
00104     tau_save = (double *)LAPACKE_malloc( (n-1) * sizeof(double) );
00105 
00106     /* Allocate memory for the row-major arrays */
00107     ap_r = (double *)LAPACKE_malloc( n*(n+1)/2 * sizeof(double) );
00108 
00109     /* Initialize input arrays */
00110     init_ap( (n*(n+1)/2), ap );
00111     init_d( n, d );
00112     init_e( (n-1), e );
00113     init_tau( (n-1), tau );
00114 
00115     /* Backup the ouptut arrays */
00116     for( i = 0; i < (n*(n+1)/2); i++ ) {
00117         ap_save[i] = ap[i];
00118     }
00119     for( i = 0; i < n; i++ ) {
00120         d_save[i] = d[i];
00121     }
00122     for( i = 0; i < (n-1); i++ ) {
00123         e_save[i] = e[i];
00124     }
00125     for( i = 0; i < (n-1); i++ ) {
00126         tau_save[i] = tau[i];
00127     }
00128 
00129     /* Call the LAPACK routine */
00130     dsptrd_( &uplo, &n, ap, d, e, tau, &info );
00131 
00132     /* Initialize input data, call the column-major middle-level
00133      * interface to LAPACK routine and check the results */
00134     for( i = 0; i < (n*(n+1)/2); i++ ) {
00135         ap_i[i] = ap_save[i];
00136     }
00137     for( i = 0; i < n; i++ ) {
00138         d_i[i] = d_save[i];
00139     }
00140     for( i = 0; i < (n-1); i++ ) {
00141         e_i[i] = e_save[i];
00142     }
00143     for( i = 0; i < (n-1); i++ ) {
00144         tau_i[i] = tau_save[i];
00145     }
00146     info_i = LAPACKE_dsptrd_work( LAPACK_COL_MAJOR, uplo_i, n_i, ap_i, d_i, e_i,
00147                                   tau_i );
00148 
00149     failed = compare_dsptrd( ap, ap_i, d, d_i, e, e_i, tau, tau_i, info, info_i,
00150                              n );
00151     if( failed == 0 ) {
00152         printf( "PASSED: column-major middle-level interface to dsptrd\n" );
00153     } else {
00154         printf( "FAILED: column-major middle-level interface to dsptrd\n" );
00155     }
00156 
00157     /* Initialize input data, call the column-major high-level
00158      * interface to LAPACK routine and check the results */
00159     for( i = 0; i < (n*(n+1)/2); i++ ) {
00160         ap_i[i] = ap_save[i];
00161     }
00162     for( i = 0; i < n; i++ ) {
00163         d_i[i] = d_save[i];
00164     }
00165     for( i = 0; i < (n-1); i++ ) {
00166         e_i[i] = e_save[i];
00167     }
00168     for( i = 0; i < (n-1); i++ ) {
00169         tau_i[i] = tau_save[i];
00170     }
00171     info_i = LAPACKE_dsptrd( LAPACK_COL_MAJOR, uplo_i, n_i, ap_i, d_i, e_i,
00172                              tau_i );
00173 
00174     failed = compare_dsptrd( ap, ap_i, d, d_i, e, e_i, tau, tau_i, info, info_i,
00175                              n );
00176     if( failed == 0 ) {
00177         printf( "PASSED: column-major high-level interface to dsptrd\n" );
00178     } else {
00179         printf( "FAILED: column-major high-level interface to dsptrd\n" );
00180     }
00181 
00182     /* Initialize input data, call the row-major middle-level
00183      * interface to LAPACK routine and check the results */
00184     for( i = 0; i < (n*(n+1)/2); i++ ) {
00185         ap_i[i] = ap_save[i];
00186     }
00187     for( i = 0; i < n; i++ ) {
00188         d_i[i] = d_save[i];
00189     }
00190     for( i = 0; i < (n-1); i++ ) {
00191         e_i[i] = e_save[i];
00192     }
00193     for( i = 0; i < (n-1); i++ ) {
00194         tau_i[i] = tau_save[i];
00195     }
00196 
00197     LAPACKE_dpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00198     info_i = LAPACKE_dsptrd_work( LAPACK_ROW_MAJOR, uplo_i, n_i, ap_r, d_i, e_i,
00199                                   tau_i );
00200 
00201     LAPACKE_dpp_trans( LAPACK_ROW_MAJOR, uplo, n, ap_r, ap_i );
00202 
00203     failed = compare_dsptrd( ap, ap_i, d, d_i, e, e_i, tau, tau_i, info, info_i,
00204                              n );
00205     if( failed == 0 ) {
00206         printf( "PASSED: row-major middle-level interface to dsptrd\n" );
00207     } else {
00208         printf( "FAILED: row-major middle-level interface to dsptrd\n" );
00209     }
00210 
00211     /* Initialize input data, call the row-major high-level
00212      * interface to LAPACK routine and check the results */
00213     for( i = 0; i < (n*(n+1)/2); i++ ) {
00214         ap_i[i] = ap_save[i];
00215     }
00216     for( i = 0; i < n; i++ ) {
00217         d_i[i] = d_save[i];
00218     }
00219     for( i = 0; i < (n-1); i++ ) {
00220         e_i[i] = e_save[i];
00221     }
00222     for( i = 0; i < (n-1); i++ ) {
00223         tau_i[i] = tau_save[i];
00224     }
00225 
00226     /* Init row_major arrays */
00227     LAPACKE_dpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00228     info_i = LAPACKE_dsptrd( LAPACK_ROW_MAJOR, uplo_i, n_i, ap_r, d_i, e_i,
00229                              tau_i );
00230 
00231     LAPACKE_dpp_trans( LAPACK_ROW_MAJOR, uplo, n, ap_r, ap_i );
00232 
00233     failed = compare_dsptrd( ap, ap_i, d, d_i, e, e_i, tau, tau_i, info, info_i,
00234                              n );
00235     if( failed == 0 ) {
00236         printf( "PASSED: row-major high-level interface to dsptrd\n" );
00237     } else {
00238         printf( "FAILED: row-major high-level interface to dsptrd\n" );
00239     }
00240 
00241     /* Release memory */
00242     if( ap != NULL ) {
00243         LAPACKE_free( ap );
00244     }
00245     if( ap_i != NULL ) {
00246         LAPACKE_free( ap_i );
00247     }
00248     if( ap_r != NULL ) {
00249         LAPACKE_free( ap_r );
00250     }
00251     if( ap_save != NULL ) {
00252         LAPACKE_free( ap_save );
00253     }
00254     if( d != NULL ) {
00255         LAPACKE_free( d );
00256     }
00257     if( d_i != NULL ) {
00258         LAPACKE_free( d_i );
00259     }
00260     if( d_save != NULL ) {
00261         LAPACKE_free( d_save );
00262     }
00263     if( e != NULL ) {
00264         LAPACKE_free( e );
00265     }
00266     if( e_i != NULL ) {
00267         LAPACKE_free( e_i );
00268     }
00269     if( e_save != NULL ) {
00270         LAPACKE_free( e_save );
00271     }
00272     if( tau != NULL ) {
00273         LAPACKE_free( tau );
00274     }
00275     if( tau_i != NULL ) {
00276         LAPACKE_free( tau_i );
00277     }
00278     if( tau_save != NULL ) {
00279         LAPACKE_free( tau_save );
00280     }
00281 
00282     return 0;
00283 }
00284 
00285 /* Auxiliary function: dsptrd scalar parameters initialization */
00286 static void init_scalars_dsptrd( char *uplo, lapack_int *n )
00287 {
00288     *uplo = 'L';
00289     *n = 4;
00290 
00291     return;
00292 }
00293 
00294 /* Auxiliary functions: dsptrd array parameters initialization */
00295 static void init_ap( lapack_int size, double *ap ) {
00296     lapack_int i;
00297     for( i = 0; i < size; i++ ) {
00298         ap[i] = 0;
00299     }
00300     ap[0] = 5.76923076923076890e-002;
00301     ap[1] = 1.70393118107254630e-001;
00302     ap[2] = 2.94994937709884000e-001;
00303     ap[3] = -6.02408803967131700e-001;
00304     ap[4] = 2.26765799256505530e-001;
00305     ap[5] = 8.66732278893501460e-001;
00306     ap[6] = -6.15902621315513990e-001;
00307     ap[7] = -5.00011600337520040e-002;
00308     ap[8] = 3.97218700415568730e-001;
00309     ap[9] = -1.68754520903792620e+000;
00310 }
00311 static void init_d( lapack_int size, double *d ) {
00312     lapack_int i;
00313     for( i = 0; i < size; i++ ) {
00314         d[i] = 0;
00315     }
00316 }
00317 static void init_e( lapack_int size, double *e ) {
00318     lapack_int i;
00319     for( i = 0; i < size; i++ ) {
00320         e[i] = 0;
00321     }
00322 }
00323 static void init_tau( lapack_int size, double *tau ) {
00324     lapack_int i;
00325     for( i = 0; i < size; i++ ) {
00326         tau[i] = 0;
00327     }
00328 }
00329 
00330 /* Auxiliary function: C interface to dsptrd results check */
00331 /* Return value: 0 - test is passed, non-zero - test is failed */
00332 static int compare_dsptrd( double *ap, double *ap_i, double *d, double *d_i,
00333                            double *e, double *e_i, double *tau, double *tau_i,
00334                            lapack_int info, lapack_int info_i, lapack_int n )
00335 {
00336     lapack_int i;
00337     int failed = 0;
00338     for( i = 0; i < (n*(n+1)/2); i++ ) {
00339         failed += compare_doubles(ap[i],ap_i[i]);
00340     }
00341     for( i = 0; i < n; i++ ) {
00342         failed += compare_doubles(d[i],d_i[i]);
00343     }
00344     for( i = 0; i < (n-1); i++ ) {
00345         failed += compare_doubles(e[i],e_i[i]);
00346     }
00347     for( i = 0; i < (n-1); i++ ) {
00348         failed += compare_doubles(tau[i],tau_i[i]);
00349     }
00350     failed += (info == info_i) ? 0 : 1;
00351     if( info != 0 || info_i != 0 ) {
00352         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00353     }
00354 
00355     return failed;
00356 }


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