Une nouvelle version du portail de gestion des comptes externes sera mise en production lundi 09 août. Elle permettra d'allonger la validité d'un compte externe jusqu'à 3 ans. Pour plus de détails sur cette version consulter : https://doc-si.inria.fr/x/FCeS

pzlange.c 14.7 KB
Newer Older
1
/**
2 3
 *
 * @file pzlange.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
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
10
 ***
11
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
12
 * @brief Chameleon zlange parallel algorithm
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.6.0 for CHAMELEON 1.0.0
17 18 19 20 21 22
 * @author Emmanuel Agullo
 * @author Mathieu Faverge
 * @author Florent Pruvost
 * @date 2014-07-21
 * @precisions normal z -> s d c
 *
23
 */
24 25 26
//ALLOC_WS :  A->mb
//ALLOC_WS :  A->nb
//WS_ADD :  A->mb + A->nb
27
#include "control/common.h"
28

Mathieu Faverge's avatar
Mathieu Faverge committed
29 30 31 32 33 34 35 36
#define A(m, n)    A,    (m), (n)
#define Wcol(m, n) Wcol, (m), (n)
#define Welt(m, n) Welt, (m), (n)

static inline void
chameleon_pzlange_one( cham_uplo_t uplo, cham_diag_t diag, CHAM_desc_t *A,
                       CHAM_desc_t *Wcol, CHAM_desc_t *Welt,
                       RUNTIME_option_t *options)
37
{
38
    int m, n;
Mathieu Faverge's avatar
Mathieu Faverge committed
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
    int minMNT = chameleon_min( A->mt, A->nt );
    int minMN  = chameleon_min( A->m,  A->n  );
    int MT = (uplo == ChamUpper) ? minMNT : A->mt;
    int NT = (uplo == ChamLower) ? minMNT : A->nt;
    int M  = (uplo == ChamUpper) ? minMN  : A->m;
    int N  = (uplo == ChamLower) ? minMN  : A->n;
    int P  = Welt->p;
    int Q  = Welt->q;

    /**
     * Step 1:
     *  For j in [1,P], W(i, n) = reduce( A(i+k*P, n) )
     */
    for(n = 0; n < NT; n++) {
        int mmin = ( uplo == ChamLower ) ? n                      : 0;
        int mmax = ( uplo == ChamUpper ) ? chameleon_min(n+1, MT) : MT;

        int tempnn = ( n == (NT-1) ) ? N - n * A->nb : A->nb;

        for(m = mmin; m < mmax; m++) {
            int tempmm = ( m == (MT-1) ) ? M - m * A->mb : A->mb;
            int ldam = BLKLDD( A, m );

            if ( (n == m)  && (uplo != ChamUpperLower) ) {
                INSERT_TASK_ztrasm(
                    options,
                    ChamColumnwise, uplo, diag, tempmm, tempnn,
                    A(m, n), ldam, Wcol(m, n) );
            }
            else {
                INSERT_TASK_dzasum(
                    options,
                    ChamColumnwise, ChamUpperLower, tempmm, tempnn,
                    A(m, n), ldam, Wcol(m, n) );
            }
74

Mathieu Faverge's avatar
Mathieu Faverge committed
75 76 77 78 79 80 81 82
            if ( m >= P ) {
                INSERT_TASK_dgeadd(
                    options,
                    ChamNoTrans, tempnn, 1, A->nb,
                    1.0, Wcol(m,   n), tempnn,
                    1.0, Wcol(m%P, n), tempnn );
            }
        }
83

Mathieu Faverge's avatar
Mathieu Faverge committed
84 85 86
        /**
         * Step 2:
         *  For each i, W(i, n) = reduce( W(0..P-1, n) )
87
         */
Mathieu Faverge's avatar
Mathieu Faverge committed
88 89 90 91 92 93 94
        for(m = 1; m < P; n++) {
            INSERT_TASK_dgeadd(
                options,
                ChamNoTrans, tempnn, 1, A->nb,
                1.0, Wcol(m, n), tempnn,
                1.0, Wcol(0, n), tempnn );
        }
95

Mathieu Faverge's avatar
Mathieu Faverge committed
96 97 98 99 100
        INSERT_TASK_dlange(
            options,
            ChamMaxNorm, tempnn, 1, A->nb,
            Wcol(0, n), tempnn, Welt(0, n));
    }
101

Mathieu Faverge's avatar
Mathieu Faverge committed
102 103 104 105 106 107 108 109 110
    /**
     * Step 3:
     *  For n in 0..Q-1, W(m, n) = max( W(m, n..nt[Q] ) )
     */
    for(n = Q; n < NT; n++) {
        INSERT_TASK_dlange_max(
            options,
            Welt(0, n), Welt(0, n%Q) );
    }
111

Mathieu Faverge's avatar
Mathieu Faverge committed
112 113 114 115 116 117 118 119 120 121
    /**
     * Step 4:
     *  For each i, Welt(i, n) = max( Welt(0..P-1, n) )
     */
    for(n = 1; n < Q; n++) {
        INSERT_TASK_dlange_max(
            options,
            Welt(0, n), Welt(0, 0) );
    }
}
122

