44 if ( ((tree == 0) && (argc != 4)) ||
45 ((tree != 0) && (argc != 5)) ){
47 USAGE(
"GESVD",
"MODE M N LDA [RH]",
48 " - MODE : 0: flat, 1: tree (RH needed)\n"
49 " - M : number of rows of the matrix A\n"
50 " - N : number of columns of the matrix A\n"
51 " - LDA : leading dimension of the matrix A\n"
52 " - RH : Size of each subdomains\n");
56 int M = atoi(argv[1]);
57 int N = atoi(argv[2]);
58 int LDA = atoi(argv[3]);
67 printf(
"LDA should be >= M !\n");
71 float eps = LAPACKE_slamch_work(
'e');
77 int info_solution = 0;
78 int info_reduction = 0;
79 int minMN =
min(M, N);
81 float rcond = (float) minMN;
84 float *S1 = (
float *) malloc(minMN*
sizeof(
float));
85 float *S2 = (
float *) malloc(minMN*
sizeof(
float));
93 if ( (!A1) || (!S1) || (!S2) || (!work) ) {
94 printf(
"Out of Memory \n ");
112 LAPACKE_clatms_work( LAPACK_COL_MAJOR, M, N,
122 LAPACKE_clacpy_work(LAPACK_COL_MAJOR,
'A', M, N, A1, LDA, A2, LDA);
126 LAPACKE_claset_work(LAPACK_COL_MAJOR,
'A', M, M, 0., 1., U, M);
130 LAPACKE_claset_work(LAPACK_COL_MAJOR,
'A', N, N, 0., 1., VT, N);
134 PLASMA_cgesvd(vecu, vecvt, M, N, A1, LDA, S2, U, M, VT, N, T);
136 if (getenv(
"PLASMA_TESTING_VERBOSE"))
139 printf(
"Eigenvalues original\n");
140 for (i = 0; i <
min(N,25); i++){
141 printf(
"%f ", S1[i]);
145 printf(
"Eigenvalues computed\n");
146 for (i = 0; i <
min(N,25); i++){
147 printf(
"%f ", S2[i]);
153 printf(
"------ TESTS FOR PLASMA CGESVD ROUTINE ------- \n");
154 printf(
" Size of the Matrix %d by %d\n", M, N);
156 printf(
" The matrix A is randomly generated for each test.\n");
157 printf(
"============\n");
158 printf(
" The relative machine precision (eps) is to be %e \n",eps);
159 printf(
" Computational tests pass if scaled residuals are less than 60.\n");
176 info_reduction = check_reduction(M, N, A2, A1, LDA, U, M, VT, N, eps);
180 if ( (info_solution == 0) & (info_orthou == 0) &
181 (info_orthovt == 0) & (info_reduction == 0) ) {
183 printf(
"***************************************************\n");
184 printf(
" ---- TESTING CGESVD .. M >= N ........... PASSED !\n");
185 printf(
"***************************************************\n");
188 printf(
"***************************************************\n");
189 printf(
" ---- TESTING CGESVD .. M < N ............ PASSED !\n");
190 printf(
"***************************************************\n");
195 printf(
"************************************************\n");
196 printf(
" - TESTING CGESVD .. M >= N .. FAILED !\n");
197 printf(
"************************************************\n");
200 printf(
"************************************************\n");
201 printf(
" - TESTING CGESVD .. M < N .. FAILED !\n");
202 printf(
"************************************************\n");
206 if ( A2 != NULL ) free(A2);
207 if ( U != NULL ) free(U);
208 if ( VT != NULL ) free(VT);
209 free(A1); free(S1); free(S2);
224 int minMN =
min(M, N);
225 float *work = (
float *)malloc(minMN*
sizeof(
float));
229 LAPACKE_claset_work(LAPACK_COL_MAJOR,
'A', minMN, minMN, 0., 1., Id, minMN);
233 cblas_cherk(
CblasColMajor,
CblasUpper,
CblasConjTrans, N, M, alpha, Q, LDQ, beta, Id, N);
235 cblas_cherk(
CblasColMajor,
CblasUpper,
CblasNoTrans, M, N, alpha, Q, LDQ, beta, Id, M);
239 if (getenv(
"PLASMA_TESTING_VERBOSE"))
240 printf(
"||Q||_oo=%f\n", normQ );
242 printf(
"================================\n");
243 result = normQ / (M * eps);
246 printf(
"Checking the orthogonality of U (Left singular vectors)\n");
247 printf(
"||Id-U'*U||_oo / (N*eps) = %e \n", result);
251 printf(
"Checking the orthogonality of VT (Right singular vectors)\n");
252 printf(
"||Id-VT'*VT||_oo / (N*eps) = %e \n", result);
255 if ( isnan(result) || isinf(result) || (result > 60.0) ) {
256 printf(
"-- Orthogonality is suspicious ! \n");
260 printf(
"-- Orthogonality is CORRECT ! \n");
264 free(work); free(Id);
277 float Anorm, Rnorm, result;
280 int maxMN =
max(M, N);
285 float *work = (
float *)malloc(N*
sizeof(
float));
290 LAPACKE_clacpy_work(LAPACK_COL_MAJOR,
PlasmaUpperLower, M, N, A2, LDA, B, M);
294 cblas_cgemm(
CblasColMajor,
CblasNoTrans,
CblasNoTrans, M, N, M,
CBLAS_SADDR(alpha), U, LDU, B, M,
CBLAS_SADDR(beta), Aorig, M);
295 cblas_cgemm(
CblasColMajor,
CblasNoTrans,
CblasNoTrans, M, N, N,
CBLAS_SADDR(alpha), Aorig, M, VT, LDVT,
CBLAS_SADDR(beta), B, M);
298 for (i = 0; i < M; i++)
299 for (j = 0 ; j < N; j++)
300 Residual[j*M+i] = A1[j*LDA+i] - B[j*M+i];
305 if (getenv(
"PLASMA_TESTING_VERBOSE"))
306 printf(
"||A||_oo=%f\n||A - U*B*VT||_oo=%e\n", Anorm, Rnorm );
308 result = Rnorm / ( Anorm * maxMN * eps);
309 printf(
"============\n");
310 printf(
"Checking the bidiagonal reduction \n");
311 printf(
"-- ||A-U*B*VT||_oo/(||A||_oo.max(M,N).eps) = %e \n", result);
313 if ( isnan(result) || isinf(result) || (result > 60.0) ) {
314 printf(
"-- Reduction is suspicious ! \n");
318 printf(
"-- Reduction is CORRECT ! \n");
322 free(Aorig); free(Residual); free(B); free(work);
324 return info_reduction;
329 int info_solution, i;
332 float maxel = fabs( fabs(E1[0]) - fabs(E2[0]) );
333 float maxeig =
max( fabs(E1[0]), fabs(E2[0]) );
334 for (i = 1; i < N; i++){
335 resid = fabs(fabs(E1[i])-fabs(E2[i]));
336 maxtmp =
max(fabs(E1[i]), fabs(E2[i]));
339 maxeig =
max(maxtmp, maxeig);
340 maxel =
max(resid, maxel );
343 maxel = maxel / (maxeig * N * eps);
344 printf(
" ======================================================\n");
345 printf(
" Checking the singular values of A\n");
346 printf(
" | D - eigcomputed | / (|D| * N * eps) : %15.3E \n", maxel );
348 if ( isnan(maxel) || isinf(maxel) || (maxel > 100) ) {
349 printf(
"-- The singular values are suspicious ! \n");
353 printf(
"-- The singular values are CORRECT ! \n");
357 return info_solution;