zsptrs_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 * zsptrs_1 is the test program for the C interface to LAPACK
00036 * routine zsptrs
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_zsptrs( 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_zsptrs( 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_zsptrs( &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     zsptrs_( &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_zsptrs_work( LAPACK_COL_MAJOR, uplo_i, n_i, nrhs_i, ap_i,
00140                                   ipiv_i, b_i, ldb_i );
00141 
00142     failed = compare_zsptrs( b, b_i, info, info_i, ldb, nrhs );
00143     if( failed == 0 ) {
00144         printf( "PASSED: column-major middle-level interface to zsptrs\n" );
00145     } else {
00146         printf( "FAILED: column-major middle-level interface to zsptrs\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_zsptrs( LAPACK_COL_MAJOR, uplo_i, n_i, nrhs_i, ap_i,
00161                              ipiv_i, b_i, ldb_i );
00162 
00163     failed = compare_zsptrs( b, b_i, info, info_i, ldb, nrhs );
00164     if( failed == 0 ) {
00165         printf( "PASSED: column-major high-level interface to zsptrs\n" );
00166     } else {
00167         printf( "FAILED: column-major high-level interface to zsptrs\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_zsptrs_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_zsptrs( b, b_i, info, info_i, ldb, nrhs );
00190     if( failed == 0 ) {
00191         printf( "PASSED: row-major middle-level interface to zsptrs\n" );
00192     } else {
00193         printf( "FAILED: row-major middle-level interface to zsptrs\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_zsptrs( 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_zsptrs( b, b_i, info, info_i, ldb, nrhs );
00217     if( failed == 0 ) {
00218         printf( "PASSED: row-major high-level interface to zsptrs\n" );
00219     } else {
00220         printf( "FAILED: row-major high-level interface to zsptrs\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: zsptrs scalar parameters initialization */
00256 static void init_scalars_zsptrs( 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: zsptrs 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( -3.90000000000000010e-001,
00274                                         -7.09999999999999960e-001 );
00275     ap[1] = lapack_make_complex_double( -7.86000000000000030e+000,
00276                                         -2.96000000000000000e+000 );
00277     ap[2] = lapack_make_complex_double( 5.27872480164079950e-001,
00278                                         -3.71466001482590570e-001 );
00279     ap[3] = lapack_make_complex_double( 4.42558238872675090e-001,
00280                                         1.93648369829740290e-001 );
00281     ap[4] = lapack_make_complex_double( -2.83000000000000010e+000,
00282                                         -2.99999999999999990e-002 );
00283     ap[5] = lapack_make_complex_double( -6.07839105668319330e-001,
00284                                         2.81079647893121950e-001 );
00285     ap[6] = lapack_make_complex_double( -4.82282297518538240e-001,
00286                                         1.49893621910528460e-002 );
00287     ap[7] = lapack_make_complex_double( 4.40790623673101310e+000,
00288                                         5.39912067679694110e+000 );
00289     ap[8] = lapack_make_complex_double( -1.07082188009268410e-001,
00290                                         -3.15678086248845520e-001 );
00291     ap[9] = lapack_make_complex_double( -2.09541488784005650e+000,
00292                                         -2.20113928144078570e+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] = -3;
00300     ipiv[1] = -3;
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( -5.56400000000000010e+001,
00310                                        4.12199999999999990e+001 );
00311     b[8] = lapack_make_complex_double( -1.90900000000000000e+001,
00312                                        -3.59699999999999990e+001 );
00313     b[1] = lapack_make_complex_double( -4.81800000000000000e+001,
00314                                        6.60000000000000000e+001 );
00315     b[9] = lapack_make_complex_double( -1.20800000000000000e+001,
00316                                        -2.70200000000000000e+001 );
00317     b[2] = lapack_make_complex_double( -4.89999999999999990e-001,
00318                                        -1.47000000000000000e+000 );
00319     b[10] = lapack_make_complex_double( 6.95000000000000020e+000,
00320                                         2.04899999999999980e+001 );
00321     b[3] = lapack_make_complex_double( -6.42999999999999970e+000,
00322                                        1.92399999999999980e+001 );
00323     b[11] = lapack_make_complex_double( -4.58999999999999990e+000,
00324                                         -3.55300000000000010e+001 );
00325 }
00326 
00327 /* Auxiliary function: C interface to zsptrs results check */
00328 /* Return value: 0 - test is passed, non-zero - test is failed */
00329 static int compare_zsptrs( 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:43