Mathieu Faverge's avatar
Mathieu Faverge committed
123 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
static inline void
chameleon_pzlange_inf( cham_uplo_t uplo, cham_diag_t diag, CHAM_desc_t *A,
                       CHAM_desc_t *Wcol, CHAM_desc_t *Welt,
                       RUNTIME_option_t *options)
{
    int m, n;
    int minMNT = chameleon_min( A->mt, A->nt );
    int minMN  = chameleon_min( A->m,  A->n  );
    int MT = (uplo == ChamUpper) ? minMNT : A->mt;
    int NT = (uplo == ChamLower) ? minMNT : A->nt;
    int M  = (uplo == ChamUpper) ? minMN  : A->m;
    int N  = (uplo == ChamLower) ? minMN  : A->n;
    int P  = Welt->p;
    int Q  = Welt->q;

    /**
     * Step 1:
     *  For j in [1,Q], Wcol(m, j) = reduce( A(m, j+k*Q) )
     */
    for(m = 0; m < MT; m++) {
        int nmin = ( uplo == ChamUpper ) ? m                      : 0;
        int nmax = ( uplo == ChamLower ) ? chameleon_min(m+1, NT) : NT;

        int tempmm = ( m == (MT-1) ) ? M - m * A->mb : A->mb;
        int ldam = BLKLDD( A, m );

        for(n = nmin; n < nmax; n++) {
            int tempnn = ( n == (NT-1) ) ? N - n * A->nb : A->nb;

            if ( (n == m)  && (uplo != ChamUpperLower) ) {
                INSERT_TASK_ztrasm(
                    options,
                    ChamRowwise, uplo, diag, tempmm, tempnn,
                    A(m, n), ldam, Wcol(m, n) );
157
            }
Mathieu Faverge's avatar
Mathieu Faverge committed
158
            else {
Mathieu Faverge's avatar
Mathieu Faverge committed
159
                INSERT_TASK_dzasum(
Mathieu Faverge's avatar
Mathieu Faverge committed
160 161 162
                    options,
                    ChamRowwise, ChamUpperLower, tempmm, tempnn,
                    A(m, n), ldam, Wcol(m, n) );
163 164
            }

Mathieu Faverge's avatar
Mathieu Faverge committed
165
            if ( n >= Q ) {
Mathieu Faverge's avatar
Mathieu Faverge committed
166
                INSERT_TASK_dgeadd(
Mathieu Faverge's avatar
Mathieu Faverge committed
167 168 169 170
                    options,
                    ChamNoTrans, tempmm, 1, A->mb,
                    1.0, Wcol(m, n  ), tempmm,
                    1.0, Wcol(m, n%Q), tempmm );
171
            }
Mathieu Faverge's avatar
Mathieu Faverge committed
172
        }
173

Mathieu Faverge's avatar
Mathieu Faverge committed
174 175 176 177 178 179 180 181 182 183
        /**
         * Step 2:
         *  For each j, W(m, j) = reduce( Wcol(m, 0..Q-1) )
         */
        for(n = 1; n < Q; n++) {
            INSERT_TASK_dgeadd(
                options,
                ChamNoTrans, tempmm, 1, A->mb,
                1.0, Wcol(m, n), tempmm,
                1.0, Wcol(m, 0), tempmm );
184 185
        }

Mathieu Faverge's avatar
Mathieu Faverge committed
186 187 188 189 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 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 244 245 246 247 248 249 250 251 252
        INSERT_TASK_dlange(
            options,
            ChamMaxNorm, tempmm, 1, A->nb,
            Wcol(m, 0), 1, Welt(m, 0));
    }

    /**
     * Step 3:
     *  For m in 0..P-1, Welt(m, n) = max( Wcol(m..mt[P], n ) )
     */
    for(m = P; m < MT; m++) {
        INSERT_TASK_dlange_max(
            options,
            Welt(m, 0), Welt(m%P, 0) );
    }

    /**
     * Step 4:
     *  For each i, Welt(i, n) = max( Welt(0..P-1, n) )
     */
    for(m = 1; m < P; m++) {
        INSERT_TASK_dlange_max(
            options,
            Welt(m, 0), Welt(0, 0) );
    }
}

