pzgeqrfrh.c 6.84 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
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
10
 ***
11
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
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
Mathieu Faverge's avatar
Mathieu Faverge committed
16
 *          from Plasma 2.5.0 for CHAMELEON 1.0.0
17 18 19 20 21 22 23 24 25
 * @author Jakub Kurzak
 * @author Hatem Ltaief
 * @author Dulceneia Becker
 * @author Mathieu Faverge
 * @author Emmanuel Agullo
 * @author Cedric Castagnede
 * @date 2010-11-15
 * @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;
Mathieu Faverge's avatar
Mathieu Faverge committed
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;
Mathieu Faverge's avatar
Mathieu Faverge committed
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
    RUNTIME_options_init(&options, chamctxt, sequence, request);
55

Mathieu Faverge's avatar
Mathieu Faverge committed
56
    ib = CHAMELEON_IB;
57

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

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

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

Mathieu Faverge's avatar
Mathieu Faverge committed
81 82
    ws_worker *= sizeof(CHAMELEON_Complex64_t);
    ws_host   *= sizeof(CHAMELEON_Complex64_t);
83 84 85

    RUNTIME_options_ws_alloc( &options, ws_worker, ws_host );

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

90 91 92
        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;
93
            tempkmin = chameleon_min(tempMm, tempkn);
94
            ldaM = BLKLDD(A, M);
Mathieu Faverge's avatar
Mathieu Faverge committed
95
            lddM = BLKLDD(D, M);
96

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

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

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

136
                /* TS kernel */
Mathieu Faverge's avatar
Mathieu Faverge committed
137
                INSERT_TASK_ztpqrt(
138
                    &options,
139
                    tempmm, tempkn, 0, ib, T->nb,
140 141 142 143 144 145
                    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;
146 147 148 149

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

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

169 170 171
                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 );
172

173
                /* TT kernel */
Mathieu Faverge's avatar
Mathieu Faverge committed
174
                INSERT_TASK_ztpqrt(
175
                    &options,
Mathieu Faverge's avatar
Mathieu Faverge committed
176
                    tempMRDm, tempkn, chameleon_min( tempMRDm, tempkn ), ib, T->nb,
177 178 179 180 181 182
                    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;
183

184 185 186
                    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 );
187

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

        /* 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
208
        RUNTIME_iteration_pop(chamctxt);
209
    }
Mathieu Faverge's avatar
Mathieu Faverge committed
210

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