testing_ztrsm.c 7.04 KB
Newer Older
1
/**
2 3
 *
 * @file testing_ztrsm.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.
7 8
 * @copyright 2012-2014 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
 *                      Univ. Bordeaux. All rights reserved.
9
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
10
 ***
11
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
12
 * @brief Chameleon ztrsm testing
13
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
14
 * @version 1.0.0
15
 * @comment This file has been automatically generated
Mathieu Faverge's avatar
Mathieu Faverge committed
16
 *          from Plasma 2.5.0 for CHAMELEON 1.0.0
17 18 19 20 21 22
 * @author Mathieu Faverge
 * @author Emmanuel Agullo
 * @author Cedric Castagnede
 * @date 2010-11-15
 * @precisions normal z -> c d s
 *
23
 */
24 25 26 27 28
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>

Mathieu Faverge's avatar
Mathieu Faverge committed
29
#include <chameleon.h>
30 31 32
#include <coreblas/cblas.h>
#include <coreblas/lapacke.h>
#include <coreblas.h>
33 34
#include "testing_zauxiliary.h"

Mathieu Faverge's avatar
Mathieu Faverge committed
35 36 37 38
static int check_solution(cham_side_t side, cham_uplo_t uplo, cham_trans_t trans, cham_diag_t diag,
                          int M, int N, CHAMELEON_Complex64_t alpha,
                          CHAMELEON_Complex64_t *A, int LDA,
                          CHAMELEON_Complex64_t *Bref, CHAMELEON_Complex64_t *Bmorse, int LDB);
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53

