cgetrf_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 * cgetrf_1 is the test program for the C interface to LAPACK
00036 * routine cgetrf
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_cgetrf( lapack_int *m, lapack_int *n,
00055                                  lapack_int *lda );
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 int compare_cgetrf( lapack_complex_float *a, lapack_complex_float *a_i,
00059                            lapack_int *ipiv, lapack_int *ipiv_i,
00060                            lapack_int info, lapack_int info_i, lapack_int lda,
00061                            lapack_int m, lapack_int n );
00062 
00063 int main(void)
00064 {
00065     /* Local scalars */
00066     lapack_int m, m_i;
00067     lapack_int n, n_i;
00068     lapack_int lda, lda_i;
00069     lapack_int lda_r;
00070     lapack_int info, info_i;
00071     lapack_int i;
00072     int failed;
00073 
00074     /* Local arrays */
00075     lapack_complex_float *a = NULL, *a_i = NULL;
00076     lapack_int *ipiv = NULL, *ipiv_i = NULL;
00077     lapack_complex_float *a_save = NULL;
00078     lapack_int *ipiv_save = NULL;
00079     lapack_complex_float *a_r = NULL;
00080 
00081     /* Iniitialize the scalar parameters */
00082     init_scalars_cgetrf( &m, &n, &lda );
00083     lda_r = n+2;
00084     m_i = m;
00085     n_i = n;
00086     lda_i = lda;
00087 
00088     /* Allocate memory for the LAPACK routine arrays */
00089     a = (lapack_complex_float *)
00090         LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00091     ipiv = (lapack_int *)LAPACKE_malloc( MIN(m,n) * sizeof(lapack_int) );
00092 
00093     /* Allocate memory for the C interface function arrays */
00094     a_i = (lapack_complex_float *)
00095         LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00096     ipiv_i = (lapack_int *)LAPACKE_malloc( MIN(m,n) * sizeof(lapack_int) );
00097 
00098     /* Allocate memory for the backup arrays */
00099     a_save = (lapack_complex_float *)
00100         LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) );
00101     ipiv_save = (lapack_int *)LAPACKE_malloc( MIN(m,n) * sizeof(lapack_int) );
00102 
00103     /* Allocate memory for the row-major arrays */
00104     a_r = (lapack_complex_float *)
00105         LAPACKE_malloc( m*(n+2) * sizeof(lapack_complex_float) );
00106 
00107     /* Initialize input arrays */
00108     init_a( lda*n, a );
00109     init_ipiv( (MIN(m,n)), ipiv );
00110 
00111     /* Backup the ouptut arrays */
00112     for( i = 0; i < lda*n; i++ ) {
00113         a_save[i] = a[i];
00114     }
00115     for( i = 0; i < (MIN(m,n)); i++ ) {
00116         ipiv_save[i] = ipiv[i];
00117     }
00118 
00119     /* Call the LAPACK routine */
00120     cgetrf_( &m, &n, a, &lda, ipiv, &info );
00121 
00122     /* Initialize input data, call the column-major middle-level
00123      * interface to LAPACK routine and check the results */
00124     for( i = 0; i < lda*n; i++ ) {
00125         a_i[i] = a_save[i];
00126     }
00127     for( i = 0; i < (MIN(m,n)); i++ ) {
00128         ipiv_i[i] = ipiv_save[i];
00129     }
00130     info_i = LAPACKE_cgetrf_work( LAPACK_COL_MAJOR, m_i, n_i, a_i, lda_i,
00131                                   ipiv_i );
00132 
00133     failed = compare_cgetrf( a, a_i, ipiv, ipiv_i, info, info_i, lda, m, n );
00134     if( failed == 0 ) {
00135         printf( "PASSED: column-major middle-level interface to cgetrf\n" );
00136     } else {
00137         printf( "FAILED: column-major middle-level interface to cgetrf\n" );
00138     }
00139 
00140     /* Initialize input data, call the column-major high-level
00141      * interface to LAPACK routine and check the results */
00142     for( i = 0; i < lda*n; i++ ) {
00143         a_i[i] = a_save[i];
00144     }
00145     for( i = 0; i < (MIN(m,n)); i++ ) {
00146         ipiv_i[i] = ipiv_save[i];
00147     }
00148     info_i = LAPACKE_cgetrf( LAPACK_COL_MAJOR, m_i, n_i, a_i, lda_i, ipiv_i );
00149 
00150     failed = compare_cgetrf( a, a_i, ipiv, ipiv_i, info, info_i, lda, m, n );
00151     if( failed == 0 ) {
00152         printf( "PASSED: column-major high-level interface to cgetrf\n" );
00153     } else {
00154         printf( "FAILED: column-major high-level interface to cgetrf\n" );
00155     }
00156 
00157     /* Initialize input data, call the row-major middle-level
00158      * interface to LAPACK routine and check the results */
00159     for( i = 0; i < lda*n; i++ ) {
00160         a_i[i] = a_save[i];
00161     }
00162     for( i = 0; i < (MIN(m,n)); i++ ) {
00163         ipiv_i[i] = ipiv_save[i];
00164     }
00165 
00166     LAPACKE_cge_trans( LAPACK_COL_MAJOR, m, n, a_i, lda, a_r, n+2 );
00167     info_i = LAPACKE_cgetrf_work( LAPACK_ROW_MAJOR, m_i, n_i, a_r, lda_r,
00168                                   ipiv_i );
00169 
00170     LAPACKE_cge_trans( LAPACK_ROW_MAJOR, m, n, a_r, n+2, a_i, lda );
00171 
00172     failed = compare_cgetrf( a, a_i, ipiv, ipiv_i, info, info_i, lda, m, n );
00173     if( failed == 0 ) {
00174         printf( "PASSED: row-major middle-level interface to cgetrf\n" );
00175     } else {
00176         printf( "FAILED: row-major middle-level interface to cgetrf\n" );
00177     }
00178 
00179     /* Initialize input data, call the row-major high-level
00180      * interface to LAPACK routine and check the results */
00181     for( i = 0; i < lda*n; i++ ) {
00182         a_i[i] = a_save[i];
00183     }
00184     for( i = 0; i < (MIN(m,n)); i++ ) {
00185         ipiv_i[i] = ipiv_save[i];
00186     }
00187 
00188     /* Init row_major arrays */
00189     LAPACKE_cge_trans( LAPACK_COL_MAJOR, m, n, a_i, lda, a_r, n+2 );
00190     info_i = LAPACKE_cgetrf( LAPACK_ROW_MAJOR, m_i, n_i, a_r, lda_r, ipiv_i );
00191 
00192     LAPACKE_cge_trans( LAPACK_ROW_MAJOR, m, n, a_r, n+2, a_i, lda );
00193 
00194     failed = compare_cgetrf( a, a_i, ipiv, ipiv_i, info, info_i, lda, m, n );
00195     if( failed == 0 ) {
00196         printf( "PASSED: row-major high-level interface to cgetrf\n" );
00197     } else {
00198         printf( "FAILED: row-major high-level interface to cgetrf\n" );
00199     }
00200 
00201     /* Release memory */
00202     if( a != NULL ) {
00203         LAPACKE_free( a );
00204     }
00205     if( a_i != NULL ) {
00206         LAPACKE_free( a_i );
00207     }
00208     if( a_r != NULL ) {
00209         LAPACKE_free( a_r );
00210     }
00211     if( a_save != NULL ) {
00212         LAPACKE_free( a_save );
00213     }
00214     if( ipiv != NULL ) {
00215         LAPACKE_free( ipiv );
00216     }
00217     if( ipiv_i != NULL ) {
00218         LAPACKE_free( ipiv_i );
00219     }
00220     if( ipiv_save != NULL ) {
00221         LAPACKE_free( ipiv_save );
00222     }
00223 
00224     return 0;
00225 }
00226 
00227 /* Auxiliary function: cgetrf scalar parameters initialization */
00228 static void init_scalars_cgetrf( lapack_int *m, lapack_int *n, lapack_int *lda )
00229 {
00230     *m = 4;
00231     *n = 4;
00232     *lda = 8;
00233 
00234     return;
00235 }
00236 
00237 /* Auxiliary functions: cgetrf array parameters initialization */
00238 static void init_a( lapack_int size, lapack_complex_float *a ) {
00239     lapack_int i;
00240     for( i = 0; i < size; i++ ) {
00241         a[i] = lapack_make_complex_float( 0.0f, 0.0f );
00242     }
00243     a[0] = lapack_make_complex_float( -1.340000033e+000, 2.549999952e+000 );
00244     a[8] = lapack_make_complex_float( 2.800000012e-001, 3.170000076e+000 );
00245     a[16] = lapack_make_complex_float( -6.389999866e+000, -2.200000048e+000 );
00246     a[24] = lapack_make_complex_float( 7.200000286e-001, -9.200000167e-001 );
00247     a[1] = lapack_make_complex_float( -1.700000018e-001, -1.409999967e+000 );
00248     a[9] = lapack_make_complex_float( 3.309999943e+000, -1.500000060e-001 );
00249     a[17] = lapack_make_complex_float( -1.500000060e-001, 1.340000033e+000 );
00250     a[25] = lapack_make_complex_float( 1.289999962e+000, 1.379999995e+000 );
00251     a[2] = lapack_make_complex_float( -3.289999962e+000, -2.390000105e+000 );
00252     a[10] = lapack_make_complex_float( -1.909999967e+000, 4.420000076e+000 );
00253     a[18] = lapack_make_complex_float( -1.400000006e-001, -1.350000024e+000 );
00254     a[26] = lapack_make_complex_float( 1.720000029e+000, 1.350000024e+000 );
00255     a[3] = lapack_make_complex_float( 2.410000086e+000, 3.899999857e-001 );
00256     a[11] = lapack_make_complex_float( -5.600000024e-001, 1.470000029e+000 );
00257     a[19] = lapack_make_complex_float( -8.299999833e-001, -6.899999976e-001 );
00258     a[27] = lapack_make_complex_float( -1.960000038e+000, 6.700000167e-001 );
00259 }
00260 static void init_ipiv( lapack_int size, lapack_int *ipiv ) {
00261     lapack_int i;
00262     for( i = 0; i < size; i++ ) {
00263         ipiv[i] = 0;
00264     }
00265 }
00266 
00267 /* Auxiliary function: C interface to cgetrf results check */
00268 /* Return value: 0 - test is passed, non-zero - test is failed */
00269 static int compare_cgetrf( lapack_complex_float *a, lapack_complex_float *a_i,
00270                            lapack_int *ipiv, lapack_int *ipiv_i,
00271                            lapack_int info, lapack_int info_i, lapack_int lda,
00272                            lapack_int m, lapack_int n )
00273 {
00274     lapack_int i;
00275     int failed = 0;
00276     for( i = 0; i < lda*n; i++ ) {
00277         failed += compare_complex_floats(a[i],a_i[i]);
00278     }
00279     for( i = 0; i < (MIN(m,n)); i++ ) {
00280         failed += (ipiv[i] == ipiv_i[i]) ? 0 : 1;
00281     }
00282     failed += (info == info_i) ? 0 : 1;
00283     if( info != 0 || info_i != 0 ) {
00284         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00285     }
00286 
00287     return failed;
00288 }


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