pzunmlqrh.c 15.8 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 pzunmlqrh.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 Dulceneia Becker
 * @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 37

#define A(m,n) A,  (m),  (n)
#define B(m,n) B,  (m),  (n)
#define T(m,n) T,  (m),  (n)
#define T2(m,n) T,  (m),  (n)+A->nt
38
#if defined(CHAMELEON_COPY_DIAG)
39
#define D(m,n) D, ((n)/BS), 0
40
#else
41
#define D(m,n) A, (m), (n)
42
#endif
43

44 45 46 47 48
/***************************************************************************//**
 *  Parallel application of Q using tile V - LQ factorization (reduction
 *  Householder) - dynamic scheduling
 **/
void morse_pzunmlqrh(MORSE_enum side, MORSE_enum trans,
49
                     MORSE_desc_t *A, MORSE_desc_t *B, MORSE_desc_t *T, MORSE_desc_t *D, int BS,
50 51 52 53 54 55 56 57 58
                     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;
    int K, N, RD, lastRD;
59
    int ldak, ldbN, ldbm, ldbNRD;
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
    int tempNn, tempkm, tempnn, tempmm, tempNRDn, tempkmin;
    int ib;

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

    ib = MORSE_IB;

    /*
     * zunmlq = A->nb * ib
     * ztsmlq = A->nb * ib
     * zttmlq = A->nb * ib
     */
    ws_worker = A->nb * ib;

77
#if defined(CHAMELEON_USE_CUDA)
78 79 80 81 82
    /* Worker space
     *
     * zunmlq = A->nb * ib
     * ztsmlq = 2 * A->nb * ib
     */
83
    ws_worker = chameleon_max( ws_worker, ib * A->nb * 2 );
84 85 86 87 88 89 90
#endif

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

    RUNTIME_options_ws_alloc( &options, ws_worker, ws_host );

91
    K = chameleon_min(A->mt, A->nt);
92 93 94 95 96 97
    if (side == MorseLeft ) {
        if (trans == MorseNoTrans) {
            /*
             *  MorseLeft / MorseNoTrans
             */
            for (k = 0; k < K; k++) {
98
                RUNTIME_iteration_push(morse, k);
99

100 101 102 103
                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;
104
                    tempkmin = chameleon_min(tempkm,tempNn);
105
                    ldbN = BLKLDD(B, N);
106
#if defined(CHAMELEON_COPY_DIAG)
107 108 109 110
                    MORSE_TASK_zlacpy(
                        &options,
                        MorseUpper, tempkmin, tempNn, A->nb,
                        A(k, N), ldak,
111
                        D(k, N), ldak );
112
#if defined(CHAMELEON_USE_CUDA)
113 114 115 116
                    MORSE_TASK_zlaset(
                        &options,
                        MorseLower, tempkmin, tempNn,
                        0., 1.,
117
                        D(k, N), ldak );
118
#endif
119 120 121 122 123 124 125 126
#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,
                            tempNn, tempnn,
                            tempkmin, ib, T->nb,
127
                            D(k, N), ldak,
128 129 130
                            T(k, N), T->mb,
                            B(N, n), ldbN);
                    }
131
                    for (m = N+1; m < chameleon_min(N+BS, A->nt); m++) {
132 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 158 159 160 161 162 163 164 165 166
                        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->nb, tempnn, tempmm, tempnn,
                                tempkm, ib, T->nb,
                                B(N, n), ldbN,
                                B(m, n), ldbm,
                                A(k, m), ldak,
                                T(k, m), T->mb);
                        }
                    }
                }
                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;
                        ldbN   = BLKLDD(B, N   );
                        ldbNRD = BLKLDD(B, N+RD);
                        for (n = 0; n < B->nt; n++) {
                            tempnn = n == B->nt-1 ? B->n-n*B->nb : B->nb;
                            MORSE_TASK_zttmlq(
                                &options,
                                side, trans,
                                B->mb, tempnn, tempNRDn, tempnn,
                                tempkm, ib, T->nb,
                                B (N,    n), ldbN,
                                B (N+RD, n), ldbNRD,
                                A (k, N+RD), ldak,
                                T2(k, N+RD), T->mb);
                        }
                    }
                }
