testing_zgels_hqr.c 19.9 KB
Newer Older
1
/**
2 3
 *
 * @file testing_zgels_hqr.c
4
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
5 6
 * @copyright 2009-2014 The University of Tennessee and The University of
 *                      Tennessee Research Foundation. All rights reserved.
Mathieu Faverge's avatar
Mathieu Faverge committed
7
 * @copyright 2012-2018 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
8
 *                      Univ. Bordeaux. All rights reserved.
9
 *
10
 ***
11
 *
12
 * @brief Chameleon zgels_hqr testing
13
 *
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
14
 * @version 1.0.0
15 16
 * @author Mathieu Faverge
 * @author Boucherie Raphael
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
17
 * @date 2017-05-17
18 19
 * @precisions normal z -> c d s
 *
20
 */
21 22 23 24 25 26
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <assert.h>

27
#include <chameleon.h>
28 29 30
#include <coreblas/cblas.h>
#include <coreblas/lapacke.h>
#include <coreblas.h>
31 32
#include "testing_zauxiliary.h"

33 34 35
static int check_orthogonality(int, int, int, CHAMELEON_Complex64_t*, double);
static int check_factorization(int, int, CHAMELEON_Complex64_t*, CHAMELEON_Complex64_t*, int, CHAMELEON_Complex64_t*, double);
static int check_solution(int, int, int, CHAMELEON_Complex64_t*, int, CHAMELEON_Complex64_t*, CHAMELEON_Complex64_t*, int, double);
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53

