cpotrf_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 * cpotrf_1 is the test program for the C interface to LAPACK
00036 * routine cpotrf
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_cpotrf( char *uplo, lapack_int *n, lapack_int *lda );
00055 static void init_a( lapack_int size, lapack_complex_float *a );
00056 static int compare_cpotrf( lapack_complex_float *a, lapack_complex_float *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_float *a = NULL, *a_i = NULL;
00073     lapack_complex_float *a_save = NULL;
00074     lapack_complex_float *a_r = NULL;
00075 
00076     /* Iniitialize the scalar parameters */
00077     init_scalars_cpotrf( &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_float *)
00085         LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00086 
00087     /* Allocate memory for the C interface function arrays */
00088     a_i = (lapack_complex_float *)
00089         LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00090 
00091     /* Allocate memory for the backup arrays */
00092     a_save = (lapack_complex_float *)
00093         LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00094 
00095     /* Allocate memory for the row-major arrays */
00096     a_r = (lapack_complex_float *)
00097         LAPACKE_malloc( n*(n+2) * sizeof(lapack_complex_float) );
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     cpotrf_( &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_cpotrf_work( LAPACK_COL_MAJOR, uplo_i, n_i, a_i, lda_i );
00116 
00117     failed = compare_cpotrf( a, a_i, info, info_i, lda, n );
00118     if( failed == 0 ) {
00119         printf( "PASSED: column-major middle-level interface to cpotrf\n" );
00120     } else {
00121         printf( "FAILED: column-major middle-level interface to cpotrf\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_cpotrf( LAPACK_COL_MAJOR, uplo_i, n_i, a_i, lda_i );
00130 
00131     failed = compare_cpotrf( a, a_i, info, info_i, lda, n );
00132     if( failed == 0 ) {
00133         printf( "PASSED: column-major high-level interface to cpotrf\n" );
00134     } else {
00135         printf( "FAILED: column-major high-level interface to cpotrf\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_cge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00145     info_i = LAPACKE_cpotrf_work( LAPACK_ROW_MAJOR, uplo_i, n_i, a_r, lda_r );
00146 
00147     LAPACKE_cge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00148 
00149     failed = compare_cpotrf( a, a_i, info, info_i, lda, n );
00150     if( failed == 0 ) {
00151         printf( "PASSED: row-major middle-level interface to cpotrf\n" );
00152     } else {
00153         printf( "FAILED: row-major middle-level interface to cpotrf\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_cge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00164     info_i = LAPACKE_cpotrf( LAPACK_ROW_MAJOR, uplo_i, n_i, a_r, lda_r );
00165 
00166     LAPACKE_cge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00167 
00168     failed = compare_cpotrf( a, a_i, info, info_i, lda, n );
00169     if( failed == 0 ) {
00170         printf( "PASSED: row-major high-level interface to cpotrf\n" );
00171     } else {
00172         printf( "FAILED: row-major high-level interface to cpotrf\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: cpotrf scalar parameters initialization */
00193 static void init_scalars_cpotrf( 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: cpotrf array parameters initialization */
00203 static void init_a( lapack_int size, lapack_complex_float *a ) {
00204     lapack_int i;
00205     for( i = 0; i < size; i++ ) {
00206         a[i] = lapack_make_complex_float( 0.0f, 0.0f );
00207     }
00208     a[0] = lapack_make_complex_float( 3.230000019e+000, 0.000000000e+000 );
00209     a[8] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00210     a[16] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00211     a[24] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00212     a[1] = lapack_make_complex_float( 1.509999990e+000, 1.919999957e+000 );
00213     a[9] = lapack_make_complex_float( 3.579999924e+000, 0.000000000e+000 );
00214     a[17] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00215     a[25] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00216     a[2] = lapack_make_complex_float( 1.899999976e+000, -8.399999738e-001 );
00217     a[10] = lapack_make_complex_float( -2.300000042e-001, -1.110000014e+000 );
00218     a[18] = lapack_make_complex_float( 4.090000153e+000, 0.000000000e+000 );
00219     a[26] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00220     a[3] = lapack_make_complex_float( 4.199999869e-001, -2.500000000e+000 );
00221     a[11] = lapack_make_complex_float( -1.179999948e+000, -1.370000005e+000 );
00222     a[19] = lapack_make_complex_float( 2.329999924e+000, 1.400000006e-001 );
00223     a[27] = lapack_make_complex_float( 4.289999962e+000, 0.000000000e+000 );
00224 }
00225 
00226 /* Auxiliary function: C interface to cpotrf results check */
00227 /* Return value: 0 - test is passed, non-zero - test is failed */
00228 static int compare_cpotrf( lapack_complex_float *a, lapack_complex_float *a_i,
00229                            lapack_int info, lapack_int info_i, lapack_int lda,
00230                            lapack_int n )
00231 {
00232     lapack_int i;
00233     int failed = 0;
00234     for( i = 0; i < lda*n; i++ ) {
00235         failed += compare_complex_floats(a[i],a_i[i]);
00236     }
00237     failed += (info == info_i) ? 0 : 1;
00238     if( info != 0 || info_i != 0 ) {
00239         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00240     }
00241 
00242     return failed;
00243 }


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