csytrf_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 * csytrf_1 is the test program for the C interface to LAPACK
00036 * routine csytrf
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_csytrf( char *uplo, lapack_int *n, lapack_int *lda,
00055                                  lapack_int *lwork );
00056 static void init_a( lapack_int size, lapack_complex_float *a );
00057 static void init_ipiv( lapack_int size, lapack_int *ipiv );
00058 static void init_work( lapack_int size, lapack_complex_float *work );
00059 static int compare_csytrf( lapack_complex_float *a, lapack_complex_float *a_i,
00060                            lapack_int *ipiv, lapack_int *ipiv_i,
00061                            lapack_int info, lapack_int info_i, lapack_int lda,
00062                            lapack_int n );
00063 
00064 int main(void)
00065 {
00066     /* Local scalars */
00067     char uplo, uplo_i;
00068     lapack_int n, n_i;
00069     lapack_int lda, lda_i;
00070     lapack_int lda_r;
00071     lapack_int lwork, lwork_i;
00072     lapack_int info, info_i;
00073     lapack_int i;
00074     int failed;
00075 
00076     /* Local arrays */
00077     lapack_complex_float *a = NULL, *a_i = NULL;
00078     lapack_int *ipiv = NULL, *ipiv_i = NULL;
00079     lapack_complex_float *work = NULL, *work_i = NULL;
00080     lapack_complex_float *a_save = NULL;
00081     lapack_int *ipiv_save = NULL;
00082     lapack_complex_float *a_r = NULL;
00083 
00084     /* Iniitialize the scalar parameters */
00085     init_scalars_csytrf( &uplo, &n, &lda, &lwork );
00086     lda_r = n+2;
00087     uplo_i = uplo;
00088     n_i = n;
00089     lda_i = lda;
00090     lwork_i = lwork;
00091 
00092     /* Allocate memory for the LAPACK routine arrays */
00093     a = (lapack_complex_float *)
00094         LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00095     ipiv = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00096     work = (lapack_complex_float *)
00097         LAPACKE_malloc( lwork * sizeof(lapack_complex_float) );
00098 
00099     /* Allocate memory for the C interface function arrays */
00100     a_i = (lapack_complex_float *)
00101         LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00102     ipiv_i = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00103     work_i = (lapack_complex_float *)
00104         LAPACKE_malloc( lwork * sizeof(lapack_complex_float) );
00105 
00106     /* Allocate memory for the backup arrays */
00107     a_save = (lapack_complex_float *)
00108         LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00109     ipiv_save = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00110 
00111     /* Allocate memory for the row-major arrays */
00112     a_r = (lapack_complex_float *)
00113         LAPACKE_malloc( n*(n+2) * sizeof(lapack_complex_float) );
00114 
00115     /* Initialize input arrays */
00116     init_a( lda*n, a );
00117     init_ipiv( n, ipiv );
00118     init_work( lwork, work );
00119 
00120     /* Backup the ouptut arrays */
00121     for( i = 0; i < lda*n; i++ ) {
00122         a_save[i] = a[i];
00123     }
00124     for( i = 0; i < n; i++ ) {
00125         ipiv_save[i] = ipiv[i];
00126     }
00127 
00128     /* Call the LAPACK routine */
00129     csytrf_( &uplo, &n, a, &lda, ipiv, work, &lwork, &info );
00130 
00131     /* Initialize input data, call the column-major middle-level
00132      * interface to LAPACK routine and check the results */
00133     for( i = 0; i < lda*n; i++ ) {
00134         a_i[i] = a_save[i];
00135     }
00136     for( i = 0; i < n; i++ ) {
00137         ipiv_i[i] = ipiv_save[i];
00138     }
00139     for( i = 0; i < lwork; i++ ) {
00140         work_i[i] = work[i];
00141     }
00142     info_i = LAPACKE_csytrf_work( LAPACK_COL_MAJOR, uplo_i, n_i, a_i, lda_i,
00143                                   ipiv_i, work_i, lwork_i );
00144 
00145     failed = compare_csytrf( a, a_i, ipiv, ipiv_i, info, info_i, lda, n );
00146     if( failed == 0 ) {
00147         printf( "PASSED: column-major middle-level interface to csytrf\n" );
00148     } else {
00149         printf( "FAILED: column-major middle-level interface to csytrf\n" );
00150     }
00151 
00152     /* Initialize input data, call the column-major high-level
00153      * interface to LAPACK routine and check the results */
00154     for( i = 0; i < lda*n; i++ ) {
00155         a_i[i] = a_save[i];
00156     }
00157     for( i = 0; i < n; i++ ) {
00158         ipiv_i[i] = ipiv_save[i];
00159     }
00160     for( i = 0; i < lwork; i++ ) {
00161         work_i[i] = work[i];
00162     }
00163     info_i = LAPACKE_csytrf( LAPACK_COL_MAJOR, uplo_i, n_i, a_i, lda_i,
00164                              ipiv_i );
00165 
00166     failed = compare_csytrf( a, a_i, ipiv, ipiv_i, info, info_i, lda, n );
00167     if( failed == 0 ) {
00168         printf( "PASSED: column-major high-level interface to csytrf\n" );
00169     } else {
00170         printf( "FAILED: column-major high-level interface to csytrf\n" );
00171     }
00172 
00173     /* Initialize input data, call the row-major middle-level
00174      * interface to LAPACK routine and check the results */
00175     for( i = 0; i < lda*n; i++ ) {
00176         a_i[i] = a_save[i];
00177     }
00178     for( i = 0; i < n; i++ ) {
00179         ipiv_i[i] = ipiv_save[i];
00180     }
00181     for( i = 0; i < lwork; i++ ) {
00182         work_i[i] = work[i];
00183     }
00184 
00185     LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00186     info_i = LAPACKE_csytrf_work( LAPACK_ROW_MAJOR, uplo_i, n_i, a_r, lda_r,
00187                                   ipiv_i, work_i, lwork_i );
00188 
00189     LAPACKE_cge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00190 
00191     failed = compare_csytrf( a, a_i, ipiv, ipiv_i, info, info_i, lda, n );
00192     if( failed == 0 ) {
00193         printf( "PASSED: row-major middle-level interface to csytrf\n" );
00194     } else {
00195         printf( "FAILED: row-major middle-level interface to csytrf\n" );
00196     }
00197 
00198     /* Initialize input data, call the row-major high-level
00199      * interface to LAPACK routine and check the results */
00200     for( i = 0; i < lda*n; i++ ) {
00201         a_i[i] = a_save[i];
00202     }
00203     for( i = 0; i < n; i++ ) {
00204         ipiv_i[i] = ipiv_save[i];
00205     }
00206     for( i = 0; i < lwork; i++ ) {
00207         work_i[i] = work[i];
00208     }
00209 
00210     /* Init row_major arrays */
00211     LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00212     info_i = LAPACKE_csytrf( LAPACK_ROW_MAJOR, uplo_i, n_i, a_r, lda_r,
00213                              ipiv_i );
00214 
00215     LAPACKE_cge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00216 
00217     failed = compare_csytrf( a, a_i, ipiv, ipiv_i, info, info_i, lda, n );
00218     if( failed == 0 ) {
00219         printf( "PASSED: row-major high-level interface to csytrf\n" );
00220     } else {
00221         printf( "FAILED: row-major high-level interface to csytrf\n" );
00222     }
00223 
00224     /* Release memory */
00225     if( a != NULL ) {
00226         LAPACKE_free( a );
00227     }
00228     if( a_i != NULL ) {
00229         LAPACKE_free( a_i );
00230     }
00231     if( a_r != NULL ) {
00232         LAPACKE_free( a_r );
00233     }
00234     if( a_save != NULL ) {
00235         LAPACKE_free( a_save );
00236     }
00237     if( ipiv != NULL ) {
00238         LAPACKE_free( ipiv );
00239     }
00240     if( ipiv_i != NULL ) {
00241         LAPACKE_free( ipiv_i );
00242     }
00243     if( ipiv_save != NULL ) {
00244         LAPACKE_free( ipiv_save );
00245     }
00246     if( work != NULL ) {
00247         LAPACKE_free( work );
00248     }
00249     if( work_i != NULL ) {
00250         LAPACKE_free( work_i );
00251     }
00252 
00253     return 0;
00254 }
00255 
00256 /* Auxiliary function: csytrf scalar parameters initialization */
00257 static void init_scalars_csytrf( char *uplo, lapack_int *n, lapack_int *lda,
00258                                  lapack_int *lwork )
00259 {
00260     *uplo = 'L';
00261     *n = 4;
00262     *lda = 8;
00263     *lwork = 512;
00264 
00265     return;
00266 }
00267 
00268 /* Auxiliary functions: csytrf array parameters initialization */
00269 static void init_a( lapack_int size, lapack_complex_float *a ) {
00270     lapack_int i;
00271     for( i = 0; i < size; i++ ) {
00272         a[i] = lapack_make_complex_float( 0.0f, 0.0f );
00273     }
00274     a[0] = lapack_make_complex_float( -3.899999857e-001, -7.099999785e-001 );
00275     a[8] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00276     a[16] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00277     a[24] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00278     a[1] = lapack_make_complex_float( 5.139999866e+000, -6.399999857e-001 );
00279     a[9] = lapack_make_complex_float( 8.859999657e+000, 1.809999943e+000 );
00280     a[17] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00281     a[25] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00282     a[2] = lapack_make_complex_float( -7.860000134e+000, -2.960000038e+000 );
00283     a[10] = lapack_make_complex_float( -3.519999981e+000, 5.799999833e-001 );
00284     a[18] = lapack_make_complex_float( -2.829999924e+000, -2.999999933e-002 );
00285     a[26] = lapack_make_complex_float( 0.000000000e+000, 0.000000000e+000 );
00286     a[3] = lapack_make_complex_float( 3.799999952e+000, 9.200000167e-001 );
00287     a[11] = lapack_make_complex_float( 5.320000172e+000, -1.590000033e+000 );
00288     a[19] = lapack_make_complex_float( -1.539999962e+000, -2.859999895e+000 );
00289     a[27] = lapack_make_complex_float( -5.600000024e-001, 1.199999973e-001 );
00290 }
00291 static void init_ipiv( lapack_int size, lapack_int *ipiv ) {
00292     lapack_int i;
00293     for( i = 0; i < size; i++ ) {
00294         ipiv[i] = 0;
00295     }
00296 }
00297 static void init_work( lapack_int size, lapack_complex_float *work ) {
00298     lapack_int i;
00299     for( i = 0; i < size; i++ ) {
00300         work[i] = lapack_make_complex_float( 0.0f, 0.0f );
00301     }
00302 }
00303 
00304 /* Auxiliary function: C interface to csytrf results check */
00305 /* Return value: 0 - test is passed, non-zero - test is failed */
00306 static int compare_csytrf( lapack_complex_float *a, lapack_complex_float *a_i,
00307                            lapack_int *ipiv, lapack_int *ipiv_i,
00308                            lapack_int info, lapack_int info_i, lapack_int lda,
00309                            lapack_int n )
00310 {
00311     lapack_int i;
00312     int failed = 0;
00313     for( i = 0; i < lda*n; i++ ) {
00314         failed += compare_complex_floats(a[i],a_i[i]);
00315     }
00316     for( i = 0; i < n; i++ ) {
00317         failed += (ipiv[i] == ipiv_i[i]) ? 0 : 1;
00318     }
00319     failed += (info == info_i) ? 0 : 1;
00320     if( info != 0 || info_i != 0 ) {
00321         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00322     }
00323 
00324     return failed;
00325 }


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