pzpotrimm.c 16.6 KB
Newer Older
1 2
/**
 *
3 4
 * @copyright (c) 2009-2014 The University of Tennessee and The University
 *                          of Tennessee Research Foundation.
5
 *                          All rights reserved.
6
 * @copyright (c) 2012-2016 Inria. All rights reserved.
7
 * @copyright (c) 2012-2014 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria, Univ. Bordeaux. All rights reserved.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 **/

/**
 *
 * @file pzpotrimm.c
 *
 *  MORSE auxiliary routines
 *  MORSE is a software package provided by Univ. of Tennessee,
 *  Univ. of California Berkeley and Univ. of Colorado Denver
 *
 * @version 2.5.0
 * @comment This file has been automatically generated
 *          from Plasma 2.5.0 for MORSE 1.0.0
 * @author Hatem Ltaief
 * @author Mathieu Faverge
24
 * @author Ali M Charara
25 26 27 28
 * @date 2010-11-15
 * @precisions normal z -> s d c
 *
 **/
29
#include "control/common.h"
30 31 32 33 34 35 36 37

#define A(m,n) A,  m,  n
#define B(m,n) B,  m,  n
#define C(m,n) C,  m,  n
/***************************************************************************//**
 *  Parallel tile Cholesky factorization - dynamic scheduling
 **/
void morse_pzpotrimm(MORSE_enum uplo, MORSE_desc_t *A, MORSE_desc_t *B, MORSE_desc_t *C,
38
                     MORSE_sequence_t *sequence, MORSE_request_t *request)
