28 #define max(a, b) ((a) > (b) ? (a) : (b))
31 #define min(a, b) ((a) < (b) ? (a) : (b))
41 int main (
int argc,
char **argv)
45 printf(
" Proper Usage is : ./testing_zcgels ncores M N LDA NRHS LDB with \n - ncores : number of cores \n - M : number of rows of the matrix A \n - N : number of columns of the matrix A \n - LDA : leading dimension of the matrix A \n - NRHS : number of RHS \n - LDB : leading dimension of the matrix B\n");
49 int cores = atoi(argv[1]);
50 int M = atoi(argv[2]);
51 int N = atoi(argv[3]);
52 int LDA = atoi(argv[4]);
53 int NRHS = atoi(argv[5]);
54 int LDB = atoi(argv[6]);
60 int info, info_solution;
64 int LDBxNRHS = LDB*NRHS;
74 if ((!A1)||(!A2)||(!B1)||(!B2)||(!Q)||(!X)){
75 printf(
"Out of Memory \n ");
88 eps = LAPACKE_dlamch_work(
'e');
95 LAPACKE_zlarnv_work(
IONE,
ISEED, LDAxN, A1);
96 for (i = 0; i < M; i++)
97 for (j = 0; j < N; j++)
98 A2[LDA*j+i] = A1[LDA*j+i] ;
101 LAPACKE_zlarnv_work(
IONE,
ISEED, LDBxNRHS, B1);
102 for (i = 0; i < M; i++)
103 for (j = 0; j < NRHS; j++)
104 B2[LDB*j+i] = B1[LDB*j+i] ;
106 for (i = 0; i < K; i++)
110 printf(
"------ TESTS FOR PLASMA ZCGELS ROUTINE ------- \n");
111 printf(
" Size of the Matrix %d by %d\n", M, N);
113 printf(
" The matrix A is randomly generated for each test.\n");
114 printf(
"============\n");
115 printf(
" The relative machine precision (eps) is to be %e \n",eps);
116 printf(
" Computational tests pass if scaled residuals are less than 60.\n");
119 info =
PLASMA_zcgels(
PlasmaNoTrans, M, N, NRHS, A2, LDA, B2, LDB, X, LDX, &ITER);
121 printf(
"PLASMA_zcgels is not completed: info = %d\n", info);
124 printf(
" Solution obtained with %d iterations\n", ITER);
136 info_solution =
check_solution(M, N, NRHS, A1, LDA, B1, X, LDB, eps);
140 if (info_solution == 0) {
141 printf(
"***************************************************\n");
142 printf(
" ---- TESTING ZCGELS ..................... PASSED !\n");
143 printf(
"***************************************************\n");
146 printf(
"************************************************\n");
147 printf(
" - TESTING ZCGELS .. FAILED !\n");
148 printf(
"************************************************\n");
152 free(A1); free(A2); free(B1); free(B2); free(X); free(Q);
169 int minMN =
min(M, N);
171 double *work = (
double *)malloc(minMN*
sizeof(
double));
179 for (i = 0; i < minMN; i++)
184 cblas_zherk(
CblasColMajor,
CblasUpper,
CblasConjTrans, N, M, alpha, Q, LDQ, beta, Id, N);
186 cblas_zherk(
CblasColMajor,
CblasUpper,
CblasNoTrans, M, N, alpha, Q, LDQ, beta, Id, M);
190 printf(
"============\n");
191 printf(
"Checking the orthogonality of Q \n");
192 printf(
"||Id-Q'*Q||_oo / (N*eps) = %e \n",normQ/(minMN*eps));
194 if ( isnan(normQ / (minMN * eps)) || isinf(normQ / (minMN * eps)) || (normQ / (minMN * eps) > 60.0) ) {
195 printf(
"-- Orthogonality is suspicious ! \n");
199 printf(
"-- Orthogonality is CORRECT ! \n");
203 free(work); free(Id);
216 int info_factorization;
221 double *work = (
double *)malloc(
max(M,N)*
sizeof(double));
230 LAPACKE_zlacpy_work(LAPACK_COL_MAJOR,
'u', M, N, A2, LDA, R, N);
234 cblas_zgemm(
CblasColMajor,
CblasNoTrans,
CblasNoTrans, M, N, N,
CBLAS_SADDR(alpha), Q, LDA, R, N,
CBLAS_SADDR(beta), Ql, M);
241 LAPACKE_zlacpy_work(LAPACK_COL_MAJOR,
'l', M, N, A2, LDA, L, M);
245 cblas_zgemm(
CblasColMajor,
CblasNoTrans,
CblasNoTrans, M, N, M,
CBLAS_SADDR(alpha), L, M, Q, LDA,
CBLAS_SADDR(beta), Ql, M);
250 for (i = 0; i < M; i++)
251 for (j = 0 ; j < N; j++)
252 Residual[j*M+i] = A1[j*LDA+i]-Ql[j*M+i];
258 printf(
"============\n");
259 printf(
"Checking the QR Factorization \n");
260 printf(
"-- ||A-QR||_oo/(||A||_oo.N.eps) = %e \n",Rnorm/(Anorm*N*eps));
263 printf(
"============\n");
264 printf(
"Checking the LQ Factorization \n");
265 printf(
"-- ||A-LQ||_oo/(||A||_oo.N.eps) = %e \n",Rnorm/(Anorm*N*eps));
268 if (isnan(Rnorm / (Anorm * N *eps)) || isinf(Rnorm / (Anorm * N *eps)) || (Rnorm / (Anorm * N * eps) > 60.0) ) {
269 printf(
"-- Factorization is suspicious ! \n");
270 info_factorization = 1;
273 printf(
"-- Factorization is CORRECT ! \n");
274 info_factorization = 0;
277 free(work); free(Ql); free(Residual);
279 return info_factorization;
289 double Rnorm, Anorm, Xnorm, Bnorm;
292 double *work = (
double *)malloc(
max(M, N)*
sizeof(double));
301 cblas_zgemm(
CblasColMajor,
CblasNoTrans,
CblasNoTrans, M, NRHS, N,
CBLAS_SADDR(alpha), A1, LDA, B2, LDB,
CBLAS_SADDR(beta), B1, LDB);
306 cblas_zgemm(
CblasColMajor,
CblasConjTrans,
CblasNoTrans, N, NRHS, M,
CBLAS_SADDR(alpha), A1, LDA, B1, LDB,
CBLAS_SADDR(beta), Residual, M);
313 cblas_zgemm(
CblasColMajor,
CblasConjTrans,
CblasNoTrans, N, NRHS, M,
CBLAS_SADDR(alpha), A1, LDA, B1, LDB,
CBLAS_SADDR(beta), Residual, N);
318 result = Rnorm / ( (Anorm*Xnorm+Bnorm)*N*eps ) ;
319 printf(
"============\n");
320 printf(
"Checking the Residual of the solution \n");
321 printf(
"-- ||Ax-B||_oo/((||A||_oo||x||_oo+||B||_oo).N.eps) = %e \n", result);
323 if ( isnan(Xnorm) || isinf(Xnorm) || isnan(result) || isinf(result) || (result > 60.0) ) {
324 printf(
"-- The solution is suspicious ! \n");
328 printf(
"-- The solution is CORRECT ! \n");
332 return info_solution;