pzgelqfrh.c 6.78 KB
Newer Older
1
2
/**
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
3
4
 * @copyright 2009-2014 The University of Tennessee and The University of
 *                      Tennessee Research Foundation. All rights reserved.
Mathieu Faverge's avatar
Mathieu Faverge committed
5
6
 * @copyright (c) 2012-2016 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
 *                          Univ. Bordeaux. All rights reserved.
7
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
8
 ***
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 *
 * @file pzgelqfrh.c
 *
 *  MORSE auxiliary routines
 *  MORSE is a software package provided by Univ. of Tennessee,
 *  Univ. of California Berkeley and Univ. of Colorado Denver
 *
 * @version 2.5.0
 * @comment This file has been automatically generated
 *          from Plasma 2.5.0 for MORSE 1.0.0
 * @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
 *
 **/
29
#include "control/common.h"
30

Mathieu Faverge's avatar
Mathieu Faverge committed
31
32
#define A(m,n)  A,  (m),  (n)
#define T(m,n)  T,  (m),  (n)
33
#define T2(m,n) T,  (m),  (n)+A->nt
34
#if defined(CHAMELEON_COPY_DIAG)
35
#define D(m,n) D, ((n)/BS), 0
36
#else
37
#define D(m,n) A,  (m),  (n)
38
#endif
39

Mathieu Faverge's avatar
Mathieu Faverge committed
40
/*
41
 *  Parallel tile LQ factorization (reduction Householder) - dynamic scheduling
Mathieu Faverge's avatar
Mathieu Faverge committed
42
 */
43
void morse_pzgelqfrh(MORSE_desc_t *A, MORSE_desc_t *T, MORSE_desc_t *D, int BS,
44
45
46
47
48
49
50
51
                     MORSE_sequence_t *sequence, MORSE_request_t *request)
{
    MORSE_context_t *morse;
    MORSE_option_t options;
    size_t ws_worker = 0;
    size_t ws_host = 0;

    int k, m, n;
Mathieu Faverge's avatar
Mathieu Faverge committed
52
    int K, N, RD;
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
    int ldak, ldam;
    int tempkmin, tempkm, tempNn, tempnn, tempmm, tempNRDn;
    int ib;

    morse = morse_context_self();
    if (sequence->status != MORSE_SUCCESS)
        return;
    RUNTIME_options_init(&options, morse, sequence, request);

    ib = MORSE_IB;

    /*
     * zgelqt = A->nb * (ib+1)
     * zunmlq = A->nb * ib
     * ztslqt = A->nb * (ib+1)
     * zttlqt = A->nb * (ib+1)
     * ztsmlq = A->nb * ib
     * zttmlq = A->nb * ib
     */
    ws_worker = A->nb * (ib+1);

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

84
85
86
87
88
    ws_worker *= sizeof(MORSE_Complex64_t);
    ws_host   *= sizeof(MORSE_Complex64_t);

    RUNTIME_options_ws_alloc( &options, ws_worker, ws_host );

Mathieu Faverge's avatar
Mathieu Faverge committed
89
90
91
92
    K = chameleon_min(A->mt, A->nt);

    /* The number of the factorization */
    for (k = 0; k < K; k++) {
93
        RUNTIME_iteration_push(morse, k);
94

95
96
97
98
        tempkm = k == A->mt-1 ? A->m-k*A->mb : A->mb;
        ldak = BLKLDD(A, k);
        for (N = k; N < A->nt; N += BS) {
            tempNn = N == A->nt-1 ? A->n-N*A->nb : A->nb;
99
            tempkmin = chameleon_min(tempkm, tempNn);
100
101
102
103
104
            MORSE_TASK_zgelqt(
                &options,
                tempkm, tempNn, ib, T->nb,
                A(k, N), ldak,
                T(k, N), T->mb);
Mathieu Faverge's avatar
Mathieu Faverge committed
105
            if ( k < (A->mt-1) ) {
106
#if defined(CHAMELEON_COPY_DIAG)
Mathieu Faverge's avatar
Mathieu Faverge committed
107
108
109
110
                MORSE_TASK_zlacpy(
                    &options,
                    MorseUpper, tempkm, tempNn, A->nb,
                    A(k, N), ldak,
111
                    D(k, N), ldak );
Mathieu Faverge's avatar
Mathieu Faverge committed
112
#if defined(CHAMELEON_USE_CUDA)
Mathieu Faverge's avatar
Mathieu Faverge committed
113
114
115
116
                MORSE_TASK_zlaset(
                    &options,
                    MorseLower, tempkm, tempNn,
                    0., 1.,
117
                    D(k, N), ldak );
118
#endif
119
#endif
Mathieu Faverge's avatar
Mathieu Faverge committed
120
            }
121
122
123
124
125
126
127
            for (m = k+1; m < A->mt; m++) {
                tempmm = m == A->mt-1 ? A->m-m*A->mb : A->mb;
                ldam = BLKLDD(A, m);
                MORSE_TASK_zunmlq(
                    &options,
                    MorseRight, MorseConjTrans,
                    tempmm, tempNn, tempkmin, ib, T->nb,
128
                    D(k, N), ldak,
129
130
131
                    T(k, N), T->mb,
                    A(m, N), ldam);
            }
132

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

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

139
                /* TS kernel */
140
                MORSE_TASK_ztplqt(
141
                    &options,
142
                    tempkm, tempnn, 0, ib, T->nb,
143
144
145
146
147
148
149
                    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);
150
151
152
153
154

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

                    MORSE_TASK_ztpmlqt(
155
156
                        &options,
                        MorseRight, MorseConjTrans,
157
                        tempmm, tempnn, tempkm, 0, ib, T->nb,
158
                        A(k, n), ldak,
159
160
161
                        T(k, n), T->mb,
                        A(m, N), ldam,
                        A(m, n), ldam);
162
163
164
165
166
167
                }
            }
        }
        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;
168
169
170
171
172
173

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

174
                /* TT kernel */
175
                MORSE_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
189
190
191

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

                    MORSE_TASK_ztpmlqt(
192
193
                        &options,
                        MorseRight, MorseConjTrans,
194
                        tempmm, tempNRDn, tempkm, tempNRDn, ib, T->nb,
195
                        A (k, N+RD), ldak,
196
197
198
                        T2(k, N+RD), T->mb,
                        A (m, N   ), ldam,
                        A (m, N+RD), ldam);
199
200
201
                }
            }
        }
202
203
204
205
206
207
208

        /* 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 ) );
        }

209
        RUNTIME_iteration_pop(morse);
210
    }
Mathieu Faverge's avatar
Mathieu Faverge committed
211

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