int testing_zgels_hqr(int argc, char **argv)
{
    int hres = 0;

    if ( argc < 1 ){
        goto usage;
    }

    /* Check for number of arguments*/
    if ( argc != 10 ) {
      usage:
        USAGE("GELS_HQR", "M N LDA NRHS LDB",
              "   - 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"
Mathieu Faverge's avatar
Mathieu Faverge committed
54
              "   - QR_A   : Size of TS domain\n"
PRUVOST Florent's avatar
PRUVOST Florent committed
55 56
              "   - QR_P   : Size of high level tree for distributed mode (default: -1)\n"
              "   - LLVL   : tree used for low level reduction insides nodes (default: -1)\n"
Mathieu Faverge's avatar
Mathieu Faverge committed
57
              "   - HLVL   : tree used for high level reduction between nodes, only if qr_p > 1(default: -1)\n"
PRUVOST Florent's avatar
PRUVOST Florent committed
58
              "   - DOMINO : Enable/Disable the domino between upper and lower trees (default: -1)\n"
59 60 61 62 63 64
              );
        return -1;
    }

    int M      = atoi(argv[0]);
    int N      = atoi(argv[1]);
65
    int LDA    = chameleon_max( atoi(argv[2]), M );
66
    int NRHS   = atoi(argv[3]);
67
    int LDB    = chameleon_max( chameleon_max( atoi(argv[4]), M ), N );
68 69 70 71 72
    int qr_a   = atoi(argv[5]);
    int qr_p   = atoi(argv[6]);
    int llvl   = atoi(argv[7]);
    int hlvl   = atoi(argv[8]);
    int domino = atoi(argv[9]);
73 74
    libhqr_tree_t   qrtree;
    libhqr_matrix_t matrix;
75 76 77 78 79 80 81

    int K = min(M, N);
    double eps;
    int info_ortho, info_solution, info_factorization;
    int LDAxN    = LDA*N;
    int LDBxNRHS = LDB*NRHS;

82 83 84 85 86 87 88
    CHAMELEON_Complex64_t *A1 = (CHAMELEON_Complex64_t *)malloc(LDA*N*sizeof(CHAMELEON_Complex64_t));
    CHAMELEON_Complex64_t *A2 = (CHAMELEON_Complex64_t *)malloc(LDA*N*sizeof(CHAMELEON_Complex64_t));
    CHAMELEON_Complex64_t *B1 = (CHAMELEON_Complex64_t *)malloc(LDB*NRHS*sizeof(CHAMELEON_Complex64_t));
    CHAMELEON_Complex64_t *B2 = (CHAMELEON_Complex64_t *)malloc(LDB*NRHS*sizeof(CHAMELEON_Complex64_t));
    CHAMELEON_Complex64_t *Q  = (CHAMELEON_Complex64_t *)malloc(LDA*N*sizeof(CHAMELEON_Complex64_t));
    CHAM_desc_t *TS;
    CHAM_desc_t *TT = NULL;
89 90

    /* Check if unable to allocate memory */
91 92 93 94 95
    if ( (!A1) || (!A2) || (!B1) || (!B2) || (!Q) )
    {
        free(A1); free(A2);
        free(B1); free(B2);
        free(Q);
96 97 98 99
        printf("Out of Memory \n ");
        return -2;
    }

100 101
    CHAMELEON_Alloc_Workspace_zgels(M, N, &TS, 1, 1);
    CHAMELEON_Alloc_Workspace_zgels(M, N, &TT, 1, 1);
102 103 104 105 106 107 108 109 110 111 112 113 114

    eps = LAPACKE_dlamch_work( 'e' );

    /*----------------------------------------------------------
     *  TESTING ZGEQRF_PARAM
     */

    /* Initialize matrix */
    matrix.mt = TS->mt;
    matrix.nt = TS->nt;
    matrix.nodes = 1;
    matrix.p = 1;

115
    libhqr_init_hqr( &qrtree,
116 117 118 119 120 121 122 123
                     ( M >= N ) ? LIBHQR_QR : LIBHQR_LQ,
                     &matrix, llvl, hlvl, qr_a, qr_p, domino, 0);

    /* Initialize A1 and A2 */
    LAPACKE_zlarnv_work(IONE, ISEED, LDAxN, A1);
    LAPACKE_zlacpy_work(LAPACK_COL_MAJOR, 'A', M, N, A1, LDA, A2, LDA );

    /* Initialize B1 and B2 */
124
    memset(B2, 0, LDB*NRHS*sizeof(CHAMELEON_Complex64_t));
125 126 127
    LAPACKE_zlarnv_work(IONE, ISEED, LDBxNRHS, B1);
    LAPACKE_zlacpy_work(LAPACK_COL_MAJOR, 'A', M, NRHS, B1, LDB, B2, LDB );

128 129
    /* CHAMELEON ZGELS */
    CHAMELEON_zgels_param(&qrtree, ChamNoTrans, M, N, NRHS, A2, LDA, TS, TT, B2, LDB);
130

131
    /* CHAMELEON ZGELS */
132 133
    if (M >= N)
        /* Building the economy-size Q */
134
        CHAMELEON_zungqr_param(&qrtree, M, N, K, A2, LDA, TS, TT, Q, LDA);
135 136
    else
        /* Building the economy-size Q */
137
        CHAMELEON_zunglq_param(&qrtree, M, N, K, A2, LDA, TS, TT, Q, LDA);
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171

    printf("\n");
    printf("------ TESTS FOR CHAMELEON ZGELS_HQR ROUTINE -------  \n");
    printf("            Size of the Matrix %d by %d\n", M, N);
    printf("\n");
    printf(" The matrix A is randomly generated for each test.\n");
    printf("============\n");
    printf(" The relative machine precision (eps) is to be %e \n",eps);
    printf(" Computational tests pass if scaled residuals are less than 60.\n");

    /* Check the orthogonality, factorization and the solution */
    info_ortho = check_orthogonality(M, N, LDA, Q, eps);
    info_factorization = check_factorization(M, N, A1, A2, LDA, Q, eps);
    info_solution = check_solution(M, N, NRHS, A1, LDA, B1, B2, LDB, eps);

    if ((info_solution == 0)&(info_factorization == 0)&(info_ortho == 0)) {
        printf("***************************************************\n");
        printf(" ---- TESTING ZGELS_HQR ............... PASSED !\n");
        printf("***************************************************\n");
    }
    else {
        printf("************************************************\n");
        printf(" - TESTING ZGELS_HQR ... FAILED !\n");    hres++;
        printf("************************************************\n");
    }

    /*-------------------------------------------------------------
     *  TESTING ZGEQRF + ZGEQRS or ZGELQF + ZGELQS
     */
    /* Initialize A1 and A2 */
    LAPACKE_zlarnv_work(IONE, ISEED, LDAxN, A1);
    LAPACKE_zlacpy_work(LAPACK_COL_MAJOR, 'A', M, N, A1, LDA, A2, LDA );

    /* Initialize B1 and B2 */
172
    memset(B2, 0, LDB*NRHS*sizeof(CHAMELEON_Complex64_t));
173 174 175 176 177 178 179 180 181 182 183 184 185
    LAPACKE_zlarnv_work(IONE, ISEED, LDBxNRHS, B1);
    LAPACKE_zlacpy_work(LAPACK_COL_MAJOR, 'A', M, NRHS, B1, LDB, B2, LDB );

    if (M >= N) {
        printf("\n");
        printf("------ TESTS FOR CHAMELEON ZGEQRF + ZGEQRS ROUTINE -------  \n");
        printf("            Size of the Matrix %d by %d\n", M, N);
        printf("\n");
        printf(" The matrix A is randomly generated for each test.\n");
        printf("============\n");
        printf(" The relative machine precision (eps) is to be %e \n", eps);
        printf(" Computational tests pass if scaled residuals are less than 60.\n");

186 187 188 189
        /* Cham routines */
        CHAMELEON_zgeqrf_param( &qrtree, M, N, A2, LDA, TS, TT );
        CHAMELEON_zungqr_param( &qrtree, M, N, K, A2, LDA, TS, TT, Q, LDA);
        CHAMELEON_zgeqrs_param( &qrtree, M, N, NRHS, A2, LDA, TS,TT, B2, LDB);
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216

        /* Check the orthogonality, factorization and the solution */
        info_ortho = check_orthogonality(M, N, LDA, Q, eps);
        info_factorization = check_factorization(M, N, A1, A2, LDA, Q, eps);
        info_solution = check_solution(M, N, NRHS, A1, LDA, B1, B2, LDB, eps);

        if ((info_solution == 0)&(info_factorization == 0)&(info_ortho == 0)) {
            printf("***************************************************\n");
            printf(" ---- TESTING ZGEQRF + ZGEQRS ............ PASSED !\n");
            printf("***************************************************\n");
        }
        else{
            printf("***************************************************\n");
            printf(" - TESTING ZGEQRF + ZGEQRS ... FAILED !\n");
            printf("***************************************************\n");
        }
    }
    else  {
        printf("\n");
        printf("------ TESTS FOR CHAMELEON ZGELQF + ZGELQS ROUTINE -------  \n");
        printf("            Size of the Matrix %d by %d\n", M, N);
        printf("\n");
        printf(" The matrix A is randomly generated for each test.\n");
        printf("============\n");
        printf(" The relative machine precision (eps) is to be %e \n", eps);
        printf(" Computational tests pass if scaled residuals are less than 60.\n");

217 218 219 220 221 222 223
        /* Cham routines */
        CHAMELEON_zgelqf_param(&qrtree, M, N, A2, LDA, TS, TT);
        //CHAMELEON_zgelqf(M, N, A2, LDA, TS);
        CHAMELEON_zunglq_param(&qrtree, M, N, K, A2, LDA, TS, TT, Q, LDA);
        //CHAMELEON_zunglq(M, N, K, A2, LDA, TS, Q, LDA);
        CHAMELEON_zgelqs_param(&qrtree, M, N, NRHS, A2, LDA, TS, TT, B2, LDB);
        //CHAMELEON_zgelqs(M, N, NRHS, A2, LDA, TS, B2, LDB);
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250

        /* Check the orthogonality, factorization and the solution */
        info_ortho = check_orthogonality(M, N, LDA, Q, eps);
        info_factorization = check_factorization(M, N, A1, A2, LDA, Q, eps);
        info_solution = check_solution(M, N, NRHS, A1, LDA, B1, B2, LDB, eps);

        if ( (info_solution == 0) & (info_factorization == 0) & (info_ortho == 0) ) {
            printf("***************************************************\n");
            printf(" ---- TESTING ZGELQF + ZGELQS ............ PASSED !\n");
            printf("***************************************************\n");
        }
        else {
            printf("***************************************************\n");
            printf(" - TESTING ZGELQF + ZGELQS ... FAILED !\n");
            printf("***************************************************\n");
        }
    }

    /*----------------------------------------------------------
     *  TESTING ZGEQRF + ZORMQR + ZTRSM
     */

    /* Initialize A1 and A2 */
    LAPACKE_zlarnv_work(IONE, ISEED, LDAxN, A1);
    LAPACKE_zlacpy_work(LAPACK_COL_MAJOR, 'A', M, N, A1, LDA, A2, LDA );

    /* Initialize B1 and B2 */
251
    memset(B2, 0, LDB*NRHS*sizeof(CHAMELEON_Complex64_t));
252 253 254 255 256 257
    LAPACKE_zlarnv_work(IONE, ISEED, LDBxNRHS, B1);
    LAPACKE_zlacpy_work(LAPACK_COL_MAJOR, 'A', M, NRHS, B1, LDB, B2, LDB );

    /* Initialize Q */
    LAPACKE_zlaset_work(LAPACK_COL_MAJOR, 'A', LDA, N, 0., 1., Q, LDA );

258
    /* CHAMELEON ZGEQRF+ ZUNMQR + ZTRSM */
259 260 261 262 263 264 265 266 267 268
    if (M >= N) {
        printf("\n");
        printf("------ TESTS FOR CHAMELEON ZGEQRF + ZUNMQR + ZTRSM  ROUTINE -------  \n");
        printf("            Size of the Matrix %d by %d\n", M, N);
        printf("\n");
        printf(" The matrix A is randomly generated for each test.\n");
        printf("============\n");
        printf(" The relative machine precision (eps) is to be %e \n",eps);
        printf(" Computational tests pass if scaled residuals are less than 60.\n");

269 270 271 272
        CHAMELEON_zgeqrf_param( &qrtree, M, N, A2, LDA, TS, TT );
        CHAMELEON_zungqr_param( &qrtree, M, N, K, A2, LDA, TS, TT, Q, LDA);
        CHAMELEON_zunmqr_param( &qrtree, ChamLeft, ChamConjTrans, M, NRHS, N, A2, LDA, TS, TT, B2, LDB);
        CHAMELEON_ztrsm(ChamLeft, ChamUpper, ChamNoTrans, ChamNonUnit, N, NRHS, 1.0, A2, LDA, B2, LDB);
273 274 275 276 277 278 279 280 281 282 283
    }
    else {
        printf("\n");
        printf("------ TESTS FOR CHAMELEON ZGELQF + ZUNMLQ + ZTRSM  ROUTINE -------  \n");
        printf("            Size of the Matrix %d by %d\n", M, N);
        printf("\n");
        printf(" The matrix A is randomly generated for each test.\n");
        printf("============\n");
        printf(" The relative machine precision (eps) is to be %e \n",eps);
        printf(" Computational tests pass if scaled residuals are less than 60.\n");

284 285 286 287
        CHAMELEON_zgelqf_param(&qrtree, M, N, A2, LDA, TS, TT);
        CHAMELEON_ztrsm(ChamLeft, ChamLower, ChamNoTrans, ChamNonUnit, M, NRHS, 1.0, A2, LDA, B2, LDB);
        CHAMELEON_zunglq_param(&qrtree, M, N, K, A2, LDA, TS, TT, Q, LDA);
        CHAMELEON_zunmlq_param(&qrtree, ChamLeft, ChamConjTrans, N, NRHS, M, A2, LDA, TS, TT, B2, LDB);
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319
    }

    /* Check the orthogonality, factorization and the solution */
    info_ortho = check_orthogonality(M, N, LDA, Q, eps);
    info_factorization = check_factorization(M, N, A1, A2, LDA, Q, eps);
    info_solution = check_solution(M, N, NRHS, A1, LDA, B1, B2, LDB, eps);

    if ( (info_solution == 0) & (info_factorization == 0) & (info_ortho == 0) ) {
        if (M >= N) {
            printf("***************************************************\n");
            printf(" ---- TESTING ZGEQRF + ZUNMQR + ZTRSM .... PASSED !\n");
            printf("***************************************************\n");
        }
        else {
            printf("***************************************************\n");
            printf(" ---- TESTING ZGELQF + ZTRSM + ZUNMLQ .... PASSED !\n");
            printf("***************************************************\n");
        }
    }
    else {
        if (M >= N) {
            printf("***************************************************\n");
            printf(" - TESTING ZGEQRF + ZUNMQR + ZTRSM ... FAILED !\n");
            printf("***************************************************\n");
        }
        else {
            printf("***************************************************\n");
            printf(" - TESTING ZGELQF + ZTRSM + ZUNMLQ ... FAILED !\n");
            printf("***************************************************\n");
        }
    }

320
    libhqr_finalize( &qrtree );
321 322

    free(A1); free(A2); free(B1); free(B2); free(Q);
323 324
    CHAMELEON_Dealloc_Workspace( &TS );
    CHAMELEON_Dealloc_Workspace( &TT );
325 326 327 328 329 330 331 332

    return hres;
}