int testing_ztrsm(int argc, char **argv)
{
    int hres = 0;
    /* Check for number of arguments*/
    if ( argc != 5 ) {
        USAGE("TRSM", "alpha M N LDA LDB",
              "   - alpha  : alpha coefficient\n"
              "   - M      : number of rows of matrices B\n"
              "   - N      : number of columns of matrices B\n"
              "   - LDA    : leading dimension of matrix A\n"
              "   - LDB    : leading dimension of matrix B\n");
        return -1;
    }

Mathieu Faverge's avatar
Mathieu Faverge committed
54
    CHAMELEON_Complex64_t alpha = (CHAMELEON_Complex64_t) atol(argv[0]);
55 56 57 58 59 60 61 62 63 64 65
    int M     = atoi(argv[1]);
    int N     = atoi(argv[2]);
    int LDA   = atoi(argv[3]);
    int LDB   = atoi(argv[4]);

    double eps;
    int info_solution;
    int s, u, t, d, i;
    int LDAxM = LDA*max(M,N);
    int LDBxN = LDB*max(M,N);

Mathieu Faverge's avatar
Mathieu Faverge committed
66 67 68 69
    CHAMELEON_Complex64_t *A      = (CHAMELEON_Complex64_t *)malloc(LDAxM*sizeof(CHAMELEON_Complex64_t));
    CHAMELEON_Complex64_t *B      = (CHAMELEON_Complex64_t *)malloc(LDBxN*sizeof(CHAMELEON_Complex64_t));
    CHAMELEON_Complex64_t *Binit  = (CHAMELEON_Complex64_t *)malloc(LDBxN*sizeof(CHAMELEON_Complex64_t));
    CHAMELEON_Complex64_t *Bfinal = (CHAMELEON_Complex64_t *)malloc(LDBxN*sizeof(CHAMELEON_Complex64_t));
70 71

    /* Check if unable to allocate memory */
72 73 74 75
    if ( (!A) || (!B) || (!Binit) || (!Bfinal) )
    {
        free(A); free(B);
        free(Binit); free(Bfinal);
76 77 78 79 80 81 82
        printf("Out of Memory \n ");
        return -2;
    }

    eps = LAPACKE_dlamch_work('e');

    printf("\n");
83
    printf("------ TESTS FOR CHAMELEON ZTRSM ROUTINE -------  \n");
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
    printf("            Size of the Matrix B : %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 10.\n");

    /*----------------------------------------------------------
     *  TESTING ZTRSM
     */

    /* Initialize A, B, C */
    LAPACKE_zlarnv_work(IONE, ISEED, LDAxM, A);
    LAPACKE_zlarnv_work(IONE, ISEED, LDBxN, B);
    for(i=0;i<max(M,N);i++)
      A[LDA*i+i] = A[LDA*i+i] + 2.0;

    for (s=0; s<2; s++) {
        for (u=0; u<2; u++) {
103
#if defined(PRECISION_z) || defined(PRECISION_c)
104 105 106 107 108 109
            for (t=0; t<3; t++) {
#else
            for (t=0; t<2; t++) {
#endif
                for (d=0; d<2; d++) {

Mathieu Faverge's avatar
Mathieu Faverge committed
110 111
                    memcpy(Binit,  B, LDBxN*sizeof(CHAMELEON_Complex64_t));
                    memcpy(Bfinal, B, LDBxN*sizeof(CHAMELEON_Complex64_t));
112

Mathieu Faverge's avatar
Mathieu Faverge committed
113 114
                    /* CHAMELEON ZTRSM */
                    CHAMELEON_ztrsm(side[s], uplo[u], trans[t], diag[d],
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
                                 M, N, alpha, A, LDA, Bfinal, LDB);

                    /* Check the solution */
                    info_solution = check_solution(side[s], uplo[u], trans[t], diag[d],
                                                   M, N, alpha, A, LDA, Binit, Bfinal, LDB);

                    printf("***************************************************\n");
                    if (info_solution == 0) {
                        printf(" ---- TESTING ZTRSM (%s, %s, %s, %s) ...... PASSED !\n",
                               sidestr[s], uplostr[u], transstr[t], diagstr[d]);
                    }
                    else {
                        printf(" ---- TESTING ZTRSM (%s, %s, %s, %s) ... FAILED !\n",
                               sidestr[s], uplostr[u], transstr[t], diagstr[d]);    hres++;
                    }
                    printf("***************************************************\n");
                }
            }
        }
    }

    free(A); free(B);
    free(Binit); free(Bfinal);

    return hres;
}

/*--------------------------------------------------------------
 * Check the solution
 */
Mathieu Faverge's avatar
Mathieu Faverge committed
145 146 147 148
static int check_solution(cham_side_t side, cham_uplo_t uplo, cham_trans_t trans, cham_diag_t diag,
                          int M, int N, CHAMELEON_Complex64_t alpha,
                          CHAMELEON_Complex64_t *A, int LDA,
                          CHAMELEON_Complex64_t *Bref, CHAMELEON_Complex64_t *Bmorse, int LDB)
149 150 151 152
{
    int info_solution;
    double Anorm, Binitnorm, Bmorsenorm, Blapacknorm, Rnorm, result;
    double eps;
Mathieu Faverge's avatar
Mathieu Faverge committed
153
    CHAMELEON_Complex64_t mzone = (CHAMELEON_Complex64_t)-1.0;
154 155 156 157

    double *work = (double *)malloc(max(M, N)* sizeof(double));
    int Am, An;

Mathieu Faverge's avatar
Mathieu Faverge committed
158
    if (side == ChamLeft) {
159 160 161 162 163
        Am = M; An = M;
    } else {
        Am = N; An = N;
    }

164
    Anorm       = LAPACKE_zlantr_work(LAPACK_COL_MAJOR, 'I', morse_lapack_const(uplo), morse_lapack_const(diag),
165
                                Am, An, A, LDA, work);
166 167
    Binitnorm   = LAPACKE_zlange_work(LAPACK_COL_MAJOR, 'I', M, N, Bref,    LDB, work);
    Bmorsenorm = LAPACKE_zlange_work(LAPACK_COL_MAJOR, 'I', M, N, Bmorse, LDB, work);
168 169 170 171

    cblas_ztrsm(CblasColMajor, (CBLAS_SIDE)side, (CBLAS_UPLO)uplo, (CBLAS_TRANSPOSE)trans,
                (CBLAS_DIAG)diag, M, N, CBLAS_SADDR(alpha), A, LDA, Bref, LDB);

172
    Blapacknorm = LAPACKE_zlange_work(LAPACK_COL_MAJOR, 'I', M, N, Bref, LDB, work);
173 174 175

    cblas_zaxpy(LDB * N, CBLAS_SADDR(mzone), Bmorse, 1, Bref, 1);

176
    Rnorm = LAPACKE_zlange_work(LAPACK_COL_MAJOR, 'I', M, N, Bref, LDB, work);
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200

    eps = LAPACKE_dlamch_work('e');

    printf("Rnorm %e, Anorm %e, Binitnorm %e, Bmorsenorm %e, Blapacknorm %e\n",
           Rnorm, Anorm, Binitnorm, Bmorsenorm, Blapacknorm);

    result = Rnorm / ((Anorm + Blapacknorm) * max(M,N) * eps);

    printf("============\n");
    printf("Checking the norm of the difference against reference ZTRSM \n");
    printf("-- ||Cmorse - Clapack||_oo/((||A||_oo+||B||_oo).N.eps) = %e \n", result);

    if ( isinf(Blapacknorm) || isinf(Bmorsenorm) || isnan(result) || isinf(result) || (result > 10.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;
}