ctptrs_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 * ctptrs_1 is the test program for the C interface to LAPACK
00036 * routine ctptrs
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_ctptrs( char *uplo, char *trans, char *diag,
00055                                  lapack_int *n, lapack_int *nrhs,
00056                                  lapack_int *ldb );
00057 static void init_ap( lapack_int size, lapack_complex_float *ap );
00058 static void init_b( lapack_int size, lapack_complex_float *b );
00059 static int compare_ctptrs( lapack_complex_float *b, lapack_complex_float *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     char trans, trans_i;
00068     char diag, diag_i;
00069     lapack_int n, n_i;
00070     lapack_int nrhs, nrhs_i;
00071     lapack_int ldb, ldb_i;
00072     lapack_int ldb_r;
00073     lapack_int info, info_i;
00074     lapack_int i;
00075     int failed;
00076 
00077     /* Local arrays */
00078     lapack_complex_float *ap = NULL, *ap_i = NULL;
00079     lapack_complex_float *b = NULL, *b_i = NULL;
00080     lapack_complex_float *b_save = NULL;
00081     lapack_complex_float *ap_r = NULL;
00082     lapack_complex_float *b_r = NULL;
00083 
00084     /* Iniitialize the scalar parameters */
00085     init_scalars_ctptrs( &uplo, &trans, &diag, &n, &nrhs, &ldb );
00086     ldb_r = nrhs+2;
00087     uplo_i = uplo;
00088     trans_i = trans;
00089     diag_i = diag;
00090     n_i = n;
00091     nrhs_i = nrhs;
00092     ldb_i = ldb;
00093 
00094     /* Allocate memory for the LAPACK routine arrays */
00095     ap = (lapack_complex_float *)
00096         LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_float) );
00097     b = (lapack_complex_float *)
00098         LAPACKE_malloc( ldb*nrhs * sizeof(lapack_complex_float) );
00099 
00100     /* Allocate memory for the C interface function arrays */
00101     ap_i = (lapack_complex_float *)
00102         LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_float) );
00103     b_i = (lapack_complex_float *)
00104         LAPACKE_malloc( ldb*nrhs * sizeof(lapack_complex_float) );
00105 
00106     /* Allocate memory for the backup arrays */
00107     b_save = (lapack_complex_float *)
00108         LAPACKE_malloc( ldb*nrhs * sizeof(lapack_complex_float) );
00109 
00110     /* Allocate memory for the row-major arrays */
00111     ap_r = (lapack_complex_float *)
00112         LAPACKE_malloc( n*(n+1)/2 * sizeof(lapack_complex_float) );
00113     b_r = (lapack_complex_float *)
00114         LAPACKE_malloc( n*(nrhs+2) * sizeof(lapack_complex_float) );
00115 
00116     /* Initialize input arrays */
00117     init_ap( (n*(n+1)/2), ap );
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     ctptrs_( &uplo, &trans, &diag, &n, &nrhs, ap, 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 < ldb*nrhs; i++ ) {
00134         b_i[i] = b_save[i];
00135     }
00136     info_i = LAPACKE_ctptrs_work( LAPACK_COL_MAJOR, uplo_i, trans_i, diag_i,
00137                                   n_i, nrhs_i, ap_i, b_i, ldb_i );
00138 
00139     failed = compare_ctptrs( b, b_i, info, info_i, ldb, nrhs );
00140     if( failed == 0 ) {
00141         printf( "PASSED: column-major middle-level interface to ctptrs\n" );
00142     } else {
00143         printf( "FAILED: column-major middle-level interface to ctptrs\n" );
00144     }
00145 
00146     /* Initialize input data, call the column-major high-level
00147      * interface to LAPACK routine and check the results */
00148     for( i = 0; i < (n*(n+1)/2); i++ ) {
00149         ap_i[i] = ap[i];
00150     }
00151     for( i = 0; i < ldb*nrhs; i++ ) {
00152         b_i[i] = b_save[i];
00153     }
00154     info_i = LAPACKE_ctptrs( LAPACK_COL_MAJOR, uplo_i, trans_i, diag_i, n_i,
00155                              nrhs_i, ap_i, b_i, ldb_i );
00156 
00157     failed = compare_ctptrs( b, b_i, info, info_i, ldb, nrhs );
00158     if( failed == 0 ) {
00159         printf( "PASSED: column-major high-level interface to ctptrs\n" );
00160     } else {
00161         printf( "FAILED: column-major high-level interface to ctptrs\n" );
00162     }
00163 
00164     /* Initialize input data, call the row-major middle-level
00165      * interface to LAPACK routine and check the results */
00166     for( i = 0; i < (n*(n+1)/2); i++ ) {
00167         ap_i[i] = ap[i];
00168     }
00169     for( i = 0; i < ldb*nrhs; i++ ) {
00170         b_i[i] = b_save[i];
00171     }
00172 
00173     LAPACKE_cpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00174     LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00175     info_i = LAPACKE_ctptrs_work( LAPACK_ROW_MAJOR, uplo_i, trans_i, diag_i,
00176                                   n_i, nrhs_i, ap_r, b_r, ldb_r );
00177 
00178     LAPACKE_cge_trans( LAPACK_ROW_MAJOR, n, nrhs, b_r, nrhs+2, b_i, ldb );
00179 
00180     failed = compare_ctptrs( b, b_i, info, info_i, ldb, nrhs );
00181     if( failed == 0 ) {
00182         printf( "PASSED: row-major middle-level interface to ctptrs\n" );
00183     } else {
00184         printf( "FAILED: row-major middle-level interface to ctptrs\n" );
00185     }
00186 
00187     /* Initialize input data, call the row-major high-level
00188      * interface to LAPACK routine and check the results */
00189     for( i = 0; i < (n*(n+1)/2); i++ ) {
00190         ap_i[i] = ap[i];
00191     }
00192     for( i = 0; i < ldb*nrhs; i++ ) {
00193         b_i[i] = b_save[i];
00194     }
00195 
00196     /* Init row_major arrays */
00197     LAPACKE_cpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r );
00198     LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00199     info_i = LAPACKE_ctptrs( LAPACK_ROW_MAJOR, uplo_i, trans_i, diag_i, n_i,
00200                              nrhs_i, ap_r, b_r, ldb_r );
00201 
00202     LAPACKE_cge_trans( LAPACK_ROW_MAJOR, n, nrhs, b_r, nrhs+2, b_i, ldb );
00203 
00204     failed = compare_ctptrs( b, b_i, info, info_i, ldb, nrhs );
00205     if( failed == 0 ) {
00206         printf( "PASSED: row-major high-level interface to ctptrs\n" );
00207     } else {
00208         printf( "FAILED: row-major high-level interface to ctptrs\n" );
00209     }
00210 
00211     /* Release memory */
00212     if( ap != NULL ) {
00213         LAPACKE_free( ap );
00214     }
00215     if( ap_i != NULL ) {
00216         LAPACKE_free( ap_i );
00217     }
00218     if( ap_r != NULL ) {
00219         LAPACKE_free( ap_r );
00220     }
00221     if( b != NULL ) {
00222         LAPACKE_free( b );
00223     }
00224     if( b_i != NULL ) {
00225         LAPACKE_free( b_i );
00226     }
00227     if( b_r != NULL ) {
00228         LAPACKE_free( b_r );
00229     }
00230     if( b_save != NULL ) {
00231         LAPACKE_free( b_save );
00232     }
00233 
00234     return 0;
00235 }
00236 
00237 /* Auxiliary function: ctptrs scalar parameters initialization */
00238 static void init_scalars_ctptrs( char *uplo, char *trans, char *diag,
00239                                  lapack_int *n, lapack_int *nrhs,
00240                                  lapack_int *ldb )
00241 {
00242     *uplo = 'L';
00243     *trans = 'N';
00244     *diag = 'N';
00245     *n = 4;
00246     *nrhs = 2;
00247     *ldb = 8;
00248 
00249     return;
00250 }
00251 
00252 /* Auxiliary functions: ctptrs array parameters initialization */
00253 static void init_ap( lapack_int size, lapack_complex_float *ap ) {
00254     lapack_int i;
00255     for( i = 0; i < size; i++ ) {
00256         ap[i] = lapack_make_complex_float( 0.0f, 0.0f );
00257     }
00258     ap[0] = lapack_make_complex_float( 4.780000210e+000, 4.559999943e+000 );
00259     ap[1] = lapack_make_complex_float( 2.000000000e+000, -3.000000119e-001 );
00260     ap[2] = lapack_make_complex_float( 2.890000105e+000, -1.340000033e+000 );
00261     ap[3] = lapack_make_complex_float( -1.889999986e+000, 1.149999976e+000 );
00262     ap[4] = lapack_make_complex_float( -4.110000134e+000, 1.250000000e+000 );
00263     ap[5] = lapack_make_complex_float( 2.359999895e+000, -4.250000000e+000 );
00264     ap[6] = lapack_make_complex_float( 3.999999911e-002, -3.690000057e+000 );
00265     ap[7] = lapack_make_complex_float( 4.150000095e+000, 8.000000119e-001 );
00266     ap[8] = lapack_make_complex_float( -1.999999955e-002, 4.600000083e-001 );
00267     ap[9] = lapack_make_complex_float( 3.300000131e-001, -2.599999905e-001 );
00268 }
00269 static void init_b( lapack_int size, lapack_complex_float *b ) {
00270     lapack_int i;
00271     for( i = 0; i < size; i++ ) {
00272         b[i] = lapack_make_complex_float( 0.0f, 0.0f );
00273     }
00274     b[0] = lapack_make_complex_float( -1.477999973e+001, -3.236000061e+001 );
00275     b[8] = lapack_make_complex_float( -1.802000046e+001, 2.845999908e+001 );
00276     b[1] = lapack_make_complex_float( 2.980000019e+000, -2.140000105e+000 );
00277     b[9] = lapack_make_complex_float( 1.422000027e+001, 1.542000008e+001 );
00278     b[2] = lapack_make_complex_float( -2.095999908e+001, 1.705999947e+001 );
00279     b[10] = lapack_make_complex_float( 5.619999886e+000, 3.588999939e+001 );
00280     b[3] = lapack_make_complex_float( 9.539999962e+000, 9.909999847e+000 );
00281     b[11] = lapack_make_complex_float( -1.645999908e+001, -1.730000019e+000 );
00282 }
00283 
00284 /* Auxiliary function: C interface to ctptrs results check */
00285 /* Return value: 0 - test is passed, non-zero - test is failed */
00286 static int compare_ctptrs( lapack_complex_float *b, lapack_complex_float *b_i,
00287                            lapack_int info, lapack_int info_i, lapack_int ldb,
00288                            lapack_int nrhs )
00289 {
00290     lapack_int i;
00291     int failed = 0;
00292     for( i = 0; i < ldb*nrhs; i++ ) {
00293         failed += compare_complex_floats(b[i],b_i[i]);
00294     }
00295     failed += (info == info_i) ? 0 : 1;
00296     if( info != 0 || info_i != 0 ) {
00297         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00298     }
00299 
00300     return failed;
00301 }


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