/*-------------------------------------------------------------------
 * Check the orthogonality of Q
 */

333
static int check_orthogonality(int M, int N, int LDQ, CHAMELEON_Complex64_t *Q, double eps)
334 335 336 337 338 339 340 341 342 343 344 345
{
    double alpha, beta;
    double normQ;
    int info_ortho;
    int minMN = min(M, N);

    double *work = (double *)malloc(minMN*sizeof(double));

    alpha = 1.0;
    beta  = -1.0;

    /* Build the idendity matrix USE DLASET?*/
346
    CHAMELEON_Complex64_t *Id = (CHAMELEON_Complex64_t *) malloc(minMN*minMN*sizeof(CHAMELEON_Complex64_t));
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
    LAPACKE_zlaset_work(LAPACK_COL_MAJOR, 'A', minMN, minMN, 0., 1., Id, minMN );

    /* Perform Id - Q'Q */
    if (M >= N)
        cblas_zherk(CblasColMajor, CblasUpper, CblasConjTrans, N, M, alpha, Q, LDQ, beta, Id, N);
    else
        cblas_zherk(CblasColMajor, CblasUpper, CblasNoTrans, M, N, alpha, Q, LDQ, beta, Id, M);

    normQ = LAPACKE_zlansy( LAPACK_COL_MAJOR, 'I', 'U', minMN, Id, minMN );

    printf("============\n");
    printf("Checking the orthogonality of Q \n");
    printf("||Id-Q'*Q||_oo / (N*eps) = %e \n", normQ/(minMN*eps));

    if ( isnan(normQ / (minMN * eps)) || isinf(normQ / (minMN * eps)) || (normQ / (minMN * eps) > 60.0) ) {
        printf("-- Orthogonality is suspicious ! \n");
        info_ortho=1;
    }
    else {
        printf("-- Orthogonality is CORRECT ! \n");
        info_ortho=0;
    }

    free(work); free(Id);

    return info_ortho;
}

