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_zgbtrs( 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, lapack_complex_double *ab );
00058 static void init_ipiv( lapack_int size, lapack_int *ipiv );
00059 static void init_b( lapack_int size, lapack_complex_double *b );
00060 static int compare_zgbtrs( lapack_complex_double *b, lapack_complex_double *b_i,
00061 lapack_int info, lapack_int info_i, lapack_int ldb,
00062 lapack_int nrhs );
00063
00064 int main(void)
00065 {
00066
00067 char trans, trans_i;
00068 lapack_int n, n_i;
00069 lapack_int kl, kl_i;
00070 lapack_int ku, ku_i;
00071 lapack_int nrhs, nrhs_i;
00072 lapack_int ldab, ldab_i;
00073 lapack_int ldab_r;
00074 lapack_int ldb, ldb_i;
00075 lapack_int ldb_r;
00076 lapack_int info, info_i;
00077 lapack_int i;
00078 int failed;
00079
00080
00081 lapack_complex_double *ab = NULL, *ab_i = NULL;
00082 lapack_int *ipiv = NULL, *ipiv_i = NULL;
00083 lapack_complex_double *b = NULL, *b_i = NULL;
00084 lapack_complex_double *b_save = NULL;
00085 lapack_complex_double *ab_r = NULL;
00086 lapack_complex_double *b_r = NULL;
00087
00088
00089 init_scalars_zgbtrs( &trans, &n, &kl, &ku, &nrhs, &ldab, &ldb );
00090 ldab_r = n+2;
00091 ldb_r = nrhs+2;
00092 trans_i = trans;
00093 n_i = n;
00094 kl_i = kl;
00095 ku_i = ku;
00096 nrhs_i = nrhs;
00097 ldab_i = ldab;
00098 ldb_i = ldb;
00099
00100
00101 ab = (lapack_complex_double *)
00102 LAPACKE_malloc( ldab*n * sizeof(lapack_complex_double) );
00103 ipiv = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00104 b = (lapack_complex_double *)
00105 LAPACKE_malloc( ldb*nrhs * sizeof(lapack_complex_double) );
00106
00107
00108 ab_i = (lapack_complex_double *)
00109 LAPACKE_malloc( ldab*n * sizeof(lapack_complex_double) );
00110 ipiv_i = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) );
00111 b_i = (lapack_complex_double *)
00112 LAPACKE_malloc( ldb*nrhs * sizeof(lapack_complex_double) );
00113
00114
00115 b_save = (lapack_complex_double *)
00116 LAPACKE_malloc( ldb*nrhs * sizeof(lapack_complex_double) );
00117
00118
00119 ab_r = (lapack_complex_double *)
00120 LAPACKE_malloc( ((2*kl+ku+1)*(n+2)) * sizeof(lapack_complex_double) );
00121 b_r = (lapack_complex_double *)
00122 LAPACKE_malloc( n*(nrhs+2) * sizeof(lapack_complex_double) );
00123
00124
00125 init_ab( ldab*n, ab );
00126 init_ipiv( n, ipiv );
00127 init_b( ldb*nrhs, b );
00128
00129
00130 for( i = 0; i < ldb*nrhs; i++ ) {
00131 b_save[i] = b[i];
00132 }
00133
00134
00135 zgbtrs_( &trans, &n, &kl, &ku, &nrhs, ab, &ldab, ipiv, b, &ldb, &info );
00136
00137
00138
00139 for( i = 0; i < ldab*n; i++ ) {
00140 ab_i[i] = ab[i];
00141 }
00142 for( i = 0; i < n; i++ ) {
00143 ipiv_i[i] = ipiv[i];
00144 }
00145 for( i = 0; i < ldb*nrhs; i++ ) {
00146 b_i[i] = b_save[i];
00147 }
00148 info_i = LAPACKE_zgbtrs_work( LAPACK_COL_MAJOR, trans_i, n_i, kl_i, ku_i,
00149 nrhs_i, ab_i, ldab_i, ipiv_i, b_i, ldb_i );
00150
00151 failed = compare_zgbtrs( b, b_i, info, info_i, ldb, nrhs );
00152 if( failed == 0 ) {
00153 printf( "PASSED: column-major middle-level interface to zgbtrs\n" );
00154 } else {
00155 printf( "FAILED: column-major middle-level interface to zgbtrs\n" );
00156 }
00157
00158
00159
00160 for( i = 0; i < ldab*n; i++ ) {
00161 ab_i[i] = ab[i];
00162 }
00163 for( i = 0; i < n; i++ ) {
00164 ipiv_i[i] = ipiv[i];
00165 }
00166 for( i = 0; i < ldb*nrhs; i++ ) {
00167 b_i[i] = b_save[i];
00168 }
00169 info_i = LAPACKE_zgbtrs( LAPACK_COL_MAJOR, trans_i, n_i, kl_i, ku_i, nrhs_i,
00170 ab_i, ldab_i, ipiv_i, b_i, ldb_i );
00171
00172 failed = compare_zgbtrs( b, b_i, info, info_i, ldb, nrhs );
00173 if( failed == 0 ) {
00174 printf( "PASSED: column-major high-level interface to zgbtrs\n" );
00175 } else {
00176 printf( "FAILED: column-major high-level interface to zgbtrs\n" );
00177 }
00178
00179
00180
00181 for( i = 0; i < ldab*n; i++ ) {
00182 ab_i[i] = ab[i];
00183 }
00184 for( i = 0; i < n; i++ ) {
00185 ipiv_i[i] = ipiv[i];
00186 }
00187 for( i = 0; i < ldb*nrhs; i++ ) {
00188 b_i[i] = b_save[i];
00189 }
00190
00191 LAPACKE_zge_trans( LAPACK_COL_MAJOR, 2*kl+ku+1, n, ab_i, ldab, ab_r, n+2 );
00192 LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00193 info_i = LAPACKE_zgbtrs_work( LAPACK_ROW_MAJOR, trans_i, n_i, kl_i, ku_i,
00194 nrhs_i, ab_r, ldab_r, ipiv_i, b_r, ldb_r );
00195
00196 LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, nrhs, b_r, nrhs+2, b_i, ldb );
00197
00198 failed = compare_zgbtrs( b, b_i, info, info_i, ldb, nrhs );
00199 if( failed == 0 ) {
00200 printf( "PASSED: row-major middle-level interface to zgbtrs\n" );
00201 } else {
00202 printf( "FAILED: row-major middle-level interface to zgbtrs\n" );
00203 }
00204
00205
00206
00207 for( i = 0; i < ldab*n; i++ ) {
00208 ab_i[i] = ab[i];
00209 }
00210 for( i = 0; i < n; i++ ) {
00211 ipiv_i[i] = ipiv[i];
00212 }
00213 for( i = 0; i < ldb*nrhs; i++ ) {
00214 b_i[i] = b_save[i];
00215 }
00216
00217
00218 LAPACKE_zge_trans( LAPACK_COL_MAJOR, 2*kl+ku+1, n, ab_i, ldab, ab_r, n+2 );
00219 LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 );
00220 info_i = LAPACKE_zgbtrs( LAPACK_ROW_MAJOR, trans_i, n_i, kl_i, ku_i, nrhs_i,
00221 ab_r, ldab_r, ipiv_i, b_r, ldb_r );
00222
00223 LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, nrhs, b_r, nrhs+2, b_i, ldb );
00224
00225 failed = compare_zgbtrs( b, b_i, info, info_i, ldb, nrhs );
00226 if( failed == 0 ) {
00227 printf( "PASSED: row-major high-level interface to zgbtrs\n" );
00228 } else {
00229 printf( "FAILED: row-major high-level interface to zgbtrs\n" );
00230 }
00231
00232
00233 if( ab != NULL ) {
00234 LAPACKE_free( ab );
00235 }
00236 if( ab_i != NULL ) {
00237 LAPACKE_free( ab_i );
00238 }
00239 if( ab_r != NULL ) {
00240 LAPACKE_free( ab_r );
00241 }
00242 if( ipiv != NULL ) {
00243 LAPACKE_free( ipiv );
00244 }
00245 if( ipiv_i != NULL ) {
00246 LAPACKE_free( ipiv_i );
00247 }
00248 if( b != NULL ) {
00249 LAPACKE_free( b );
00250 }
00251 if( b_i != NULL ) {
00252 LAPACKE_free( b_i );
00253 }
00254 if( b_r != NULL ) {
00255 LAPACKE_free( b_r );
00256 }
00257 if( b_save != NULL ) {
00258 LAPACKE_free( b_save );
00259 }
00260
00261 return 0;
00262 }
00263
00264
00265 static void init_scalars_zgbtrs( char *trans, lapack_int *n, lapack_int *kl,
00266 lapack_int *ku, lapack_int *nrhs,
00267 lapack_int *ldab, lapack_int *ldb )
00268 {
00269 *trans = 'N';
00270 *n = 4;
00271 *kl = 1;
00272 *ku = 2;
00273 *nrhs = 2;
00274 *ldab = 25;
00275 *ldb = 8;
00276
00277 return;
00278 }
00279
00280
00281 static void init_ab( lapack_int size, lapack_complex_double *ab ) {
00282 lapack_int i;
00283 for( i = 0; i < size; i++ ) {
00284 ab[i] = lapack_make_complex_double( 0.0, 0.0 );
00285 }
00286 ab[0] = lapack_make_complex_double( 0.00000000000000000e+000,
00287 0.00000000000000000e+000 );
00288 ab[25] = lapack_make_complex_double( 0.00000000000000000e+000,
00289 0.00000000000000000e+000 );
00290 ab[50] = lapack_make_complex_double( 0.00000000000000000e+000,
00291 0.00000000000000000e+000 );
00292 ab[75] = lapack_make_complex_double( 5.89999999999999970e-001,
00293 -4.79999999999999980e-001 );
00294 ab[1] = lapack_make_complex_double( 0.00000000000000000e+000,
00295 0.00000000000000000e+000 );
00296 ab[26] = lapack_make_complex_double( 0.00000000000000000e+000,
00297 0.00000000000000000e+000 );
00298 ab[51] = lapack_make_complex_double( -3.99000000000000020e+000,
00299 4.00999999999999980e+000 );
00300 ab[76] = lapack_make_complex_double( 3.33000000000000010e+000,
00301 -1.04000000000000000e+000 );
00302 ab[2] = lapack_make_complex_double( 0.00000000000000000e+000,
00303 0.00000000000000000e+000 );
00304 ab[27] = lapack_make_complex_double( -1.48000000000000000e+000,
00305 -1.75000000000000000e+000 );
00306 ab[52] = lapack_make_complex_double( -1.06000000000000010e+000,
00307 1.93999999999999990e+000 );
00308 ab[77] = lapack_make_complex_double( -1.76920938160968100e+000,
00309 -1.85874728194578730e+000 );
00310 ab[3] = lapack_make_complex_double( 0.00000000000000000e+000,
00311 6.29999999999999980e+000 );
00312 ab[28] = lapack_make_complex_double( -7.70000000000000020e-001,
00313 2.83000000000000010e+000 );
00314 ab[53] = lapack_make_complex_double( 4.93026694117547140e+000,
00315 -3.00856374062719210e+000 );
00316 ab[78] = lapack_make_complex_double( 4.33774926590159760e-001,
00317 1.23252818156083470e-001 );
00318 ab[4] = lapack_make_complex_double( 3.58730158730158680e-001,
00319 2.61904761904761860e-001 );
00320 ab[29] = lapack_make_complex_double( 2.31426072874374280e-001,
00321 6.35764884204745640e-001 );
00322 ab[54] = lapack_make_complex_double( 7.60422661963551130e-001,
00323 2.42944258926713260e-001 );
00324 ab[79] = lapack_make_complex_double( 0.00000000000000000e+000,
00325 0.00000000000000000e+000 );
00326 }
00327 static void init_ipiv( lapack_int size, lapack_int *ipiv ) {
00328 lapack_int i;
00329 for( i = 0; i < size; i++ ) {
00330 ipiv[i] = 0;
00331 }
00332 ipiv[0] = 2;
00333 ipiv[1] = 3;
00334 ipiv[2] = 3;
00335 ipiv[3] = 4;
00336 }
00337 static void init_b( lapack_int size, lapack_complex_double *b ) {
00338 lapack_int i;
00339 for( i = 0; i < size; i++ ) {
00340 b[i] = lapack_make_complex_double( 0.0, 0.0 );
00341 }
00342 b[0] = lapack_make_complex_double( -1.06000000000000010e+000,
00343 2.15000000000000000e+001 );
00344 b[8] = lapack_make_complex_double( 1.28500000000000000e+001,
00345 2.83999999999999990e+000 );
00346 b[1] = lapack_make_complex_double( -2.27199999999999990e+001,
00347 -5.38999999999999990e+001 );
00348 b[9] = lapack_make_complex_double( -7.02199999999999990e+001,
00349 2.15700000000000000e+001 );
00350 b[2] = lapack_make_complex_double( 2.82399999999999980e+001,
00351 -3.86000000000000010e+001 );
00352 b[10] = lapack_make_complex_double( -2.07300000000000000e+001,
00353 -1.23000000000000000e+000 );
00354 b[3] = lapack_make_complex_double( -3.45600000000000020e+001,
00355 1.67300000000000000e+001 );
00356 b[11] = lapack_make_complex_double( 2.60100000000000020e+001,
00357 3.19699999999999990e+001 );
00358 }
00359
00360
00361
00362 static int compare_zgbtrs( lapack_complex_double *b, lapack_complex_double *b_i,
00363 lapack_int info, lapack_int info_i, lapack_int ldb,
00364 lapack_int nrhs )
00365 {
00366 lapack_int i;
00367 int failed = 0;
00368 for( i = 0; i < ldb*nrhs; i++ ) {
00369 failed += compare_complex_doubles(b[i],b_i[i]);
00370 }
00371 failed += (info == info_i) ? 0 : 1;
00372 if( info != 0 || info_i != 0 ) {
00373 printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00374 }
00375
00376 return failed;
00377 }