pzgeqrf_param.c 5.87 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
 * @copyright (c) 2012-2017 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
 *                          Univ. Bordeaux. All rights reserved.
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
8
 ***
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
9
 *
10
 * @file pzgeqrf_param.c
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
11 12 13 14 15
 *
 *  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
16
 * @version 1.0.0
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
17 18
 * @author Mathieu Faverge
 * @author Raphael Boucherie
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
19
 * @date 2017-05-17
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
20 21 22 23
 * @precisions normal z -> s d c
 *
 **/
#include "control/common.h"
Mathieu Faverge's avatar
Mathieu Faverge committed
24
#include <stdlib.h>
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
25 26
#include "libhqr.h"

27 28 29
#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
30

31 32 33
/**
 *  Parallel tile QR factorization (reduction Householder) - dynamic scheduling
 */
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
34 35
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,
36
                          MORSE_sequence_t *sequence, MORSE_request_t *request)
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
37 38 39
{
    MORSE_context_t *morse;
    MORSE_option_t options;
40
    MORSE_desc_t *T;
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
41 42
    size_t ws_worker = 0;
    size_t ws_host = 0;
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
43

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

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

    ib = MORSE_IB;

58 59 60 61
    if ( D == NULL ) {
        D = A;
    }

BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
    /*
     * 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

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

    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);

104 105
            T = TS;

BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
106 107
            MORSE_TASK_zgeqrt(
                &options,
108 109 110
                tempmm, tempkn, ib, T->nb,
                A(m, k), ldam,
                T(m, k), T->mb);
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
111 112 113 114 115 116
            if ( k < (A->nt-1) ) {
#if defined(CHAMELEON_COPY_DIAG)
                MORSE_TASK_zlacpy(
                    &options,
                    MorseLower, tempmm, A->nb, A->nb,
                    A(m, k), ldam,
117
                    D(m, k), ldam );
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
118 119 120 121 122
#if defined(CHAMELEON_USE_CUDA)
                MORSE_TASK_zlaset(
                    &options,
                    MorseUpper, tempmm, A->nb,
                    0., 1.,
123
                    D(m, k), ldam );
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
124 125 126 127 128 129 130 131
#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,
132 133 134 135
                    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
136 137 138 139
            }
        }

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

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

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

150
            if (qrtree->gettype(qrtree, k, m) == 0) {
151
                /* TS kernel */
152 153
                T = TS;
                L = 0;
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
154 155
            }
            else {
156
                /* TT kernel */
157 158 159 160 161 162 163 164 165 166 167
                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
168
                tempmm, tempkn, chameleon_min(L, tempkn), ib, T->nb,
169 170 171 172 173 174 175 176 177 178 179 180 181
                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
182
                    &options,
183 184 185 186 187 188
                    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
189 190
            }
        }
191 192 193 194 195 196 197

        /* 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
198 199 200 201 202 203 204
        RUNTIME_iteration_pop(morse);
    }

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