/*------------------------------------------------------------
 *  Check the factorization QR
 */

379
static int check_factorization(int M, int N, CHAMELEON_Complex64_t *A1, CHAMELEON_Complex64_t *A2, int LDA, CHAMELEON_Complex64_t *Q, double eps )
380 381
{
    double Anorm, Rnorm;
382
    CHAMELEON_Complex64_t alpha, beta;
383 384 385
    int info_factorization;
    int i,j;

386 387
    CHAMELEON_Complex64_t *Ql       = (CHAMELEON_Complex64_t *)malloc(M*N*sizeof(CHAMELEON_Complex64_t));
    CHAMELEON_Complex64_t *Residual = (CHAMELEON_Complex64_t *)malloc(M*N*sizeof(CHAMELEON_Complex64_t));
388 389 390 391 392 393 394
    double *work              = (double *)malloc(max(M,N)*sizeof(double));

    alpha=1.0;
    beta=0.0;

    if (M >= N) {
        /* Extract the R */
395 396
        CHAMELEON_Complex64_t *R = (CHAMELEON_Complex64_t *)malloc(N*N*sizeof(CHAMELEON_Complex64_t));
        memset((void*)R, 0, N*N*sizeof(CHAMELEON_Complex64_t));
397 398 399
        LAPACKE_zlacpy_work(LAPACK_COL_MAJOR,'u', M, N, A2, LDA, R, N);

        /* Perform Ql=Q*R */
400
        memset((void*)Ql, 0, M*N*sizeof(CHAMELEON_Complex64_t));
401 402 403 404 405
        cblas_zgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, M, N, N, CBLAS_SADDR(alpha), Q, LDA, R, N, CBLAS_SADDR(beta), Ql, M);
        free(R);
    }
    else {
        /* Extract the L */
406 407
        CHAMELEON_Complex64_t *L = (CHAMELEON_Complex64_t *)malloc(M*M*sizeof(CHAMELEON_Complex64_t));
        memset((void*)L, 0, M*M*sizeof(CHAMELEON_Complex64_t));
408 409 410
        LAPACKE_zlacpy_work(LAPACK_COL_MAJOR,'l', M, N, A2, LDA, L, M);

        /* Perform Ql=LQ */
411
        memset((void*)Ql, 0, M*N*sizeof(CHAMELEON_Complex64_t));
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452
        cblas_zgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, M, N, M, CBLAS_SADDR(alpha), L, M, Q, LDA, CBLAS_SADDR(beta), Ql, M);
        free(L);
    }

    /* Compute the Residual */
    for (i = 0; i < M; i++)
        for (j = 0 ; j < N; j++)
            Residual[j*M+i] = A1[j*LDA+i]-Ql[j*M+i];

    Rnorm = LAPACKE_zlange( LAPACK_COL_MAJOR, 'I', M, N, Residual, M );
    Anorm = LAPACKE_zlange( LAPACK_COL_MAJOR, 'I', M, N, A2, LDA );

    if (M >= N) {
        printf("============\n");
        printf("Checking the QR Factorization \n");
        printf("-- ||A-QR||_oo/(||A||_oo.N.eps) = %e \n",Rnorm/(Anorm*N*eps));
    }
    else {
        printf("============\n");
        printf("Checking the LQ Factorization \n");
        printf("-- ||A-LQ||_oo/(||A||_oo.N.eps) = %e \n",Rnorm/(Anorm*N*eps));
    }

    if (isnan(Rnorm / (Anorm * N *eps)) || isinf(Rnorm / (Anorm * N *eps)) || (Rnorm / (Anorm * N * eps) > 60.0) ) {
        printf("-- Factorization is suspicious ! \n");
        info_factorization = 1;
    }
    else {
        printf("-- Factorization is CORRECT ! \n");
        info_factorization = 0;
    }

    free(work); free(Ql); free(Residual);

    return info_factorization;
}