39 40 41 42 43
{
    MORSE_context_t *morse;
    MORSE_option_t options;

    int k, m, n;
44
    int ldbm, ldcm;
45 46 47
    int ldak, ldam, ldan;
    int tempkm, tempmm, tempnn, tempkn;

48
    MORSE_Complex64_t alpha = (MORSE_Complex64_t) 1.0;
49 50 51 52 53 54 55 56 57 58 59
    MORSE_Complex64_t beta  = (MORSE_Complex64_t) 0.0;
    MORSE_Complex64_t zbeta;
    MORSE_Complex64_t zone  = (MORSE_Complex64_t) 1.0;
    MORSE_Complex64_t mzone = (MORSE_Complex64_t)-1.0;


    morse = morse_context_self();
    if (sequence->status != MORSE_SUCCESS)
        return;
    RUNTIME_options_init(&options, morse, sequence, request);

60
#ifdef CHAMELEON_USE_MAGMA
61
    {
62
#if !defined(CHAMELEON_SIMULATION)
PRUVOST Florent's avatar
PRUVOST Florent committed
63 64
        int nb = magma_get_zpotrf_nb(A->nb);
#else
PRUVOST Florent's avatar
PRUVOST Florent committed
65
        int nb = A->nb;
66
#endif
PRUVOST Florent's avatar
PRUVOST Florent committed
67
        RUNTIME_options_ws_alloc( &options, nb*nb, 0 );
68 69 70 71 72 73 74 75 76 77
    }
#endif

    /*
     *  MorseLower
     */
    if (uplo == MorseLower) {
        /*
         *  ZPOTRF
         */
78
        for (k = 0; k < A->mt; k++) {
79 80
            RUNTIME_set_iteration(k);

81 82
            tempkm = k == A->mt-1 ? A->m-k*A->mb : A->mb;
            ldak = BLKLDD(A, k);
83

84 85 86
            MORSE_TASK_zpotrf(
                &options,
                MorseLower, tempkm, A->mb,
87
                A(k, k), ldak, A->nb*k);
88

89 90 91 92 93 94 95 96 97 98 99 100
            for (m = k+1; m < A->mt; m++) {
                tempmm = m == A->mt-1 ? A->m-m*A->mb : A->mb;
                ldam = BLKLDD(A, m);
                MORSE_TASK_ztrsm(
                    &options,
                    MorseRight, MorseLower, MorseConjTrans, MorseNonUnit,
                    tempmm, A->mb, A->mb,
                    zone, A(k, k), ldak,
                          A(m, k), ldam);
            }
            MORSE_TASK_dataflush( &options, A(k, k) );

101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
            for (n = k+1; n < A->nt; n++) {
                tempnn = n == A->nt-1 ? A->n-n*A->nb : A->nb;
                ldan = BLKLDD(A, n);
                MORSE_TASK_zherk(
                    &options,
                    MorseLower, MorseNoTrans,
                    tempnn, A->nb, A->mb,
                    -1.0, A(n, k), ldan,
                     1.0, A(n, n), ldan);

                for (m = n+1; m < A->mt; m++) {
                    tempmm = m == A->mt-1 ? A->m - m*A->mb : A->mb;
                    ldam = BLKLDD(A, m);
                    MORSE_TASK_zgemm(
                        &options,
                        MorseNoTrans, MorseConjTrans,
                        tempmm, tempnn, A->mb, A->mb,
                        mzone, A(m, k), ldam,
                               A(n, k), ldan,
                        zone,  A(m, n), ldam);
                }
                MORSE_TASK_dataflush( &options, A(n, k) );
            }
        }
125 126 127
        /*
         *  ZTRTRI
         */
128
        for (k = 0; k < A->nt; k++) {
129 130
            RUNTIME_set_iteration(A->nt + k);

131 132 133
            tempkn = k == A->nt-1 ? A->n-k*A->nb : A->nb;
            ldak = BLKLDD(A, k);
            for (m = k+1; m < A->mt; m++) {
134 135 136 137 138
                tempmm = m == A->mt-1 ? A->m-m*A->mb : A->mb;
                ldam = BLKLDD(A, m);
                MORSE_TASK_ztrsm(
                    &options,
                    MorseRight, uplo, MorseNoTrans, MorseNonUnit,
139 140 141
                    tempmm, tempkn, A->mb,
                    mzone, A(k, k), ldak,
                           A(m, k), ldam);
142
            }
143
            for (m = k+1; m < A->mt; m++) {
144 145
                tempmm = m == A->mt-1 ? A->m-m*A->mb : A->mb;
                ldam = BLKLDD(A, m);
146
                for (n = 0; n < k; n++) {
147 148 149
                    MORSE_TASK_zgemm(
                        &options,
                        MorseNoTrans, MorseNoTrans,
150 151 152 153
                        tempmm, A->nb, tempkn, A->mb,
                        zone, A(m, k), ldam,
                              A(k, n), ldak,
                        zone, A(m, n), ldam);
154
                }
155
                MORSE_TASK_dataflush( &options, A(m, k) );
156
            }
157 158
            for (n = 0; n < k; n++) {
                MORSE_TASK_dataflush( &options, A(k, n) );
159 160 161
                MORSE_TASK_ztrsm(
                    &options,
                    MorseLeft, uplo, MorseNoTrans, MorseNonUnit,
162 163 164
                    tempkn, A->nb, A->mb,
                    zone, A(k, k), ldak,
                          A(k, n), ldak);
165
            }
166
            MORSE_TASK_dataflush( &options, A(k, k) );
167 168 169
            MORSE_TASK_ztrtri(
                &options,
                uplo, MorseNonUnit,
170 171
                tempkn, A->mb,
                A(k, k), ldak, A->nb*k);
172 173 174 175
        }
        /*
         *  ZLAUUM
         */
176
        for (k = 0; k < A->mt; k++) {
177 178
            RUNTIME_set_iteration(2*A->nt + k);

179 180 181 182
            tempkm = k == A->mt-1 ? A->m-k*A->mb : A->mb;
            ldak = BLKLDD(A, k);
            for(n = 0; n < k; n++) {
                ldan = BLKLDD(A, n);
183 184 185
                MORSE_TASK_zherk(
                    &options,
                    uplo, MorseConjTrans,
186 187 188
                    A->mb, tempkm, A->mb,
                    1.0, A(k, n), ldak,
                    1.0, A(n, n), ldan);
189

190 191
                for(m = n+1; m < k; m++) {
                    ldam = BLKLDD(A, m);
192 193 194
                    MORSE_TASK_zgemm(
                        &options,
                        MorseConjTrans, MorseNoTrans,
195 196 197 198
                        A->mb, A->nb, tempkm, A->mb,
                        1.0, A(k, m), ldak,
                             A(k, n), ldak,
                        1.0, A(m, n), ldam);
199 200
                }
            }
201 202
            for (n = 0; n < k; n++) {
                MORSE_TASK_dataflush( &options, A(k, n) );
203 204 205
                MORSE_TASK_ztrmm(
                    &options,
                    MorseLeft, uplo, MorseConjTrans, MorseNonUnit,
206 207 208
                    tempkm, A->nb, A->mb,
                    1.0, A(k, k), ldak,
                         A(k, n), ldak);
209
            }
210
            MORSE_TASK_dataflush( &options, A(k, k) );
211 212
            MORSE_TASK_zlauum(
                &options,
213 214
                uplo, tempkm, A->mb,
                A(k, k), ldak);
215 216
        }
        /*
217
         *  ZSYMM Right / Lower
218
         */
219
        for (k = 0; k < C->nt; k++) {
220 221
            RUNTIME_set_iteration(3*A->nt + k);

222 223 224 225 226 227 228 229 230 231 232 233 234
            tempkn = k == C->nt-1 ? C->n-k*C->nb : C->nb;
            ldak = BLKLDD(A, k);
            zbeta = k == 0 ? beta : zone;

            for (m = 0; m < C->mt; m++) {
                tempmm = m == C->mt-1 ? C->m-m*C->mb : C->mb;
                ldbm = BLKLDD(B, m);
                ldcm = BLKLDD(C, m);

                for (n = 0; n < C->nt; n++) {
                    tempnn = n == C->nt-1 ? C->n-n*C->nb : C->nb;
                    ldan = BLKLDD(A, n);

235 236 237 238 239
                    if (k < n) {
                       MORSE_TASK_zgemm(
                           &options,
                           MorseNoTrans, MorseTrans,
                           tempmm, tempnn, tempkn, A->mb,
240 241 242
                           alpha, B(m, k), ldbm,  /* ldbm * K */
                                  A(n, k), ldan,  /* ldan * K */
                           zbeta, C(m, n), ldcm); /* ldcm * Y */
243 244 245 246 247 248 249
                    }
                    else {
                        if (k == n) {
                           MORSE_TASK_zsymm(
                               &options,
                               MorseRight, uplo,
                               tempmm, tempnn, A->mb,
250 251 252
                               alpha, A(k, k), ldak,  /* ldak * Y */
                                      B(m, k), ldbm,  /* ldbm * Y */
                               zbeta, C(m, n), ldcm); /* ldcm * Y */
253 254 255 256 257 258
                        }
                        else {
                            MORSE_TASK_zgemm(
                                &options,
                                MorseNoTrans, MorseNoTrans,
                                tempmm, tempnn, tempkn, A->mb,
259 260 261
                                alpha, B(m, k), ldbm,  /* ldbm * K */
                                       A(k, n), ldak,  /* ldak * Y */
                                zbeta, C(m, n), ldcm); /* ldcm * Y */
262 263 264
                        }
                    }
                }
265 266 267 268
                MORSE_TASK_dataflush( &options, B(m, k) );
            }
            for (n = 0; n <= k; n++) {
                MORSE_TASK_dataflush( &options, A(k, n) );
269 270 271 272 273 274 275 276 277 278 279
            }
        }
    }
    /*
     *  MorseUpper
     */
    else {
        /*
         *  ZPOTRF
         */
        for (k = 0; k < A->nt; k++) {
280 281
            RUNTIME_set_iteration(k);

282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
            tempkm = k == A->nt-1 ? A->n-k*A->nb : A->nb;
            ldak = BLKLDD(A, k);
            MORSE_TASK_zpotrf(
                &options,
                MorseUpper,
                tempkm, A->mb,
                A(k, k), ldak, A->nb*k);

            for (n = k+1; n < A->nt; n++) {
                tempnn = n == A->nt-1 ? A->n - n*A->nb : A->nb;
                MORSE_TASK_ztrsm(
                    &options,
                    MorseLeft, MorseUpper, MorseConjTrans, MorseNonUnit,
                    A->mb, tempnn, A->mb,
                    zone, A(k, k), ldak,
297
                          A(k, n), ldak);
298 299 300
            }
            MORSE_TASK_dataflush( &options, A(k, k) );

301 302 303
            for (m = k+1; m < A->mt; m++) {
                tempmm = m == A->mt-1 ? A->m - m*A->mb : A->mb;
                ldam = BLKLDD(A, m);
304 305 306 307 308 309

                MORSE_TASK_zherk(
                    &options,
                    MorseUpper, MorseConjTrans,
                    tempmm, A->mb, A->mb,
                    -1.0, A(k, m), ldak,
310 311 312 313
                     1.0, A(m, m), ldam);

                for (n = m+1; n < A->nt; n++) {
                    tempnn = n == A->nt-1 ? A->n-n*A->nb : A->nb;
314 315 316 317 318 319

                    MORSE_TASK_zgemm(
                        &options,
                        MorseConjTrans, MorseNoTrans,
                        tempmm, tempnn, A->mb, A->mb,
                        mzone, A(k, m), ldak,
320
                               A(k, n), ldak,
321
                        zone,  A(m, n), ldam);
322 323 324 325
                }
                MORSE_TASK_dataflush( &options, A(k, m) );
            }
        }
326 327 328
        /*
         *  ZTRTRI
         */
329
        for (k = 0; k < A->mt; k++) {
330 331
            RUNTIME_set_iteration(A->nt + k);

332 333 334
            tempkm = k == A->mt-1 ? A->m-k*A->mb : A->mb;
            ldak = BLKLDD(A, k);
            for (n = k+1; n < A->nt; n++) {
335 336 337 338
                tempnn = n == A->nt-1 ? A->n-n*A->nb : A->nb;
                MORSE_TASK_ztrsm(
                    &options,
                    MorseLeft, uplo, MorseNoTrans, MorseNonUnit,
339 340 341
                    tempkm, tempnn, A->mb,
                    mzone, A(k, k), ldak,
                           A(k, n), ldak);
342
            }
343
            for (n = k+1; n < A->nt; n++) {
344
                tempnn = n == A->nt-1 ? A->n-n*A->nb : A->nb;
345 346
                for (m = 0; m < k; m++) {
                    ldam = BLKLDD(A, m);
347 348 349
                    MORSE_TASK_zgemm(
                        &options,
                        MorseNoTrans, MorseNoTrans,
350 351 352 353
                        A->mb, tempnn, tempkm, A->mb,
                        zone, A(m, k), ldam,
                              A(k, n), ldak,
                        zone, A(m, n), ldam);
354
                }
355 356 357 358 359
                MORSE_TASK_dataflush( &options, A(k, n) );
            }
            for (m = 0; m < k; m++) {
                ldam = BLKLDD(A, m);
                MORSE_TASK_dataflush( &options, A(m, k) );
360 361 362
                MORSE_TASK_ztrsm(
                    &options,
                    MorseRight, uplo, MorseNoTrans, MorseNonUnit,
363 364 365
                    A->mb, tempkm, A->mb,
                    zone, A(k, k), ldak,
                          A(m, k), ldam);
366
            }
367
            MORSE_TASK_dataflush( &options, A(k, k) );
368 369 370
            MORSE_TASK_ztrtri(
                &options,
                uplo, MorseNonUnit,
371 372
                tempkm, A->mb,
                A(k, k), ldak, A->mb*k);
373 374 375 376
        }
        /*
         *  ZLAUUM
         */
377
        for (k = 0; k < A->mt; k++) {
378 379
            RUNTIME_set_iteration(2*A->nt + k);

380 381 382 383 384
            tempkn = k == A->nt-1 ? A->n-k*A->nb : A->nb;
            ldak = BLKLDD(A, k);

            for (m = 0; m < k; m++) {
                ldam = BLKLDD(A, m);
385 386 387
                MORSE_TASK_zherk(
                    &options,
                    uplo, MorseNoTrans,
388 389 390
                    A->mb, tempkn, A->mb,
                    1.0, A(m, k), ldam,
                    1.0, A(m, m), ldam);
391

392 393
                for (n = m+1; n < k; n++){
                    ldan = BLKLDD(A, n);
394 395 396
                    MORSE_TASK_zgemm(
                        &options,
                        MorseNoTrans, MorseConjTrans,
397 398 399 400
                        A->mb, A->nb, tempkn, A->mb,
                        1.0, A(m, k), ldam,
                             A(n, k), ldan,
                        1.0, A(m, n), ldam);
401 402
                }
            }
403 404 405
            for (m = 0; m < k; m++) {
                ldam = BLKLDD(A, m);
                MORSE_TASK_dataflush( &options, A(m, k) );
406 407 408
                MORSE_TASK_ztrmm(
                    &options,
                    MorseRight, uplo, MorseConjTrans, MorseNonUnit,
409 410 411
                    A->mb, tempkn, A->mb,
                    1.0, A(k, k), ldak,
                         A(m, k), ldam);
412
            }
413
            MORSE_TASK_dataflush( &options, A(k, k) );
414 415
            MORSE_TASK_zlauum(
                &options,
416 417
                uplo, tempkn, A->mb,
                A(k, k), ldak);
418 419
        }
        /*
420
         *  ZSYMM Right / Upper
421
         */
422
        for (k = 0; k < C->nt; k++) {
423 424
            RUNTIME_set_iteration(3*A->nt + k);

425 426 427 428 429 430 431 432 433 434 435 436 437
            tempkn = k == C->nt-1 ? C->n-k*C->nb : C->nb;
            ldak = BLKLDD(A, k);
            zbeta = k == 0 ? beta : zone;

            for (m = 0; m < C->mt; m++) {
                tempmm = m == C->mt-1 ? C->m-m*C->mb : C->mb;
                ldbm = BLKLDD(B, m);
                ldcm = BLKLDD(C, m);

                for (n = 0; n < C->nt; n++) {
                    tempnn = n == C->nt-1 ? C->n-n*C->nb : C->nb;
                    ldan = BLKLDD(A, n);

438 439 440 441 442
                    if (k < n) {
                        MORSE_TASK_zgemm(
                            &options,
                            MorseNoTrans, MorseNoTrans,
                            tempmm, tempnn, tempkn, A->mb,
443 444 445
                            alpha, B(m, k), ldbm,  /* ldbm * K */
                                   A(k, n), ldak,  /* ldak * Y */
                            zbeta, C(m, n), ldcm); /* ldcm * Y */
446 447 448 449 450 451 452
                    }
                    else {
                        if (k == n) {
                            MORSE_TASK_zsymm(
                                &options,
                                MorseRight, uplo,
                                tempmm, tempnn, A->mb,
453 454 455
                                alpha, A(k, k), ldak,  /* ldak * Y */
                                       B(m, k), ldbm,  /* ldbm * Y */
                                zbeta, C(m, n), ldcm); /* ldcm * Y */
456 457 458 459 460 461
                        }
                        else {
                            MORSE_TASK_zgemm(
                                &options,
                                MorseNoTrans, MorseTrans,
                                tempmm, tempnn, tempkn, A->mb,
462 463 464
                                alpha, B(m, k), ldbm,  /* ldbm * K */
                                       A(n, k), ldan,  /* ldan * K */
                                zbeta, C(m, n), ldcm); /* ldcm * Y */
465 466 467
                        }
                    }
                }
468 469 470 471
                MORSE_TASK_dataflush( &options, B(m, k) );
            }
            for (m = 0; m <= k; m++) {
                MORSE_TASK_dataflush( &options, A(m, k) );
472 473 474 475
            }
        }
    }

476
#ifdef CHAMELEON_USE_MAGMA
477 478 479 480
    RUNTIME_options_ws_free(&options);
#endif
    RUNTIME_options_finalize(&options, morse);
}