pzunglqrh.c 5.14 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
 *
 **/

/**
 *
 * @file pzunglqrh.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 Dulceneia Becker
 * @author Mathieu Faverge
 * @author Emmanuel Agullo
 * @author Cedric Castagnede
 * @date 2011-05-24
 * @precisions normal z -> s d c
 *
 **/
30
#include "control/common.h"
31 32 33 34 35

#define A(m,n) A,  (m),  (n)
#define Q(m,n) Q,  (m),  (n)
#define T(m,n) T,  (m),  (n)
#define T2(m,n) T,  (m),  (n)+(A->nt)
36
#if defined(CHAMELEON_COPY_DIAG)
37
#define D(m,n) D, ((n)/BS), 0
38
#else
39
#define D(m,n) A, (m), (n)
40
#endif
41

42 43 44 45 46
/**
 *  Parallel construction of Q using tile V (application to identity;
 *  reduction Householder) - dynamic scheduling
 **/
void morse_pzunglqrh(MORSE_desc_t *A, MORSE_desc_t *Q,
47
                     MORSE_desc_t *T, MORSE_desc_t *D, int BS,
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
                     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;

    int k, m, n;
    int K, N, RD, lastRD;
    int ldak;
    int ldqm;
    int tempkm, tempkmin, tempNn, tempnn, tempmm, tempNRDn;
    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
76
#if defined(CHAMELEON_USE_CUDA)
77 78 79 80 81
    /* Worker space
     *
     * zunmqr = A->nb * ib
     * ztsmqr = 2 * A->nb * ib
     */
82
    ws_worker = chameleon_max( ws_worker, ib * A->nb * 2 );
83 84 85 86 87 88 89
#endif

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

    RUNTIME_options_ws_alloc( &options, ws_worker, ws_host );

90
    K = chameleon_min(A->mt, A->nt);
91
    for (k = K-1; k >= 0; k--) {
92
        RUNTIME_iteration_push(morse, k);
93

94 95 96 97 98 99 100 101
        tempkm = k == A->mt-1 ? A->m-k*A->mb : A->mb;
        ldak = BLKLDD(A, k);
        lastRD = 0;
        for (RD = BS; RD < A->nt-k; RD *= 2)
            lastRD = RD;
        for (RD = lastRD; RD >= BS; RD /= 2) {
            for (N = k; N+RD < A->nt; N += 2*RD) {
                tempNRDn = N+RD == A->nt-1 ? A->n-(N+RD)*A->nb : A->nb;
102
                for (m = k; m < Q->mt; m++) {
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
                    tempmm = m == Q->mt-1 ? Q->m-m*Q->mb : Q->mb;
                    ldqm   = BLKLDD(Q, m   );
                    MORSE_TASK_zttmlq(
                        &options,
                        MorseRight, MorseNoTrans,
                        tempmm, Q->nb, tempmm, tempNRDn,
                        tempkm, ib, T->nb,
                        Q (m, N   ), ldqm,
                        Q (m, N+RD), ldqm,
                        A (k, N+RD), ldak,
                        T2(k, N+RD), T->mb);
                }
            }
        }
        for (N = k; N < A->nt; N += BS) {
            tempNn = N == A->nt-1 ? A->n-N*A->nb : A->nb;
119 120
            tempkmin = chameleon_min(tempkm, tempNn);
            for (n = chameleon_min(N+BS, A->nt)-1; n > N; n--) {
121 122
                tempnn = n == Q->nt-1 ? Q->n-n*Q->nb : Q->nb;

123
                for (m = k; m < Q->mt; m++) {
124 125 126 127 128 129 130 131 132 133 134 135 136
                    tempmm = m == Q->mt-1 ? Q->m-m*Q->mb : Q->mb;
                    ldqm = BLKLDD(Q, m);
                    MORSE_TASK_ztsmlq(
                        &options,
                        MorseRight, MorseNoTrans,
                        tempmm, Q->nb, tempmm, tempnn,
                        tempkm, ib, T->nb,
                        Q(m, N), ldqm,
                        Q(m, n), ldqm,
                        A(k, n), ldak,
                        T(k, n), T->mb);
                }
            }
137
#if defined(CHAMELEON_COPY_DIAG)
138 139 140 141
            MORSE_TASK_zlacpy(
                &options,
                MorseUpper, tempkmin, tempNn, A->nb,
                A(k, N), ldak,
142
                D(k, N), ldak );
Mathieu Faverge's avatar
Mathieu Faverge committed
143
#if defined(CHAMELEON_USE_CUDA)
144 145 146 147
            MORSE_TASK_zlaset(
                &options,
                MorseLower, tempkmin, tempNn,
                0., 1.,
148
                D(k, N), ldak );
149
#endif
150 151
#endif
            for (m = k; m < Q->mt; m++) {
152 153 154 155 156 157 158
                tempmm = m == Q->mt-1 ? Q->m-m*Q->mb : Q->mb;
                ldqm = BLKLDD(Q, m);
                MORSE_TASK_zunmlq(
                    &options,
                    MorseRight, MorseNoTrans,
                    tempmm, tempNn,
                    tempkmin, ib, T->nb,
159
                    D(k, N), ldak,
160 161 162 163
                    T(k, N), T->mb,
                    Q(m, N), ldqm);
            }
        }
164 165

        RUNTIME_iteration_pop(morse);
166 167 168 169 170
    }
    RUNTIME_options_ws_free(&options);
    RUNTIME_options_finalize(&options, morse);
    MORSE_TASK_dataflush_all();
}