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_zsytrf( char *uplo, lapack_int *n, lapack_int *lda,
00055 lapack_int *lwork );
00056 static void init_a( lapack_int size, lapack_complex_double *a );
00057 static void init_ipiv( lapack_int size, lapack_int *ipiv );
00058 static void init_work( lapack_int size, lapack_complex_double *work );
00059 static int compare_zsytrf( lapack_complex_double *a, lapack_complex_double *a_i,
00060 lapack_int *ipiv, lapack_int *ipiv_i,
00061 lapack_int info, lapack_int info_i, lapack_int lda,
00062 lapack_int n );
00063
00064 int main(void)
00065 {
00066
00067 char uplo, uplo_i;
00068 lapack_int n, n_i;
00069 lapack_int lda, lda_i;
00070 lapack_int lda_r;
00071 lapack_int lwork, lwork_i;
00072 lapack_int info, info_i;
00073 lapack_int i;
00074 int failed;
00075
00076
00077 lapack_complex_double *a = NULL, *a_i = NULL;
00078 lapack_int *ipiv = NULL, *ipiv_i = NULL;
00079 lapack_complex_double *work = NULL, *work_i = NULL;
00080 lapack_complex_double *a_save = NULL;
00081 lapack_int *ipiv_save = NULL;
00082 lapack_complex_double *a_r = NULL;
00083
00084
00085 init_scalars_zsytrf( &uplo, &n, &lda, &lwork );
00086 lda_r = n+2;
00087 uplo_i = uplo;
00088 n_i = n;
00089 lda_i = lda;
00090 lwork_i = lwork;
00091
00092
00093 a = (lapack_complex_double *)
00094 LAPACKE_malloc( lda*n * sizeof(lapack_complex_double) );
00095 ipiv = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00096 work = (lapack_complex_double *)
00097 LAPACKE_malloc( lwork * sizeof(lapack_complex_double) );
00098
00099
00100 a_i = (lapack_complex_double *)
00101 LAPACKE_malloc( lda*n * sizeof(lapack_complex_double) );
00102 ipiv_i = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00103 work_i = (lapack_complex_double *)
00104 LAPACKE_malloc( lwork * sizeof(lapack_complex_double) );
00105
00106
00107 a_save = (lapack_complex_double *)
00108 LAPACKE_malloc( lda*n * sizeof(lapack_complex_double) );
00109 ipiv_save = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00110
00111
00112 a_r = (lapack_complex_double *)
00113 LAPACKE_malloc( n*(n+2) * sizeof(lapack_complex_double) );
00114
00115
00116 init_a( lda*n, a );
00117 init_ipiv( n, ipiv );
00118 init_work( lwork, work );
00119
00120
00121 for( i = 0; i < lda*n; i++ ) {
00122 a_save[i] = a[i];
00123 }
00124 for( i = 0; i < n; i++ ) {
00125 ipiv_save[i] = ipiv[i];
00126 }
00127
00128
00129 zsytrf_( &uplo, &n, a, &lda, ipiv, work, &lwork, &info );
00130
00131
00132
00133 for( i = 0; i < lda*n; i++ ) {
00134 a_i[i] = a_save[i];
00135 }
00136 for( i = 0; i < n; i++ ) {
00137 ipiv_i[i] = ipiv_save[i];
00138 }
00139 for( i = 0; i < lwork; i++ ) {
00140 work_i[i] = work[i];
00141 }
00142 info_i = LAPACKE_zsytrf_work( LAPACK_COL_MAJOR, uplo_i, n_i, a_i, lda_i,
00143 ipiv_i, work_i, lwork_i );
00144
00145 failed = compare_zsytrf( a, a_i, ipiv, ipiv_i, info, info_i, lda, n );
00146 if( failed == 0 ) {
00147 printf( "PASSED: column-major middle-level interface to zsytrf\n" );
00148 } else {
00149 printf( "FAILED: column-major middle-level interface to zsytrf\n" );
00150 }
00151
00152
00153
00154 for( i = 0; i < lda*n; i++ ) {
00155 a_i[i] = a_save[i];
00156 }
00157 for( i = 0; i < n; i++ ) {
00158 ipiv_i[i] = ipiv_save[i];
00159 }
00160 for( i = 0; i < lwork; i++ ) {
00161 work_i[i] = work[i];
00162 }
00163 info_i = LAPACKE_zsytrf( LAPACK_COL_MAJOR, uplo_i, n_i, a_i, lda_i,
00164 ipiv_i );
00165
00166 failed = compare_zsytrf( a, a_i, ipiv, ipiv_i, info, info_i, lda, n );
00167 if( failed == 0 ) {
00168 printf( "PASSED: column-major high-level interface to zsytrf\n" );
00169 } else {
00170 printf( "FAILED: column-major high-level interface to zsytrf\n" );
00171 }
00172
00173
00174
00175 for( i = 0; i < lda*n; i++ ) {
00176 a_i[i] = a_save[i];
00177 }
00178 for( i = 0; i < n; i++ ) {
00179 ipiv_i[i] = ipiv_save[i];
00180 }
00181 for( i = 0; i < lwork; i++ ) {
00182 work_i[i] = work[i];
00183 }
00184
00185 LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00186 info_i = LAPACKE_zsytrf_work( LAPACK_ROW_MAJOR, uplo_i, n_i, a_r, lda_r,
00187 ipiv_i, work_i, lwork_i );
00188
00189 LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00190
00191 failed = compare_zsytrf( a, a_i, ipiv, ipiv_i, info, info_i, lda, n );
00192 if( failed == 0 ) {
00193 printf( "PASSED: row-major middle-level interface to zsytrf\n" );
00194 } else {
00195 printf( "FAILED: row-major middle-level interface to zsytrf\n" );
00196 }
00197
00198
00199
00200 for( i = 0; i < lda*n; i++ ) {
00201 a_i[i] = a_save[i];
00202 }
00203 for( i = 0; i < n; i++ ) {
00204 ipiv_i[i] = ipiv_save[i];
00205 }
00206 for( i = 0; i < lwork; i++ ) {
00207 work_i[i] = work[i];
00208 }
00209
00210
00211 LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00212 info_i = LAPACKE_zsytrf( LAPACK_ROW_MAJOR, uplo_i, n_i, a_r, lda_r,
00213 ipiv_i );
00214
00215 LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, n, a_r, n+2, a_i, lda );
00216
00217 failed = compare_zsytrf( a, a_i, ipiv, ipiv_i, info, info_i, lda, n );
00218 if( failed == 0 ) {
00219 printf( "PASSED: row-major high-level interface to zsytrf\n" );
00220 } else {
00221 printf( "FAILED: row-major high-level interface to zsytrf\n" );
00222 }
00223
00224
00225 if( a != NULL ) {
00226 LAPACKE_free( a );
00227 }
00228 if( a_i != NULL ) {
00229 LAPACKE_free( a_i );
00230 }
00231 if( a_r != NULL ) {
00232 LAPACKE_free( a_r );
00233 }
00234 if( a_save != NULL ) {
00235 LAPACKE_free( a_save );
00236 }
00237 if( ipiv != NULL ) {
00238 LAPACKE_free( ipiv );
00239 }
00240 if( ipiv_i != NULL ) {
00241 LAPACKE_free( ipiv_i );
00242 }
00243 if( ipiv_save != NULL ) {
00244 LAPACKE_free( ipiv_save );
00245 }
00246 if( work != NULL ) {
00247 LAPACKE_free( work );
00248 }
00249 if( work_i != NULL ) {
00250 LAPACKE_free( work_i );
00251 }
00252
00253 return 0;
00254 }
00255
00256
00257 static void init_scalars_zsytrf( char *uplo, lapack_int *n, lapack_int *lda,
00258 lapack_int *lwork )
00259 {
00260 *uplo = 'L';
00261 *n = 4;
00262 *lda = 8;
00263 *lwork = 512;
00264
00265 return;
00266 }
00267
00268
00269 static void init_a( lapack_int size, lapack_complex_double *a ) {
00270 lapack_int i;
00271 for( i = 0; i < size; i++ ) {
00272 a[i] = lapack_make_complex_double( 0.0, 0.0 );
00273 }
00274 a[0] = lapack_make_complex_double( -3.90000000000000010e-001,
00275 -7.09999999999999960e-001 );
00276 a[8] = lapack_make_complex_double( 0.00000000000000000e+000,
00277 0.00000000000000000e+000 );
00278 a[16] = lapack_make_complex_double( 0.00000000000000000e+000,
00279 0.00000000000000000e+000 );
00280 a[24] = lapack_make_complex_double( 0.00000000000000000e+000,
00281 0.00000000000000000e+000 );
00282 a[1] = lapack_make_complex_double( 5.13999999999999970e+000,
00283 -6.40000000000000010e-001 );
00284 a[9] = lapack_make_complex_double( 8.85999999999999940e+000,
00285 1.81000000000000010e+000 );
00286 a[17] = lapack_make_complex_double( 0.00000000000000000e+000,
00287 0.00000000000000000e+000 );
00288 a[25] = lapack_make_complex_double( 0.00000000000000000e+000,
00289 0.00000000000000000e+000 );
00290 a[2] = lapack_make_complex_double( -7.86000000000000030e+000,
00291 -2.96000000000000000e+000 );
00292 a[10] = lapack_make_complex_double( -3.52000000000000000e+000,
00293 5.79999999999999960e-001 );
00294 a[18] = lapack_make_complex_double( -2.83000000000000010e+000,
00295 -2.99999999999999990e-002 );
00296 a[26] = lapack_make_complex_double( 0.00000000000000000e+000,
00297 0.00000000000000000e+000 );
00298 a[3] = lapack_make_complex_double( 3.79999999999999980e+000,
00299 9.20000000000000040e-001 );
00300 a[11] = lapack_make_complex_double( 5.32000000000000030e+000,
00301 -1.59000000000000010e+000 );
00302 a[19] = lapack_make_complex_double( -1.54000000000000000e+000,
00303 -2.85999999999999990e+000 );
00304 a[27] = lapack_make_complex_double( -5.60000000000000050e-001,
00305 1.20000000000000000e-001 );
00306 }
00307 static void init_ipiv( lapack_int size, lapack_int *ipiv ) {
00308 lapack_int i;
00309 for( i = 0; i < size; i++ ) {
00310 ipiv[i] = 0;
00311 }
00312 }
00313 static void init_work( lapack_int size, lapack_complex_double *work ) {
00314 lapack_int i;
00315 for( i = 0; i < size; i++ ) {
00316 work[i] = lapack_make_complex_double( 0.0, 0.0 );
00317 }
00318 }
00319
00320
00321
00322 static int compare_zsytrf( lapack_complex_double *a, lapack_complex_double *a_i,
00323 lapack_int *ipiv, lapack_int *ipiv_i,
00324 lapack_int info, lapack_int info_i, lapack_int lda,
00325 lapack_int n )
00326 {
00327 lapack_int i;
00328 int failed = 0;
00329 for( i = 0; i < lda*n; i++ ) {
00330 failed += compare_complex_doubles(a[i],a_i[i]);
00331 }
00332 for( i = 0; i < n; i++ ) {
00333 failed += (ipiv[i] == ipiv_i[i]) ? 0 : 1;
00334 }
00335 failed += (info == info_i) ? 0 : 1;
00336 if( info != 0 || info_i != 0 ) {
00337 printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00338 }
00339
00340 return failed;
00341 }