pzunmqrrh.c 16.8 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 24 25 26 27 28 29 30 31
 *
 **/

/**
 *
 * @file pzunmqrrh.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 Jakub Kurzak
 * @author Dulceneia Becker
 * @author Mathieu Faverge
 * @author Emmanuel Agullo
 * @author Cedric Castagnede
 * @date 2010-11-15
 * @precisions normal z -> s d c
 *
 **/
32
#include "control/common.h"
33 34 35 36 37

#define A(m,n) A,  (m),  (n)
#define B(m,n) B,  (m),  (n)
#define T(m,n) T,  (m),  (n)
#define T2(m,n) T,  (m),  ((n)+A->nt)
38
#if defined(CHAMELEON_COPY_DIAG)
39
#define DIAG(m,n) DIAG, ((m)/BS), 0
40 41 42
#else
#define DIAG(m,n) A, (m), (n)
#endif
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 74 75 76 77 78
/***************************************************************************//**
 *  Parallel application of Q using tile V - QR factorization (reduction
 *  Householder) - dynamic scheduling
 **/
void morse_pzunmqrrh(MORSE_enum side, MORSE_enum trans,
                     MORSE_desc_t *A, MORSE_desc_t *B, MORSE_desc_t *T, int BS,
                     MORSE_sequence_t *sequence, MORSE_request_t *request)
{
    MORSE_context_t *morse;
    MORSE_option_t options;
    size_t ws_worker = 0;
    size_t ws_host = 0;
    MORSE_desc_t *DIAG = NULL;

    int k, m, n;
    int K, M, RD, lastRD;
    int ldaM, ldam, ldan, ldaMRD;
    int ldbM, ldbm, ldbMRD;
    int tempMm, tempkn, tempnn, tempmm, tempMRDm, tempkmin;
    int ib;

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

    ib = MORSE_IB;

    /*
     * zunmqr = A->nb * ib
     * ztsmqr = A->nb * ib
     * zttmqr = A->nb * ib
     */
    ws_worker = A->nb * ib;

Mathieu Faverge's avatar
Mathieu Faverge committed
79
#if defined(CHAMELEON_USE_CUDA)
80 81 82 83 84
    /* Worker space
     *
     * zunmqr = A->nb * ib
     * ztsmqr = 2 * A->nb * ib
     */
85
    ws_worker = chameleon_max( ws_worker, ib * A->nb * 2 );
86 87 88 89 90 91 92
#endif

    ws_worker *= sizeof(MORSE_Complex64_t);
    ws_host   *= sizeof(MORSE_Complex64_t);

    RUNTIME_options_ws_alloc( &options, ws_worker, ws_host );

93
#if defined(CHAMELEON_COPY_DIAG)
94 95 96 97 98 99 100
    /* necessary to avoid dependencies between tasks regarding the diag tile */
    {
        int nblk = ( A->mt + BS -1 ) / BS;
        nblk = ( A->mt + BS -1 ) / BS;
        DIAG = (MORSE_desc_t*)malloc(sizeof(MORSE_desc_t));
        morse_zdesc_alloc_diag(*DIAG, A->mb, A->nb, nblk * A->mb, A->nb, 0, 0, nblk * A->mb, A->nb, A->p, A->q);
    }
101
#endif
102

103
    K = chameleon_min(A->mt, A->nt);
104 105 106 107 108 109
    if (side == MorseLeft ) {
        if (trans == MorseConjTrans) {
            /*
             *  MorseLeft / MorseConjTrans
             */
            for (k = 0; k < K; k++) {
110
                RUNTIME_iteration_push(morse, k);
111

112 113 114
                tempkn = k == A->nt-1 ? A->n-k*A->nb : A->nb;
                for (M = k; M < A->mt; M += BS) {
                    tempMm   = M == A->mt-1 ? A->m-M*A->mb : A->mb;
115
                    tempkmin = chameleon_min(tempMm, tempkn);
116 117
                    ldaM = BLKLDD(A, M);
                    ldbM = BLKLDD(B, M);
118
#if defined(CHAMELEON_COPY_DIAG)
119 120 121 122 123
                    MORSE_TASK_zlacpy(
                        &options,
                        MorseLower, tempMm, tempkmin, A->nb,
                        A(M, k), ldaM,
                        DIAG(M, k), ldaM );
Mathieu Faverge's avatar
Mathieu Faverge committed
124
#if defined(CHAMELEON_USE_CUDA)
125 126 127 128 129
                    MORSE_TASK_zlaset(
                        &options,
                        MorseUpper, tempMm, tempkmin,
                        0., 1.,
                        DIAG(M, k), ldaM );
130
#endif
131 132 133 134 135 136 137 138 139 140 141 142
#endif
                    for (n = 0; n < B->nt; n++) {
                        tempnn = n == B->nt-1 ? B->n-n*B->nb : B->nb;
                        MORSE_TASK_zunmqr(
                            &options,
                            side, trans,
                            tempMm, tempnn,
                            tempkmin, ib, T->nb,
                            DIAG(M, k), ldaM,
                            T(M, k), T->mb,
                            B(M, n), ldbM);
                    }
143
                    for (m = M+1; m < chameleon_min(M+BS, A->mt); m++) {
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 172 173 174 175 176 177 178 179 180
                        tempmm = m == A->mt-1 ? A->m-m*A->mb : A->mb;
                        ldbm = BLKLDD(B, m);
                        ldam = BLKLDD(A, m);
                        for (n = 0; n < B->nt; n++) {
                            tempnn = n == B->nt-1 ? B->n-n*B->nb : B->nb;
                            MORSE_TASK_ztsmqr(
                                &options,
                                side, trans,
                                A->nb, tempnn, tempmm, tempnn,
                                tempkn, ib, T->nb,
                                B(M, n), ldbM,
                                B(m, n), ldbm,
                                A(m, k), ldam,
                                T(m, k), T->mb);
                        }
                    }
                }
                for (RD = BS; RD < A->mt-k; RD *= 2) {
                    for (M = k; M+RD < A->mt; M += 2*RD) {
                        tempMRDm = M+RD == A->mt-1 ? A->m-(M+RD)*A->mb : A->mb;
                        ldbM   = BLKLDD(B, M   );
                        ldbMRD = BLKLDD(B, M+RD);
                        ldaMRD = BLKLDD(A, M+RD);
                        for (n = 0; n < B->nt; n++) {
                            tempnn = n == B->nt-1 ? B->n-n*B->nb : B->nb;
                            MORSE_TASK_zttmqr(
                                &options,
                                side, trans,
                                A->nb, tempnn, tempMRDm, tempnn,
                                tempkn, ib, T->nb,
                                B (M,    n), ldbM,
                                B (M+RD, n), ldbMRD,
                                A (M+RD, k), ldaMRD,
                                T2(M+RD, k), T->mb);
                        }
                    }
                }
181 182

                RUNTIME_iteration_pop(morse);
183 184 185 186 187 188
            }
        } else {
            /*
             *  MorseLeft / MorseNoTrans
             */
            for (k = K-1; k >= 0; k--) {
189
                RUNTIME_iteration_push(morse, k);
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
                tempkn = k == A->nt-1 ? A->n-k*A->nb : A->nb;
                lastRD = 0;
                for (RD = BS; RD < A->mt-k; RD *= 2)
                    lastRD = RD;
                for (RD = lastRD; RD >= BS; RD /= 2) {
                    for (M = k; M+RD < A->mt; M += 2*RD) {
                        tempMRDm = M+RD == A->mt-1 ? A->m-(M+RD)*A->mb : A->mb;
                        ldbM   = BLKLDD(B, M   );
                        ldbMRD = BLKLDD(B, M+RD);
                        ldaMRD = BLKLDD(A, M+RD);
                        for (n = 0; n < B->nt; n++) {
                            tempnn = n == B->nt-1 ? B->n-n*B->nb : B->nb;
                            MORSE_TASK_zttmqr(
                                &options,
                                side, trans,
                                A->nb, tempnn, tempMRDm, tempnn,
                                tempkn, ib, T->nb,
                                B (M,    n), ldbM,
                                B (M+RD, n), ldbMRD,
                                A (M+RD, k), ldaMRD,
                                T2(M+RD, k), T->mb);
                        }
                    }
                }
                for (M = k; M < A->mt; M += BS) {
                    tempMm   = M == A->mt-1 ? A->m-M*A->mb : A->mb;
217
                    tempkmin = chameleon_min(tempMm, tempkn);
218 219
                    ldaM = BLKLDD(A, M);
                    ldbM = BLKLDD(B, M);
220
                    for (m = chameleon_min(M+BS, A->mt)-1; m > M; m--) {
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
                        tempmm = m == A->mt-1 ? A->m-m*A->mb : A->mb;
                        ldbm = BLKLDD(B, m);
                        ldam = BLKLDD(A, m);
                        for (n = 0; n < B->nt; n++) {
                            tempnn = n == B->nt-1 ? B->n-n*B->nb : B->nb;
                            MORSE_TASK_ztsmqr(
                                &options,
                                side, trans,
                                A->nb, tempnn, tempmm, tempnn,
                                tempkn, ib, T->nb,
                                B(M, n), ldbM,
                                B(m, n), ldbm,
                                A(m, k), ldam,
                                T(m, k), T->mb);
                        }
                    }
237
#if defined(CHAMELEON_COPY_DIAG)
238 239 240 241 242
                    MORSE_TASK_zlacpy(
                        &options,
                        MorseLower, tempMm, tempkmin, A->nb,
                        A(M, k), ldaM,
                        DIAG(M, k), ldaM );
Mathieu Faverge's avatar
Mathieu Faverge committed
243
#if defined(CHAMELEON_USE_CUDA)
244 245 246 247 248
                    MORSE_TASK_zlaset(
                        &options,
                        MorseUpper, tempMm, tempkmin,
                        0., 1.,
                        DIAG(M, k), ldaM );
249
#endif
250 251 252 253 254 255 256 257 258 259 260 261 262
#endif
                    for (n = 0; n < B->nt; n++) {
                        tempnn = n == B->nt-1 ? B->n-n*B->nb : B->nb;
                        MORSE_TASK_zunmqr(
                            &options,
                            side, trans,
                            tempMm, tempnn,
                            tempkmin, ib, T->nb,
                            DIAG(M, k), ldaM,
                            T(M, k), T->mb,
                            B(M, n), ldbM);
                    }
                }
263 264

                RUNTIME_iteration_pop(morse);
265 266 267 268 269 270 271 272
            }
        }
    } else {
        if (trans == MorseConjTrans) {
            /*
             *  MorseRight / MorseConjTrans
             */
            for (k = K-1; k >= 0; k--) {
273
                RUNTIME_iteration_push(morse, k);
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
                tempkn = k == A->nt-1 ? A->n-k*A->nb : A->nb;
                lastRD = 0;
                for (RD = BS; RD < A->mt-k; RD *= 2)
                    lastRD = RD;
                for (RD = lastRD; RD >= BS; RD /= 2) {
                    for (M = k; M+RD < A->mt; M += 2*RD) {
                        tempMRDm = M+RD == A->mt-1 ? A->m-(M+RD)*A->mb : A->mb;
                        ldaMRD = BLKLDD(A, M+RD);
                        for (m = 0; m < B->mt; m++) {
                            ldbm   = BLKLDD(B, m);
                            tempmm = m == B->mt-1 ? B->m-m*B->mb : B->mb;
                            MORSE_TASK_zttmqr(
                                &options,
                                side, trans,
                                tempmm, B->nb, tempmm, tempMRDm,
                                tempkn, ib, T->nb,
                                B (m, M), ldbm,
                                B (m, M+RD), ldbm,
                                A (M+RD, k), ldaMRD,
                                T2(M+RD, k), T->mb);
                        }
                    }
                }
                for (M = k; M < A->mt; M += BS) {
                    tempMm   = M == A->mt-1 ? A->m-M*A->mb : A->mb;
300
                    tempkmin = chameleon_min(tempMm, tempkn);
301 302
                    ldaM = BLKLDD(A, M);
                    ldbM = BLKLDD(B, M);
303
                    for (n = chameleon_min(M+BS, A->mt)-1; n > M; n--) {
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319
                        ldan = BLKLDD(A, n);
                        tempnn = n == B->nt-1 ? B->n-n*B->nb : B->nb;
                        for (m = 0; m < B->mt; m++) {
                            ldbm = BLKLDD(B, m);
                            tempmm = m == B->mt-1 ? B->m-m*B->mb : B->mb;
                            MORSE_TASK_ztsmqr(
                                &options,
                                side, trans,
                                tempmm, tempMm, tempmm, tempnn,
                                tempkn, ib, T->nb,
                                B(m, M), ldbm,
                                B(m, n), ldbm,
                                A(n, k), ldan,
                                T(n, k), T->mb);
                        }
                    }
320
#if defined(CHAMELEON_COPY_DIAG)
321 322 323 324 325
                    MORSE_TASK_zlacpy(
                        &options,
                        MorseLower, tempMm, tempkmin, A->nb,
                        A(M, k), ldaM,
                        DIAG(M, k), ldaM );
Mathieu Faverge's avatar
Mathieu Faverge committed
326
#if defined(CHAMELEON_USE_CUDA)
327 328 329 330 331
                    MORSE_TASK_zlaset(
                        &options,
                        MorseUpper, tempMm, tempkmin,
                        0., 1.,
                        DIAG(M, k), ldaM );
332
#endif
333 334 335 336 337 338 339 340 341 342 343 344 345 346
#endif
                    for (m = 0; m < B->mt; m++) {
                        ldbm = BLKLDD(B, m);
                        tempmm = m == B->mt-1 ? B->m-m*B->mb : B->mb;
                        MORSE_TASK_zunmqr(
                            &options,
                            side, trans,
                            tempmm, tempMm,
                            tempkmin, ib, T->nb,
                            DIAG(M, k), ldaM,
                            T(M, k), T->mb,
                            B(m, M), ldbm);
                    }
                }
347 348

                RUNTIME_iteration_pop(morse);
349 350 351 352 353 354
            }
        } else {
            /*
             *  MorseRight / MorseNoTrans
             */
            for (k = 0; k < K; k++) {
355
                RUNTIME_iteration_push(morse, k);
356

357 358 359
                tempkn = k == A->nt-1 ? A->n-k*A->nb : A->nb;
                for (M = k; M < A->mt; M += BS) {
                    tempMm   = M == A->mt-1 ? A->m-M*A->mb : A->mb;
360
                    tempkmin = chameleon_min(tempMm, tempkn);
361
                    ldaM = BLKLDD(A, M);
362
#if defined(CHAMELEON_COPY_DIAG)
363 364 365 366 367
                    MORSE_TASK_zlacpy(
                        &options,
                        MorseLower, tempMm, tempkmin, A->nb,
                        A(M, k), ldaM,
                        DIAG(M, k), ldaM );
Mathieu Faverge's avatar
Mathieu Faverge committed
368
#if defined(CHAMELEON_USE_CUDA)
369 370 371 372 373
                    MORSE_TASK_zlaset(
                        &options,
                        MorseUpper, tempMm, tempkmin,
                        0., 1.,
                        DIAG(M, k), ldaM );
374
#endif
375 376 377 378 379 380 381 382 383 384 385 386 387
#endif
                    for (m = 0; m < B->mt; m++) {
                        ldbm = BLKLDD(B, m);
                        tempmm = m == B->mt-1 ? B->m-m*B->mb : B->mb;
                        MORSE_TASK_zunmqr(
                            &options,
                            side, trans,
                            tempmm, tempMm,
                            tempkmin, ib, T->nb,
                            DIAG(M, k), ldaM,
                            T(M, k), T->mb,
                            B(m, M), ldbm);
                    }
388
                    for (n = M+1; n < chameleon_min(M+BS,  A->mt); n++) {
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424
                        tempnn = n == B->nt-1 ? B->n-n*B->nb : B->nb;
                        ldan = BLKLDD(A, n);
                        for (m = 0; m < B->mt; m++) {
                            tempmm = m == B->mt-1 ? B->m-m*B->mb : B->mb;
                            ldbm = BLKLDD(B, m);
                            MORSE_TASK_ztsmqr(
                                &options,
                                side, trans,
                                tempmm, tempMm, tempmm, tempnn,
                                tempkn, ib, T->nb,
                                B(m, M), ldbm,
                                B(m, n), ldbm,
                                A(n, k), ldan,
                                T(n, k), T->mb);
                        }
                    }
                }
                for (RD = BS; RD < A->mt-k; RD *= 2) {
                    for (M = k; M+RD < A->mt; M += 2*RD) {
                        tempMRDm = M+RD == A->mt-1 ? A->m-(M+RD)*A->mb : A->mb;
                        ldaMRD = BLKLDD(A, M+RD);
                        for (m = 0; m < B->mt; m++) {
                            tempmm = m == B->mt-1 ? B->m-m*B->mb : B->mb;
                            ldbm   = BLKLDD(B, m);
                            MORSE_TASK_zttmqr(
                                &options,
                                side, trans,
                                tempmm, B->nb, tempmm, tempMRDm,
                                tempkn, ib, T->nb,
                                B (m, M   ), ldbm,
                                B (m, M+RD), ldbm,
                                A (M+RD, k), ldaMRD,
                                T2(M+RD, k), T->mb);
                        }
                    }
                }
425 426

                RUNTIME_iteration_pop(morse);
427 428 429 430 431 432 433
            }
        }
    }
    RUNTIME_options_ws_free(&options);
    RUNTIME_options_finalize(&options, morse);
    MORSE_TASK_dataflush_all();

434 435
#if defined(CHAMELEON_COPY_DIAG)
    MORSE_Sequence_Wait(sequence);
436 437
    morse_desc_mat_free(DIAG);
    free(DIAG);
438
#endif
439
    (void)DIAG;
440
}