pzgelqf_param.c 5.89 KB
Newer Older
1
/**
2 3
 *
 * @file pzgelqf_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 zgelqf_param parallel algorithm
13
 *
Mathieu Faverge's avatar
Mathieu Faverge 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 28
#define A(m,n) A, (m), (n)
#define T(m,n) T, (m), (n)
#define D(m,n) D, (m), (n)

29
/**
30
 *  Parallel tile LQ factorization (reduction Householder) - dynamic scheduling
31
 */
32 33 34
void chameleon_pzgelqf_param( int genD, const libhqr_tree_t *qrtree, CHAM_desc_t *A,
                              CHAM_desc_t *TS, CHAM_desc_t *TT, CHAM_desc_t *D,
                              RUNTIME_sequence_t *sequence, RUNTIME_request_t *request )
35
{
Mathieu Faverge's avatar
Mathieu Faverge committed
36
    CHAM_context_t *chamctxt;
37 38
    RUNTIME_option_t options;
    CHAM_desc_t *T;
39 40 41 42
    size_t ws_worker = 0;
    size_t ws_host = 0;

    int k, m, n, i, p;
43
    int K, L, nbgeqrt;
44
    int ldak, ldam, lddk;
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
45
    int tempkmin, tempkm, tempnn, tempmm, temppn;
46
    int ib, node, nbtiles, *tiles;
47

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

54
    ib = CHAMELEON_IB;
55

56
    if ( D == NULL ) {
57 58
        D    = A;
        genD = 0;
59 60
    }

61
    /*
62 63 64 65
     * zgelqt  = A->nb * (ib+1)
     * zunmlq  = A->nb * ib
     * ztplqt  = A->nb * (ib+1)
     * ztpmlqt = A->nb * ib
66 67 68 69 70
     */
    ws_worker = A->nb * (ib+1);

    /* Allocation of temporary (scratch) working space */
#if defined(CHAMELEON_USE_CUDA)
71
    /*
72 73
     * zunmlq  =     A->nb * ib
     * ztpmlqt = 3 * A->nb * ib
74
     */
75
    ws_worker = chameleon_max( ws_worker, ib * A->nb * 3 );
76 77
#endif

78 79
    ws_worker *= sizeof(CHAMELEON_Complex64_t);
    ws_host   *= sizeof(CHAMELEON_Complex64_t);
80 81 82

    RUNTIME_options_ws_alloc( &options, ws_worker, ws_host );

83 84 85
    /* Initialisation of temporary tiles array */
    tiles = (int*)calloc(qrtree->mt, sizeof(int));

86 87 88
    K = chameleon_min(A->mt, A->nt);

    for (k = 0; k < K; k++) {
Mathieu Faverge's avatar
Mathieu Faverge committed
89
        RUNTIME_iteration_push(chamctxt, k);
90

BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
91 92
        tempkm = k == A->mt-1 ? A->m-k*A->mb : A->mb;
        ldak = BLKLDD(A, k);
93
        lddk = BLKLDD(D, k);
94

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

        T = TS;
        for (i = 0; i < nbgeqrt; i++) {
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
100 101 102
            p = qrtree->getm(qrtree, k, i);
            temppn = p == A->nt-1 ? A->n-p*A->nb : A->nb;
            tempkmin = chameleon_min(tempkm, temppn);
103

104
            INSERT_TASK_zgelqt(
105
                &options,
106
                tempkm, temppn, ib, T->nb,
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
107
                A( k, p), ldak,
108
                T(k, p), T->mb);
109

110
            if ( genD ) {
111
                INSERT_TASK_zlacpy(
112
                    &options,
113
                    ChamUpper, tempkm, temppn, A->nb,
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
114
                    A(k, p), ldak,
115
                    D(k, p), lddk );
116
#if defined(CHAMELEON_USE_CUDA)
117
                INSERT_TASK_zlaset(
118
                    &options,
119
                    ChamLower, tempkm, temppn,
120
                    0., 1.,
121
                    D(k, p), lddk );
122 123
#endif
            }
124

125
            for (m = k+1; m < A->mt; m++) {
126
                tempmm = m == A->mt-1 ? A->m-m*A->mb : A->mb;
127
                ldam = BLKLDD(A, m);
128
                INSERT_TASK_zunmlq(
129
                    &options,
130
                    ChamRight, ChamConjTrans,
131
                    tempmm, temppn, tempkmin, ib, T->nb,
132
                    D(k, p), lddk,
133 134
                    T(k, p), T->mb,
                    A(m, p), ldam);
135
            }
Mathieu Faverge's avatar
Mathieu Faverge committed
136 137
            RUNTIME_data_flush( sequence, D(k, p) );
            RUNTIME_data_flush( sequence, T(k, p) );
138 139 140
        }

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

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

147
            tempnn = n == A->nt-1 ? A->n-n*A->nb : A->nb;
148

149
            if ( qrtree->gettype(qrtree, k, n) == LIBHQR_KILLED_BY_TS ) {
150
                /* TS kernel */
151 152
                T = TS;
                L = 0;
153 154
            }
            else {
155
                /* TT kernel */
156 157 158 159
                T = TT;
                L = tempnn;
            }

160 161 162
            node = A->get_rankof( A, k, n );
            RUNTIME_data_migrate( sequence, A(k, p), node );
            RUNTIME_data_migrate( sequence, A(k, n), node );
163

164
            INSERT_TASK_ztplqt(
165 166 167 168 169 170 171 172 173 174
                &options,
                tempkm, tempnn, chameleon_min(L, tempkm), ib, T->nb,
                A(k, p), ldak,
                A(k, n), ldak,
                T(k, n), T->mb);

            for (m = k+1; m < A->mt; m++) {
                tempmm = m == A->mt-1 ? A->m-m*A->mb : A->mb;
                ldam = BLKLDD(A, m);

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

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

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

Mathieu Faverge's avatar
Mathieu Faverge committed
198
        RUNTIME_iteration_pop(chamctxt);
199 200 201 202
    }

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