static inline void
chameleon_pzlange_max( cham_uplo_t uplo, cham_diag_t diag, CHAM_desc_t *A, CHAM_desc_t *Welt,
                       RUNTIME_option_t *options)
{
    int m, n;
    int minMNT = chameleon_min( A->mt, A->nt );
    int minMN  = chameleon_min( A->m,  A->n  );
    int MT = (uplo == ChamUpper) ? minMNT : A->mt;
    int NT = (uplo == ChamLower) ? minMNT : A->nt;
    int M  = (uplo == ChamUpper) ? minMN  : A->m;
    int N  = (uplo == ChamLower) ? minMN  : A->n;
    int P  = Welt->p;
    int Q  = Welt->q;

    /**
     * Step 1:
     *  For j in [1,Q], Welt(m, j) = reduce( A(m, j+k*Q) )
     */
    for(m = 0; m < MT; m++) {
        int nmin = ( uplo == ChamUpper ) ? m                      : 0;
        int nmax = ( uplo == ChamLower ) ? chameleon_min(m+1, NT) : NT;

        int tempmm = ( m == (MT-1) ) ? M - m * A->mb : A->mb;
        int ldam = BLKLDD( A, m );

        for(n = nmin; n < nmax; n++) {
            int tempnn = ( n == (NT-1) ) ? N - n * A->nb : A->nb;

            if ( (n == m)  && (uplo != ChamUpperLower) ) {
                INSERT_TASK_zlantr(
                    options,
                    ChamMaxNorm, uplo, diag, tempmm, tempnn, A->nb,
                    A(m, n), ldam, Welt(m, n));
            }
            else {
                INSERT_TASK_zlange(
                    options,
                    ChamMaxNorm, tempmm, tempnn, A->nb,
                    A(m, n), ldam, Welt(m, n));
            }
253

Mathieu Faverge's avatar
Mathieu Faverge committed
254
            if ( n >= Q ) {
Mathieu Faverge's avatar
Mathieu Faverge committed
255
                INSERT_TASK_dlange_max(
Mathieu Faverge's avatar
Mathieu Faverge committed
256 257
                    options,
                    Welt(m, n), Welt(m, n%Q) );
258 259 260
            }
        }

Mathieu Faverge's avatar
Mathieu Faverge committed
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 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 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
        /**
         * Step 2:
         *  For each j, W(m, j) = reduce( Welt(m, 0..Q-1) )
         */
        for(n = 1; n < Q; n++) {
            INSERT_TASK_dlange_max(
                options,
                Welt(m, n), Welt(m, 0) );
        }
    }

    /**
     * Step 3:
     *  For m in 0..P-1, Welt(m, n) = max( Welt(m..mt[P], n ) )
     */
    for(m = P; m < MT; m++) {
        INSERT_TASK_dlange_max(
            options,
            Welt(m, 0), Welt(m%P, 0) );
    }

    /**
     * Step 4:
     *  For each i, Welt(i, n) = max( Welt(0..P-1, n) )
     */
    for(m = 1; m < P; m++) {
        INSERT_TASK_dlange_max(
            options,
            Welt(m, 0), Welt(0, 0) );
    }
}

