pzunmlq.c 10.7 KB
Newer Older
1 2
/**
 *
3 4
 * @copyright (c) 2009-2014 The University of Tennessee and The University
 *                          of Tennessee Research Foundation.
5
 *                          All rights reserved.
6
 * @copyright (c) 2012-2016 Inria. All rights reserved.
7
 * @copyright (c) 2012-2014 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria, Univ. Bordeaux. All rights reserved.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
 *
 **/

/**
 *
 * @file pzunmlq.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 Hatem Ltaief
 * @author Jakub Kurzak
 * @author Azzam Haidar
 * @author Mathieu Faverge
 * @author Emmanuel Agullo
 * @author Cedric Castagnede
 * @date 2010-11-15
 * @precisions normal z -> s d c
 *
 **/
32
#include "control/common.h"
33 34 35 36

#define A(m,n) A,  m,  n
#define B(m,n) B,  m,  n
#define T(m,n) T,  m,  n
37
#if defined(CHAMELEON_COPY_DIAG)
38
#define DIAG(k) DIAG, k, 0
39 40 41
#else
#define DIAG(k) A, k, k
#endif
42

43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
/***************************************************************************//**
 *  Parallel application of Q using tile V - LQ factorization - dynamic scheduling
 **/
void morse_pzunmlq(MORSE_enum side, MORSE_enum trans,
                   MORSE_desc_t *A, MORSE_desc_t *B, MORSE_desc_t *T,
                   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;
    MORSE_desc_t *DIAG = NULL;

    int k, m, n;
    int ldak, ldbk, ldbm;
    int tempmm, tempnn, tempkn, tempkm, tempkmin;
    int ib, minMT, minM;

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

    ib = MORSE_IB;

    if (A->m > A->n) {
        minM  = A->n;
        minMT = A->nt;
    } else {
        minM  = A->m;
        minMT = A->mt;
    }

    /*
77 78
     * zunmlq = A->mb * ib
     * ztsmlq = A->mb * ib
79
     */
80
    ws_worker = A->mb * ib;
81

Mathieu Faverge's avatar
Mathieu Faverge committed
82
#if defined(CHAMELEON_USE_CUDA)
83 84
    /* Worker space
     *
85 86
     * zunmlq = A->mb * ib
     * ztsmlq = 2 * A->mb * ib
87
     */
88
    ws_worker = chameleon_max( ws_worker, ib * A->mb * 2 );
89 90 91 92 93 94 95
#endif

    ws_worker *= sizeof(MORSE_Complex64_t);
    ws_host   *= sizeof(MORSE_Complex64_t);

    RUNTIME_options_ws_alloc( &options, ws_worker, ws_host );

96
    /* necessary to avoid dependencies between tasks regarding the diag tile */
97
#if defined(CHAMELEON_COPY_DIAG)
98
    DIAG = (MORSE_desc_t*)malloc(sizeof(MORSE_desc_t));
99
    morse_zdesc_alloc_diag(*DIAG, A->mb, A->nb, minMT*A->mb, A->nb, 0, 0, minMT*A->mb, A->nb, A->p, A->q);
100
#endif
101

102 103 104 105 106 107
    if (side == MorseLeft ) {
        if (trans == MorseNoTrans) {
            /*
             *  MorseLeft / MorseNoTrans
             */
            for (k = 0; k < minMT; k++) {
108 109
                RUNTIME_set_iteration(k);

110
                tempkm   = k == B->mt-1 ? B->m-k*B->mb : B->mb;
111 112 113
                tempkmin = k == minMT-1 ? minM-k*A->nb : A->nb;
                ldak = BLKLDD(A, k);
                ldbk = BLKLDD(B, k);
114
#if defined(CHAMELEON_COPY_DIAG)
115 116 117 118
                MORSE_TASK_zlacpy(
                    &options,
                    MorseUpper, tempkmin, tempkm, A->nb,
                    A(k, k), ldak,
119
                    DIAG(k), ldak );
Mathieu Faverge's avatar
Mathieu Faverge committed
120
#if defined(CHAMELEON_USE_CUDA)
121 122 123 124
                MORSE_TASK_zlaset(
                    &options,
                    MorseLower, tempkmin, tempkm,
                    0., 1.,
125 126
                    DIAG(k), ldak );
#endif
127 128 129 130 131 132 133
#endif
                for (n = 0; n < B->nt; n++) {
                    tempnn = n == B->nt-1 ? B->n-n*B->nb : B->nb;
                    MORSE_TASK_zunmlq(
                        &options,
                        side, trans,
                        tempkm, tempnn, tempkmin, ib, T->nb,
134
                        DIAG(k), ldak,
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
                        T(k, k), T->mb,
                        B(k, n), ldbk);
                }
                for (m = k+1; m < B->mt; m++) {
                    tempmm = m == B->mt-1 ? B->m-m*B->mb : B->mb;
                    ldbm = BLKLDD(B, m);
                    for (n = 0; n < B->nt; n++) {
                        tempnn = n == B->nt-1 ? B->n-n*B->nb : B->nb;
                        MORSE_TASK_ztsmlq(
                            &options,
                            side, trans,
                            B->mb, tempnn, tempmm, tempnn, tempkmin, ib, T->nb,
                            B(k, n), ldbk,
                            B(m, n), ldbm,
                            A(k, m), ldak,
                            T(k, m), T->mb);
                    }
                }
            }
        }
        else {
            /*
             *  MorseLeft / MorseConjTrans
             */
            for (k = minMT-1; k >= 0; k--) {
160 161
                RUNTIME_set_iteration(k);

162
                tempkm   = k == B->mt-1 ? B->m-k*B->mb : B->mb;
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
                tempkmin = k == minMT-1 ? minM-k*A->nb : A->nb;
                ldak = BLKLDD(A, k);
                ldbk = BLKLDD(B, k);
                for (m = B->mt-1; m > k; m--) {
                    tempmm = m == B->mt-1 ? B->m-m*B->mb : B->mb;
                    ldbm = BLKLDD(B, m);
                    for (n = 0; n < B->nt; n++) {
                        tempnn   = n == B->nt-1 ? B->n-n*B->nb : B->nb;
                        MORSE_TASK_ztsmlq(
                            &options,
                            side, trans,
                            B->mb, tempnn, tempmm, tempnn, tempkmin, ib, T->nb,
                            B(k, n), ldbk,
                            B(m, n), ldbm,
                            A(k, m), ldak,
                            T(k, m), T->mb);
                    }
                }
181
#if defined(CHAMELEON_COPY_DIAG)
182 183 184 185
                MORSE_TASK_zlacpy(
                    &options,
                    MorseUpper, tempkmin, tempkm, A->nb,
                    A(k, k), ldak,
186
                    DIAG(k), ldak );
Mathieu Faverge's avatar
Mathieu Faverge committed
187
#if defined(CHAMELEON_USE_CUDA)
188 189 190 191
                MORSE_TASK_zlaset(
                    &options,
                    MorseLower, tempkmin, tempkm,
                    0., 1.,
192 193
                    DIAG(k), ldak );
#endif
194 195 196 197 198 199 200
#endif
                for (n = 0; n < B->nt; n++) {
                    tempnn = n == B->nt-1 ? B->n-n*B->nb : B->nb;
                    MORSE_TASK_zunmlq(
                        &options,
                        side, trans,
                        tempkm, tempnn, tempkmin, ib, T->nb,
201
                        DIAG(k), ldak,
202 203 204 205 206 207 208 209 210 211 212 213
                        T(k, k), T->mb,
                        B(k, n), ldbk);
                }
            }
        }
    }
    else {
        if (trans == MorseNoTrans) {
            /*
             *  MorseRight / MorseNoTrans
             */
            for (k = minMT-1; k >= 0; k--) {
214 215
                RUNTIME_set_iteration(k);

216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
                tempkn   = k == B->nt -1 ? B->n -k*B->nb : B->nb;
                tempkmin = k == minMT-1 ? minM-k*A->nb : A->nb;
                ldak = BLKLDD(A, k);
                for (n = B->nt-1; n > k; n--) {
                    tempnn = n == B->nt-1 ? B->n-n*B->nb : B->nb;
                    for (m = 0; m < B->mt; m++) {
                        tempmm = m == B->mt-1 ? B->m-m*B->mb : B->mb;
                        ldbm = BLKLDD(B, m);
                        MORSE_TASK_ztsmlq(
                            &options,
                            side, trans,
                            tempmm, B->nb, tempmm, tempnn, tempkmin, ib, T->nb,
                            B(m, k), ldbm,
                            B(m, n), ldbm,
                            A(k, n), ldak,
                            T(k, n), T->mb);
                    }
                }
234
#if defined(CHAMELEON_COPY_DIAG)
235 236 237 238
                MORSE_TASK_zlacpy(
                    &options,
                    MorseUpper, tempkmin, tempkn, A->nb,
                    A(k, k), ldak,
239
                    DIAG(k), ldak );
Mathieu Faverge's avatar
Mathieu Faverge committed
240
#if defined(CHAMELEON_USE_CUDA)
241 242 243 244
                MORSE_TASK_zlaset(
                    &options,
                    MorseLower, tempkmin, tempkn,
                    0., 1.,
245 246
                    DIAG(k), ldak );
#endif
247 248 249 250 251 252 253 254
#endif
                for (m = 0; m < B->mt; m++) {
                    tempmm = m == B->mt-1 ? B->m-m*B->mb : B->mb;
                    ldbm = BLKLDD(B, m);
                    MORSE_TASK_zunmlq(
                        &options,
                        side, trans,
                        tempmm, tempkn, tempkmin, ib, T->nb,
255
                        DIAG(k), ldak,
256 257 258 259 260 261 262 263 264 265
                        T(k, k), T->mb,
                        B(m, k), ldbm);
                }
            }
        }
        else {
            /*
             *  MorseRight / MorseConjTrans
             */
            for (k = 0; k < minMT; k++) {
266 267
                RUNTIME_set_iteration(k);

268 269 270
                tempkn   = k == B->nt -1 ? B->n -k*B->nb : B->nb;
                tempkmin = k == minMT-1 ? minM-k*A->mb : A->mb;
                ldak = BLKLDD(A, k);
271
#if defined(CHAMELEON_COPY_DIAG)
272 273 274 275
                MORSE_TASK_zlacpy(
                    &options,
                    MorseUpper, tempkmin, tempkn, A->nb,
                    A(k, k), ldak,
276
                    DIAG(k), ldak );
Mathieu Faverge's avatar
Mathieu Faverge committed
277
#if defined(CHAMELEON_USE_CUDA)
278 279 280 281
                MORSE_TASK_zlaset(
                    &options,
                    MorseLower, tempkmin, tempkn,
                    0., 1.,
282 283
                    DIAG(k), ldak );
#endif
284 285 286 287 288 289 290 291
#endif
                for (m = 0; m < B->mt; m++) {
                    tempmm = m == B->mt-1 ? B->m-m*B->mb : B->mb;
                    ldbm = BLKLDD(B, m);
                    MORSE_TASK_zunmlq(
                        &options,
                        side, trans,
                        tempmm, tempkn, tempkmin, ib, T->nb,
292
                        DIAG(k), ldak,
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317
                        T(k, k), T->mb,
                        B(m, k), ldbm);
                }
                for (n = k+1; n < B->nt; n++) {
                    tempnn = n == B->nt-1 ? B->n-n*B->nb : B->nb;
                    for (m = 0; m < B->mt; m++) {
                        tempmm = m == B->mt-1 ? B->m-m*B->mb : B->mb;
                        ldbm = BLKLDD(B, m);
                        MORSE_TASK_ztsmlq(
                            &options,
                            side, trans,
                            tempmm, B->nb, tempmm, tempnn, tempkmin, ib, T->nb,
                            B(m, k), ldbm,
                            B(m, n), ldbm,
                            A(k, n), ldak,
                            T(k, n), T->mb);
                    }
                }
            }
        }
    }
    RUNTIME_options_ws_free(&options);
    RUNTIME_options_finalize(&options, morse);
    MORSE_TASK_dataflush_all();

318 319
#if defined(CHAMELEON_COPY_DIAG)
    MORSE_Sequence_Wait(sequence);
320 321
    morse_desc_mat_free(DIAG);
    free(DIAG);
322
#endif
323
    (void)DIAG;
324
}