pzgelqfrh.c 6.83 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 32 33
 *
 **/

/**
 *
 * @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
 *
 **/
//ALLOC_WS :  A->nb + ib*T->nb
//WS_ADD :  A->nb + ib*T->nb
34
#include "control/common.h"
35 36 37 38

#define A(m,n) A,  (m),  (n)
#define T(m,n) T,  (m),  (n)
#define T2(m,n) T,  (m),  (n)+A->nt
39
#if defined(CHAMELEON_COPY_DIAG)
40
#define DIAG(m,n) DIAG, ((n)/BS), 0
41 42 43
#else
#define DIAG(m,n) A,  (m),  (n)
#endif
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 77 78 79 80
/***************************************************************************//**
 *  Parallel tile LQ factorization (reduction Householder) - dynamic scheduling
 **/
void morse_pzgelqfrh(MORSE_desc_t *A, MORSE_desc_t *T, int BS,
                     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 N, RD;
    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
81 82 83 84 85 86
#if defined(CHAMELEON_USE_CUDA)
    /* Worker space
     *
     * zunmqr = A->nb * ib
     * ztsmqr = 2 * A->nb * ib
     */
87
    ws_worker = chameleon_max( ws_worker, ib * A->nb * 2 );
Mathieu Faverge's avatar
Mathieu Faverge committed
88 89
#endif

90
#if defined(CHAMELEON_USE_MAGMA)
91 92
    /* Worker space
     *
Mathieu Faverge's avatar
Mathieu Faverge committed
93 94
     * zgeqrt = max( A->nb * (ib+1), ib * (ib + A->nb) )
     * ztsqrt = max( A->nb * (ib+1), ib * (ib + A->nb) )
95
     */
96
    ws_worker = chameleon_max( ws_worker, ib * (ib + A->nb) );
97 98 99 100 101 102

    /* Host space
     *
     * zgelqt =     ib * A->nb + 3 * ib * ib + A->nb
     * ztslqt = 3 * ib * A->nb +     ib * ib + A->nb
     */
103 104
    ws_host = chameleon_max( ws_host,     ib * A->nb + 3 * ib * ib + A->nb );
    ws_host = chameleon_max( ws_host, 3 * ib * A->nb +     ib * ib + A->nb );
105 106 107 108 109 110 111
#endif

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

    RUNTIME_options_ws_alloc( &options, ws_worker, ws_host );

112
#if defined(CHAMELEON_COPY_DIAG)
113
    /* necessary to avoid dependencies between tasks regarding the diag tile */
114 115 116 117 118
    {
        int nblk = ( A->nt + BS -1 ) / BS;
        DIAG = (MORSE_desc_t*)malloc(sizeof(MORSE_desc_t));
        morse_zdesc_alloc_diag(*DIAG, A->mb, A->nb, nblk * A->mb, A->nb, 0, 0, nblk * A->mb, A->nb, A->p, A->q);
    }
119
#endif
120

121
    for (k = 0; k < chameleon_min(A->mt, A->nt); k++) {
122 123
        RUNTIME_set_iteration(k);

124 125 126 127
        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;
128
            tempkmin = chameleon_min(tempkm, tempNn);
129 130 131 132 133 134
            MORSE_TASK_zgelqt(
                &options,
                tempkm, tempNn, ib, T->nb,
                A(k, N), ldak,
                T(k, N), T->mb);
        if ( k < (A->mt-1) ) {
135
#if defined(CHAMELEON_COPY_DIAG)
136 137 138 139 140
            MORSE_TASK_zlacpy(
                &options,
                MorseUpper, tempkm, tempNn, A->nb,
                A(k, N), ldak,
                DIAG(k, N), ldak );
Mathieu Faverge's avatar
Mathieu Faverge committed
141
#if defined(CHAMELEON_USE_CUDA)
142 143 144 145 146
            MORSE_TASK_zlaset(
                &options,
                MorseLower, tempkm, tempNn,
                0., 1.,
                DIAG(k, N), ldak );
147
#endif
148
#endif
149
        }
150 151 152 153 154 155 156 157 158 159 160
            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,
                    DIAG(k, N), ldak,
                    T(k, N), T->mb,
                    A(m, N), ldam);
            }
161
            for (n = N+1; n < chameleon_min(N+BS, A->nt); n++) {
162 163 164 165 166 167 168 169 170 171 172 173 174 175 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 203 204 205 206 207 208 209 210 211 212
                tempnn = n == A->nt-1 ? A->n-n*A->nb : A->nb;
                MORSE_TASK_ztslqt(
                    &options,
                    tempkm, tempnn, ib, T->nb,
                    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);
                    MORSE_TASK_ztsmlq(
                        &options,
                        MorseRight, MorseConjTrans,
                        tempmm, A->nb, tempmm, tempnn, tempkm, ib, T->nb,
                        A(m, N), ldam,
                        A(m, n), ldam,
                        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;
                MORSE_TASK_zttlqt(
                    &options,
                    tempkm, tempNRDn, ib, T->nb,
                    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 );
                    MORSE_TASK_zttmlq(
                        &options,
                        MorseRight, MorseConjTrans,
                        tempmm, A->nb, tempmm, tempNRDn, tempkm, ib, T->nb,
                        A (m, N   ), ldam,
                        A (m, N+RD), ldam,
                        A (k, N+RD), ldak,
                        T2(k, N+RD), T->mb);
                }
            }
        }
    }
    RUNTIME_options_ws_free(&options);
    RUNTIME_options_finalize(&options, morse);
    MORSE_TASK_dataflush_all();

213 214
#if defined(CHAMELEON_COPY_DIAG)
    MORSE_Sequence_Wait(sequence);
215 216
    morse_desc_mat_free(DIAG);
    free(DIAG);
217
#endif
218
    (void)DIAG;
219
}