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


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:56:43