zsytrf_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 * zsytrf_1 is the test program for the C interface to LAPACK
00036 * routine zsytrf
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_zsytrf( char *uplo, lapack_int *n, lapack_int *lda,
00055                                  lapack_int *lwork );
00056 static void init_a( lapack_int size, lapack_complex_double *a );
00057 static void init_ipiv( lapack_int size, lapack_int *ipiv );
00058 static void init_work( lapack_int size, lapack_complex_double *work );
00059 static int compare_zsytrf( lapack_complex_double *a, lapack_complex_double *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_double *a = NULL, *a_i = NULL;
00078     lapack_int *ipiv = NULL, *ipiv_i = NULL;
00079     lapack_complex_double *work = NULL, *work_i = NULL;
00080     lapack_complex_double *a_save = NULL;
00081     lapack_int *ipiv_save = NULL;
00082     lapack_complex_double *a_r = NULL;
00083 
00084     /* Iniitialize the scalar parameters */
00085     init_scalars_zsytrf( &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_double *)
00094         LAPACKE_malloc( lda*n * sizeof(lapack_complex_double) );
00095     ipiv = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00096     work = (lapack_complex_double *)
00097         LAPACKE_malloc( lwork * sizeof(lapack_complex_double) );
00098 
00099     /* Allocate memory for the C interface function arrays */
00100     a_i = (lapack_complex_double *)
00101         LAPACKE_malloc( lda*n * sizeof(lapack_complex_double) );
00102     ipiv_i = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00103     work_i = (lapack_complex_double *)
00104         LAPACKE_malloc( lwork * sizeof(lapack_complex_double) );
00105 
00106     /* Allocate memory for the backup arrays */
00107     a_save = (lapack_complex_double *)
00108         LAPACKE_malloc( lda*n * sizeof(lapack_complex_double) );
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_double *)
00113         LAPACKE_malloc( n*(n+2) * sizeof(lapack_complex_double) );
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     zsytrf_( &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_zsytrf_work( LAPACK_COL_MAJOR, uplo_i, n_i, a_i, lda_i,
00143                                   ipiv_i, work_i, lwork_i );
00144 
00145     failed = compare_zsytrf( a, a_i, ipiv, ipiv_i, info, info_i, lda, n );
00146     if( failed == 0 ) {
00147         printf( "PASSED: column-major middle-level interface to zsytrf\n" );
00148     } else {
00149         printf( "FAILED: column-major middle-level interface to zsytrf\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_zsytrf( LAPACK_COL_MAJOR, uplo_i, n_i, a_i, lda_i,
00164                              ipiv_i );
00165 
00166     failed = compare_zsytrf( a, a_i, ipiv, ipiv_i, info, info_i, lda, n );
00167     if( failed == 0 ) {
00168         printf( "PASSED: column-major high-level interface to zsytrf\n" );
00169     } else {
00170         printf( "FAILED: column-major high-level interface to zsytrf\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_zge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00186     info_i = LAPACKE_zsytrf_work( LAPACK_ROW_MAJOR, uplo_i, n_i, a_r, lda_r,
00187                                   ipiv_i, work_i, lwork_i );
00188 
00189     LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00190 
00191     failed = compare_zsytrf( a, a_i, ipiv, ipiv_i, info, info_i, lda, n );
00192     if( failed == 0 ) {
00193         printf( "PASSED: row-major middle-level interface to zsytrf\n" );
00194     } else {
00195         printf( "FAILED: row-major middle-level interface to zsytrf\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_zge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00212     info_i = LAPACKE_zsytrf( LAPACK_ROW_MAJOR, uplo_i, n_i, a_r, lda_r,
00213                              ipiv_i );
00214 
00215     LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00216 
00217     failed = compare_zsytrf( a, a_i, ipiv, ipiv_i, info, info_i, lda, n );
00218     if( failed == 0 ) {
00219         printf( "PASSED: row-major high-level interface to zsytrf\n" );
00220     } else {
00221         printf( "FAILED: row-major high-level interface to zsytrf\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: zsytrf scalar parameters initialization */
00257 static void init_scalars_zsytrf( 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: zsytrf array parameters initialization */
00269 static void init_a( lapack_int size, lapack_complex_double *a ) {
00270     lapack_int i;
00271     for( i = 0; i < size; i++ ) {
00272         a[i] = lapack_make_complex_double( 0.0, 0.0 );
00273     }
00274     a[0] = lapack_make_complex_double( -3.90000000000000010e-001,
00275                                        -7.09999999999999960e-001 );
00276     a[8] = lapack_make_complex_double( 0.00000000000000000e+000,
00277                                        0.00000000000000000e+000 );
00278     a[16] = lapack_make_complex_double( 0.00000000000000000e+000,
00279                                         0.00000000000000000e+000 );
00280     a[24] = lapack_make_complex_double( 0.00000000000000000e+000,
00281                                         0.00000000000000000e+000 );
00282     a[1] = lapack_make_complex_double( 5.13999999999999970e+000,
00283                                        -6.40000000000000010e-001 );
00284     a[9] = lapack_make_complex_double( 8.85999999999999940e+000,
00285                                        1.81000000000000010e+000 );
00286     a[17] = lapack_make_complex_double( 0.00000000000000000e+000,
00287                                         0.00000000000000000e+000 );
00288     a[25] = lapack_make_complex_double( 0.00000000000000000e+000,
00289                                         0.00000000000000000e+000 );
00290     a[2] = lapack_make_complex_double( -7.86000000000000030e+000,
00291                                        -2.96000000000000000e+000 );
00292     a[10] = lapack_make_complex_double( -3.52000000000000000e+000,
00293                                         5.79999999999999960e-001 );
00294     a[18] = lapack_make_complex_double( -2.83000000000000010e+000,
00295                                         -2.99999999999999990e-002 );
00296     a[26] = lapack_make_complex_double( 0.00000000000000000e+000,
00297                                         0.00000000000000000e+000 );
00298     a[3] = lapack_make_complex_double( 3.79999999999999980e+000,
00299                                        9.20000000000000040e-001 );
00300     a[11] = lapack_make_complex_double( 5.32000000000000030e+000,
00301                                         -1.59000000000000010e+000 );
00302     a[19] = lapack_make_complex_double( -1.54000000000000000e+000,
00303                                         -2.85999999999999990e+000 );
00304     a[27] = lapack_make_complex_double( -5.60000000000000050e-001,
00305                                         1.20000000000000000e-001 );
00306 }
00307 static void init_ipiv( lapack_int size, lapack_int *ipiv ) {
00308     lapack_int i;
00309     for( i = 0; i < size; i++ ) {
00310         ipiv[i] = 0;
00311     }
00312 }
00313 static void init_work( lapack_int size, lapack_complex_double *work ) {
00314     lapack_int i;
00315     for( i = 0; i < size; i++ ) {
00316         work[i] = lapack_make_complex_double( 0.0, 0.0 );
00317     }
00318 }
00319 
00320 /* Auxiliary function: C interface to zsytrf results check */
00321 /* Return value: 0 - test is passed, non-zero - test is failed */
00322 static int compare_zsytrf( lapack_complex_double *a, lapack_complex_double *a_i,
00323                            lapack_int *ipiv, lapack_int *ipiv_i,
00324                            lapack_int info, lapack_int info_i, lapack_int lda,
00325                            lapack_int n )
00326 {
00327     lapack_int i;
00328     int failed = 0;
00329     for( i = 0; i < lda*n; i++ ) {
00330         failed += compare_complex_doubles(a[i],a_i[i]);
00331     }
00332     for( i = 0; i < n; i++ ) {
00333         failed += (ipiv[i] == ipiv_i[i]) ? 0 : 1;
00334     }
00335     failed += (info == info_i) ? 0 : 1;
00336     if( info != 0 || info_i != 0 ) {
00337         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00338     }
00339 
00340     return failed;
00341 }


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