167 168

                RUNTIME_iteration_pop(morse);
169 170 171 172 173 174
            }
        } else {
            /*
             *  MorseLeft / MorseConjTrans
             */
            for (k = K-1; k >= 0; k--) {
175
                RUNTIME_iteration_push(morse, k);
176

177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
                tempkm = k == A->mt-1 ? A->m-k*A->mb : A->mb;
                ldak = BLKLDD(A, k);
                lastRD = 0;
                for (RD = BS; RD < A->nt-k; RD *= 2)
                    lastRD = RD;
                for (RD = lastRD; RD >= BS; 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;
                        ldbN   = BLKLDD(B, N   );
                        ldbNRD = BLKLDD(B, N+RD);
                        for (n = 0; n < B->nt; n++) {
                            tempnn = n == B->nt-1 ? B->n-n*B->nb : B->nb;
                            MORSE_TASK_zttmlq(
                                &options,
                                side, trans,
                                B->nb, tempnn, tempNRDn, tempnn,
                                tempkm, ib, T->nb,
                                B (N,    n), ldbN,
                                B (N+RD, n), ldbNRD,
                                A (k, N+RD), ldak,
                                T2(k, N+RD), T->mb);
                        }
                    }
                }
                for (N = k; N < A->nt; N += BS) {
                    tempNn   = N == A->nt-1 ? A->n-N*A->nb : A->nb;
203
                    tempkmin = chameleon_min(tempkm,tempNn);
204
                    ldbN = BLKLDD(B, N);
205
                    for (m = chameleon_min(N+BS, A->nt)-1; m > N; m--) {
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
                        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,
                                tempkm, ib, T->nb,
                                B(N, n), ldbN,
                                B(m, n), ldbm,
                                A(k, m), ldak,
                                T(k, m), T->mb);
                        }
                    }
221
#if defined(CHAMELEON_COPY_DIAG)
222 223 224 225
                    MORSE_TASK_zlacpy(
                        &options,
                        MorseUpper, tempkmin, tempNn, A->nb,
                        A(k, N), ldak,
226
                        D(k, N), ldak );
227
#if defined(CHAMELEON_USE_CUDA)
228 229 230 231
                    MORSE_TASK_zlaset(
                        &options,
                        MorseLower, tempkmin, tempNn,
                        0., 1.,
232
                        D(k, N), ldak );
233
#endif
234 235 236 237 238 239 240 241
#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,
                            tempNn, tempnn,
                            tempkmin, ib, T->nb,
242
                            D(k, N), ldak,
243 244 245 246
                            T(k, N), T->mb,
                            B(N, n), ldbN);
                    }
                }
247 248

                RUNTIME_iteration_pop(morse);
