27 static int check_inverse(
int,
double *,
double *,
int,
int*,
double);
34 USAGE(
"GETRI",
"N LDA",
35 " - N : the size of the matrix\n"
36 " - LDA : leading dimension of the matrix A\n");
40 int N = atoi(argv[0]);
41 int LDA = atoi(argv[1]);
43 int info_inverse, info_factorization;
46 double *A1 = (
double *)malloc(LDA*N*
sizeof(
double));
47 double *A2 = (
double *)malloc(LDA*N*
sizeof(
double));
48 double *WORK = (
double *)malloc(2*LDA*
sizeof(
double));
49 double *D = (
double *)malloc(LDA*
sizeof(
double));
50 int *
IPIV = (
int *)malloc(N*
sizeof(
int));
53 if ( (!A1) || (!A2) || (!IPIV) ){
54 printf(
"Out of Memory \n ");
58 eps = LAPACKE_dlamch_work(
'e');
66 for ( i = 0; i < N; i++)
67 for ( j = 0; j < N; j++)
68 A2[LDA*j+i] = A1[LDA*j+i];
71 printf(
"------ TESTS FOR PLASMA DGETRI ROUTINE ------- \n");
72 printf(
" Size of the Matrix %d by %d\n", N, N);
74 printf(
" The matrix A is randomly generated for each test.\n");
75 printf(
"============\n");
76 printf(
" The relative machine precision (eps) is to be %e \n", eps);
77 printf(
" Computational tests pass if scaled residuals are less than 60.\n");
89 info_inverse = check_inverse(N, A1, A2, LDA, IPIV, eps);
91 if ( (info_inverse == 0) && (info_factorization == 0) ) {
92 printf(
"***************************************************\n");
93 printf(
" ---- TESTING DGETRI ..................... PASSED !\n");
94 printf(
"***************************************************\n");
97 printf(
"***************************************************\n");
98 printf(
" - TESTING DGETRI ... FAILED !\n");
99 printf(
"***************************************************\n");
102 free(A1); free(A2); free(IPIV); free(WORK); free(D);
113 int info_factorization;
114 double Rnorm, Anorm, Xnorm, Bnorm, result;
116 double *work = (
double *)malloc(N*
sizeof(
double));
121 double *b = (
double *)malloc(LDA*
sizeof(
double));
122 double *x = (
double *)malloc(LDA*
sizeof(
double));
124 LAPACKE_dlarnv_work(1,
ISEED, LDA, x);
125 LAPACKE_dlacpy_work(LAPACK_COL_MAJOR,
'A', N, 1, x, LDA, b, LDA);
134 alpha, A1, LDA, x, LDA, beta, b, LDA);
138 if (getenv(
"PLASMA_TESTING_VERBOSE"))
139 printf(
"||A||_oo=%f\n||X||_oo=%f\n||B||_oo=%f\n||A X - B||_oo=%e\n", Anorm, Xnorm, Bnorm, Rnorm );
141 result = Rnorm / ( (Anorm*Xnorm+Bnorm)*N*eps ) ;
142 printf(
"============\n");
143 printf(
"Checking the Residual of the solution \n");
144 printf(
"-- ||Ax-B||_oo/((||A||_oo||x||_oo+||B||_oo).N.eps) = %e \n", result);
146 if ( isnan(Xnorm) || isinf(Xnorm) || isnan(result) || isinf(result) || (result > 60.0) ) {
147 printf(
"-- The factorization is suspicious ! \n");
148 info_factorization = 1;
151 printf(
"-- The factorization is CORRECT ! \n");
152 info_factorization = 0;
154 free(x); free(b); free(work);
156 return info_factorization;
164 static int check_inverse(
int N,
double *A1,
double *A2,
int LDA,
int *IPIV,
double eps )
168 double Rnorm, Anorm, Ainvnorm, result;
169 double alpha, beta, zone;
170 double *
W = (
double *)malloc(N*
sizeof(
double));
171 double *work = (
double *)malloc(N*N*
sizeof(
double));
177 PLASMA_dgemm(
PlasmaNoTrans,
PlasmaNoTrans, N, N, N, alpha, A2, LDA, A1, LDA, beta, work, N);
181 *(work+i+i*N) = *(work+i+i*N) + zone;
187 if (getenv(
"PLASMA_TESTING_VERBOSE"))
188 printf(
"||A||_1=%f\n||Ainv||_1=%f\n||Id - A*Ainv||_1=%e\n", Anorm, Ainvnorm, Rnorm );
190 result = Rnorm / ( (Anorm*Ainvnorm)*N*eps ) ;
191 printf(
"============\n");
192 printf(
"Checking the Residual of the inverse \n");
193 printf(
"-- ||Id - A*Ainv||_1/((||A||_1||Ainv||_1).N.eps) = %e \n", result);
195 if ( isnan(Ainvnorm) || isinf(Ainvnorm) || isnan(result) || isinf(result) || (result > 60.0) ) {
196 printf(
"-- The inverse is suspicious ! \n");
200 printf(
"-- The inverse is CORRECT ! \n");