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_dpotrs( char *uplo, lapack_int *n, lapack_int *nrhs,
00055 lapack_int *lda, lapack_int *ldb );
00056 static void init_a( lapack_int size, double *a );
00057 static void init_b( lapack_int size, double *b );
00058 static int compare_dpotrs( double *b, double *b_i, lapack_int info,
00059 lapack_int info_i, lapack_int ldb, lapack_int nrhs );
00060
00061 int main(void)
00062 {
00063
00064 char uplo, uplo_i;
00065 lapack_int n, n_i;
00066 lapack_int nrhs, nrhs_i;
00067 lapack_int lda, lda_i;
00068 lapack_int lda_r;
00069 lapack_int ldb, ldb_i;
00070 lapack_int ldb_r;
00071 lapack_int info, info_i;
00072 lapack_int i;
00073 int failed;
00074
00075
00076 double *a = NULL, *a_i = NULL;
00077 double *b = NULL, *b_i = NULL;
00078 double *b_save = NULL;
00079 double *a_r = NULL;
00080 double *b_r = NULL;
00081
00082
00083 init_scalars_dpotrs( &uplo, &n, &nrhs, &lda, &ldb );
00084 lda_r = n+2;
00085 ldb_r = nrhs+2;
00086 uplo_i = uplo;
00087 n_i = n;
00088 nrhs_i = nrhs;
00089 lda_i = lda;
00090 ldb_i = ldb;
00091
00092
00093 a = (double *)LAPACKE_malloc( lda*n * sizeof(double) );
00094 b = (double *)LAPACKE_malloc( ldb*nrhs * sizeof(double) );
00095
00096
00097 a_i = (double *)LAPACKE_malloc( lda*n * sizeof(double) );
00098 b_i = (double *)LAPACKE_malloc( ldb*nrhs * sizeof(double) );
00099
00100
00101 b_save = (double *)LAPACKE_malloc( ldb*nrhs * sizeof(double) );
00102
00103
00104 a_r = (double *)LAPACKE_malloc( n*(n+2) * sizeof(double) );
00105 b_r = (double *)LAPACKE_malloc( n*(nrhs+2) * sizeof(double) );
00106
00107
00108 init_a( lda*n, a );
00109 init_b( ldb*nrhs, b );
00110
00111
00112 for( i = 0; i < ldb*nrhs; i++ ) {
00113 b_save[i] = b[i];
00114 }
00115
00116
00117 dpotrs_( &uplo, &n, &nrhs, a, &lda, b, &ldb, &info );
00118
00119
00120
00121 for( i = 0; i < lda*n; i++ ) {
00122 a_i[i] = a[i];
00123 }
00124 for( i = 0; i < ldb*nrhs; i++ ) {
00125 b_i[i] = b_save[i];
00126 }
00127 info_i = LAPACKE_dpotrs_work( LAPACK_COL_MAJOR, uplo_i, n_i, nrhs_i, a_i,
00128 lda_i, b_i, ldb_i );
00129
00130 failed = compare_dpotrs( b, b_i, info, info_i, ldb, nrhs );
00131 if( failed == 0 ) {
00132 printf( "PASSED: column-major middle-level interface to dpotrs\n" );
00133 } else {
00134 printf( "FAILED: column-major middle-level interface to dpotrs\n" );
00135 }
00136
00137
00138
00139 for( i = 0; i < lda*n; i++ ) {
00140 a_i[i] = a[i];
00141 }
00142 for( i = 0; i < ldb*nrhs; i++ ) {
00143 b_i[i] = b_save[i];
00144 }
00145 info_i = LAPACKE_dpotrs( LAPACK_COL_MAJOR, uplo_i, n_i, nrhs_i, a_i, lda_i,
00146 b_i, ldb_i );
00147
00148 failed = compare_dpotrs( b, b_i, info, info_i, ldb, nrhs );
00149 if( failed == 0 ) {
00150 printf( "PASSED: column-major high-level interface to dpotrs\n" );
00151 } else {
00152 printf( "FAILED: column-major high-level interface to dpotrs\n" );
00153 }
00154
00155
00156
00157 for( i = 0; i < lda*n; i++ ) {
00158 a_i[i] = a[i];
00159 }
00160 for( i = 0; i < ldb*nrhs; i++ ) {
00161 b_i[i] = b_save[i];
00162 }
00163
00164 LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00165 LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00166 info_i = LAPACKE_dpotrs_work( LAPACK_ROW_MAJOR, uplo_i, n_i, nrhs_i, a_r,
00167 lda_r, b_r, ldb_r );
00168
00169 LAPACKE_dge_trans( LAPACK_ROW_MAJOR, n, nrhs, b_r, nrhs+2, b_i, ldb );
00170
00171 failed = compare_dpotrs( b, b_i, info, info_i, ldb, nrhs );
00172 if( failed == 0 ) {
00173 printf( "PASSED: row-major middle-level interface to dpotrs\n" );
00174 } else {
00175 printf( "FAILED: row-major middle-level interface to dpotrs\n" );
00176 }
00177
00178
00179
00180 for( i = 0; i < lda*n; i++ ) {
00181 a_i[i] = a[i];
00182 }
00183 for( i = 0; i < ldb*nrhs; i++ ) {
00184 b_i[i] = b_save[i];
00185 }
00186
00187
00188 LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 );
00189 LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00190 info_i = LAPACKE_dpotrs( LAPACK_ROW_MAJOR, uplo_i, n_i, nrhs_i, a_r, lda_r,
00191 b_r, ldb_r );
00192
00193 LAPACKE_dge_trans( LAPACK_ROW_MAJOR, n, nrhs, b_r, nrhs+2, b_i, ldb );
00194
00195 failed = compare_dpotrs( b, b_i, info, info_i, ldb, nrhs );
00196 if( failed == 0 ) {
00197 printf( "PASSED: row-major high-level interface to dpotrs\n" );
00198 } else {
00199 printf( "FAILED: row-major high-level interface to dpotrs\n" );
00200 }
00201
00202
00203 if( a != NULL ) {
00204 LAPACKE_free( a );
00205 }
00206 if( a_i != NULL ) {
00207 LAPACKE_free( a_i );
00208 }
00209 if( a_r != NULL ) {
00210 LAPACKE_free( a_r );
00211 }
00212 if( b != NULL ) {
00213 LAPACKE_free( b );
00214 }
00215 if( b_i != NULL ) {
00216 LAPACKE_free( b_i );
00217 }
00218 if( b_r != NULL ) {
00219 LAPACKE_free( b_r );
00220 }
00221 if( b_save != NULL ) {
00222 LAPACKE_free( b_save );
00223 }
00224
00225 return 0;
00226 }
00227
00228
00229 static void init_scalars_dpotrs( char *uplo, lapack_int *n, lapack_int *nrhs,
00230 lapack_int *lda, lapack_int *ldb )
00231 {
00232 *uplo = 'L';
00233 *n = 4;
00234 *nrhs = 2;
00235 *lda = 8;
00236 *ldb = 8;
00237
00238 return;
00239 }
00240
00241
00242 static void init_a( lapack_int size, double *a ) {
00243 lapack_int i;
00244 for( i = 0; i < size; i++ ) {
00245 a[i] = 0;
00246 }
00247 a[0] = 2.03960780543711410e+000;
00248 a[8] = 0.00000000000000000e+000;
00249 a[16] = 0.00000000000000000e+000;
00250 a[24] = 0.00000000000000000e+000;
00251 a[1] = -1.52970585407783540e+000;
00252 a[9] = 1.64012194668567270e+000;
00253 a[17] = 0.00000000000000000e+000;
00254 a[25] = 0.00000000000000000e+000;
00255 a[2] = 2.74562589193457660e-001;
00256 a[10] = -2.49981411948373810e-001;
00257 a[18] = 7.88748805574805310e-001;
00258 a[26] = 0.00000000000000000e+000;
00259 a[3] = -4.90290337845460110e-002;
00260 a[11] = 6.73730390738910060e-001;
00261 a[19] = 6.61657563374256520e-001;
00262 a[27] = 5.34689426929868430e-001;
00263 }
00264 static void init_b( lapack_int size, double *b ) {
00265 lapack_int i;
00266 for( i = 0; i < size; i++ ) {
00267 b[i] = 0;
00268 }
00269 b[0] = 8.69999999999999930e+000;
00270 b[8] = 8.30000000000000070e+000;
00271 b[1] = -1.33500000000000000e+001;
00272 b[9] = 2.12999999999999990e+000;
00273 b[2] = 1.88999999999999990e+000;
00274 b[10] = 1.61000000000000010e+000;
00275 b[3] = -4.13999999999999970e+000;
00276 b[11] = 5.00000000000000000e+000;
00277 }
00278
00279
00280
00281 static int compare_dpotrs( double *b, double *b_i, lapack_int info,
00282 lapack_int info_i, lapack_int ldb, lapack_int nrhs )
00283 {
00284 lapack_int i;
00285 int failed = 0;
00286 for( i = 0; i < ldb*nrhs; i++ ) {
00287 failed += compare_doubles(b[i],b_i[i]);
00288 }
00289 failed += (info == info_i) ? 0 : 1;
00290 if( info != 0 || info_i != 0 ) {
00291 printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00292 }
00293
00294 return failed;
00295 }