56 BLAS_error(
char *rname,
int err,
int val,
int x) {
57 fprintf( stderr,
"%s %d %d %d\n", rname, err, val, x );
64 int m,
int n,
const double *a,
int lda,
double *res) {
65 int i, j;
float anorm, v;
66 char rname[] =
"BLAS_dge_norm";
68 if (order !=
blas_colmajor) BLAS_error( rname, -1, order, 0 );
80 anorm = sqrt( anorm );
83 for (i = 0; i < m; ++i) {
85 for (j = 0; j < n; ++j) {
86 v += fabs( a[i + j * lda] );
92 BLAS_error( rname, -2, norm, 0 );
96 if (res) *res = anorm;
101 BLAS_dpow_di(
double x,
int n) {
109 for (; n; n >>= 1, x *= x) {
120 double eps = 1.0, r = 1.0, o = 1.0, b = 2.0;
121 int t = 53, l = 1024, m = -1021;
122 char rname[] =
"BLAS_dfpinfo";
124 if ((
sizeof eps) ==
sizeof(
float)) {
135 eps = BLAS_dpow_di( b, -t );
137 r = BLAS_dpow_di( b, m-1 );
141 o = (o * BLAS_dpow_di( b, l-1 )) * b;
147 BLAS_error( rname, -1, cmach, 0 );
153 static int check_solution(
int,
int ,
double *,
int,
double *,
double *,
int,
double);
159 USAGE(
"GESV",
"N LDA NRHS LDB",
160 " - N : the size of the matrix\n"
161 " - LDA : leading dimension of the matrix A\n"
162 " - NRHS : number of RHS\n"
163 " - LDB : leading dimension of the matrix B\n");
167 int N = atoi(argv[0]);
168 int LDA = atoi(argv[1]);
169 int NRHS = atoi(argv[2]);
170 int LDB = atoi(argv[3]);
175 int LDBxNRHS = LDB*NRHS;
177 double *A1 = (
double *)malloc(LDA*N *
sizeof(
double));
178 double *A2 = (
double *)malloc(LDA*N *
sizeof(
double));
179 double *B1 = (
double *)malloc(LDB*NRHS*
sizeof(
double));
180 double *B2 = (
double *)malloc(LDB*NRHS*
sizeof(
double));
181 int *
IPIV = (
int *)malloc(N*
sizeof(
int));
184 if ( (!A1) || (!A2)|| (!B1) || (!B2) || (!IPIV) ) {
185 printf(
"Out of Memory \n ");
196 LAPACKE_dlarnv_work(
IONE,
ISEED, LDAxN, A1);
197 for ( i = 0; i < N; i++)
198 for ( j = 0; j < N; j++)
199 A2[LDA*j+i] = A1[LDA*j+i];
202 LAPACKE_dlarnv_work(
IONE,
ISEED, LDBxNRHS, B1);
203 for ( i = 0; i < N; i++)
204 for ( j = 0; j < NRHS; j++)
205 B2[LDB*j+i] = B1[LDB*j+i];
211 printf(
"------ TESTS FOR PLASMA DGESV ROUTINE ------- \n");
212 printf(
" Size of the Matrix %d by %d\n", N, N);
214 printf(
" The matrix A is randomly generated for each test.\n");
215 printf(
"============\n");
216 printf(
" The relative machine precision (eps) is to be %e \n", eps);
217 printf(
" Computational tests pass if scaled residuals are less than 60.\n");
220 info_solution =
check_solution(N, NRHS, A1, LDA, B1, B2, LDB, eps);
222 if ((info_solution == 0)){
223 printf(
"***************************************************\n");
224 printf(
" ---- TESTING DGESV ...................... PASSED !\n");
225 printf(
"***************************************************\n");
228 printf(
"************************************************\n");
229 printf(
" - TESTING DGESV ... FAILED !\n");
230 printf(
"************************************************\n");
238 LAPACKE_dlarnv_work(
IONE,
ISEED, LDAxN, A1);
239 for ( i = 0; i < N; i++)
240 for ( j = 0; j < N; j++)
241 A2[LDA*j+i] = A1[LDA*j+i];
244 LAPACKE_dlarnv_work(
IONE,
ISEED, LDBxNRHS, B1);
245 for ( i = 0; i < N; i++)
246 for ( j = 0; j < NRHS; j++)
247 B2[LDB*j+i] = B1[LDB*j+i];
254 printf(
"------ TESTS FOR PLASMA DGETRF + DGETRS ROUTINE ------- \n");
255 printf(
" Size of the Matrix %d by %d\n", N, N);
257 printf(
" The matrix A is randomly generated for each test.\n");
258 printf(
"============\n");
259 printf(
" The relative machine precision (eps) is to be %e \n", eps);
260 printf(
" Computational tests pass if scaled residuals are less than 60.\n");
263 info_solution =
check_solution(N, NRHS, A1, LDA, B1, B2, LDB, eps);
265 if ((info_solution == 0)){
266 printf(
"***************************************************\n");
267 printf(
" ---- TESTING DGETRF + DGETRS ............ PASSED !\n");
268 printf(
"***************************************************\n");
271 printf(
"***************************************************\n");
272 printf(
" - TESTING DGETRF + DGETRS ... FAILED !\n");
273 printf(
"***************************************************\n");
281 LAPACKE_dlarnv_work(
IONE,
ISEED, LDAxN, A1);
282 for ( i = 0; i < N; i++)
283 for ( j = 0; j < N; j++)
284 A2[LDA*j+i] = A1[LDA*j+i];
287 LAPACKE_dlarnv_work(
IONE,
ISEED, LDBxNRHS, B1);
288 for ( i = 0; i < N; i++)
289 for ( j = 0; j < NRHS; j++)
290 B2[LDB*j+i] = B1[LDB*j+i];
296 N, NRHS, 1.0, A2, LDA, B2, LDB);
298 N, NRHS, 1.0, A2, LDA, B2, LDB);
301 printf(
"------ TESTS FOR PLASMA DGETRF + DLASWP + DTRSM + DTRSM ROUTINE ------- \n");
302 printf(
" Size of the Matrix %d by %d\n", N, N);
304 printf(
" The matrix A is randomly generated for each test.\n");
305 printf(
"============\n");
306 printf(
" The relative machine precision (eps) is to be %e \n", eps);
307 printf(
" Computational tests pass if scaled residuals are less than 60.\n");
310 info_solution =
check_solution(N, NRHS, A1, LDA, B1, B2, LDB, eps);
312 if ((info_solution == 0)){
313 printf(
"***************************************************\n");
314 printf(
" ---- TESTING DGETRF + DLASWP + DTRSM + DTRSM ... PASSED !\n");
315 printf(
"***************************************************\n");
318 printf(
"**************************************************\n");
319 printf(
" - TESTING DGETRF + DLASWP + DTRSM + DTRSM ... FAILED !\n");
320 printf(
"**************************************************\n");
323 free(A1); free(A2); free(B1); free(B2); free(IPIV);
332 static int check_solution(
int N,
int NRHS,
double *A1,
int LDA,
double *B1,
double *B2,
int LDB,
double eps )
335 double Rnorm, Anorm, Xnorm, Bnorm, result;
337 double *work = (
double *)malloc(N*
sizeof(
double));
346 cblas_dgemm(
CblasColMajor,
CblasNoTrans,
CblasNoTrans, N, NRHS, N, (alpha), A1, LDA, B2, LDB, (beta), B1, LDB);
349 if (getenv(
"PLASMA_TESTING_VERBOSE"))
350 printf(
"||A||_oo=%f\n||X||_oo=%f\n||B||_oo=%f\n||A X - B||_oo=%e\n", Anorm, Xnorm, Bnorm, Rnorm );
352 result = Rnorm / ( (Anorm*Xnorm+Bnorm)*N*eps ) ;
353 printf(
"============\n");
354 printf(
"Checking the Residual of the solution \n");
355 printf(
"-- ||Ax-B||_oo/((||A||_oo||x||_oo+||B||_oo).N.eps) = %e \n", result);
357 if ( isnan(Xnorm) || isinf(Xnorm) || isnan(result) || isinf(result) || (result > 60.0) ) {
358 printf(
"-- The solution is suspicious ! \n");
362 printf(
"-- The solution is CORRECT ! \n");
366 return info_solution;