/*--------------------------------------------------------------
 * Check the solution
 */

453
static int check_solution(int M, int N, int NRHS, CHAMELEON_Complex64_t *A, int LDA, CHAMELEON_Complex64_t *B, CHAMELEON_Complex64_t *X, int LDB, double eps)
454 455 456
{
    int info_solution;
    double Rnorm, Anorm, Xnorm, Bnorm;
457
    CHAMELEON_Complex64_t alpha, beta;
458 459 460 461 462 463 464 465 466 467 468 469 470
    double result;
    double *work = (double *)malloc(max(M, N)* sizeof(double));

    alpha = 1.0;
    beta  = -1.0;

    Anorm = LAPACKE_zlange( LAPACK_COL_MAJOR, 'I', M, N,    A, LDA );
    Bnorm = LAPACKE_zlange( LAPACK_COL_MAJOR, 'I', N, NRHS, B, LDB );
    Xnorm = LAPACKE_zlange( LAPACK_COL_MAJOR, 'I', M, NRHS, X, LDB );

    cblas_zgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, M, NRHS, N, CBLAS_SADDR(alpha), A, LDA, X, LDB, CBLAS_SADDR(beta), B, LDB);

    if (M >= N) {
471 472
        CHAMELEON_Complex64_t *Residual = (CHAMELEON_Complex64_t *)malloc(M*NRHS*sizeof(CHAMELEON_Complex64_t));
        memset((void*)Residual, 0, M*NRHS*sizeof(CHAMELEON_Complex64_t));
473 474 475 476 477
        cblas_zgemm(CblasColMajor, CblasConjTrans, CblasNoTrans, N, NRHS, M, CBLAS_SADDR(alpha), A, LDA, B, LDB, CBLAS_SADDR(beta), Residual, M);
        Rnorm = LAPACKE_zlange( LAPACK_COL_MAJOR, 'I', M, NRHS, Residual, M );
        free(Residual);
    }
    else {
478 479
        CHAMELEON_Complex64_t *Residual = (CHAMELEON_Complex64_t *)malloc(N*NRHS*sizeof(CHAMELEON_Complex64_t));
        memset((void*)Residual, 0, N*NRHS*sizeof(CHAMELEON_Complex64_t));
480 481 482 483 484
        cblas_zgemm(CblasColMajor, CblasConjTrans, CblasNoTrans, N, NRHS, M, CBLAS_SADDR(alpha), A, LDA, B, LDB, CBLAS_SADDR(beta), Residual, N);
        Rnorm = LAPACKE_zlange( LAPACK_COL_MAJOR, 'I', N, NRHS, Residual, N );
        free(Residual);
    }

485
    if (getenv("CHAMELEON_TESTING_VERBOSE"))
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503
        printf( "||A||_oo=%f\n||X||_oo=%f\n||B||_oo=%f\n||A X - B||_oo=%e\n", Anorm, Xnorm, Bnorm, Rnorm );

    result = Rnorm / ( (Anorm*Xnorm+Bnorm)*N*eps ) ;
    printf("============\n");
    printf("Checking the Residual of the solution \n");
    printf("-- ||Ax-B||_oo/((||A||_oo||x||_oo+||B||_oo).N.eps) = %e \n", result);

    if (  isnan(Xnorm) || isinf(Xnorm) || isnan(result) || isinf(result) || (result > 60.0) ) {
        printf("-- The solution is suspicious ! \n");
        info_solution = 1;
    }
    else{
        printf("-- The solution is CORRECT ! \n");
        info_solution = 0;
    }
    free(work);
    return info_solution;
}