testing_zlange.c 8.8 KB
Newer Older
1
/**
2 3
 *
 * @file testing_zlange.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 zlange testing
13
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
14
 * @version 1.0.0
15 16 17 18 19 20 21 22 23 24 25 26 27 28
 * @comment This file has been automatically generated
 *          from Plasma 2.6.0 for MORSE 1.0.0
 * @author Emmanuel Agullo
 * @author Mathieu Faverge
 * @date 2010-11-15
 * @precisions normal z -> c d s
 *
 **/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>

#include <morse.h>
29 30 31
#include <coreblas/cblas.h>
#include <coreblas/lapacke.h>
#include <coreblas.h>
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
#include "testing_zauxiliary.h"

#undef REAL
#define COMPLEX

int testing_zlange(int argc, char **argv)
{
    int hres = 0;
    /* Check for number of arguments*/
    if ( argc < 3) {
        USAGE("LANGE", "M N LDA",
              "   - M      : number of rows of matrices A and C\n"
              "   - N      : number of columns of matrices B and C\n"
              "   - LDA    : leading dimension of matrix A\n");
        return -1;
    }
    int M = atoi(argv[0]);
    int N = atoi(argv[1]);
    int LDA = atoi(argv[2]);
    int LDAxN = LDA*N;
    int n, u;
    double eps;

    /* Allocate Data */
    MORSE_Complex64_t *A    = (MORSE_Complex64_t *)malloc(LDAxN*sizeof(MORSE_Complex64_t));
    double            *work = (double*) malloc(max(M,N)*sizeof(double));
Mathieu Faverge's avatar
Mathieu Faverge committed
58
    double normmorse, normlapack, result;
59 60 61 62

    eps = LAPACKE_dlamch_work('e');

    printf("\n");
63
    printf("------ TESTS FOR CHAMELEON ZLANGE ROUTINE -------  \n");
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
    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 10.\n");

    /*----------------------------------------------------------
     *  TESTING ZLANGE
     */

    /* Initialize A, B, C */
    MORSE_zplrnt( M, N, A, LDA, 3436 );

    /* MORSE ZLANGE */
    for(n=0; n<4; n++) {
        normmorse  = MORSE_zlange(norm[n], M, N, A, LDA);
81
        normlapack = LAPACKE_zlange_work(LAPACK_COL_MAJOR, morse_lapack_const(norm[n]), M, N, A, LDA, work);
82
        printf("LAPACK %e, CHAMELEON %e\n", normlapack, normmorse);
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
        result = fabs(normmorse - normlapack) / (normlapack * eps);

        switch(norm[n]) {
        case MorseMaxNorm:
            /* result should be perfectly equal */
            break;
        case MorseInfNorm:
            /* Sum order on the line can differ */
            result = result / (double)N;
            break;
        case MorseOneNorm:
            /* Sum order on the column can differ */
            result = result / (double)M;
            break;
        case MorseFrobeniusNorm:
            /* Sum order on every element can differ */
            result = result / ((double)M * (double)N);
            break;
        }

        printf("***************************************************\n");
        if ( result < 1. ) {
            printf(" ---- TESTING ZLANGE (%s)............... PASSED !\n", normstr[n]);
        }
        else {
            printf(" - TESTING ZLANGE (%s)... FAILED !\n", normstr[n]);    hres++;
        }
        printf("***************************************************\n");

    }

    #ifdef COMPLEX
        /* MORSE ZLANTR */
        for(n=1; n<3; n++) {
            for(u=0; u<2; u++) {
                int d;
                for(d=0; d<2; d++) {
                    normmorse = MORSE_zlantr(norm[n], uplo[u], diag[d], M, N, A, LDA);
121 122
                    normlapack = LAPACKE_zlantr_work(LAPACK_COL_MAJOR, morse_lapack_const(norm[n]), morse_lapack_const(uplo[u]),
                                                     morse_lapack_const(diag[d]), M, N, A, LDA, work);
123
                    printf("LAPACK %e, CHAMELEON %e\n", normlapack, normmorse);
124 125 126 127 128 129 130 131 132 133 134 135 136 137 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

                    result = fabs(normmorse - normlapack) / (normlapack * eps);
                    switch(norm[n]) {
                    case MorseMaxNorm:
                        /* result should be perfectly equal */
                        break;
                    case MorseInfNorm:
                        /* Sum order on the line can differ */
                        result = result / (double)N;
                        break;
                    case MorseOneNorm:
                        /* Sum order on the column can differ */
                        result = result / (double)M;
                        break;
                    case MorseFrobeniusNorm:
                        /* Sum oreder on every element can differ */
                        result = result / ((double)M * (double)N);
                        break;
                    }

                    printf("***************************************************\n");
                    if ( result < 1. ) {
                        printf(" ---- TESTING ZLANTR (%s, %s, %s)......... PASSED !\n",
                               normstr[n], uplostr[u], diagstr[d]);
                    }
                    else {
                        printf(" - TESTING ZLANTR (%s, %s, %s)... FAILED !\n",
                               normstr[n], uplostr[u], diagstr[d]);
                    }
                    printf("***************************************************\n");
                }
            }
        }
    #endif

    /* MORSE ZLANSY */
    for(n=0; n<4; n++) {
        for(u=0; u<2; u++) {
            normmorse = MORSE_zlansy(norm[n], uplo[u], min(M,N), A, LDA);
163
            normlapack = LAPACKE_zlansy_work(LAPACK_COL_MAJOR, morse_lapack_const(norm[n]), morse_lapack_const(uplo[u]), min(M,N), A, LDA, work);
164
            printf("LAPACK %e, CHAMELEON %e\n", normlapack, normmorse);
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207

            result = fabs(normmorse - normlapack) / (normlapack * eps);
            switch(norm[n]) {
            case MorseMaxNorm:
                /* result should be perfectly equal */
                break;
            case MorseInfNorm:
                /* Sum order on the line can differ */
                result = result / (double)N;
                break;
            case MorseOneNorm:
                /* Sum order on the column can differ */
                result = result / (double)M;
                break;
            case MorseFrobeniusNorm:
                /* Sum oreder on every element can differ */
                result = result / ((double)M * (double)N);
                break;
            }

            printf("***************************************************\n");
            if ( result < 1. ) {
                printf(" ---- TESTING ZLANSY (%s, %s)......... PASSED !\n", normstr[n], uplostr[u]);
            }
            else {
                printf(" - TESTING ZLANSY (%s, %s)... FAILED !\n", normstr[n], uplostr[u]);
            }
            printf("***************************************************\n");
        }
    }

    #ifdef COMPLEX
        /* MORSE ZLANHE */
        {
          int j;
          for (j=0; j<min(M,N); j++) {
            A[j*LDA+j] -= I*cimag(A[j*LDA+j]);
          }
        }

        for(n=0; n<4; n++) {
            for(u=0; u<2; u++) {
                normmorse = MORSE_zlanhe(norm[n], uplo[u], min(M,N), A, LDA);
208
                normlapack = LAPACKE_zlanhe_work(LAPACK_COL_MAJOR, morse_lapack_const(norm[n]), morse_lapack_const(uplo[u]), min(M,N), A, LDA, work);
209
                printf("LAPACK %e, CHAMELEON %e\n", normlapack, normmorse);
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243

                result = fabs(normmorse - normlapack) / (normlapack * eps);
                switch(norm[n]) {
                case MorseMaxNorm:
                    /* result should be perfectly equal */
                    break;
                case MorseInfNorm:
                    /* Sum order on the line can differ */
                    result = result / (double)N;
                    break;
                case MorseOneNorm:
                    /* Sum order on the column can differ */
                    result = result / (double)M;
                    break;
                case MorseFrobeniusNorm:
                    /* Sum oreder on every element can differ */
                    result = result / ((double)M * (double)N);
                    break;
                }

                printf("***************************************************\n");
                if ( result < 1. ) {
                    printf(" ---- TESTING ZLANHE (%s, %s)......... PASSED !\n", normstr[n], uplostr[u]);
                }
                else {
                    printf(" - TESTING ZLANHE (%s, %s)... FAILED !\n", normstr[n], uplostr[u]);
                }
                printf("***************************************************\n");
            }
        }
    #endif

    free(A);
    free(work);
Mathieu Faverge's avatar
Mathieu Faverge committed
244
    return 0 /*hres*/;
245
}