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_dgbtrf( lapack_int *m, lapack_int *n, lapack_int *kl,
00055 lapack_int *ku, lapack_int *ldab );
00056 static void init_ab( lapack_int size, double *ab );
00057 static void init_ipiv( lapack_int size, lapack_int *ipiv );
00058 static int compare_dgbtrf( double *ab, double *ab_i, lapack_int *ipiv,
00059 lapack_int *ipiv_i, lapack_int info,
00060 lapack_int info_i, lapack_int ldab, lapack_int m,
00061 lapack_int n );
00062
00063 int main(void)
00064 {
00065
00066 lapack_int m, m_i;
00067 lapack_int n, n_i;
00068 lapack_int kl, kl_i;
00069 lapack_int ku, ku_i;
00070 lapack_int ldab, ldab_i;
00071 lapack_int ldab_r;
00072 lapack_int info, info_i;
00073 lapack_int i;
00074 int failed;
00075
00076
00077 double *ab = NULL, *ab_i = NULL;
00078 lapack_int *ipiv = NULL, *ipiv_i = NULL;
00079 double *ab_save = NULL;
00080 lapack_int *ipiv_save = NULL;
00081 double *ab_r = NULL;
00082
00083
00084 init_scalars_dgbtrf( &m, &n, &kl, &ku, &ldab );
00085 ldab_r = n+2;
00086 m_i = m;
00087 n_i = n;
00088 kl_i = kl;
00089 ku_i = ku;
00090 ldab_i = ldab;
00091
00092
00093 ab = (double *)LAPACKE_malloc( ldab*n * sizeof(double) );
00094 ipiv = (lapack_int *)LAPACKE_malloc( MIN(m,n) * sizeof(lapack_int) );
00095
00096
00097 ab_i = (double *)LAPACKE_malloc( ldab*n * sizeof(double) );
00098 ipiv_i = (lapack_int *)LAPACKE_malloc( MIN(m,n) * sizeof(lapack_int) );
00099
00100
00101 ab_save = (double *)LAPACKE_malloc( ldab*n * sizeof(double) );
00102 ipiv_save = (lapack_int *)LAPACKE_malloc( MIN(m,n) * sizeof(lapack_int) );
00103
00104
00105 ab_r = (double *)LAPACKE_malloc( ((2*kl+ku+1)*(n+2)) * sizeof(double) );
00106
00107
00108 init_ab( ldab*n, ab );
00109 init_ipiv( (MIN(m,n)), ipiv );
00110
00111
00112 for( i = 0; i < ldab*n; i++ ) {
00113 ab_save[i] = ab[i];
00114 }
00115 for( i = 0; i < (MIN(m,n)); i++ ) {
00116 ipiv_save[i] = ipiv[i];
00117 }
00118
00119
00120 dgbtrf_( &m, &n, &kl, &ku, ab, &ldab, ipiv, &info );
00121
00122
00123
00124 for( i = 0; i < ldab*n; i++ ) {
00125 ab_i[i] = ab_save[i];
00126 }
00127 for( i = 0; i < (MIN(m,n)); i++ ) {
00128 ipiv_i[i] = ipiv_save[i];
00129 }
00130 info_i = LAPACKE_dgbtrf_work( LAPACK_COL_MAJOR, m_i, n_i, kl_i, ku_i, ab_i,
00131 ldab_i, ipiv_i );
00132
00133 failed = compare_dgbtrf( ab, ab_i, ipiv, ipiv_i, info, info_i, ldab, m, n );
00134 if( failed == 0 ) {
00135 printf( "PASSED: column-major middle-level interface to dgbtrf\n" );
00136 } else {
00137 printf( "FAILED: column-major middle-level interface to dgbtrf\n" );
00138 }
00139
00140
00141
00142 for( i = 0; i < ldab*n; i++ ) {
00143 ab_i[i] = ab_save[i];
00144 }
00145 for( i = 0; i < (MIN(m,n)); i++ ) {
00146 ipiv_i[i] = ipiv_save[i];
00147 }
00148 info_i = LAPACKE_dgbtrf( LAPACK_COL_MAJOR, m_i, n_i, kl_i, ku_i, ab_i,
00149 ldab_i, ipiv_i );
00150
00151 failed = compare_dgbtrf( ab, ab_i, ipiv, ipiv_i, info, info_i, ldab, m, n );
00152 if( failed == 0 ) {
00153 printf( "PASSED: column-major high-level interface to dgbtrf\n" );
00154 } else {
00155 printf( "FAILED: column-major high-level interface to dgbtrf\n" );
00156 }
00157
00158
00159
00160 for( i = 0; i < ldab*n; i++ ) {
00161 ab_i[i] = ab_save[i];
00162 }
00163 for( i = 0; i < (MIN(m,n)); i++ ) {
00164 ipiv_i[i] = ipiv_save[i];
00165 }
00166
00167 LAPACKE_dge_trans( LAPACK_COL_MAJOR, 2*kl+ku+1, n, ab_i, ldab, ab_r, n+2 );
00168 info_i = LAPACKE_dgbtrf_work( LAPACK_ROW_MAJOR, m_i, n_i, kl_i, ku_i, ab_r,
00169 ldab_r, ipiv_i );
00170
00171 LAPACKE_dge_trans( LAPACK_ROW_MAJOR, 2*kl+ku+1, n, ab_r, n+2, ab_i, ldab );
00172
00173 failed = compare_dgbtrf( ab, ab_i, ipiv, ipiv_i, info, info_i, ldab, m, n );
00174 if( failed == 0 ) {
00175 printf( "PASSED: row-major middle-level interface to dgbtrf\n" );
00176 } else {
00177 printf( "FAILED: row-major middle-level interface to dgbtrf\n" );
00178 }
00179
00180
00181
00182 for( i = 0; i < ldab*n; i++ ) {
00183 ab_i[i] = ab_save[i];
00184 }
00185 for( i = 0; i < (MIN(m,n)); i++ ) {
00186 ipiv_i[i] = ipiv_save[i];
00187 }
00188
00189
00190 LAPACKE_dge_trans( LAPACK_COL_MAJOR, 2*kl+ku+1, n, ab_i, ldab, ab_r, n+2 );
00191 info_i = LAPACKE_dgbtrf( LAPACK_ROW_MAJOR, m_i, n_i, kl_i, ku_i, ab_r,
00192 ldab_r, ipiv_i );
00193
00194 LAPACKE_dge_trans( LAPACK_ROW_MAJOR, 2*kl+ku+1, n, ab_r, n+2, ab_i, ldab );
00195
00196 failed = compare_dgbtrf( ab, ab_i, ipiv, ipiv_i, info, info_i, ldab, m, n );
00197 if( failed == 0 ) {
00198 printf( "PASSED: row-major high-level interface to dgbtrf\n" );
00199 } else {
00200 printf( "FAILED: row-major high-level interface to dgbtrf\n" );
00201 }
00202
00203
00204 if( ab != NULL ) {
00205 LAPACKE_free( ab );
00206 }
00207 if( ab_i != NULL ) {
00208 LAPACKE_free( ab_i );
00209 }
00210 if( ab_r != NULL ) {
00211 LAPACKE_free( ab_r );
00212 }
00213 if( ab_save != NULL ) {
00214 LAPACKE_free( ab_save );
00215 }
00216 if( ipiv != NULL ) {
00217 LAPACKE_free( ipiv );
00218 }
00219 if( ipiv_i != NULL ) {
00220 LAPACKE_free( ipiv_i );
00221 }
00222 if( ipiv_save != NULL ) {
00223 LAPACKE_free( ipiv_save );
00224 }
00225
00226 return 0;
00227 }
00228
00229
00230 static void init_scalars_dgbtrf( lapack_int *m, lapack_int *n, lapack_int *kl,
00231 lapack_int *ku, lapack_int *ldab )
00232 {
00233 *m = 4;
00234 *n = 4;
00235 *kl = 1;
00236 *ku = 2;
00237 *ldab = 25;
00238
00239 return;
00240 }
00241
00242
00243 static void init_ab( lapack_int size, double *ab ) {
00244 lapack_int i;
00245 for( i = 0; i < size; i++ ) {
00246 ab[i] = 0;
00247 }
00248 ab[0] = 0.00000000000000000e+000;
00249 ab[25] = 0.00000000000000000e+000;
00250 ab[50] = 0.00000000000000000e+000;
00251 ab[75] = 0.00000000000000000e+000;
00252 ab[1] = 0.00000000000000000e+000;
00253 ab[26] = 0.00000000000000000e+000;
00254 ab[51] = -3.66000000000000010e+000;
00255 ab[76] = -2.12999999999999990e+000;
00256 ab[2] = 0.00000000000000000e+000;
00257 ab[27] = 2.54000000000000000e+000;
00258 ab[52] = -2.73000000000000000e+000;
00259 ab[77] = 4.07000000000000030e+000;
00260 ab[3] = -2.30000000000000010e-001;
00261 ab[28] = 2.46000000000000000e+000;
00262 ab[53] = 2.46000000000000000e+000;
00263 ab[78] = -3.81999999999999980e+000;
00264 ab[4] = -6.98000000000000040e+000;
00265 ab[29] = 2.56000000000000010e+000;
00266 ab[54] = -4.78000000000000020e+000;
00267 ab[79] = 0.00000000000000000e+000;
00268 }
00269 static void init_ipiv( lapack_int size, lapack_int *ipiv ) {
00270 lapack_int i;
00271 for( i = 0; i < size; i++ ) {
00272 ipiv[i] = 0;
00273 }
00274 }
00275
00276
00277
00278 static int compare_dgbtrf( double *ab, double *ab_i, lapack_int *ipiv,
00279 lapack_int *ipiv_i, lapack_int info,
00280 lapack_int info_i, lapack_int ldab, lapack_int m,
00281 lapack_int n )
00282 {
00283 lapack_int i;
00284 int failed = 0;
00285 for( i = 0; i < ldab*n; i++ ) {
00286 failed += compare_doubles(ab[i],ab_i[i]);
00287 }
00288 for( i = 0; i < (MIN(m,n)); i++ ) {
00289 failed += (ipiv[i] == ipiv_i[i]) ? 0 : 1;
00290 }
00291 failed += (info == info_i) ? 0 : 1;
00292 if( info != 0 || info_i != 0 ) {
00293 printf( "info=%d, info_i=%d\n",(int)info,(int)info_i );
00294 }
00295
00296 return failed;
00297 }