pzgeqrfrh.c 6.85 KB
Newer Older
1
/**
2 3
 *
 * @file pzgeqrfrh.c
4
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
5 6
 * @copyright 2009-2014 The University of Tennessee and The University of
 *                      Tennessee Research Foundation. All rights reserved.
Mathieu Faverge's avatar
Mathieu Faverge committed
7
 * @copyright 2012-2018 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
8
 *                      Univ. Bordeaux. All rights reserved.
9
 *
10
 ***
11
 *
12
 * @brief Chameleon zgeqrfrh parallel algorithm
13
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
14
 * @version 1.0.0
15
 * @comment This file has been automatically generated
16
 *          from Plasma 2.5.0 for CHAMELEON 1.0.0
17 18 19 20 21 22
 * @author Jakub Kurzak
 * @author Hatem Ltaief
 * @author Dulceneia Becker
 * @author Mathieu Faverge
 * @author Emmanuel Agullo
 * @author Cedric Castagnede
23
 * @date 2018-11-09
24 25
 * @precisions normal z -> s d c
 *
26
 */
27
#include "control/common.h"
28

29 30
#define A(m,n)  A,  (m),  (n)
#define T(m,n)  T,  (m),  (n)
31
#define T2(m,n) T,  (m), ((n)+A->nt)
32
#define D(m,n)  D,  (m),  (n)
33

34
/**
35
 *  Parallel tile QR factorization (reduction Householder) - dynamic scheduling
36
 */
37 38
void chameleon_pzgeqrfrh( int genD, int BS, CHAM_desc_t *A, CHAM_desc_t *T, CHAM_desc_t *D,
                          RUNTIME_sequence_t *sequence, RUNTIME_request_t *request )
