pzgeqrf_param.c 6 KB
Newer Older
1
/**
2 3
 *
 * @file pzgeqrf_param.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.
7 8
 * @copyright 2012-2018 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
 *                      Univ. Bordeaux. All rights reserved.
9
 *
10
 ***
11
 *
12
 * @brief Chameleon zgeqrf_param parallel algorithm
13
 *
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
14
 * @version 1.0.0
15 16
 * @author Mathieu Faverge
 * @author Raphael Boucherie
17
 * @date 2018-11-09
18 19
 * @precisions normal z -> s d c
 *
20
 */
21
#include "control/common.h"
Mathieu Faverge's avatar
Mathieu Faverge committed
22
#include <stdlib.h>
23 24
#include "libhqr.h"

25 26 27
#define A(m,n) A, (m), (n)
#define T(m,n) T, (m), (n)
#define D(m,n) D, (m), (n)
28

29 30
/**
 *  Parallel tile QR factorization (reduction Householder) - dynamic scheduling
31 32 33 34
 *
 * @param[in] genD
 *         Indicate if the copies of the geqrt tiles must be done to speedup
 *         computations in updates.
35
 */
36 37
void chameleon_pzgeqrf_param( int genD, int K,
                              const libhqr_tree_t *qrtree, CHAM_desc_t *A,
38
                              CHAM_desc_t *TS, CHAM_desc_t *TT, CHAM_desc_t *D,
39
                              RUNTIME_sequence_t *sequence, RUNTIME_request_t *request )
40
{
Mathieu Faverge's avatar
Mathieu Faverge committed
41
    CHAM_context_t *chamctxt;
42 43
    RUNTIME_option_t options;
    CHAM_desc_t *T;
44 45
    size_t ws_worker = 0;
    size_t ws_host = 0;
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
46

47
    int k, m, n, i, p;
48
    int L, nbgeqrt;
49
    int ldap, ldam, lddm;
50
    int tempkmin, tempkn, tempnn, tempmm;
51
    int ib, node, nbtiles, *tiles;
52

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

59
    ib = CHAMELEON_IB;
60

61
    if ( D == NULL ) {
62 63
        D    = A;
        genD = 0;
64 65
    }

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

    /* Allocation of temporary (scratch) working space */
#if defined(CHAMELEON_USE_CUDA)
76
    /*
77 78
     * zunmqr  =     A->nb * ib
     * ztpmqrt = 3 * A->nb * ib
79
     */
80
    ws_worker = chameleon_max( ws_worker, ib * A->nb * 3 );
81 82
#endif

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

    RUNTIME_options_ws_alloc( &options, ws_worker, ws_host );

88 89
    /* Initialisation of temporary tiles array */
    tiles = (int*)calloc(qrtree->mt, sizeof(int));
90 91

    for (k = 0; k < K; k++) {
Mathieu Faverge's avatar
Mathieu Faverge committed
92
        RUNTIME_iteration_push(chamctxt, k);
93 94 95
        tempkn = k == A->nt-1 ? A->n-k*A->nb : A->nb;

        /* The number of geqrt to apply */
96
        nbgeqrt = qrtree->getnbgeqrf(qrtree, k);
97 98

        T = TS;
99
        for (i = 0; i < nbgeqrt; i++) {
100 101 102 103
            m = qrtree->getm(qrtree, k, i);
            tempmm = m == A->mt-1 ? A->m-m*A->mb : A->mb;
            tempkmin = chameleon_min(tempmm, tempkn);
            ldam = BLKLDD(A, m);
104
            lddm = BLKLDD(D, m);
105

106
            INSERT_TASK_zgeqrt(
107
                &options,
108 109 110
                tempmm, tempkn, ib, T->nb,
                A(m, k), ldam,
                T(m, k), T->mb);
111

112
            if ( genD ) {
113
                INSERT_TASK_zlacpy(
114
                    &options,
115
                    ChamLower, tempmm, tempkn, A->nb,
116
                    A(m, k), ldam,
117
                    D(m, k), lddm );
118
#if defined(CHAMELEON_USE_CUDA)
119
                INSERT_TASK_zlaset(
120
                    &options,
121
                    ChamUpper, tempmm, tempkn,
122
                    0., 1.,
123
                    D(m, k), lddm );
124 125
#endif
            }
126

127 128
            for (n = k+1; n < A->nt; n++) {
                tempnn = n == A->nt-1 ? A->n-n*A->nb : A->nb;
129
                INSERT_TASK_zunmqr(
130
                    &options,
131
                    ChamLeft, ChamConjTrans,
132
                    tempmm, tempnn, tempkmin, ib, T->nb,
133
                    D(m, k), lddm,
134 135
                    T(m, k), T->mb,
                    A(m, n), ldam);
136
            }
Mathieu Faverge's avatar
Mathieu Faverge committed
137 138
            RUNTIME_data_flush( sequence, D(m, k) );
            RUNTIME_data_flush( sequence, T(m, k) );
139 140 141
        }

        /* Setting the order of the tiles */
142
        nbtiles = libhqr_walk_stepk( qrtree, k, tiles );
143

144
        for (i = 0; i < nbtiles; i++) {
145
            m = tiles[i];
146 147
            p = qrtree->currpiv(qrtree, k, m);

148
            tempmm = m == A->mt-1 ? A->m-m*A->mb : A->mb;
149
            ldap = BLKLDD(A, p);
150
            ldam = BLKLDD(A, m);
151

152
            if ( qrtree->gettype(qrtree, k, m) == LIBHQR_KILLED_BY_TS ) {
153
                /* TS kernel */
154 155
                T = TS;
                L = 0;
156 157
            }
            else {
158
                /* TT kernel */
159 160 161 162
                T = TT;
                L = tempmm;
            }

163 164 165
            node = A->get_rankof( A, m, k );
            RUNTIME_data_migrate( sequence, A(p, k), node );
            RUNTIME_data_migrate( sequence, A(m, k), node );
166

167
            INSERT_TASK_ztpqrt(
168
                &options,
169
                tempmm, tempkn, chameleon_min(L, tempkn), ib, T->nb,
170 171 172 173 174 175 176
                A(p, k), ldap,
                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;

177 178 179
                node = A->get_rankof( A, m, n );
                RUNTIME_data_migrate( sequence, A(p, n), node );
                RUNTIME_data_migrate( sequence, A(m, n), node );
180

181
                INSERT_TASK_ztpmqrt(
182
                    &options,
183
                    ChamLeft, ChamConjTrans,
184 185 186 187 188
                    tempmm, tempnn, A->nb, L, ib, T->nb,
                    A(m, k), ldam,
                    T(m, k), T->mb,
                    A(p, n), ldap,
                    A(m, n), ldam);
189
            }
Mathieu Faverge's avatar
Mathieu Faverge committed
190 191
            RUNTIME_data_flush( sequence, A(m, k) );
            RUNTIME_data_flush( sequence, T(m, k) );
192
        }
193 194 195 196 197 198 199

        /* 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
200
        RUNTIME_iteration_pop(chamctxt);
201 202 203 204
    }

    free(tiles);
    RUNTIME_options_ws_free(&options);
Mathieu Faverge's avatar
Mathieu Faverge committed
205
    RUNTIME_options_finalize(&options, chamctxt);
206
}