pzgelqfrh.c 6.86 KB
Newer Older
1
/**
2 3
 *
 * @file pzgelqfrh.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
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
10
 ***
11
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
12
 * @brief Chameleon zgelqfrh 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

Mathieu Faverge's avatar
Mathieu Faverge committed
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

Mathieu Faverge's avatar
Mathieu Faverge committed
34
/*
35
 *  Parallel tile LQ factorization (reduction Householder) - dynamic scheduling
Mathieu Faverge's avatar
Mathieu Faverge committed
36
 */
37 38
void chameleon_pzgelqfrh( 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
    size_t ws_worker = 0;
    size_t ws_host = 0;

    int k, m, n;
Mathieu Faverge's avatar
Mathieu Faverge committed
46
    int K, N, RD;
Mathieu Faverge's avatar
Mathieu Faverge committed
47
    int ldak, ldam, lddk;
48
    int tempkmin, tempkm, tempNn, tempnn, tempmm, tempNRDn;
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 63
     if ( D == NULL ) {
        D    = A;
        genD = 0;
    }

     /*
64 65
     * zgelqt = A->nb * (ib+1)
     * zunmlq = A->nb * ib
66 67
     * ztplqt = A->nb * (ib+1)
     * ztpmlq = 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 );

Mathieu Faverge's avatar
Mathieu Faverge committed
86 87 88 89
    K = chameleon_min(A->mt, A->nt);

    /* The number of the factorization */
    for (k = 0; k < K; k++) {
Mathieu Faverge's avatar
Mathieu Faverge committed
90
        RUNTIME_iteration_push(chamctxt, k);
91

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

96 97
        for (N = k; N < A->nt; N += BS) {
            tempNn = N == A->nt-1 ? A->n-N*A->nb : A->nb;
98
            tempkmin = chameleon_min(tempkm, tempNn);
Mathieu Faverge's avatar
Mathieu Faverge committed
99
            INSERT_TASK_zgelqt(
100 101 102 103
                &options,
                tempkm, tempNn, ib, T->nb,
                A(k, N), ldak,
                T(k, N), T->mb);
104
            if ( genD ) {
Mathieu Faverge's avatar
Mathieu Faverge committed
105
                INSERT_TASK_zlacpy(
Mathieu Faverge's avatar
Mathieu Faverge committed
106
                    &options,
Mathieu Faverge's avatar
Mathieu Faverge committed
107
                    ChamUpper, tempkm, tempNn, A->nb,
Mathieu Faverge's avatar
Mathieu Faverge committed
108
                    A(k, N), ldak,
Mathieu Faverge's avatar
Mathieu Faverge committed
109
                    D(k, N), lddk );
Mathieu Faverge's avatar
Mathieu Faverge committed
110
#if defined(CHAMELEON_USE_CUDA)
Mathieu Faverge's avatar
Mathieu Faverge committed
111
                INSERT_TASK_zlaset(
Mathieu Faverge's avatar
Mathieu Faverge committed
112
                    &options,
Mathieu Faverge's avatar
Mathieu Faverge committed
113
                    ChamLower, tempkm, tempNn,
Mathieu Faverge's avatar
Mathieu Faverge committed
114
                    0., 1.,
Mathieu Faverge's avatar
Mathieu Faverge committed
115
                    D(k, N), lddk );
116
#endif
Mathieu Faverge's avatar
Mathieu Faverge committed
117
            }
118 119 120
            for (m = k+1; m < A->mt; m++) {
                tempmm = m == A->mt-1 ? A->m-m*A->mb : A->mb;
                ldam = BLKLDD(A, m);
Mathieu Faverge's avatar
Mathieu Faverge committed
121
                INSERT_TASK_zunmlq(
122
                    &options,
Mathieu Faverge's avatar
Mathieu Faverge committed
123
                    ChamRight, ChamConjTrans,
124
                    tempmm, tempNn, tempkmin, ib, T->nb,
Mathieu Faverge's avatar
Mathieu Faverge committed
125
                    D(k, N), lddk,
126 127 128
                    T(k, N), T->mb,
                    A(m, N), ldam);
            }
Mathieu Faverge's avatar
Mathieu Faverge committed
129 130
            RUNTIME_data_flush( sequence, D(k, N) );
            RUNTIME_data_flush( sequence, T(k, N) );
131

132
            for (n = N+1; n < chameleon_min(N+BS, A->nt); n++) {
133
                tempnn = n == A->nt-1 ? A->n-n*A->nb : A->nb;
134 135 136 137

                RUNTIME_data_migrate( sequence, A(k, N),
                                      A->get_rankof( A, k, n ) );

138
                /* TS kernel */
Mathieu Faverge's avatar
Mathieu Faverge committed
139
                INSERT_TASK_ztplqt(
140
                    &options,
141
                    tempkm, tempnn, 0, ib, T->nb,
142 143 144 145 146 147 148
                    A(k, N), 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);
149 150 151 152

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

Mathieu Faverge's avatar
Mathieu Faverge committed
153
                    INSERT_TASK_ztpmlqt(
154
                        &options,
Mathieu Faverge's avatar
Mathieu Faverge committed
155
                        ChamRight, ChamConjTrans,
156
                        tempmm, tempnn, tempkm, 0, ib, T->nb,
157
                        A(k, n), ldak,
158 159 160
                        T(k, n), T->mb,
                        A(m, N), ldam,
                        A(m, n), ldam);
161
                }
Mathieu Faverge's avatar
Mathieu Faverge committed
162 163
                RUNTIME_data_flush( sequence, A(k, n) );
                RUNTIME_data_flush( sequence, T(k, n) );
164 165 166 167 168
            }
        }
        for (RD = BS; RD < A->nt-k; RD *= 2) {
            for (N = k; N+RD < A->nt; N += 2*RD) {
                tempNRDn = N+RD == A->nt-1 ? A->n-(N+RD)*A->nb : A->nb;
169

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

174
                /* TT kernel */
Mathieu Faverge's avatar
Mathieu Faverge committed
175
                INSERT_TASK_ztplqt(
176
                    &options,
177
                    tempkm, tempNRDn, chameleon_min(tempNRDn, tempkm), ib, T->nb,
178 179 180 181 182 183 184
                    A (k, N   ), ldak,
                    A (k, N+RD), ldak,
                    T2(k, N+RD), 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 );
185

186 187 188
                    node = A->get_rankof( A, m, N+RD );
                    RUNTIME_data_migrate( sequence, A(m, N),    node );
                    RUNTIME_data_migrate( sequence, A(m, N+RD), node );
189

Mathieu Faverge's avatar
Mathieu Faverge committed
190
                    INSERT_TASK_ztpmlqt(
191
                        &options,
Mathieu Faverge's avatar
Mathieu Faverge committed
192
                        ChamRight, ChamConjTrans,
193
                        tempmm, tempNRDn, tempkm, tempNRDn, ib, T->nb,
194
                        A (k, N+RD), ldak,
195 196 197
                        T2(k, N+RD), T->mb,
                        A (m, N   ), ldam,
                        A (m, N+RD), ldam);
198
                }
Mathieu Faverge's avatar
Mathieu Faverge committed
199 200
                RUNTIME_data_flush( sequence, A (k, N+RD) );
                RUNTIME_data_flush( sequence, T2(k, N+RD) );
201 202
            }
        }
203 204 205 206 207 208 209

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

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