39
{
Mathieu Faverge's avatar
Mathieu Faverge committed
40
    CHAM_context_t *chamctxt;
41
    RUNTIME_option_t options;
42 43 44 45 46
    size_t ws_worker = 0;
    size_t ws_host = 0;

    int k, m, n;
    int K, M, RD;
47
    int ldaM, ldam, ldaMRD, lddM;
48
    int tempkmin, tempkn, tempMm, tempnn, tempmm, tempMRDm;
49
    int ib, node;
50

Mathieu Faverge's avatar
Mathieu Faverge committed
51
    chamctxt = chameleon_context_self();
Mathieu Faverge's avatar
Mathieu Faverge committed
52
    if (sequence->status != CHAMELEON_SUCCESS) {
53
        return;
Mathieu Faverge's avatar
Mathieu Faverge committed
54
    }
Mathieu Faverge's avatar
Mathieu Faverge committed
55
    RUNTIME_options_init(&options, chamctxt, sequence, request);
56

57
    ib = CHAMELEON_IB;
58

59 60 61 62 63
    if ( D == NULL ) {
        D    = A;
        genD = 0;
    }

64
    /*
65 66 67 68
     * zgeqrt  = A->nb * (ib+1)
     * zunmqr  = A->nb * ib
     * ztpqrt  = A->nb * (ib+1)
     * ztpmqrt = A->nb * ib
69 70 71 72
     */
    ws_worker = A->nb * (ib+1);

    /* Allocation of temporary (scratch) working space */
Mathieu Faverge's avatar
Mathieu Faverge committed
73 74 75
#if defined(CHAMELEON_USE_CUDA)
    /* Worker space
     *
76
     * zunmqr  =     A->nb * ib
Mathieu Faverge's avatar
Mathieu Faverge committed
77
     * ztpmqrt = 3 * A->nb * ib
Mathieu Faverge's avatar
Mathieu Faverge committed
78
     */
79
    ws_worker = chameleon_max( ws_worker, ib * A->nb * 3 );
Mathieu Faverge's avatar
Mathieu Faverge committed
80 81
#endif

82 83
    ws_worker *= sizeof(CHAMELEON_Complex64_t);
    ws_host   *= sizeof(CHAMELEON_Complex64_t);
84 85 86

    RUNTIME_options_ws_alloc( &options, ws_worker, ws_host );

87
    K = chameleon_min(A->mt, A->nt);
88
    for (k = 0; k < K; k++) {
Mathieu Faverge's avatar
Mathieu Faverge committed
89
        RUNTIME_iteration_push(chamctxt, k);
90

91 92 93
        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;
94
            tempkmin = chameleon_min(tempMm, tempkn);
95
            ldaM = BLKLDD(A, M);
96
            lddM = BLKLDD(D, M);
97

98
            INSERT_TASK_zgeqrt(
99 100 101 102
                &options,
                tempMm, tempkn, ib, T->nb,
                A(M, k), ldaM,
                T(M, k), T->mb);
103 104 105
            if ( genD ) {
                INSERT_TASK_zlacpy(
                    &options,
106
                    ChamLower, tempMm, tempkn, A->nb,
107
                    A(M, k), ldaM,
108
                    D(M, k), lddM );
Mathieu Faverge's avatar
Mathieu Faverge committed
109
#if defined(CHAMELEON_USE_CUDA)
110
                INSERT_TASK_zlaset(
111
                    &options,
112
                    ChamUpper, tempMm, tempkn,
113
                    0., 1.,
114
                    D(M, k), lddM );
115
#endif
116
            }
117 118
            for (n = k+1; n < A->nt; n++) {
                tempnn = n == A->nt-1 ? A->n-n*A->nb : A->nb;
119
                INSERT_TASK_zunmqr(
120
                    &options,
121
                    ChamLeft, ChamConjTrans,
122
                    tempMm, tempnn, tempkmin, ib, T->nb,
123
                    D(M, k), lddM,
124 125 126
                    T(M, k), T->mb,
                    A(M, n), ldaM);
            }
Mathieu Faverge's avatar
Mathieu Faverge committed
127 128
            RUNTIME_data_flush( sequence, D(M, k) );
            RUNTIME_data_flush( sequence, T(M, k) );
129

130
            for (m = M+1; m < chameleon_min(M+BS, A->mt); m++) {
131 132
                tempmm = m == A->mt-1 ? A->m-m*A->mb : A->mb;
                ldam = BLKLDD(A, m);
133 134 135 136

                RUNTIME_data_migrate( sequence, A(M, k),
                                      A->get_rankof( A, m, k ) );

137
                /* TS kernel */
138
                INSERT_TASK_ztpqrt(
139
                    &options,
140
                    tempmm, tempkn, 0, ib, T->nb,
141 142 143 144 145 146
                    A(M, k), ldaM,
                    A(m, k), ldam,
                    T(m, k), T->mb);

                for (n = k+1; n < A->nt; n++) {
                    tempnn = n == A->nt-1 ? A->n-n*A->nb : A->nb;
147 148 149 150

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

151
                    INSERT_TASK_ztpmqrt(
152
                        &options,
153
                        ChamLeft, ChamConjTrans,
154
                        tempmm, tempnn, A->nb, 0, ib, T->nb,
155
                        A(m, k), ldam,
156 157 158
                        T(m, k), T->mb,
                        A(M, n), ldaM,
                        A(m, n), ldam);
159
                }
Mathieu Faverge's avatar
Mathieu Faverge committed
160 161
                RUNTIME_data_flush( sequence, A(m, k) );
                RUNTIME_data_flush( sequence, T(m, k) );
162 163 164 165 166 167 168
            }
        }
        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;
                ldaM   = BLKLDD(A, M   );
                ldaMRD = BLKLDD(A, M+RD);
169

170 171 172
                node = A->get_rankof( A, M+RD, k );
                RUNTIME_data_migrate( sequence, A(M, k),    node );
                RUNTIME_data_migrate( sequence, A(M+RD, k), node );
173

174
                /* TT kernel */
175
                INSERT_TASK_ztpqrt(
176
                    &options,
177
                    tempMRDm, tempkn, chameleon_min( tempMRDm, tempkn ), ib, T->nb,
178 179 180 181 182 183
                    A (M   , k), ldaM,
                    A (M+RD, k), ldaMRD,
                    T2(M+RD, k), T->mb);

                for (n = k+1; n < A->nt; n++) {
                    tempnn = n == A->nt-1 ? A->n-n*A->nb : A->nb;
184

185 186 187
                    node = A->get_rankof( A, M+RD, n );
                    RUNTIME_data_migrate( sequence, A(M, n),    node );
                    RUNTIME_data_migrate( sequence, A(M+RD, n), node );
188

189
                    INSERT_TASK_ztpmqrt(
190
                        &options,
191
                        ChamLeft, ChamConjTrans,
192
                        tempMRDm, tempnn, A->nb, tempMRDm, ib, T->nb,
193
                        A (M+RD, k), ldaMRD,
194 195 196
                        T2(M+RD, k), T->mb,
                        A (M,    n), ldaM,
                        A (M+RD, n), ldaMRD);
197
                }
Mathieu Faverge's avatar
Mathieu Faverge committed
198 199
                RUNTIME_data_flush( sequence, A (M+RD, k) );
                RUNTIME_data_flush( sequence, T2(M+RD, k) );
200 201
            }
        }
202 203 204 205 206 207 208

        /* Restore the original location of the tiles */
        for (n = k; n < A->nt; n++) {
            RUNTIME_data_migrate( sequence, A(k, n),
                                  A->get_rankof( A, k, n ) );
        }

Mathieu Faverge's avatar
Mathieu Faverge committed
209
        RUNTIME_iteration_pop(chamctxt);
210
    }
211

212
    RUNTIME_options_ws_free(&options);
Mathieu Faverge's avatar
Mathieu Faverge committed
213
    RUNTIME_options_finalize(&options, chamctxt);
Mathieu Faverge's avatar
Mathieu Faverge committed
214
    (void)D;
215
}