54 BLAS_error(
char *rname,
int err,
int val,
int x) {
55 fprintf( stderr,
"%s %d %d %d\n", rname, err, val, x );
62 int m,
int n,
const double *a,
int lda,
double *res) {
63 int i, j;
float anorm, v;
64 char rname[] =
"BLAS_dge_norm";
66 if (order !=
blas_colmajor) BLAS_error( rname, -1, order, 0 );
78 anorm = sqrt( anorm );
81 for (i = 0; i < m; ++i) {
83 for (j = 0; j < n; ++j) {
84 v += fabs( a[i + j * lda] );
91 for (i = 0; i < m; ++i) {
93 for (j = 0; j < n; ++j) {
94 v += fabs( a[i + j * lda] );
100 BLAS_error( rname, -2, norm, 0 );
104 if (res) *res = anorm;
109 BLAS_dpow_di(
double x,
int n) {
117 for (; n; n >>= 1, x *= x) {
128 double eps = 1.0, r = 1.0, o = 1.0, b = 2.0;
129 int t = 53, l = 1024, m = -1021;
130 char rname[] =
"BLAS_dfpinfo";
132 if ((
sizeof eps) ==
sizeof(
float)) {
143 eps = BLAS_dpow_di( b, -t );
145 r = BLAS_dpow_di( b, m-1 );
149 o = (o * BLAS_dpow_di( b, l-1 )) * b;
155 BLAS_error( rname, -1, cmach, 0 );
162 static int check_inverse(
int,
double *,
double *,
int,
int,
double);
169 USAGE(
"POTRI",
"N LDA",
170 " - N : the size of the matrix\n"
171 " - LDA : leading dimension of the matrix A\n");
175 int N = atoi(argv[0]);
176 int LDA = atoi(argv[1]);
179 int info_inverse, info_factorization;
181 double *A1 = (
double *)malloc(LDA*N*
sizeof(
double));
182 double *A2 = (
double *)malloc(LDA*N*
sizeof(
double));
183 double *WORK = (
double *)malloc(2*LDA*
sizeof(
double));
187 printf(
"Out of Memory \n ");
204 printf(
"------ TESTS FOR PLASMA DPOTRI ROUTINE ------- \n");
205 printf(
" Size of the Matrix %d by %d\n", N, N);
207 printf(
" The matrix A is randomly generated for each test.\n");
208 printf(
"============\n");
209 printf(
" The relative machine precision (eps) is to be %e \n", eps);
210 printf(
" Computational tests pass if scaled residuals are less than 60.\n");
222 info_inverse = check_inverse(N, A1, A2, LDA, uplo, eps);
224 if ( (info_inverse == 0) && (info_factorization == 0) ) {
225 printf(
"***************************************************\n");
226 printf(
" ---- TESTING DPOTRI ..................... PASSED !\n");
227 printf(
"***************************************************\n");
230 printf(
"***************************************************\n");
231 printf(
" - TESTING DPOTRI ... FAILED !\n");
232 printf(
"***************************************************\n");
235 free(A1); free(A2); free(WORK);
248 int info_factorization;
251 double *Residual = (
double *)malloc(N*N*
sizeof(
double));
252 double *L1 = (
double *)malloc(N*N*
sizeof(
double));
253 double *L2 = (
double *)malloc(N*N*
sizeof(
double));
254 double *work = (
double *)malloc(N*
sizeof(
double));
256 memset((
void*)L1, 0, N*N*
sizeof(
double));
257 memset((
void*)L2, 0, N*N*
sizeof(
double));
261 LAPACKE_dlacpy_work(LAPACK_COL_MAJOR,
' ', N, N, A1, LDA, Residual, N);
265 LAPACKE_dlacpy_work(LAPACK_COL_MAJOR,
'u', N, N, A2, LDA, L1, N);
266 LAPACKE_dlacpy_work(LAPACK_COL_MAJOR,
'u', N, N, A2, LDA, L2, N);
267 cblas_dtrmm(
CblasColMajor,
CblasLeft,
CblasUpper,
CblasTrans,
CblasNonUnit, N, N, (alpha), L1, N, L2, N);
270 LAPACKE_dlacpy_work(LAPACK_COL_MAJOR,
'l', N, N, A2, LDA, L1, N);
271 LAPACKE_dlacpy_work(LAPACK_COL_MAJOR,
'l', N, N, A2, LDA, L2, N);
272 cblas_dtrmm(
CblasColMajor,
CblasRight,
CblasLower,
CblasTrans,
CblasNonUnit, N, N, (alpha), L1, N, L2, N);
276 for (i = 0; i < N; i++)
277 for (j = 0; j < N; j++)
278 Residual[j*N+i] = L2[j*N+i] - Residual[j*N+i];
283 printf(
"============\n");
284 printf(
"Checking the Cholesky Factorization \n");
285 printf(
"-- ||L'L-A||_oo/(||A||_oo.N.eps) = %e \n",Rnorm/(Anorm*N*eps));
287 if ( isnan(Rnorm/(Anorm*N*eps)) || isinf(Rnorm/(Anorm*N*eps)) || (Rnorm/(Anorm*N*eps) > 60.0) ){
288 printf(
"-- Factorization is suspicious ! \n");
289 info_factorization = 1;
292 printf(
"-- Factorization is CORRECT ! \n");
293 info_factorization = 0;
296 free(Residual); free(L1); free(L2); free(work);
298 return info_factorization;
306 static int check_inverse(
int N,
double *A1,
double *A2,
int LDA,
int uplo,
double eps )
310 double Rnorm, Anorm, Ainvnorm, result;
311 double alpha, beta, zone;
312 double *work = (
double *)malloc(N*N*
sizeof(
double));
322 *(A2+j+i*LDA) = *(A2+i+j*LDA);
323 cblas_dsymm(
CblasColMajor,
CblasLeft,
CblasUpper, N, N, (alpha), A2, LDA, A1, LDA, (beta), work, N);
329 *(A2+j+i*LDA) = *(A2+i+j*LDA);
330 cblas_dsymm(
CblasColMajor,
CblasLeft,
CblasLower, N, N, (alpha), A2, LDA, A1, LDA, (beta), work, N);
335 *(work+i+i*N) = *(work+i+i*N) + zone;
341 if (getenv(
"PLASMA_TESTING_VERBOSE"))
342 printf(
"||A||_1=%f\n||Ainv||_1=%f\n||Id - A*Ainv||_1=%e\n", Anorm, Ainvnorm, Rnorm );
344 result = Rnorm / ( (Anorm*Ainvnorm)*N*eps ) ;
345 printf(
"============\n");
346 printf(
"Checking the Residual of the inverse \n");
347 printf(
"-- ||Id - A*Ainv||_1/((||A||_1||Ainv||_1).N.eps) = %e \n", result);
349 if ( isnan(Ainvnorm) || isinf(Ainvnorm) || isnan(result) || isinf(result) || (result > 60.0) ) {
350 printf(
"-- The inverse is suspicious ! \n");
354 printf(
"-- The inverse is CORRECT ! \n");