pzgeqrf.c 4.8 KB
Newer Older
1
/**
2 3
 *
 * @file pzgeqrf.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.
PRUVOST Florent's avatar
PRUVOST Florent committed
7
 * @copyright 2012-2019 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
8
 *                      Univ. Bordeaux. All rights reserved.
9
 *
10
 ***
11
 *
12
 * @brief Chameleon zgeqrf parallel algorithm
13
 *
PRUVOST Florent's avatar
PRUVOST Florent committed
14
 * @version 0.9.2
15
 * @comment This file has been automatically generated
PRUVOST Florent's avatar
PRUVOST Florent committed
16
 *          from Plasma 2.5.0 for CHAMELEON 0.9.2
17 18 19 20 21
 * @author Jakub Kurzak
 * @author Hatem Ltaief
 * @author Mathieu Faverge
 * @author Emmanuel Agullo
 * @author Cedric Castagnede
PRUVOST Florent's avatar
PRUVOST Florent committed
22
 * @date 2014-11-16
23 24
 * @precisions normal z -> s d c
 *
25
 */
26
#include "control/common.h"
27 28 29

#define A(m,n) A,  m,  n
#define T(m,n) T,  m,  n
30
#define D(k)   D,  k,  k
31

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

    int k, m, n;
44
    int ldak, ldam, lddk;
45 46
    int tempkm, tempkn, tempnn, tempmm;
    int ib;
47
    int minMNT = chameleon_min(A->mt, A->nt);
48

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

55
    ib = CHAMELEON_IB;
56

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

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

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

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

    RUNTIME_options_ws_alloc( &options, ws_worker, ws_host );

    for (k = 0; k < minMNT; k++) {
Mathieu Faverge's avatar
Mathieu Faverge committed
86
        RUNTIME_iteration_push(chamctxt, k);
87

88 89 90
        tempkm = k == A->mt-1 ? A->m-k*A->mb : A->mb;
        tempkn = k == A->nt-1 ? A->n-k*A->nb : A->nb;
        ldak = BLKLDD(A, k);
91
        lddk = BLKLDD(D, k);
92
        INSERT_TASK_zgeqrt(
93 94 95 96
            &options,
            tempkm, tempkn, ib, T->nb,
            A(k, k), ldak,
            T(k, k), T->mb);
97
        if ( genD ) {
98
            INSERT_TASK_zlacpy(
99
                &options,
100
                ChamLower, tempkm, tempkn, A->nb,
101
                A(k, k), ldak,
102
                D(k), lddk );
Mathieu Faverge's avatar
Mathieu Faverge committed
103
#if defined(CHAMELEON_USE_CUDA)
104
            INSERT_TASK_zlaset(
105
                &options,
106
                ChamUpper, tempkm, tempkn,
107
                0., 1.,
108
                D(k), lddk );
109
#endif
110
        }
111 112
        for (n = k+1; n < A->nt; n++) {
            tempnn = n == A->nt-1 ? A->n-n*A->nb : A->nb;
113
            INSERT_TASK_zunmqr(
114
                &options,
115
                ChamLeft, ChamConjTrans,
116
                tempkm, tempnn, tempkm, ib, T->nb,
117
                D(k),    lddk,
118 119 120
                T(k, k), T->mb,
                A(k, n), ldak);
        }
Mathieu Faverge's avatar
Mathieu Faverge committed
121 122
        RUNTIME_data_flush( sequence, D(k)    );
        RUNTIME_data_flush( sequence, T(k, k) );
123

124 125 126
        for (m = k+1; m < A->mt; m++) {
            tempmm = m == A->mt-1 ? A->m-m*A->mb : A->mb;
            ldam = BLKLDD(A, m);
127 128 129 130

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

131
            /* TS kernel */
132
            INSERT_TASK_ztpqrt(
133
                &options,
134
                tempmm, tempkn, 0, ib, T->nb,
135 136 137
                A(k, k), ldak,
                A(m, k), ldam,
                T(m, k), T->mb);
138

139 140
            for (n = k+1; n < A->nt; n++) {
                tempnn = n == A->nt-1 ? A->n-n*A->nb : A->nb;
141 142 143 144

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

145
                /* TS kernel */
146
                INSERT_TASK_ztpmqrt(
147
                    &options,
148
                    ChamLeft, ChamConjTrans,
149
                    tempmm, tempnn, A->nb, 0, ib, T->nb,
150
                    A(m, k), ldam,
151 152 153
                    T(m, k), T->mb,
                    A(k, n), ldak,
                    A(m, n), ldam);
154
            }
Mathieu Faverge's avatar
Mathieu Faverge committed
155 156
            RUNTIME_data_flush( sequence, A(m, k) );
            RUNTIME_data_flush( sequence, T(m, k) );
157
        }
158

159 160 161 162 163 164
        /* 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
165
        RUNTIME_iteration_pop(chamctxt);
166
    }
167

168
    RUNTIME_options_ws_free(&options);
Mathieu Faverge's avatar
Mathieu Faverge committed
169
    RUNTIME_options_finalize(&options, chamctxt);
Mathieu Faverge's avatar
Mathieu Faverge committed
170
    (void)D;
171
}