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_dgbtrs( char *trans, lapack_int *n, lapack_int *kl,
00055 lapack_int *ku, lapack_int *nrhs,
00056 lapack_int *ldab, lapack_int *ldb );
00057 static void init_ab( lapack_int size, double *ab );
00058 static void init_ipiv( lapack_int size, lapack_int *ipiv );
00059 static void init_b( lapack_int size, double *b );
00060 static int compare_dgbtrs( double *b, double *b_i, lapack_int info,
00061 lapack_int info_i, lapack_int ldb, lapack_int nrhs );
00062
00063 int main(void)
00064 {
00065
00066 char trans, trans_i;
00067 lapack_int n, n_i;
00068 lapack_int kl, kl_i;
00069 lapack_int ku, ku_i;
00070 lapack_int nrhs, nrhs_i;
00071 lapack_int ldab, ldab_i;
00072 lapack_int ldab_r;
00073 lapack_int ldb, ldb_i;
00074 lapack_int ldb_r;
00075 lapack_int info, info_i;
00076 lapack_int i;
00077 int failed;
00078
00079
00080 double *ab = NULL, *ab_i = NULL;
00081 lapack_int *ipiv = NULL, *ipiv_i = NULL;
00082 double *b = NULL, *b_i = NULL;
00083 double *b_save = NULL;
00084 double *ab_r = NULL;
00085 double *b_r = NULL;
00086
00087
00088 init_scalars_dgbtrs( &trans, &n, &kl, &ku, &nrhs, &ldab, &ldb );
00089 ldab_r = n+2;
00090 ldb_r = nrhs+2;
00091 trans_i = trans;
00092 n_i = n;
00093 kl_i = kl;
00094 ku_i = ku;
00095 nrhs_i = nrhs;
00096 ldab_i = ldab;
00097 ldb_i = ldb;
00098
00099
00100 ab = (double *)LAPACKE_malloc( ldab*n * sizeof(double) );
00101 ipiv = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00102 b = (double *)LAPACKE_malloc( ldb*nrhs * sizeof(double) );
00103
00104
00105 ab_i = (double *)LAPACKE_malloc( ldab*n * sizeof(double) );
00106 ipiv_i = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00107 b_i = (double *)LAPACKE_malloc( ldb*nrhs * sizeof(double) );
00108
00109
00110 b_save = (double *)LAPACKE_malloc( ldb*nrhs * sizeof(double) );
00111
00112
00113 ab_r = (double *)LAPACKE_malloc( ((2*kl+ku+1)*(n+2)) * sizeof(double) );
00114 b_r = (double *)LAPACKE_malloc( n*(nrhs+2) * sizeof(double) );
00115
00116
00117 init_ab( ldab*n, ab );
00118 init_ipiv( n, ipiv );
00119 init_b( ldb*nrhs, b );
00120
00121
00122 for( i = 0; i < ldb*nrhs; i++ ) {
00123 b_save[i] = b[i];
00124 }
00125
00126
00127 dgbtrs_( &trans, &n, &kl, &ku, &nrhs, ab, &ldab, ipiv, b, &ldb, &info );
00128
00129
00130
00131 for( i = 0; i < ldab*n; i++ ) {
00132 ab_i[i] = ab[i];
00133 }
00134 for( i = 0; i < n; i++ ) {
00135 ipiv_i[i] = ipiv[i];
00136 }
00137 for( i = 0; i < ldb*nrhs; i++ ) {
00138 b_i[i] = b_save[i];
00139 }
00140 info_i = LAPACKE_dgbtrs_work( LAPACK_COL_MAJOR, trans_i, n_i, kl_i, ku_i,
00141 nrhs_i, ab_i, ldab_i, ipiv_i, b_i, ldb_i );
00142
00143 failed = compare_dgbtrs( b, b_i, info, info_i, ldb, nrhs );
00144 if( failed == 0 ) {
00145 printf( "PASSED: column-major middle-level interface to dgbtrs\n" );
00146 } else {
00147 printf( "FAILED: column-major middle-level interface to dgbtrs\n" );
00148 }
00149
00150
00151
00152 for( i = 0; i < ldab*n; i++ ) {
00153 ab_i[i] = ab[i];
00154 }
00155 for( i = 0; i < n; i++ ) {
00156 ipiv_i[i] = ipiv[i];
00157 }
00158 for( i = 0; i < ldb*nrhs; i++ ) {
00159 b_i[i] = b_save[i];
00160 }
00161 info_i = LAPACKE_dgbtrs( LAPACK_COL_MAJOR, trans_i, n_i, kl_i, ku_i, nrhs_i,
00162 ab_i, ldab_i, ipiv_i, b_i, ldb_i );
00163
00164 failed = compare_dgbtrs( b, b_i, info, info_i, ldb, nrhs );
00165 if( failed == 0 ) {
00166 printf( "PASSED: column-major high-level interface to dgbtrs\n" );
00167 } else {
00168 printf( "FAILED: column-major high-level interface to dgbtrs\n" );
00169 }
00170
00171
00172
00173 for( i = 0; i < ldab*n; i++ ) {
00174 ab_i[i] = ab[i];
00175 }
00176 for( i = 0; i < n; i++ ) {
00177 ipiv_i[i] = ipiv[i];
00178 }
00179 for( i = 0; i < ldb*nrhs; i++ ) {
00180 b_i[i] = b_save[i];
00181 }
00182
00183 LAPACKE_dge_trans( LAPACK_COL_MAJOR, 2*kl+ku+1, n, ab_i, ldab, ab_r, n+2 );
00184 LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00185 info_i = LAPACKE_dgbtrs_work( LAPACK_ROW_MAJOR, trans_i, n_i, kl_i, ku_i,
00186 nrhs_i, ab_r, ldab_r, ipiv_i, b_r, ldb_r );
00187
00188 LAPACKE_dge_trans( LAPACK_ROW_MAJOR, n, nrhs, b_r, nrhs+2, b_i, ldb );
00189
00190 failed = compare_dgbtrs( b, b_i, info, info_i, ldb, nrhs );
00191 if( failed == 0 ) {
00192 printf( "PASSED: row-major middle-level interface to dgbtrs\n" );
00193 } else {
00194 printf( "FAILED: row-major middle-level interface to dgbtrs\n" );
00195 }
00196
00197
00198
00199 for( i = 0; i < ldab*n; i++ ) {
00200 ab_i[i] = ab[i];
00201 }
00202 for( i = 0; i < n; i++ ) {
00203 ipiv_i[i] = ipiv[i];
00204 }
00205 for( i = 0; i < ldb*nrhs; i++ ) {
00206 b_i[i] = b_save[i];
00207 }
00208
00209
00210 LAPACKE_dge_trans( LAPACK_COL_MAJOR, 2*kl+ku+1, n, ab_i, ldab, ab_r, n+2 );
00211 LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00212 info_i = LAPACKE_dgbtrs( LAPACK_ROW_MAJOR, trans_i, n_i, kl_i, ku_i, nrhs_i,
00213 ab_r, ldab_r, ipiv_i, b_r, ldb_r );
00214
00215 LAPACKE_dge_trans( LAPACK_ROW_MAJOR, n, nrhs, b_r, nrhs+2, b_i, ldb );
00216
00217 failed = compare_dgbtrs( b, b_i, info, info_i, ldb, nrhs );
00218 if( failed == 0 ) {
00219 printf( "PASSED: row-major high-level interface to dgbtrs\n" );
00220 } else {
00221 printf( "FAILED: row-major high-level interface to dgbtrs\n" );
00222 }
00223
00224
00225 if( ab != NULL ) {
00226 LAPACKE_free( ab );
00227 }
00228 if( ab_i != NULL ) {
00229 LAPACKE_free( ab_i );
00230 }
00231 if( ab_r != NULL ) {
00232 LAPACKE_free( ab_r );
00233 }
00234 if( ipiv != NULL ) {
00235 LAPACKE_free( ipiv );
00236 }
00237 if( ipiv_i != NULL ) {
00238 LAPACKE_free( ipiv_i );
00239 }
00240 if( b != NULL ) {
00241 LAPACKE_free( b );
00242 }
00243 if( b_i != NULL ) {
00244 LAPACKE_free( b_i );
00245 }
00246 if( b_r != NULL ) {
00247 LAPACKE_free( b_r );
00248 }
00249 if( b_save != NULL ) {
00250 LAPACKE_free( b_save );
00251 }
00252
00253 return 0;
00254 }
00255
00256
00257 static void init_scalars_dgbtrs( char *trans, lapack_int *n, lapack_int *kl,
00258 lapack_int *ku, lapack_int *nrhs,
00259 lapack_int *ldab, lapack_int *ldb )
00260 {
00261 *trans = 'N';
00262 *n = 4;
00263 *kl = 1;
00264 *ku = 2;
00265 *nrhs = 2;
00266 *ldab = 25;
00267 *ldb = 8;
00268
00269 return;
00270 }
00271
00272
00273 static void init_ab( lapack_int size, double *ab ) {
00274 lapack_int i;
00275 for( i = 0; i < size; i++ ) {
00276 ab[i] = 0;
00277 }
00278 ab[0] = 0.00000000000000000e+000;
00279 ab[25] = 0.00000000000000000e+000;
00280 ab[50] = 0.00000000000000000e+000;
00281 ab[75] = -2.12999999999999990e+000;
00282 ab[1] = 0.00000000000000000e+000;
00283 ab[26] = 0.00000000000000000e+000;
00284 ab[51] = -2.73000000000000000e+000;
00285 ab[76] = 4.07000000000000030e+000;
00286 ab[2] = 0.00000000000000000e+000;
00287 ab[27] = 2.46000000000000000e+000;
00288 ab[52] = 2.46000000000000000e+000;
00289 ab[77] = -3.83914387088108940e+000;
00290 ab[3] = -6.98000000000000040e+000;
00291 ab[28] = 2.56000000000000010e+000;
00292 ab[53] = -5.93293047098853950e+000;
00293 ab[78] = -7.26906663992311850e-001;
00294 ab[4] = 3.29512893982807990e-002;
00295 ab[29] = 9.60523370343839610e-001;
00296 ab[54] = 8.05672681211037410e-001;
00297 ab[79] = 0.00000000000000000e+000;
00298 }
00299 static void init_ipiv( lapack_int size, lapack_int *ipiv ) {
00300 lapack_int i;
00301 for( i = 0; i < size; i++ ) {
00302 ipiv[i] = 0;
00303 }
00304 ipiv[0] = 2;
00305 ipiv[1] = 3;
00306 ipiv[2] = 3;
00307 ipiv[3] = 4;
00308 }
00309 static void init_b( lapack_int size, double *b ) {
00310 lapack_int i;
00311 for( i = 0; i < size; i++ ) {
00312 b[i] = 0;
00313 }
00314 b[0] = 4.41999999999999990e+000;
00315 b[8] = -3.60099999999999980e+001;
00316 b[1] = 2.71299999999999990e+001;
00317 b[9] = -3.16700000000000020e+001;
00318 b[2] = -6.13999999999999970e+000;
00319 b[10] = -1.15999999999999990e+000;
00320 b[3] = 1.05000000000000000e+001;
00321 b[11] = -2.58200000000000000e+001;
00322 }
00323
00324
00325
00326 static int compare_dgbtrs( double *b, double *b_i, lapack_int info,
00327 lapack_int info_i, lapack_int ldb, lapack_int nrhs )
00328 {
00329 lapack_int i;
00330 int failed = 0;
00331 for( i = 0; i < ldb*nrhs; i++ ) {
00332 failed += compare_doubles(b[i],b_i[i]);
00333 }
00334 failed += (info == info_i) ? 0 : 1;
00335 if( info != 0 || info_i != 0 ) {
00336 printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00337 }
00338
00339 return failed;
00340 }