pzunmqrrh.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 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++) {
THIBAULT Samuel's avatar
THIBAULT Samuel committed
110
                RUNTIME_set_iteration(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 181 182 183 184 185 186
                        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);
                        }
                    }
                }
            }
        } else {
            /*
             *  MorseLeft / MorseNoTrans
             */
            for (k = K-1; k >= 0; k--) {
THIBAULT Samuel's avatar
THIBAULT Samuel committed
187
                RUNTIME_set_iteration(morse, k);
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
                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;
215
                    tempkmin = chameleon_min(tempMm, tempkn);
216 217
                    ldaM = BLKLDD(A, M);
                    ldbM = BLKLDD(B, M);
218
                    for (m = chameleon_min(M+BS, A->mt)-1; m > M; m--) {
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
                        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);
                        }
                    }
235
#if defined(CHAMELEON_COPY_DIAG)
236 237 238 239 240
                    MORSE_TASK_zlacpy(
                        &options,
                        MorseLower, tempMm, tempkmin, A->nb,
                        A(M, k), ldaM,
                        DIAG(M, k), ldaM );
Mathieu Faverge's avatar
Mathieu Faverge committed
241
#if defined(CHAMELEON_USE_CUDA)
242 243 244 245 246
                    MORSE_TASK_zlaset(
                        &options,
                        MorseUpper, tempMm, tempkmin,
                        0., 1.,
                        DIAG(M, k), ldaM );
247
#endif
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
#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);
                    }
                }
            }
        }
    } else {
        if (trans == MorseConjTrans) {
            /*
             *  MorseRight / MorseConjTrans
             */
            for (k = K-1; k >= 0; k--) {
THIBAULT Samuel's avatar
THIBAULT Samuel committed
269
                RUNTIME_set_iteration(morse, k);
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
                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;
296
                    tempkmin = chameleon_min(tempMm, tempkn);
297 298
                    ldaM = BLKLDD(A, M);
                    ldbM = BLKLDD(B, M);
299
                    for (n = chameleon_min(M+BS, A->mt)-1; n > M; n--) {
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
                        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);
                        }
                    }
316
#if defined(CHAMELEON_COPY_DIAG)
317 318 319 320 321
                    MORSE_TASK_zlacpy(
                        &options,
                        MorseLower, tempMm, tempkmin, A->nb,
                        A(M, k), ldaM,
                        DIAG(M, k), ldaM );
Mathieu Faverge's avatar
Mathieu Faverge committed
322
#if defined(CHAMELEON_USE_CUDA)
323 324 325 326 327
                    MORSE_TASK_zlaset(
                        &options,
                        MorseUpper, tempMm, tempkmin,
                        0., 1.,
                        DIAG(M, k), ldaM );
328
#endif
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
#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);
                    }
                }
            }
        } else {
            /*
             *  MorseRight / MorseNoTrans
             */
            for (k = 0; k < K; k++) {
THIBAULT Samuel's avatar
THIBAULT Samuel committed
349
                RUNTIME_set_iteration(morse, k);
350

351 352 353
                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;
354
                    tempkmin = chameleon_min(tempMm, tempkn);
355
                    ldaM = BLKLDD(A, M);
356
#if defined(CHAMELEON_COPY_DIAG)
357 358 359 360 361
                    MORSE_TASK_zlacpy(
                        &options,
                        MorseLower, tempMm, tempkmin, A->nb,
                        A(M, k), ldaM,
                        DIAG(M, k), ldaM );
Mathieu Faverge's avatar
Mathieu Faverge committed
362
#if defined(CHAMELEON_USE_CUDA)
363 364 365 366 367
                    MORSE_TASK_zlaset(
                        &options,
                        MorseUpper, tempMm, tempkmin,
                        0., 1.,
                        DIAG(M, k), ldaM );
368
#endif
369 370 371 372 373 374 375 376 377 378 379 380 381
#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);
                    }
382
                    for (n = M+1; n < chameleon_min(M+BS,  A->mt); n++) {
383 384 385 386 387 388 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 425
                        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);
                        }
                    }
                }
            }
        }
    }
    RUNTIME_options_ws_free(&options);
    RUNTIME_options_finalize(&options, morse);
    MORSE_TASK_dataflush_all();

426 427
#if defined(CHAMELEON_COPY_DIAG)
    MORSE_Sequence_Wait(sequence);
428 429
    morse_desc_mat_free(DIAG);
    free(DIAG);
430
#endif
431
    (void)DIAG;
432
}