pzgeqrf_param.c 5.88 KB
Newer Older
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
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.
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
5 6 7 8 9 10 11
 * @copyright (c) 2012-2017 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
 *                          Univ. Bordeaux. All rights reserved.
 *
 **/

/**
 *
12
 * @file pzgeqrf_param.c
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
13 14 15 16 17
 *
 *  MORSE auxiliary routines
 *  MORSE is a software package provided by Univ. of Tennessee,
 *  Univ. of California Berkeley and Univ. of Colorado Denver
 *
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
18
 * @version 1.0.0
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
19 20
 * @author Mathieu Faverge
 * @author Raphael Boucherie
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
21
 * @date 2017-05-17
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
22 23 24 25
 * @precisions normal z -> s d c
 *
 **/
#include "control/common.h"
Mathieu Faverge's avatar
Mathieu Faverge committed
26
#include <stdlib.h>
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
27 28
#include "libhqr.h"

29 30 31
#define A(m,n)  A, (m), (n)
#define T(m,n)  T, (m), (n)
#define D(m,n)  D, (m), (n)
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
32

33 34 35
/**
 *  Parallel tile QR factorization (reduction Householder) - dynamic scheduling
 */
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
36 37
void morse_pzgeqrf_param( const libhqr_tree_t *qrtree, MORSE_desc_t *A,
                          MORSE_desc_t *TS, MORSE_desc_t *TT, MORSE_desc_t *D,
38
                          MORSE_sequence_t *sequence, MORSE_request_t *request)
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
39 40 41
{
    MORSE_context_t *morse;
    MORSE_option_t options;
42
    MORSE_desc_t *T;
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
43 44
    size_t ws_worker = 0;
    size_t ws_host = 0;
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
45

46
    int k, m, n, i, p;
47
    int K, L;
48 49
    int ldap, ldam;
    int tempkmin, tempkn, tempnn, tempmm;
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
50 51 52 53 54 55 56 57 58 59
    int ib;
    int *tiles;

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

    ib = MORSE_IB;

60 61 62 63
    if ( D == NULL ) {
        D = A;
    }

BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
    /*
     * zgeqrt = A->nb * (ib+1)
     * zunmqr = A->nb * ib
     * ztsqrt = A->nb * (ib+1)
     * zttqrt = A->nb * (ib+1)
     * ztsmqr = A->nb * ib
     * zttmqr = A->nb * ib
     */
    ws_worker = A->nb * (ib+1);

    /* Allocation of temporary (scratch) working space */
#if defined(CHAMELEON_USE_CUDA)
    /* Worker space
     *
     * zunmqr = A->nb * ib
     * ztsmqr = 2 * A->nb * ib
     */
    ws_worker = chameleon_max( ws_worker, ib * A->nb * 2 );
#endif

84
    /* Initialisation of temporary tiles array */
Mathieu Faverge's avatar
Mathieu Faverge committed
85
    tiles = (int*)calloc(qrtree->mt, sizeof(int));
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105

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

    RUNTIME_options_ws_alloc( &options, ws_worker, ws_host );

    K = chameleon_min(A->mt, A->nt);

    /* The number of the factorization */
    for (k = 0; k < K; k++) {
        RUNTIME_iteration_push(morse, k);
        tempkn = k == A->nt-1 ? A->n-k*A->nb : A->nb;

        /* The number of geqrt to apply */
        for (i = 0; i < qrtree->getnbgeqrf(qrtree, k); i++) {
            m = qrtree->getm(qrtree, k, i);
            tempmm = m == A->mt-1 ? A->m-m*A->mb : A->mb;
            tempkmin = chameleon_min(tempmm, tempkn);
            ldam = BLKLDD(A, m);

106 107
            T = TS;

BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
108 109
            MORSE_TASK_zgeqrt(
                &options,
110 111 112
                tempmm, tempkn, ib, T->nb,
                A(m, k), ldam,
                T(m, k), T->mb);
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
113 114 115 116 117 118
            if ( k < (A->nt-1) ) {
#if defined(CHAMELEON_COPY_DIAG)
                MORSE_TASK_zlacpy(
                    &options,
                    MorseLower, tempmm, A->nb, A->nb,
                    A(m, k), ldam,
119
                    D(m, k), ldam );
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
120 121 122 123 124
#if defined(CHAMELEON_USE_CUDA)
                MORSE_TASK_zlaset(
                    &options,
                    MorseUpper, tempmm, A->nb,
                    0., 1.,
125
                    D(m, k), ldam );
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
126 127 128 129 130 131 132 133
#endif
#endif
            }
            for (n = k+1; n < A->nt; n++) {
                tempnn = n == A->nt-1 ? A->n-n*A->nb : A->nb;
                MORSE_TASK_zunmqr(
                    &options,
                    MorseLeft, MorseConjTrans,
134 135 136 137
                    tempmm, tempnn, tempkmin, ib, T->nb,
                    D(m, k), ldam,
                    T(m, k), T->mb,
                    A(m, n), ldam);
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
138 139 140 141
            }
        }

        /* Setting the order of the tiles */
Mathieu Faverge's avatar
Mathieu Faverge committed
142
        libhqr_walk_stepk( qrtree, k, tiles + (k+1) );
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
143

Mathieu Faverge's avatar
Mathieu Faverge committed
144
        for (i = k+1; i < A->mt; i++) {
145
            m = tiles[i];
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
146 147
            p = qrtree->currpiv(qrtree, k, m);

BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
148
            tempmm = m == A->mt-1 ? A->m-m*A->mb : A->mb;
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
149
            ldap = BLKLDD(A, p);
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
150
            ldam = BLKLDD(A, m);
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
151

152
            if (qrtree->gettype(qrtree, k, m) == 0) {
153
                /* TS kernel */
154 155
                T = TS;
                L = 0;
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
156 157
            }
            else {
158
                /* TT kernel */
159 160 161 162 163 164 165 166 167 168 169
                T = TT;
                L = tempmm;
            }

            RUNTIME_data_migrate( sequence, A(p, k),
                                  A->get_rankof( A, m, k ) );
            RUNTIME_data_migrate( sequence, A(m, k),
                                  A->get_rankof( A, m, k ) );

            MORSE_TASK_ztpqrt(
                &options,
Mathieu Faverge's avatar
Mathieu Faverge committed
170
                tempmm, tempkn, chameleon_min(L, tempkn), ib, T->nb,
171 172 173 174 175 176 177 178 179 180 181 182 183
                A(p, k), ldap,
                A(m, k), ldam,
                T(m, k), T->mb);

            for (n = k+1; n < A->nt; n++) {
                tempnn = n == A->nt-1 ? A->n-n*A->nb : A->nb;

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

                MORSE_TASK_ztpmqrt(
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
184
                    &options,
185 186 187 188 189 190
                    MorseLeft, MorseConjTrans,
                    tempmm, tempnn, A->nb, L, ib, T->nb,
                    A(m, k), ldam,
                    T(m, k), T->mb,
                    A(p, n), ldap,
                    A(m, n), ldam);
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
191 192
            }
        }
193 194 195 196 197 198 199

        /* Restore the original location of the tiles */
        for (n = k; n < A->nt; n++) {
            RUNTIME_data_migrate( sequence, A(k, n),
                                  A->get_rankof( A, k, n ) );
        }

BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
200 201 202 203 204 205 206
        RUNTIME_iteration_pop(morse);
    }

    free(tiles);
    RUNTIME_options_ws_free(&options);
    RUNTIME_options_finalize(&options, morse);
}