249 250 251 252 253 254 255 256 257
            }

        }
    } else {
        if (trans == MorseNoTrans) {
            /*
             *  MorseRight / MorseNoTrans
             */
            for (k = K-1; k >= 0; k--) {
258
                RUNTIME_iteration_push(morse, k);
259

260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
                tempkm = k == A->mt-1 ? A->m-k*A->mb : A->mb;
                ldak = BLKLDD(A, k);
                lastRD = 0;
                for (RD = BS; RD < A->nt-k; RD *= 2)
                    lastRD = RD;
                for (RD = lastRD; RD >= BS; 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;
                        for (m = 0; m < B->mt; m++) {
                            ldbm   = BLKLDD(B, m);
                            tempmm = m == B->mt-1 ? B->m-m*B->mb : B->mb;
                            MORSE_TASK_zttmlq(
                                &options,
                                side, trans,
                                tempmm, B->nb, tempmm, tempNRDn,
                                tempkm, ib, T->nb,
                                B (m, N   ), ldbm,
                                B (m, N+RD), ldbm,
                                A (k, N+RD), ldak,
                                T2(k, N+RD), T->mb);
                        }
                    }
                }
                for (N = k; N < A->nt; N += BS) {
                    tempNn   = N == A->nt-1 ? A->n-N*A->nb : A->nb;
285 286
                    tempkmin = chameleon_min(tempkm,tempNn);
                    for (n = chameleon_min(N+BS, A->nt)-1; n > N; n--) {
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
                        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,
                                tempkm, ib, T->nb,
                                B(m, N), ldbm,
                                B(m, n), ldbm,
                                A(k, n), ldak,
                                T(k, n), T->mb);
                        }
                    }
302
#if defined(CHAMELEON_COPY_DIAG)
303 304 305 306
                    MORSE_TASK_zlacpy(
                        &options,
                        MorseUpper, tempkmin, tempNn, A->nb,
                        A(k, N), ldak,
307
                        D(k, N), ldak );
308
#if defined(CHAMELEON_USE_CUDA)
309 310 311 312
                    MORSE_TASK_zlaset(
                        &options,
                        MorseLower, tempkmin, tempNn,
                        0., 1.,
313
                        D(k, N), ldak );
314
#endif
315 316 317 318 319 320 321 322 323
#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, tempNn,
                            tempkmin, ib, T->nb,
324
                            D(k, N), ldak,
325 326 327 328
                            T(k, N), T->mb,
                            B(m, N), ldbm);
                    }
                }
329 330

                RUNTIME_iteration_pop(morse);
331 332 333 334 335 336
            }
        } else {
            /*
             *  MorseRight / MorseConjTrans
             */
            for (k = 0; k < K; k++) {
337
                RUNTIME_iteration_push(morse, k);
338

339 340 341 342
                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;
343
                    tempkmin = chameleon_min(tempkm,tempNn);
344
#if defined(CHAMELEON_COPY_DIAG)
345 346 347
                    MORSE_TASK_zlacpy(
                        &options,
                        MorseUpper, tempkmin, tempNn, A->nb,
348
                        A(k, N), ldak,
349
                        D(k, N), ldak );
350
#if defined(CHAMELEON_USE_CUDA)
351 352 353 354
                    MORSE_TASK_zlaset(
                        &options,
                        MorseLower, tempkmin, tempNn,
                        0., 1.,
355
                        D(k, N), ldak );
356
#endif
357 358 359 360 361 362 363 364 365
#endif
                    for (m = 0; m < B->mt; m++) {
                        ldbm = BLKLDD(B, m);
                        tempmm = m == B->mt-1 ? B->m-m*B->mb : B->mb;
                        MORSE_TASK_zunmlq(
                            &options,
                            side, trans,
                            tempmm, tempNn,
                            tempkmin, ib, T->nb,
366
                            D(k, N), ldak,
367 368 369
                            T(k, N), T->mb,
                            B(m, N), ldbm);
                    }
370
                    for (n = N+1; n < chameleon_min(N+BS, A->nt); n++) {
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404
                        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, tempNn, tempmm, tempnn,
                                tempkm, ib, T->nb,
                                B(m, N), ldbm,
                                B(m, n), ldbm,
                                A(k, n), ldak,
                                T(k, n), T->mb);
                        }
                    }
                }
                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;
                        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_zttmlq(
                                &options,
                                side, trans,
                                tempmm, B->nb, tempmm, tempNRDn,
                                tempkm, ib, T->nb,
                                B (m, N   ), ldbm,
                                B (m, N+RD), ldbm,
                                A (k, N+RD), ldak,
                                T2(k, N+RD), T->mb);
                        }
                    }
                }
405 406

                RUNTIME_iteration_pop(morse);
407 408 409 410 411 412
            }
        }
    }
    RUNTIME_options_ws_free(&options);
    RUNTIME_options_finalize(&options, morse);
    MORSE_TASK_dataflush_all();
Mathieu Faverge's avatar
Mathieu Faverge committed
413
    (void)D;
414
}