pzungqrrh.c 6.03 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 pzungqrrh.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 Q(m,n) Q,  (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 D(m,n) D, ((m)/BS), 0
40
#else
41
#define D(m,n) A, (m), (n)
42
#endif
43 44 45 46 47 48

/**
 *  Parallel construction of Q using tile V (application to identity;
 *  reduction Householder) - dynamic scheduling
 **/
void morse_pzungqrrh(MORSE_desc_t *A, MORSE_desc_t *Q,
49
                     MORSE_desc_t *T,  MORSE_desc_t *D, int BS,
50 51 52 53 54 55 56 57 58 59
                     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, M, RD, lastRD;
    int ldaM, ldam, ldaMRD;
60
    int ldqM, ldqm, ldqMRD;
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
    int tempkn, tempMm, 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
78
#if defined(CHAMELEON_USE_CUDA)
79 80 81 82 83
    /* Worker space
     *
     * zunmqr = A->nb * ib
     * ztsmqr = 2 * A->nb * ib
     */
84
    ws_worker = chameleon_max( ws_worker, ib * A->nb * 2 );
85 86 87 88 89 90 91
#endif

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

    RUNTIME_options_ws_alloc( &options, ws_worker, ws_host );

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

96 97 98 99 100 101 102
        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;
103 104
                ldqM   = BLKLDD(Q, M   );
                ldqMRD = BLKLDD(Q, M+RD);
105
                ldaMRD = BLKLDD(A, M+RD);
106
                for (n = k; n < Q->nt; n++) {
107
                    tempnn = n == Q->nt-1 ? Q->n-n*Q->nb : Q->nb;
108 109 110 111 112 113

                    RUNTIME_data_migrate( sequence, Q(M, n),
                                          Q->get_rankof( Q, M+RD, n ) );
                    RUNTIME_data_migrate( sequence, Q(M+RD, n),
                                          Q->get_rankof( Q, M+RD, n ) );

114
                    /* TT kernel */
115
                    MORSE_TASK_ztpmqrt(
116 117
                        &options,
                        MorseLeft, MorseNoTrans,
118
                        tempMRDm, tempnn, tempkn, tempMRDm, ib, T->nb,
119
                        A (M+RD, k), ldaMRD,
120 121 122
                        T2(M+RD, k), T->mb,
                        Q (M,    n), ldqM,
                        Q (M+RD, n), ldqMRD);
123 124 125 126 127
                }
            }
        }
        for (M = k; M < A->mt; M += BS) {
            tempMm   = M == A->mt-1 ? A->m-M*A->mb : A->mb;
128
            tempkmin = chameleon_min(tempMm, tempkn);
129
            ldaM = BLKLDD(A, M);
130
            ldqM = BLKLDD(Q, M);
131
            for (m = chameleon_min(M+BS, A->mt)-1; m > M; m--) {
132
                tempmm = m == A->mt-1 ? A->m-m*A->mb : A->mb;
133
                ldqm = BLKLDD(Q, m);
134 135
                ldam = BLKLDD(A, m);

136
                for (n = k; n < Q->nt; n++) {
137
                    tempnn = n == Q->nt-1 ? Q->n-n*Q->nb : Q->nb;
138 139 140 141 142 143

                    RUNTIME_data_migrate( sequence, Q(M, n),
                                          Q->get_rankof( Q, m, n ) );
                    RUNTIME_data_migrate( sequence, Q(m, n),
                                          Q->get_rankof( Q, m, n ) );

144
                    /* TS kernel */
145
                    MORSE_TASK_ztpmqrt(
146 147
                        &options,
                        MorseLeft, MorseNoTrans,
148
                        tempmm, tempnn, tempkn, 0, ib, T->nb,
149
                        A(m, k), ldam,
150 151 152
                        T(m, k), T->mb,
                        Q(M, n), ldqM,
                        Q(m, n), ldqm);
153 154
                }
            }
155

156
#if defined(CHAMELEON_COPY_DIAG)
157 158 159 160
            MORSE_TASK_zlacpy(
                &options,
                MorseLower, tempMm, tempkmin, A->nb,
                A(M, k), ldaM,
161
                D(M, k), ldaM );
Mathieu Faverge's avatar
Mathieu Faverge committed
162
#if defined(CHAMELEON_USE_CUDA)
163 164 165 166
            MORSE_TASK_zlaset(
                &options,
                MorseUpper, tempMm, tempkmin,
                0., 1.,
167
                D(M, k), ldaM );
168
#endif
169 170
#endif
            for (n = k; n < Q->nt; n++) {
171
                tempnn = n == Q->nt-1 ? Q->n-n*Q->nb : Q->nb;
172 173 174 175 176

                /* Restore the original location of the tiles */
                RUNTIME_data_migrate( sequence, Q(M, n),
                                      Q->get_rankof( Q, M, n ) );

177 178 179 180 181
                MORSE_TASK_zunmqr(
                    &options,
                    MorseLeft, MorseNoTrans,
                    tempMm, tempnn,
                    tempkmin, ib, T->nb,
182
                    D(M, k), ldaM,
183
                    T(M, k), T->mb,
184
                    Q(M, n), ldqM);
185 186
            }
        }
187
        RUNTIME_iteration_pop(morse);
188
    }
Mathieu Faverge's avatar
Mathieu Faverge committed
189

190 191
    RUNTIME_options_ws_free(&options);
    RUNTIME_options_finalize(&options, morse);
Mathieu Faverge's avatar
Mathieu Faverge committed
192
    (void)D;
193
}