static inline void
chameleon_pzlange_frb( cham_uplo_t uplo, cham_diag_t diag, CHAM_desc_t *A, CHAM_desc_t *Welt,
                       RUNTIME_option_t *options)
{
    int m, n;
    int minMNT = chameleon_min( A->mt, A->nt );
    int minMN  = chameleon_min( A->m,  A->n  );
    int MT = (uplo == ChamUpper) ? minMNT : A->mt;
    int NT = (uplo == ChamLower) ? minMNT : A->nt;
    int M  = (uplo == ChamUpper) ? minMN  : A->m;
    int N  = (uplo == ChamLower) ? minMN  : A->n;
    int P  = Welt->p;
    int Q  = Welt->q;

    /**
     * Step 1:
     *  For j in [1,Q], Welt(m, j) = reduce( A(m, j+k*Q) )
     */
    for(m = 0; m < MT; m++) {
        int nmin = ( uplo == ChamUpper ) ? m                      : 0;
        int nmax = ( uplo == ChamLower ) ? chameleon_min(m+1, NT) : NT;

        int tempmm = ( m == (MT-1) ) ? M - m * A->mb : A->mb;
        int ldam = BLKLDD( A, m );

        for(n = nmin; n < nmax; n++) {
            int tempnn = ( n == (NT-1) ) ? N - n * A->nb : A->nb;

            if ( (n == m) && (uplo != ChamUpperLower) ) {
                INSERT_TASK_ztrssq(
                    options,
                    uplo, diag, tempmm, tempnn,
                    A(m, n), ldam, Welt(m, n) );
            }
            else {
                INSERT_TASK_zgessq(
                    options,
                    tempmm, tempnn,
                    A(m, n), ldam, Welt(m, n) );
            }

            if ( n >= Q ) {
                INSERT_TASK_dplssq(
                    options, Welt(m, n), Welt(m, n%Q) );
337 338 339
            }
        }

Mathieu Faverge's avatar
Mathieu Faverge committed
340 341 342
        /**
         * Step 2:
         *  For each j, W(m, j) = reduce( Welt(m, 0..Q-1) )
343
         */
Mathieu Faverge's avatar
Mathieu Faverge committed
344 345 346 347 348
        for(n = 1; n < Q; n++) {
            INSERT_TASK_dplssq(
                options, Welt(m, n), Welt(m, 0) );
        }
    }
349

Mathieu Faverge's avatar
Mathieu Faverge committed
350 351 352 353 354 355 356 357
    /**
     * Step 3:
     *  For m in 0..P-1, Welt(m, n) = max( Welt(m..mt[P], n ) )
     */
    for(m = P; m < MT; m++) {
        INSERT_TASK_dplssq(
            options, Welt(m, 0), Welt(m%P, 0) );
    }
358

Mathieu Faverge's avatar
Mathieu Faverge committed
359 360 361 362 363 364 365 366
    /**
     * Step 4:
     *  For each i, Welt(i, n) = max( Welt(0..P-1, n) )
     */
    for(m = 1; m < P; m++) {
        INSERT_TASK_dplssq(
            options, Welt(m, 0), Welt(0, 0) );
    }
367

Mathieu Faverge's avatar
Mathieu Faverge committed
368 369 370
    INSERT_TASK_dplssq2(
        options, Welt(0, 0) );
}
371

