cgetrs_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 * cgetrs_1 is the test program for the C interface to LAPACK
00036 * routine cgetrs
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_cgetrs( char *trans, lapack_int *n, lapack_int *nrhs,
00055                                  lapack_int *lda, lapack_int *ldb );
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_b( lapack_int size, lapack_complex_float *b );
00059 static int compare_cgetrs( 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 trans, trans_i;
00067     lapack_int n, n_i;
00068     lapack_int nrhs, nrhs_i;
00069     lapack_int lda, lda_i;
00070     lapack_int lda_r;
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 *a = NULL, *a_i = NULL;
00079     lapack_int *ipiv = NULL, *ipiv_i = NULL;
00080     lapack_complex_float *b = NULL, *b_i = NULL;
00081     lapack_complex_float *b_save = NULL;
00082     lapack_complex_float *a_r = NULL;
00083     lapack_complex_float *b_r = NULL;
00084 
00085     /* Iniitialize the scalar parameters */
00086     init_scalars_cgetrs( &trans, &n, &nrhs, &lda, &ldb );
00087     lda_r = n+2;
00088     ldb_r = nrhs+2;
00089     trans_i = trans;
00090     n_i = n;
00091     nrhs_i = nrhs;
00092     lda_i = lda;
00093     ldb_i = ldb;
00094 
00095     /* Allocate memory for the LAPACK routine arrays */
00096     a = (lapack_complex_float *)
00097         LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00098     ipiv = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00099     b = (lapack_complex_float *)
00100         LAPACKE_malloc( ldb*nrhs * sizeof(lapack_complex_float) );
00101 
00102     /* Allocate memory for the C interface function arrays */
00103     a_i = (lapack_complex_float *)
00104         LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00105     ipiv_i = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00106     b_i = (lapack_complex_float *)
00107         LAPACKE_malloc( ldb*nrhs * sizeof(lapack_complex_float) );
00108 
00109     /* Allocate memory for the backup arrays */
00110     b_save = (lapack_complex_float *)
00111         LAPACKE_malloc( ldb*nrhs * sizeof(lapack_complex_float) );
00112 
00113     /* Allocate memory for the row-major arrays */
00114     a_r = (lapack_complex_float *)
00115         LAPACKE_malloc( n*(n+2) * sizeof(lapack_complex_float) );
00116     b_r = (lapack_complex_float *)
00117         LAPACKE_malloc( n*(nrhs+2) * sizeof(lapack_complex_float) );
00118 
00119     /* Initialize input arrays */
00120     init_a( lda*n, a );
00121     init_ipiv( n, ipiv );
00122     init_b( ldb*nrhs, b );
00123 
00124     /* Backup the ouptut arrays */
00125     for( i = 0; i < ldb*nrhs; i++ ) {
00126         b_save[i] = b[i];
00127     }
00128 
00129     /* Call the LAPACK routine */
00130     cgetrs_( &trans, &n, &nrhs, a, &lda, ipiv, b, &ldb, &info );
00131 
00132     /* Initialize input data, call the column-major middle-level
00133      * interface to LAPACK routine and check the results */
00134     for( i = 0; i < lda*n; i++ ) {
00135         a_i[i] = a[i];
00136     }
00137     for( i = 0; i < n; i++ ) {
00138         ipiv_i[i] = ipiv[i];
00139     }
00140     for( i = 0; i < ldb*nrhs; i++ ) {
00141         b_i[i] = b_save[i];
00142     }
00143     info_i = LAPACKE_cgetrs_work( LAPACK_COL_MAJOR, trans_i, n_i, nrhs_i, a_i,
00144                                   lda_i, ipiv_i, b_i, ldb_i );
00145 
00146     failed = compare_cgetrs( b, b_i, info, info_i, ldb, nrhs );
00147     if( failed == 0 ) {
00148         printf( "PASSED: column-major middle-level interface to cgetrs\n" );
00149     } else {
00150         printf( "FAILED: column-major middle-level interface to cgetrs\n" );
00151     }
00152 
00153     /* Initialize input data, call the column-major high-level
00154      * interface to LAPACK routine and check the results */
00155     for( i = 0; i < lda*n; i++ ) {
00156         a_i[i] = a[i];
00157     }
00158     for( i = 0; i < n; i++ ) {
00159         ipiv_i[i] = ipiv[i];
00160     }
00161     for( i = 0; i < ldb*nrhs; i++ ) {
00162         b_i[i] = b_save[i];
00163     }
00164     info_i = LAPACKE_cgetrs( LAPACK_COL_MAJOR, trans_i, n_i, nrhs_i, a_i, lda_i,
00165                              ipiv_i, b_i, ldb_i );
00166 
00167     failed = compare_cgetrs( b, b_i, info, info_i, ldb, nrhs );
00168     if( failed == 0 ) {
00169         printf( "PASSED: column-major high-level interface to cgetrs\n" );
00170     } else {
00171         printf( "FAILED: column-major high-level interface to cgetrs\n" );
00172     }
00173 
00174     /* Initialize input data, call the row-major middle-level
00175      * interface to LAPACK routine and check the results */
00176     for( i = 0; i < lda*n; i++ ) {
00177         a_i[i] = a[i];
00178     }
00179     for( i = 0; i < n; i++ ) {
00180         ipiv_i[i] = ipiv[i];
00181     }
00182     for( i = 0; i < ldb*nrhs; i++ ) {
00183         b_i[i] = b_save[i];
00184     }
00185 
00186     LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00187     LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00188     info_i = LAPACKE_cgetrs_work( LAPACK_ROW_MAJOR, trans_i, n_i, nrhs_i, a_r,
00189                                   lda_r, ipiv_i, b_r, ldb_r );
00190 
00191     LAPACKE_cge_trans( LAPACK_ROW_MAJOR, n, nrhs, b_r, nrhs+2, b_i, ldb );
00192 
00193     failed = compare_cgetrs( b, b_i, info, info_i, ldb, nrhs );
00194     if( failed == 0 ) {
00195         printf( "PASSED: row-major middle-level interface to cgetrs\n" );
00196     } else {
00197         printf( "FAILED: row-major middle-level interface to cgetrs\n" );
00198     }
00199 
00200     /* Initialize input data, call the row-major high-level
00201      * interface to LAPACK routine and check the results */
00202     for( i = 0; i < lda*n; i++ ) {
00203         a_i[i] = a[i];
00204     }
00205     for( i = 0; i < n; i++ ) {
00206         ipiv_i[i] = ipiv[i];
00207     }
00208     for( i = 0; i < ldb*nrhs; i++ ) {
00209         b_i[i] = b_save[i];
00210     }
00211 
00212     /* Init row_major arrays */
00213     LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00214     LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00215     info_i = LAPACKE_cgetrs( LAPACK_ROW_MAJOR, trans_i, n_i, nrhs_i, a_r, lda_r,
00216                              ipiv_i, b_r, ldb_r );
00217 
00218     LAPACKE_cge_trans( LAPACK_ROW_MAJOR, n, nrhs, b_r, nrhs+2, b_i, ldb );
00219 
00220     failed = compare_cgetrs( b, b_i, info, info_i, ldb, nrhs );
00221     if( failed == 0 ) {
00222         printf( "PASSED: row-major high-level interface to cgetrs\n" );
00223     } else {
00224         printf( "FAILED: row-major high-level interface to cgetrs\n" );
00225     }
00226 
00227     /* Release memory */
00228     if( a != NULL ) {
00229         LAPACKE_free( a );
00230     }
00231     if( a_i != NULL ) {
00232         LAPACKE_free( a_i );
00233     }
00234     if( a_r != NULL ) {
00235         LAPACKE_free( a_r );
00236     }
00237     if( ipiv != NULL ) {
00238         LAPACKE_free( ipiv );
00239     }
00240     if( ipiv_i != NULL ) {
00241         LAPACKE_free( ipiv_i );
00242     }
00243     if( b != NULL ) {
00244         LAPACKE_free( b );
00245     }
00246     if( b_i != NULL ) {
00247         LAPACKE_free( b_i );
00248     }
00249     if( b_r != NULL ) {
00250         LAPACKE_free( b_r );
00251     }
00252     if( b_save != NULL ) {
00253         LAPACKE_free( b_save );
00254     }
00255 
00256     return 0;
00257 }
00258 
00259 /* Auxiliary function: cgetrs scalar parameters initialization */
00260 static void init_scalars_cgetrs( char *trans, lapack_int *n, lapack_int *nrhs,
00261                                  lapack_int *lda, lapack_int *ldb )
00262 {
00263     *trans = 'N';
00264     *n = 4;
00265     *nrhs = 2;
00266     *lda = 8;
00267     *ldb = 8;
00268 
00269     return;
00270 }
00271 
00272 /* Auxiliary functions: cgetrs array parameters initialization */
00273 static void init_a( lapack_int size, lapack_complex_float *a ) {
00274     lapack_int i;
00275     for( i = 0; i < size; i++ ) {
00276         a[i] = lapack_make_complex_float( 0.0f, 0.0f );
00277     }
00278     a[0] = lapack_make_complex_float( -3.289999962e+000, -2.390000105e+000 );
00279     a[8] = lapack_make_complex_float( -1.909999967e+000, 4.420000076e+000 );
00280     a[16] = lapack_make_complex_float( -1.400000006e-001, -1.350000024e+000 );
00281     a[24] = lapack_make_complex_float( 1.720000029e+000, 1.350000024e+000 );
00282     a[1] = lapack_make_complex_float( 2.376120239e-001, 2.559596300e-001 );
00283     a[9] = lapack_make_complex_float( 4.895180702e+000, -7.113622427e-001 );
00284     a[17] = lapack_make_complex_float( -4.622798264e-001, 1.696610570e+000 );
00285     a[25] = lapack_make_complex_float( 1.226852775e+000, 6.189731956e-001 );
00286     a[2] = lapack_make_complex_float( -1.019521058e-001, -7.010135055e-001 );
00287     a[10] = lapack_make_complex_float( -6.691496968e-001, 3.688699007e-001 );
00288     a[18] = lapack_make_complex_float( -5.141410828e+000, -1.129969597e+000 );
00289     a[26] = lapack_make_complex_float( 9.982581139e-001, 3.850151896e-001 );
00290     a[3] = lapack_make_complex_float( -5.358546376e-001, 2.707273066e-001 );
00291     a[11] = lapack_make_complex_float( -2.040217221e-001, 8.601181507e-001 );
00292     a[19] = lapack_make_complex_float( 8.233040571e-003, 1.210636795e-001 );
00293     a[27] = lapack_make_complex_float( 1.482392550e-001, -1.252242178e-001 );
00294 }
00295 static void init_ipiv( lapack_int size, lapack_int *ipiv ) {
00296     lapack_int i;
00297     for( i = 0; i < size; i++ ) {
00298         ipiv[i] = 0;
00299     }
00300     ipiv[0] = 3;
00301     ipiv[1] = 2;
00302     ipiv[2] = 3;
00303     ipiv[3] = 4;
00304 }
00305 static void init_b( lapack_int size, lapack_complex_float *b ) {
00306     lapack_int i;
00307     for( i = 0; i < size; i++ ) {
00308         b[i] = lapack_make_complex_float( 0.0f, 0.0f );
00309     }
00310     b[0] = lapack_make_complex_float( 2.626000023e+001, 5.177999878e+001 );
00311     b[8] = lapack_make_complex_float( 3.131999969e+001, -6.699999809e+000 );
00312     b[1] = lapack_make_complex_float( 6.429999828e+000, -8.680000305e+000 );
00313     b[9] = lapack_make_complex_float( 1.585999966e+001, -1.419999957e+000 );
00314     b[2] = lapack_make_complex_float( -5.750000000e+000, 2.530999947e+001 );
00315     b[10] = lapack_make_complex_float( -2.150000095e+000, 3.019000053e+001 );
00316     b[3] = lapack_make_complex_float( 1.159999967e+000, 2.569999933e+000 );
00317     b[11] = lapack_make_complex_float( -2.559999943e+000, 7.550000191e+000 );
00318 }
00319 
00320 /* Auxiliary function: C interface to cgetrs results check */
00321 /* Return value: 0 - test is passed, non-zero - test is failed */
00322 static int compare_cgetrs( lapack_complex_float *b, lapack_complex_float *b_i,
00323                            lapack_int info, lapack_int info_i, lapack_int ldb,
00324                            lapack_int nrhs )
00325 {
00326     lapack_int i;
00327     int failed = 0;
00328     for( i = 0; i < ldb*nrhs; i++ ) {
00329         failed += compare_complex_floats(b[i],b_i[i]);
00330     }
00331     failed += (info == info_i) ? 0 : 1;
00332     if( info != 0 || info_i != 0 ) {
00333         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00334     }
00335 
00336     return failed;
00337 }


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