cupmtr_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 * cupmtr_1 is the test program for the C interface to LAPACK
00036 * routine cupmtr
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_cupmtr( char *side, char *uplo, char *trans,
00055                                  lapack_int *m, lapack_int *n,
00056                                  lapack_int *ldc );
00057 static void init_ap( lapack_int size, lapack_complex_float *ap );
00058 static void init_tau( lapack_int size, lapack_complex_float *tau );
00059 static void init_c( lapack_int size, lapack_complex_float *c );
00060 static void init_work( lapack_int size, lapack_complex_float *work );
00061 static int compare_cupmtr( lapack_complex_float *c, lapack_complex_float *c_i,
00062                            lapack_int info, lapack_int info_i, lapack_int ldc,
00063                            lapack_int n );
00064 
00065 int main(void)
00066 {
00067     /* Local scalars */
00068     char side, side_i;
00069     char uplo, uplo_i;
00070     char trans, trans_i;
00071     lapack_int m, m_i;
00072     lapack_int n, n_i;
00073     lapack_int ldc, ldc_i;
00074     lapack_int ldc_r;
00075     lapack_int info, info_i;
00076     /* Declare scalars */
00077     lapack_int lwork;
00078     lapack_int i;
00079     int failed;
00080 
00081     /* Local arrays */
00082     lapack_complex_float *ap = NULL, *ap_i = NULL;
00083     lapack_complex_float *tau = NULL, *tau_i = NULL;
00084     lapack_complex_float *c = NULL, *c_i = NULL;
00085     lapack_complex_float *work = NULL, *work_i = NULL;
00086     lapack_complex_float *c_save = NULL;
00087     lapack_complex_float *ap_r = NULL;
00088     lapack_complex_float *c_r = NULL;
00089 
00090     /* Iniitialize the scalar parameters */
00091     init_scalars_cupmtr( &side, &uplo, &trans, &m, &n, &ldc );
00092     lwork = MAX(m,n);
00093     ldc_r = n+2;
00094     side_i = side;
00095     uplo_i = uplo;
00096     trans_i = trans;
00097     m_i = m;
00098     n_i = n;
00099     ldc_i = ldc;
00100 
00101     /* Allocate memory for the LAPACK routine arrays */
00102     ap = (lapack_complex_float *)
00103         LAPACKE_malloc( ((m*(m+1)/2)) * sizeof(lapack_complex_float) );
00104     tau = (lapack_complex_float *)
00105         LAPACKE_malloc( (m-1) * sizeof(lapack_complex_float) );
00106     c = (lapack_complex_float *)
00107         LAPACKE_malloc( ldc*n * sizeof(lapack_complex_float) );
00108     work = (lapack_complex_float *)
00109         LAPACKE_malloc( lwork * sizeof(lapack_complex_float) );
00110 
00111     /* Allocate memory for the C interface function arrays */
00112     ap_i = (lapack_complex_float *)
00113         LAPACKE_malloc( ((m*(m+1)/2)) * sizeof(lapack_complex_float) );
00114     tau_i = (lapack_complex_float *)
00115         LAPACKE_malloc( (m-1) * sizeof(lapack_complex_float) );
00116     c_i = (lapack_complex_float *)
00117         LAPACKE_malloc( ldc*n * sizeof(lapack_complex_float) );
00118     work_i = (lapack_complex_float *)
00119         LAPACKE_malloc( lwork * sizeof(lapack_complex_float) );
00120 
00121     /* Allocate memory for the backup arrays */
00122     c_save = (lapack_complex_float *)
00123         LAPACKE_malloc( ldc*n * sizeof(lapack_complex_float) );
00124 
00125     /* Allocate memory for the row-major arrays */
00126     ap_r = (lapack_complex_float *)
00127         LAPACKE_malloc( m*(m+1)/2 * sizeof(lapack_complex_float) );
00128     c_r = (lapack_complex_float *)
00129         LAPACKE_malloc( m*(n+2) * sizeof(lapack_complex_float) );
00130 
00131     /* Initialize input arrays */
00132     init_ap( (m*(m+1)/2), ap );
00133     init_tau( (m-1), tau );
00134     init_c( ldc*n, c );
00135     init_work( lwork, work );
00136 
00137     /* Backup the ouptut arrays */
00138     for( i = 0; i < ldc*n; i++ ) {
00139         c_save[i] = c[i];
00140     }
00141 
00142     /* Call the LAPACK routine */
00143     cupmtr_( &side, &uplo, &trans, &m, &n, ap, tau, c, &ldc, work, &info );
00144 
00145     /* Initialize input data, call the column-major middle-level
00146      * interface to LAPACK routine and check the results */
00147     for( i = 0; i < (m*(m+1)/2); i++ ) {
00148         ap_i[i] = ap[i];
00149     }
00150     for( i = 0; i < (m-1); i++ ) {
00151         tau_i[i] = tau[i];
00152     }
00153     for( i = 0; i < ldc*n; i++ ) {
00154         c_i[i] = c_save[i];
00155     }
00156     for( i = 0; i < lwork; i++ ) {
00157         work_i[i] = work[i];
00158     }
00159     info_i = LAPACKE_cupmtr_work( LAPACK_COL_MAJOR, side_i, uplo_i, trans_i,
00160                                   m_i, n_i, ap_i, tau_i, c_i, ldc_i, work_i );
00161 
00162     failed = compare_cupmtr( c, c_i, info, info_i, ldc, n );
00163     if( failed == 0 ) {
00164         printf( "PASSED: column-major middle-level interface to cupmtr\n" );
00165     } else {
00166         printf( "FAILED: column-major middle-level interface to cupmtr\n" );
00167     }
00168 
00169     /* Initialize input data, call the column-major high-level
00170      * interface to LAPACK routine and check the results */
00171     for( i = 0; i < (m*(m+1)/2); i++ ) {
00172         ap_i[i] = ap[i];
00173     }
00174     for( i = 0; i < (m-1); i++ ) {
00175         tau_i[i] = tau[i];
00176     }
00177     for( i = 0; i < ldc*n; i++ ) {
00178         c_i[i] = c_save[i];
00179     }
00180     for( i = 0; i < lwork; i++ ) {
00181         work_i[i] = work[i];
00182     }
00183     info_i = LAPACKE_cupmtr( LAPACK_COL_MAJOR, side_i, uplo_i, trans_i, m_i,
00184                              n_i, ap_i, tau_i, c_i, ldc_i );
00185 
00186     failed = compare_cupmtr( c, c_i, info, info_i, ldc, n );
00187     if( failed == 0 ) {
00188         printf( "PASSED: column-major high-level interface to cupmtr\n" );
00189     } else {
00190         printf( "FAILED: column-major high-level interface to cupmtr\n" );
00191     }
00192 
00193     /* Initialize input data, call the row-major middle-level
00194      * interface to LAPACK routine and check the results */
00195     for( i = 0; i < (m*(m+1)/2); i++ ) {
00196         ap_i[i] = ap[i];
00197     }
00198     for( i = 0; i < (m-1); i++ ) {
00199         tau_i[i] = tau[i];
00200     }
00201     for( i = 0; i < ldc*n; i++ ) {
00202         c_i[i] = c_save[i];
00203     }
00204     for( i = 0; i < lwork; i++ ) {
00205         work_i[i] = work[i];
00206     }
00207 
00208     LAPACKE_cpp_trans( LAPACK_COL_MAJOR, uplo, m, ap_i, ap_r );
00209     LAPACKE_cge_trans( LAPACK_COL_MAJOR, m, n, c_i, ldc, c_r, n+2 );
00210     info_i = LAPACKE_cupmtr_work( LAPACK_ROW_MAJOR, side_i, uplo_i, trans_i,
00211                                   m_i, n_i, ap_r, tau_i, c_r, ldc_r, work_i );
00212 
00213     LAPACKE_cge_trans( LAPACK_ROW_MAJOR, m, n, c_r, n+2, c_i, ldc );
00214 
00215     failed = compare_cupmtr( c, c_i, info, info_i, ldc, n );
00216     if( failed == 0 ) {
00217         printf( "PASSED: row-major middle-level interface to cupmtr\n" );
00218     } else {
00219         printf( "FAILED: row-major middle-level interface to cupmtr\n" );
00220     }
00221 
00222     /* Initialize input data, call the row-major high-level
00223      * interface to LAPACK routine and check the results */
00224     for( i = 0; i < (m*(m+1)/2); i++ ) {
00225         ap_i[i] = ap[i];
00226     }
00227     for( i = 0; i < (m-1); i++ ) {
00228         tau_i[i] = tau[i];
00229     }
00230     for( i = 0; i < ldc*n; i++ ) {
00231         c_i[i] = c_save[i];
00232     }
00233     for( i = 0; i < lwork; i++ ) {
00234         work_i[i] = work[i];
00235     }
00236 
00237     /* Init row_major arrays */
00238     LAPACKE_cpp_trans( LAPACK_COL_MAJOR, uplo, m, ap_i, ap_r );
00239     LAPACKE_cge_trans( LAPACK_COL_MAJOR, m, n, c_i, ldc, c_r, n+2 );
00240     info_i = LAPACKE_cupmtr( LAPACK_ROW_MAJOR, side_i, uplo_i, trans_i, m_i,
00241                              n_i, ap_r, tau_i, c_r, ldc_r );
00242 
00243     LAPACKE_cge_trans( LAPACK_ROW_MAJOR, m, n, c_r, n+2, c_i, ldc );
00244 
00245     failed = compare_cupmtr( c, c_i, info, info_i, ldc, n );
00246     if( failed == 0 ) {
00247         printf( "PASSED: row-major high-level interface to cupmtr\n" );
00248     } else {
00249         printf( "FAILED: row-major high-level interface to cupmtr\n" );
00250     }
00251 
00252     /* Release memory */
00253     if( ap != NULL ) {
00254         LAPACKE_free( ap );
00255     }
00256     if( ap_i != NULL ) {
00257         LAPACKE_free( ap_i );
00258     }
00259     if( ap_r != NULL ) {
00260         LAPACKE_free( ap_r );
00261     }
00262     if( tau != NULL ) {
00263         LAPACKE_free( tau );
00264     }
00265     if( tau_i != NULL ) {
00266         LAPACKE_free( tau_i );
00267     }
00268     if( c != NULL ) {
00269         LAPACKE_free( c );
00270     }
00271     if( c_i != NULL ) {
00272         LAPACKE_free( c_i );
00273     }
00274     if( c_r != NULL ) {
00275         LAPACKE_free( c_r );
00276     }
00277     if( c_save != NULL ) {
00278         LAPACKE_free( c_save );
00279     }
00280     if( work != NULL ) {
00281         LAPACKE_free( work );
00282     }
00283     if( work_i != NULL ) {
00284         LAPACKE_free( work_i );
00285     }
00286 
00287     return 0;
00288 }
00289 
00290 /* Auxiliary function: cupmtr scalar parameters initialization */
00291 static void init_scalars_cupmtr( char *side, char *uplo, char *trans,
00292                                  lapack_int *m, lapack_int *n, lapack_int *ldc )
00293 {
00294     *side = 'L';
00295     *uplo = 'L';
00296     *trans = 'N';
00297     *m = 4;
00298     *n = 2;
00299     *ldc = 8;
00300 
00301     return;
00302 }
00303 
00304 /* Auxiliary functions: cupmtr array parameters initialization */
00305 static void init_ap( lapack_int size, lapack_complex_float *ap ) {
00306     lapack_int i;
00307     for( i = 0; i < size; i++ ) {
00308         ap[i] = lapack_make_complex_float( 0.0f, 0.0f );
00309     }
00310     ap[0] = lapack_make_complex_float( -2.279999971e+000, 0.000000000e+000 );
00311     ap[1] = lapack_make_complex_float( -4.338455677e+000, 0.000000000e+000 );
00312     ap[2] = lapack_make_complex_float( 3.278606534e-001, -1.251226068e-001 );
00313     ap[3] = lapack_make_complex_float( -1.412565559e-001, -3.666364849e-001 );
00314     ap[4] = lapack_make_complex_float( -1.284568310e-001, 0.000000000e+000 );
00315     ap[5] = lapack_make_complex_float( -2.022594690e+000, 0.000000000e+000 );
00316     ap[6] = lapack_make_complex_float( -3.083218634e-001, 1.763225943e-001 );
00317     ap[7] = lapack_make_complex_float( -1.665935516e-001, 0.000000000e+000 );
00318     ap[8] = lapack_make_complex_float( -1.802322745e+000, 0.000000000e+000 );
00319     ap[9] = lapack_make_complex_float( -1.924949646e+000, 0.000000000e+000 );
00320 }
00321 static void init_tau( lapack_int size, lapack_complex_float *tau ) {
00322     lapack_int i;
00323     for( i = 0; i < size; i++ ) {
00324         tau[i] = lapack_make_complex_float( 0.0f, 0.0f );
00325     }
00326     tau[0] = lapack_make_complex_float( 1.410284281e+000, 4.679084122e-001 );
00327     tau[1] = lapack_make_complex_float( 1.302420378e+000, 7.853320837e-001 );
00328     tau[2] = lapack_make_complex_float( 1.093973756e+000, -9.955747128e-001 );
00329 }
00330 static void init_c( lapack_int size, lapack_complex_float *c ) {
00331     lapack_int i;
00332     for( i = 0; i < size; i++ ) {
00333         c[i] = lapack_make_complex_float( 0.0f, 0.0f );
00334     }
00335     c[0] = lapack_make_complex_float( 7.298945785e-001, 0.000000000e+000 );
00336     c[8] = lapack_make_complex_float( -2.595449984e-001, 0.000000000e+000 );
00337     c[1] = lapack_make_complex_float( 6.258777976e-001, 0.000000000e+000 );
00338     c[9] = lapack_make_complex_float( -4.325495660e-002, 0.000000000e+000 );
00339     c[2] = lapack_make_complex_float( 2.513449788e-001, 0.000000000e+000 );
00340     c[10] = lapack_make_complex_float( 4.952474236e-001, 0.000000000e+000 );
00341     c[3] = lapack_make_complex_float( 1.111603901e-001, 0.000000000e+000 );
00342     c[11] = lapack_make_complex_float( 8.279464841e-001, 0.000000000e+000 );
00343 }
00344 static void init_work( lapack_int size, lapack_complex_float *work ) {
00345     lapack_int i;
00346     for( i = 0; i < size; i++ ) {
00347         work[i] = lapack_make_complex_float( 0.0f, 0.0f );
00348     }
00349 }
00350 
00351 /* Auxiliary function: C interface to cupmtr results check */
00352 /* Return value: 0 - test is passed, non-zero - test is failed */
00353 static int compare_cupmtr( lapack_complex_float *c, lapack_complex_float *c_i,
00354                            lapack_int info, lapack_int info_i, lapack_int ldc,
00355                            lapack_int n )
00356 {
00357     lapack_int i;
00358     int failed = 0;
00359     for( i = 0; i < ldc*n; i++ ) {
00360         failed += compare_complex_floats(c[i],c_i[i]);
00361     }
00362     failed += (info == info_i) ? 0 : 1;
00363     if( info != 0 || info_i != 0 ) {
00364         printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00365     }
00366 
00367     return failed;
00368 }


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