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 6
 *                          All rights reserved.
 * @copyright (c) 2012-2014 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

82
#if defined(CHAMELEON_USE_MAGMA) || defined(CHAMELEON_SIMULATION_MAGMA)
83 84
    /* Worker space
     *
85 86
     * zunmlq = A->mb * ib
     * ztsmlq = 2 * A->mb * ib
87
     */
88
    ws_worker = 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
                tempkm   = k == B->mt-1 ? B->m-k*B->mb : B->mb;
109 110 111
                tempkmin = k == minMT-1 ? minM-k*A->nb : A->nb;
                ldak = BLKLDD(A, k);
                ldbk = BLKLDD(B, k);
112
#if defined(CHAMELEON_COPY_DIAG)
113 114 115 116
                MORSE_TASK_zlacpy(
                    &options,
                    MorseUpper, tempkmin, tempkm, A->nb,
                    A(k, k), ldak,
117
                    DIAG(k), ldak );
118
#if defined(CHAMELEON_USE_MAGMA) || defined(CHAMELEON_SIMULATION_MAGMA)
119 120 121 122
                MORSE_TASK_zlaset(
                    &options,
                    MorseLower, tempkmin, tempkm,
                    0., 1.,
123 124
                    DIAG(k), ldak );
#endif
125 126 127 128 129 130 131
#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,
132
                        DIAG(k), ldak,
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
                        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--) {
158
                tempkm   = k == B->mt-1 ? B->m-k*B->mb : B->mb;
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
                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);
                    }
                }
177
#if defined(CHAMELEON_COPY_DIAG)
178 179 180 181
                MORSE_TASK_zlacpy(
                    &options,
                    MorseUpper, tempkmin, tempkm, A->nb,
                    A(k, k), ldak,
182
                    DIAG(k), ldak );
183
#if defined(CHAMELEON_USE_MAGMA) || defined(CHAMELEON_SIMULATION_MAGMA)
184 185 186 187
                MORSE_TASK_zlaset(
                    &options,
                    MorseLower, tempkmin, tempkm,
                    0., 1.,
188 189
                    DIAG(k), ldak );
#endif
190 191 192 193 194 195 196
#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,
197
                        DIAG(k), ldak,
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
                        T(k, k), T->mb,
                        B(k, n), ldbk);
                }
            }
        }
    }
    else {
        if (trans == MorseNoTrans) {
            /*
             *  MorseRight / MorseNoTrans
             */
            for (k = minMT-1; k >= 0; k--) {
                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);
                    }
                }
228
#if defined(CHAMELEON_COPY_DIAG)
229 230 231 232
                MORSE_TASK_zlacpy(
                    &options,
                    MorseUpper, tempkmin, tempkn, A->nb,
                    A(k, k), ldak,
233
                    DIAG(k), ldak );
234
#if defined(CHAMELEON_USE_MAGMA) || defined(CHAMELEON_SIMULATION_MAGMA)
235 236 237 238
                MORSE_TASK_zlaset(
                    &options,
                    MorseLower, tempkmin, tempkn,
                    0., 1.,
239 240
                    DIAG(k), ldak );
#endif
241 242 243 244 245 246 247 248
#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,
249
                        DIAG(k), ldak,
250 251 252 253 254 255 256 257 258 259 260 261 262
                        T(k, k), T->mb,
                        B(m, k), ldbm);
                }
            }
        }
        else {
            /*
             *  MorseRight / MorseConjTrans
             */
            for (k = 0; k < minMT; k++) {
                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);
263
#if defined(CHAMELEON_COPY_DIAG)
264 265 266 267
                MORSE_TASK_zlacpy(
                    &options,
                    MorseUpper, tempkmin, tempkn, A->nb,
                    A(k, k), ldak,
268
                    DIAG(k), ldak );
269
#if defined(CHAMELEON_USE_MAGMA) || defined(CHAMELEON_SIMULATION_MAGMA)
270 271 272 273
                MORSE_TASK_zlaset(
                    &options,
                    MorseLower, tempkmin, tempkn,
                    0., 1.,
274 275
                    DIAG(k), ldak );
#endif
276 277 278 279 280 281 282 283
#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,
284
                        DIAG(k), ldak,
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
                        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();

310 311
#if defined(CHAMELEON_COPY_DIAG)
    MORSE_Sequence_Wait(sequence);
312 313
    morse_desc_mat_free(DIAG);
    free(DIAG);
314
#endif
315
}