zhptrs_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 * zhptrs_1 is the test program for the C interface to LAPACK
00036 * routine zhptrs
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_zhptrs( char *uplo, lapack_int *n, lapack_int *nrhs,
00055                                  lapack_int *ldb );
00056 static void init_ap( lapack_int size, lapack_complex_double *ap );
00057 static void init_ipiv( lapack_int size, lapack_int *ipiv );
00058 static void init_b( lapack_int size, lapack_complex_double *b );
00059 static int compare_zhptrs( lapack_complex_double *b, lapack_complex_double *b_i,
00060                            lapack_int info, lapack_int info_i, lapack_int ldb,
00061                            lapack_int nrhs );
00062 
00063 int main(void)
00064 {
00065     /* Local scalars */
00066     char uplo, uplo_i;
00067     lapack_int n, n_i;
00068     lapack_int nrhs, nrhs_i;
00069     lapack_int ldb, ldb_i;
00070     lapack_int ldb_r;
00071     lapack_int info, info_i;
00072     lapack_int i;
00073     int failed;
00074 
00075     /* Local arrays */
00076     lapack_complex_double *ap = NULL, *ap_i = NULL;
00077     lapack_int *ipiv = NULL, *ipiv_i = NULL;
00078     lapack_complex_double *b = NULL, *b_i = NULL;
00079     lapack_complex_double *b_save = NULL;
00080     lapack_complex_double *ap_r = NULL;
00081     lapack_complex_double *b_r = NULL;
00082 
00083     /* Iniitialize the scalar parameters */
00084     init_scalars_zhptrs( &uplo, &n, &nrhs, &ldb );
00085     ldb_r = nrhs+2;
00086     uplo_i = uplo;
00087     n_i = n;
00088     nrhs_i = nrhs;
00089     ldb_i = ldb;
00090 
00091     /* Allocate memory for the LAPACK routine arrays */
00092     ap = (lapack_complex_double *)
00093         LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_double) );
00094     ipiv = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00095     b = (lapack_complex_double *)
00096         LAPACKE_malloc( ldb*nrhs * sizeof(lapack_complex_double) );
00097 
00098     /* Allocate memory for the C interface function arrays */
00099     ap_i = (lapack_complex_double *)
00100         LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_double) );
00101     ipiv_i = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00102     b_i = (lapack_complex_double *)
00103         LAPACKE_malloc( ldb*nrhs * sizeof(lapack_complex_double) );
00104 
00105     /* Allocate memory for the backup arrays */
00106     b_save = (lapack_complex_double *)
00107         LAPACKE_malloc( ldb*nrhs * sizeof(lapack_complex_double) );
00108 
00109     /* Allocate memory for the row-major arrays */
00110     ap_r = (lapack_complex_double *)
00111         LAPACKE_malloc( n*(n+1)/2 * sizeof(lapack_complex_double) );
00112     b_r = (lapack_complex_double *)
00113         LAPACKE_malloc( n*(nrhs+2) * sizeof(lapack_complex_double) );
00114 
00115     /* Initialize input arrays */
00116     init_ap( (n*(n+1)/2), ap );
00117     init_ipiv( n, ipiv );
00118     init_b( ldb*nrhs, b );
00119 
00120     /* Backup the ouptut arrays */
00121     for( i = 0; i < ldb*nrhs; i++ ) {
00122         b_save[i] = b[i];
00123     }
00124 
00125     /* Call the LAPACK routine */
00126     zhptrs_( &uplo, &n, &nrhs, ap, ipiv, b, &ldb, &info );
00127 
00128     /* Initialize input data, call the column-major middle-level
00129      * interface to LAPACK routine and check the results */
00130     for( i = 0; i < (n*(n+1)/2); i++ ) {
00131         ap_i[i] = ap[i];
00132     }
00133     for( i = 0; i < n; i++ ) {
00134         ipiv_i[i] = ipiv[i];
00135     }
00136     for( i = 0; i < ldb*nrhs; i++ ) {
00137         b_i[i] = b_save[i];
00138     }
00139     info_i = LAPACKE_zhptrs_work( LAPACK_COL_MAJOR, uplo_i, n_i, nrhs_i, ap_i,
00140                                   ipiv_i, b_i, ldb_i );
00141 
00142     failed = compare_zhptrs( b, b_i, info, info_i, ldb, nrhs );
00143     if( failed == 0 ) {
00144         printf( "PASSED: column-major middle-level interface to zhptrs\n" );
00145     } else {
00146         printf( "FAILED: column-major middle-level interface to zhptrs\n" );
00147     }
00148 
00149     /* Initialize input data, call the column-major high-level
00150      * interface to LAPACK routine and check the results */
00151     for( i = 0; i < (n*(n+1)/2); i++ ) {
00152         ap_i[i] = ap[i];
00153     }
00154     for( i = 0; i < n; i++ ) {
00155         ipiv_i[i] = ipiv[i];
00156     }
00157     for( i = 0; i < ldb*nrhs; i++ ) {
00158         b_i[i] = b_save[i];
00159     }
00160     info_i = LAPACKE_zhptrs( LAPACK_COL_MAJOR, uplo_i, n_i, nrhs_i, ap_i,
00161                              ipiv_i, b_i, ldb_i );
00162 
00163     failed = compare_zhptrs( b, b_i, info, info_i, ldb, nrhs );
00164     if( failed == 0 ) {
00165         printf( "PASSED: column-major high-level interface to zhptrs\n" );
00166     } else {
00167         printf( "FAILED: column-major high-level interface to zhptrs\n" );
00168     }
00169 
00170     /* Initialize input data, call the row-major middle-level
00171      * interface to LAPACK routine and check the results */
00172     for( i = 0; i < (n*(n+1)/2); i++ ) {
00173         ap_i[i] = ap[i];
00174     }
00175     for( i = 0; i < n; i++ ) {
00176         ipiv_i[i] = ipiv[i];
00177     }
00178     for( i = 0; i < ldb*nrhs; i++ ) {
00179         b_i[i] = b_save[i];
00180     }
00181 
00182     LAPACKE_zpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00183     LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00184     info_i = LAPACKE_zhptrs_work( LAPACK_ROW_MAJOR, uplo_i, n_i, nrhs_i, ap_r,
00185                                   ipiv_i, b_r, ldb_r );
00186 
00187     LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, nrhs, b_r, nrhs+2, b_i, ldb );
00188 
00189     failed = compare_zhptrs( b, b_i, info, info_i, ldb, nrhs );
00190     if( failed == 0 ) {
00191         printf( "PASSED: row-major middle-level interface to zhptrs\n" );
00192     } else {
00193         printf( "FAILED: row-major middle-level interface to zhptrs\n" );
00194     }
00195 
00196     /* Initialize input data, call the row-major high-level
00197      * interface to LAPACK routine and check the results */
00198     for( i = 0; i < (n*(n+1)/2); i++ ) {
00199         ap_i[i] = ap[i];
00200     }
00201     for( i = 0; i < n; i++ ) {
00202         ipiv_i[i] = ipiv[i];
00203     }
00204     for( i = 0; i < ldb*nrhs; i++ ) {
00205         b_i[i] = b_save[i];
00206     }
00207 
00208     /* Init row_major arrays */
00209     LAPACKE_zpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00210     LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00211     info_i = LAPACKE_zhptrs( LAPACK_ROW_MAJOR, uplo_i, n_i, nrhs_i, ap_r,
00212                              ipiv_i, b_r, ldb_r );
00213 
00214     LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, nrhs, b_r, nrhs+2, b_i, ldb );
00215 
00216     failed = compare_zhptrs( b, b_i, info, info_i, ldb, nrhs );
00217     if( failed == 0 ) {
00218         printf( "PASSED: row-major high-level interface to zhptrs\n" );
00219     } else {
00220         printf( "FAILED: row-major high-level interface to zhptrs\n" );
00221     }
00222 
00223     /* Release memory */
00224     if( ap != NULL ) {
00225         LAPACKE_free( ap );
00226     }
00227     if( ap_i != NULL ) {
00228         LAPACKE_free( ap_i );
00229     }
00230     if( ap_r != NULL ) {
00231         LAPACKE_free( ap_r );
00232     }
00233     if( ipiv != NULL ) {
00234         LAPACKE_free( ipiv );
00235     }
00236     if( ipiv_i != NULL ) {
00237         LAPACKE_free( ipiv_i );
00238     }
00239     if( b != NULL ) {
00240         LAPACKE_free( b );
00241     }
00242     if( b_i != NULL ) {
00243         LAPACKE_free( b_i );
00244     }
00245     if( b_r != NULL ) {
00246         LAPACKE_free( b_r );
00247     }
00248     if( b_save != NULL ) {
00249         LAPACKE_free( b_save );
00250     }
00251 
00252     return 0;
00253 }
00254 
00255 /* Auxiliary function: zhptrs scalar parameters initialization */
00256 static void init_scalars_zhptrs( char *uplo, lapack_int *n, lapack_int *nrhs,
00257                                  lapack_int *ldb )
00258 {
00259     *uplo = 'L';
00260     *n = 4;
00261     *nrhs = 2;
00262     *ldb = 8;
00263 
00264     return;
00265 }
00266 
00267 /* Auxiliary functions: zhptrs array parameters initialization */
00268 static void init_ap( lapack_int size, lapack_complex_double *ap ) {
00269     lapack_int i;
00270     for( i = 0; i < size; i++ ) {
00271         ap[i] = lapack_make_complex_double( 0.0, 0.0 );
00272     }
00273     ap[0] = lapack_make_complex_double( -1.36000000000000010e+000,
00274                                         0.00000000000000000e+000 );
00275     ap[1] = lapack_make_complex_double( 3.91000000000000010e+000,
00276                                         -1.50000000000000000e+000 );
00277     ap[2] = lapack_make_complex_double( 3.10028798127124030e-001,
00278                                         4.33302074396270180e-002 );
00279     ap[3] = lapack_make_complex_double( -1.51812020724010200e-001,
00280                                         3.74295842561370500e-001 );
00281     ap[4] = lapack_make_complex_double( -1.84000000000000010e+000,
00282                                         0.00000000000000000e+000 );
00283     ap[5] = lapack_make_complex_double( 5.63705048650877560e-001,
00284                                         2.85034950151971610e-001 );
00285     ap[6] = lapack_make_complex_double( 3.39658279960360960e-001,
00286                                         3.03145181135563540e-002 );
00287     ap[7] = lapack_make_complex_double( -5.41762438729157920e+000,
00288                                         0.00000000000000000e+000 );
00289     ap[8] = lapack_make_complex_double( 2.99724464607583510e-001,
00290                                         1.57826837278577770e-001 );
00291     ap[9] = lapack_make_complex_double( -7.10280989580184220e+000,
00292                                         0.00000000000000000e+000 );
00293 }
00294 static void init_ipiv( lapack_int size, lapack_int *ipiv ) {
00295     lapack_int i;
00296     for( i = 0; i < size; i++ ) {
00297         ipiv[i] = 0;
00298     }
00299     ipiv[0] = -4;
00300     ipiv[1] = -4;
00301     ipiv[2] = 3;
00302     ipiv[3] = 4;
00303 }
00304 static void init_b( lapack_int size, lapack_complex_double *b ) {
00305     lapack_int i;
00306     for( i = 0; i < size; i++ ) {
00307         b[i] = lapack_make_complex_double( 0.0, 0.0 );
00308     }
00309     b[0] = lapack_make_complex_double( 7.79000000000000000e+000,
00310                                        5.48000000000000040e+000 );
00311     b[8] = lapack_make_complex_double( -3.53900000000000010e+001,
00312                                        1.80100000000000020e+001 );
00313     b[1] = lapack_make_complex_double( -7.70000000000000020e-001,
00314                                        -1.60500000000000010e+001 );
00315     b[9] = lapack_make_complex_double( 4.23000000000000040e+000,
00316                                        -7.00199999999999960e+001 );
00317     b[2] = lapack_make_complex_double( -9.58000000000000010e+000,
00318                                        3.87999999999999990e+000 );
00319     b[10] = lapack_make_complex_double( -2.47899999999999990e+001,
00320                                         -8.40000000000000040e+000 );
00321     b[3] = lapack_make_complex_double( 2.98000000000000000e+000,
00322                                        -1.01800000000000000e+001 );
00323     b[11] = lapack_make_complex_double( 2.86800000000000000e+001,
00324                                         -3.98900000000000010e+001 );
00325 }
00326 
00327 /* Auxiliary function: C interface to zhptrs results check */
00328 /* Return value: 0 - test is passed, non-zero - test is failed */
00329 static int compare_zhptrs( lapack_complex_double *b, lapack_complex_double *b_i,
00330                            lapack_int info, lapack_int info_i, lapack_int ldb,
00331                            lapack_int nrhs )
00332 {
00333     lapack_int i;
00334     int failed = 0;
00335     for( i = 0; i < ldb*nrhs; i++ ) {
00336         failed += compare_complex_doubles(b[i],b_i[i]);
00337     }
00338     failed += (info == info_i) ? 0 : 1;
00339     if( info != 0 || info_i != 0 ) {
00340         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00341     }
00342 
00343     return failed;
00344 }


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