00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
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_zgehrd( lapack_int *n, lapack_int *ilo,
00055 lapack_int *ihi, lapack_int *lda,
00056 lapack_int *lwork );
00057 static void init_a( lapack_int size, lapack_complex_double *a );
00058 static void init_tau( lapack_int size, lapack_complex_double *tau );
00059 static void init_work( lapack_int size, lapack_complex_double *work );
00060 static int compare_zgehrd( lapack_complex_double *a, lapack_complex_double *a_i,
00061 lapack_complex_double *tau,
00062 lapack_complex_double *tau_i, lapack_int info,
00063 lapack_int info_i, lapack_int lda, lapack_int n );
00064
00065 int main(void)
00066 {
00067
00068 lapack_int n, n_i;
00069 lapack_int ilo, ilo_i;
00070 lapack_int ihi, ihi_i;
00071 lapack_int lda, lda_i;
00072 lapack_int lda_r;
00073 lapack_int lwork, lwork_i;
00074 lapack_int info, info_i;
00075 lapack_int i;
00076 int failed;
00077
00078
00079 lapack_complex_double *a = NULL, *a_i = NULL;
00080 lapack_complex_double *tau = NULL, *tau_i = NULL;
00081 lapack_complex_double *work = NULL, *work_i = NULL;
00082 lapack_complex_double *a_save = NULL;
00083 lapack_complex_double *tau_save = NULL;
00084 lapack_complex_double *a_r = NULL;
00085
00086
00087 init_scalars_zgehrd( &n, &ilo, &ihi, &lda, &lwork );
00088 lda_r = n+2;
00089 n_i = n;
00090 ilo_i = ilo;
00091 ihi_i = ihi;
00092 lda_i = lda;
00093 lwork_i = lwork;
00094
00095
00096 a = (lapack_complex_double *)
00097 LAPACKE_malloc( lda*n * sizeof(lapack_complex_double) );
00098 tau = (lapack_complex_double *)
00099 LAPACKE_malloc( (n-1) * sizeof(lapack_complex_double) );
00100 work = (lapack_complex_double *)
00101 LAPACKE_malloc( lwork * sizeof(lapack_complex_double) );
00102
00103
00104 a_i = (lapack_complex_double *)
00105 LAPACKE_malloc( lda*n * sizeof(lapack_complex_double) );
00106 tau_i = (lapack_complex_double *)
00107 LAPACKE_malloc( (n-1) * sizeof(lapack_complex_double) );
00108 work_i = (lapack_complex_double *)
00109 LAPACKE_malloc( lwork * sizeof(lapack_complex_double) );
00110
00111
00112 a_save = (lapack_complex_double *)
00113 LAPACKE_malloc( lda*n * sizeof(lapack_complex_double) );
00114 tau_save = (lapack_complex_double *)
00115 LAPACKE_malloc( (n-1) * sizeof(lapack_complex_double) );
00116
00117
00118 a_r = (lapack_complex_double *)
00119 LAPACKE_malloc( n*(n+2) * sizeof(lapack_complex_double) );
00120
00121
00122 init_a( lda*n, a );
00123 init_tau( (n-1), tau );
00124 init_work( lwork, work );
00125
00126
00127 for( i = 0; i < lda*n; i++ ) {
00128 a_save[i] = a[i];
00129 }
00130 for( i = 0; i < (n-1); i++ ) {
00131 tau_save[i] = tau[i];
00132 }
00133
00134
00135 zgehrd_( &n, &ilo, &ihi, a, &lda, tau, work, &lwork, &info );
00136
00137
00138
00139 for( i = 0; i < lda*n; i++ ) {
00140 a_i[i] = a_save[i];
00141 }
00142 for( i = 0; i < (n-1); i++ ) {
00143 tau_i[i] = tau_save[i];
00144 }
00145 for( i = 0; i < lwork; i++ ) {
00146 work_i[i] = work[i];
00147 }
00148 info_i = LAPACKE_zgehrd_work( LAPACK_COL_MAJOR, n_i, ilo_i, ihi_i, a_i,
00149 lda_i, tau_i, work_i, lwork_i );
00150
00151 failed = compare_zgehrd( a, a_i, tau, tau_i, info, info_i, lda, n );
00152 if( failed == 0 ) {
00153 printf( "PASSED: column-major middle-level interface to zgehrd\n" );
00154 } else {
00155 printf( "FAILED: column-major middle-level interface to zgehrd\n" );
00156 }
00157
00158
00159
00160 for( i = 0; i < lda*n; i++ ) {
00161 a_i[i] = a_save[i];
00162 }
00163 for( i = 0; i < (n-1); i++ ) {
00164 tau_i[i] = tau_save[i];
00165 }
00166 for( i = 0; i < lwork; i++ ) {
00167 work_i[i] = work[i];
00168 }
00169 info_i = LAPACKE_zgehrd( LAPACK_COL_MAJOR, n_i, ilo_i, ihi_i, a_i, lda_i,
00170 tau_i );
00171
00172 failed = compare_zgehrd( a, a_i, tau, tau_i, info, info_i, lda, n );
00173 if( failed == 0 ) {
00174 printf( "PASSED: column-major high-level interface to zgehrd\n" );
00175 } else {
00176 printf( "FAILED: column-major high-level interface to zgehrd\n" );
00177 }
00178
00179
00180
00181 for( i = 0; i < lda*n; i++ ) {
00182 a_i[i] = a_save[i];
00183 }
00184 for( i = 0; i < (n-1); i++ ) {
00185 tau_i[i] = tau_save[i];
00186 }
00187 for( i = 0; i < lwork; i++ ) {
00188 work_i[i] = work[i];
00189 }
00190
00191 LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00192 info_i = LAPACKE_zgehrd_work( LAPACK_ROW_MAJOR, n_i, ilo_i, ihi_i, a_r,
00193 lda_r, tau_i, work_i, lwork_i );
00194
00195 LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00196
00197 failed = compare_zgehrd( a, a_i, tau, tau_i, info, info_i, lda, n );
00198 if( failed == 0 ) {
00199 printf( "PASSED: row-major middle-level interface to zgehrd\n" );
00200 } else {
00201 printf( "FAILED: row-major middle-level interface to zgehrd\n" );
00202 }
00203
00204
00205
00206 for( i = 0; i < lda*n; i++ ) {
00207 a_i[i] = a_save[i];
00208 }
00209 for( i = 0; i < (n-1); i++ ) {
00210 tau_i[i] = tau_save[i];
00211 }
00212 for( i = 0; i < lwork; i++ ) {
00213 work_i[i] = work[i];
00214 }
00215
00216
00217 LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00218 info_i = LAPACKE_zgehrd( LAPACK_ROW_MAJOR, n_i, ilo_i, ihi_i, a_r, lda_r,
00219 tau_i );
00220
00221 LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00222
00223 failed = compare_zgehrd( a, a_i, tau, tau_i, info, info_i, lda, n );
00224 if( failed == 0 ) {
00225 printf( "PASSED: row-major high-level interface to zgehrd\n" );
00226 } else {
00227 printf( "FAILED: row-major high-level interface to zgehrd\n" );
00228 }
00229
00230
00231 if( a != NULL ) {
00232 LAPACKE_free( a );
00233 }
00234 if( a_i != NULL ) {
00235 LAPACKE_free( a_i );
00236 }
00237 if( a_r != NULL ) {
00238 LAPACKE_free( a_r );
00239 }
00240 if( a_save != NULL ) {
00241 LAPACKE_free( a_save );
00242 }
00243 if( tau != NULL ) {
00244 LAPACKE_free( tau );
00245 }
00246 if( tau_i != NULL ) {
00247 LAPACKE_free( tau_i );
00248 }
00249 if( tau_save != NULL ) {
00250 LAPACKE_free( tau_save );
00251 }
00252 if( work != NULL ) {
00253 LAPACKE_free( work );
00254 }
00255 if( work_i != NULL ) {
00256 LAPACKE_free( work_i );
00257 }
00258
00259 return 0;
00260 }
00261
00262
00263 static void init_scalars_zgehrd( lapack_int *n, lapack_int *ilo,
00264 lapack_int *ihi, lapack_int *lda,
00265 lapack_int *lwork )
00266 {
00267 *n = 4;
00268 *ilo = 1;
00269 *ihi = 4;
00270 *lda = 8;
00271 *lwork = 512;
00272
00273 return;
00274 }
00275
00276
00277 static void init_a( lapack_int size, lapack_complex_double *a ) {
00278 lapack_int i;
00279 for( i = 0; i < size; i++ ) {
00280 a[i] = lapack_make_complex_double( 0.0, 0.0 );
00281 }
00282 a[0] = lapack_make_complex_double( -3.97000000000000020e+000,
00283 -5.04000000000000000e+000 );
00284 a[8] = lapack_make_complex_double( -4.11000000000000030e+000,
00285 3.70000000000000020e+000 );
00286 a[16] = lapack_make_complex_double( -3.40000000000000020e-001,
00287 1.01000000000000000e+000 );
00288 a[24] = lapack_make_complex_double( 1.29000000000000000e+000,
00289 -8.59999999999999990e-001 );
00290 a[1] = lapack_make_complex_double( 3.40000000000000020e-001,
00291 -1.50000000000000000e+000 );
00292 a[9] = lapack_make_complex_double( 1.52000000000000000e+000,
00293 -4.29999999999999990e-001 );
00294 a[17] = lapack_make_complex_double( 1.87999999999999990e+000,
00295 -5.37999999999999990e+000 );
00296 a[25] = lapack_make_complex_double( 3.35999999999999990e+000,
00297 6.50000000000000020e-001 );
00298 a[2] = lapack_make_complex_double( 3.31000000000000010e+000,
00299 -3.85000000000000010e+000 );
00300 a[10] = lapack_make_complex_double( 2.50000000000000000e+000,
00301 3.45000000000000020e+000 );
00302 a[18] = lapack_make_complex_double( 8.80000000000000000e-001,
00303 -1.08000000000000010e+000 );
00304 a[26] = lapack_make_complex_double( 6.40000000000000010e-001,
00305 -1.48000000000000000e+000 );
00306 a[3] = lapack_make_complex_double( -1.10000000000000010e+000,
00307 8.19999999999999950e-001 );
00308 a[11] = lapack_make_complex_double( 1.81000000000000010e+000,
00309 -1.59000000000000010e+000 );
00310 a[19] = lapack_make_complex_double( 3.25000000000000000e+000,
00311 1.33000000000000010e+000 );
00312 a[27] = lapack_make_complex_double( 1.57000000000000010e+000,
00313 -3.43999999999999990e+000 );
00314 }
00315 static void init_tau( lapack_int size, lapack_complex_double *tau ) {
00316 lapack_int i;
00317 for( i = 0; i < size; i++ ) {
00318 tau[i] = lapack_make_complex_double( 0.0, 0.0 );
00319 }
00320 }
00321 static void init_work( lapack_int size, lapack_complex_double *work ) {
00322 lapack_int i;
00323 for( i = 0; i < size; i++ ) {
00324 work[i] = lapack_make_complex_double( 0.0, 0.0 );
00325 }
00326 }
00327
00328
00329
00330 static int compare_zgehrd( lapack_complex_double *a, lapack_complex_double *a_i,
00331 lapack_complex_double *tau,
00332 lapack_complex_double *tau_i, lapack_int info,
00333 lapack_int info_i, lapack_int lda, lapack_int n )
00334 {
00335 lapack_int i;
00336 int failed = 0;
00337 for( i = 0; i < lda*n; i++ ) {
00338 failed += compare_complex_doubles(a[i],a_i[i]);
00339 }
00340 for( i = 0; i < (n-1); i++ ) {
00341 failed += compare_complex_doubles(tau[i],tau_i[i]);
00342 }
00343 failed += (info == info_i) ? 0 : 1;
00344 if( info != 0 || info_i != 0 ) {
00345 printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00346 }
00347
00348 return failed;
00349 }