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