Mathieu Faverge's avatar
Mathieu Faverge committed
372 373 374 375 376 377 378 379 380 381 382 383 384
/**
 *
 */
void chameleon_pzlange_generic( cham_normtype_t norm, cham_uplo_t uplo, cham_diag_t diag,
                                CHAM_desc_t *A, double *result,
                                RUNTIME_sequence_t *sequence, RUNTIME_request_t *request )
{
    CHAM_context_t *chamctxt;
    RUNTIME_option_t options;
    CHAM_desc_t *Wcol = NULL;
    CHAM_desc_t *Welt = NULL;
    double alpha = 0.0;
    double beta  = 0.0;
385

Mathieu Faverge's avatar
Mathieu Faverge committed
386 387
    int workn, workmt, worknt;
    int m, n;
388

Mathieu Faverge's avatar
Mathieu Faverge committed
389 390 391 392
    chamctxt = chameleon_context_self();
    if (sequence->status != CHAMELEON_SUCCESS)
        return;
    RUNTIME_options_init(&options, chamctxt, sequence, request);
393

Mathieu Faverge's avatar
Mathieu Faverge committed
394
    *result = 0.0;
395

Mathieu Faverge's avatar
Mathieu Faverge committed
396 397 398
    workmt = chameleon_max( A->mt, A->p );
    worknt = chameleon_max( A->nt, A->q );
    workn  = chameleon_max( A->n,  A->q );
399

Mathieu Faverge's avatar
Mathieu Faverge committed
400 401 402
    switch ( norm ) {
    case ChamOneNorm:
        RUNTIME_options_ws_alloc( &options, 1, 0 );
403

Mathieu Faverge's avatar
Mathieu Faverge committed
404 405
        CHAMELEON_Desc_Create( &Wcol, NULL, ChamRealDouble, 1, A->nb, A->nb,
                               workmt, worknt * A->nb, 0, 0, workmt, worknt * A->nb, A->p, A->q );
406

Mathieu Faverge's avatar
Mathieu Faverge committed
407 408
        CHAMELEON_Desc_Create( &Welt, NULL, ChamRealDouble, 1, 1, 1,
                               A->p, worknt, 0, 0, A->p, worknt, A->p, A->q );
409

Mathieu Faverge's avatar
Mathieu Faverge committed
410
        break;
411

Mathieu Faverge's avatar
Mathieu Faverge committed
412 413 414 415 416
        /*
         *  ChamInfNorm
         */
    case ChamInfNorm:
        RUNTIME_options_ws_alloc( &options, A->mb, 0 );
417

Mathieu Faverge's avatar
Mathieu Faverge committed
418 419 420 421 422
        CHAMELEON_Desc_Create( &Wcol, NULL, ChamRealDouble, A->mb, 1, A->mb,
                               workmt * A->mb, worknt, 0, 0, workmt * A->mb, worknt, A->p, A->q );

        CHAMELEON_Desc_Create( &Welt, NULL, ChamRealDouble, 1, 1, 1,
                               workmt, A->q, 0, 0, workmt, A->q, A->p, A->q );
423 424 425
        break;

        /*
Mathieu Faverge's avatar
Mathieu Faverge committed
426
         *  ChamFrobeniusNorm
427
         */
Mathieu Faverge's avatar
Mathieu Faverge committed
428
    case ChamFrobeniusNorm:
Mathieu Faverge's avatar
Mathieu Faverge committed
429
        RUNTIME_options_ws_alloc( &options, 1, 0 );
430

Mathieu Faverge's avatar
Mathieu Faverge committed
431 432 433
        alpha = 1.;
        CHAMELEON_Desc_Create( &Welt, NULL, ChamRealDouble, 2, 1, 2,
                               workmt*2, workn, 0, 0, workmt*2, workn, A->p, A->q );
434 435 436
        break;

        /*
Mathieu Faverge's avatar
Mathieu Faverge committed
437
         *  ChamMaxNorm
438
         */
Mathieu Faverge's avatar
Mathieu Faverge committed
439
    case ChamMaxNorm:
440 441 442
    default:
        RUNTIME_options_ws_alloc( &options, 1, 0 );

Mathieu Faverge's avatar
Mathieu Faverge committed
443 444 445
        CHAMELEON_Desc_Create( &Welt, NULL, ChamRealDouble, 1, 1, 1,
                               workmt, workn, 0, 0, workmt, workn, A->p, A->q );
    }
446

Mathieu Faverge's avatar
Mathieu Faverge committed
447 448 449 450 451 452 453 454
    /* Initialize workspaces */
    if ( (norm == ChamInfNorm) ||
         (norm == ChamOneNorm) )
    {
        /* Initialize Wcol tile */
        for(m = 0; m < Wcol->mt; m++) {
            for(n = 0; n < Wcol->nt; n++) {
                INSERT_TASK_dlaset(
455
                    &options,
Mathieu Faverge's avatar
Mathieu Faverge committed
456 457 458
                    ChamUpperLower, Wcol->mb, Wcol->nb,
                    alpha, beta,
                    Wcol(m,n), Wcol->mb );
459 460
            }
        }
Mathieu Faverge's avatar
Mathieu Faverge committed
461 462 463 464 465 466 467 468 469 470
    }
    for(m = 0; m < Welt->mt; m++) {
        for(n = 0; n < Welt->nt; n++) {
            INSERT_TASK_dlaset(
                &options,
                ChamUpperLower, Welt->mb, Welt->nb,
                alpha, beta,
                Welt(m,n), Welt->mb );
        }
    }
471

Mathieu Faverge's avatar
Mathieu Faverge committed
472 473 474 475 476
    switch ( norm ) {
    case ChamOneNorm:
        chameleon_pzlange_one( uplo, diag, A, Wcol, Welt, &options );
        CHAMELEON_Desc_Flush( Wcol, sequence );
        break;
477

Mathieu Faverge's avatar
Mathieu Faverge committed
478 479 480 481
    case ChamInfNorm:
        chameleon_pzlange_inf( uplo, diag, A, Wcol, Welt, &options );
        CHAMELEON_Desc_Flush( Wcol, sequence );
        break;
482

Mathieu Faverge's avatar
Mathieu Faverge committed
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497
    case ChamFrobeniusNorm:
        chameleon_pzlange_frb( uplo, diag, A, Welt, &options );
        break;

    case ChamMaxNorm:
    default:
        chameleon_pzlange_max( uplo, diag, A, Welt, &options );
    }

    /**
     * Broadcast the result
     */
    for(m = 0; m < A->p; m++) {
        for(n = 0; n < A->q; n++) {
            if ( (m != 0) && (n != 0) ) {
Mathieu Faverge's avatar
Mathieu Faverge committed
498
                INSERT_TASK_dlacpy(
499
                    &options,
Mathieu Faverge's avatar
Mathieu Faverge committed
500
                    ChamUpperLower, 1, 1, 1,
Mathieu Faverge's avatar
Mathieu Faverge committed
501
                    Welt(0,0), 1, Welt(m, n), 1);
502 503 504
            }
        }
    }
Mathieu Faverge's avatar
Mathieu Faverge committed
505

Mathieu Faverge's avatar
Mathieu Faverge committed
506 507 508 509 510 511 512 513 514
    CHAMELEON_Desc_Flush( Welt, sequence );
    RUNTIME_sequence_wait(chamctxt, sequence);

    *result = *(double *)Welt->get_blkaddr(Welt, A->myrank / A->q, A->myrank % A->q );

    if ( Wcol != NULL ) {
        CHAMELEON_Desc_Destroy( &Wcol );
    }
    CHAMELEON_Desc_Destroy( &Welt );
Mathieu Faverge's avatar
Mathieu Faverge committed
515

516
    RUNTIME_options_ws_free(&options);
Mathieu Faverge's avatar
Mathieu Faverge committed
517
    RUNTIME_options_finalize(&options, chamctxt);
518
}