pzunglq.c 4.35 KB
Newer Older
1
/**
2 3
 *
 * @file pzunglq.c
4
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
5 6
 * @copyright 2009-2014 The University of Tennessee and The University of
 *                      Tennessee Research Foundation. All rights reserved.
7 8
 * @copyright 2012-2016 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
 *                      Univ. Bordeaux. All rights reserved.
9
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
10
 ***
11
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
12
 * @brief Chameleon zunglq parallel algorithm
13
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
14
 * @version 1.0.0
15 16 17 18 19 20 21 22 23 24
 * @comment This file has been automatically generated
 *          from Plasma 2.5.0 for MORSE 1.0.0
 * @author Hatem Ltaief
 * @author Jakub Kurzak
 * @author Mathieu Faverge
 * @author Emmanuel Agullo
 * @author Cedric Castagnede
 * @date 2010-11-15
 * @precisions normal z -> s d c
 *
25
 */
26
#include "control/common.h"
27 28 29 30

#define A(m,n) A,  m,  n
#define Q(m,n) Q,  m,  n
#define T(m,n) T,  m,  n
31
#if defined(CHAMELEON_COPY_DIAG)
32
#define D(k)   D,  k,  0
33
#else
34
#define D(k)   D,  k,  k
35
#endif
36

37
/**
38
 *  Parallel construction of Q using tile V (application to identity) - dynamic scheduling
39
 */
40
void morse_pzunglq(MORSE_desc_t *A, MORSE_desc_t *Q, MORSE_desc_t *T, MORSE_desc_t *D,
41 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
                   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 ldak, ldqm;
    int tempnn, tempmm, tempkmin, tempkn;
    int tempAkm, tempAkn;
    int ib, minMT;

    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) {
        minMT = A->nt;
    } else {
        minMT = A->mt;
    }

67 68 69 70
    if (D == NULL) {
        D = A;
    }

71 72 73 74 75 76 77
    /*
     * zunmlq = A->nb * ib
     * ztsmlq = A->nb * ib
     */
    ws_worker = A->nb * ib;

    /* Allocation of temporary (scratch) working space */
Mathieu Faverge's avatar
Mathieu Faverge committed
78
#if defined(CHAMELEON_USE_CUDA)
79 80 81 82 83
    /* Worker space
     *
     * zunmlq = A->nb * ib
     * ztsmlq = 2 * A->nb * ib
     */
84
    ws_worker = chameleon_max( ws_worker, ib * A->nb * 2 );
85 86 87 88 89 90 91
#endif

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

    RUNTIME_options_ws_alloc( &options, ws_worker, ws_host );

92
    for (k = minMT-1; k >= 0; k--) {
93
        RUNTIME_iteration_push(morse, k);
94

95 96
        tempAkm  = k == A->mt-1 ? A->m-k*A->mb : A->mb;
        tempAkn  = k == A->nt-1 ? A->n-k*A->nb : A->nb;
97
        tempkmin = chameleon_min( tempAkn, tempAkm );
98 99 100 101 102 103 104
        tempkn   = k == Q->nt-1 ? Q->n-k*Q->nb : Q->nb;
        ldak = BLKLDD(A, k);
        for (n = Q->nt-1; n > k; n--) {
            tempnn = n == Q->nt-1 ? Q->n-n*Q->nb : Q->nb;
            for (m = 0; m < Q->mt; m++) {
                tempmm = m == Q->mt-1 ? Q->m-m*Q->mb : Q->mb;
                ldqm = BLKLDD(Q, m);
105 106 107 108

                RUNTIME_data_migrate( sequence, Q(m, k),
                                      Q->get_rankof( Q, m, n ) );

109
                /* TS kernel */
110
                MORSE_TASK_ztpmlqt(
111 112
                    &options,
                    MorseRight, MorseNoTrans,
113
                    tempmm, tempnn, tempAkm, 0, ib, T->nb,
114
                    A(k, n), ldak,
115 116 117
                    T(k, n), T->mb,
                    Q(m, k), ldqm,
                    Q(m, n), ldqm);
118
            }
Mathieu Faverge's avatar
Mathieu Faverge committed
119 120
            RUNTIME_data_flush( sequence, A(k, n) );
            RUNTIME_data_flush( sequence, T(k, n) );
121
        }
122
#if defined(CHAMELEON_COPY_DIAG)
123 124 125 126
        MORSE_TASK_zlacpy(
            &options,
            MorseUpper, tempkmin, tempkn, A->nb,
            A(k, k), ldak,
127
            D(k), ldak );
Mathieu Faverge's avatar
Mathieu Faverge committed
128
#if defined(CHAMELEON_USE_CUDA)
129 130 131 132
        MORSE_TASK_zlaset(
            &options,
            MorseLower, tempkmin, tempkn,
            0., 1.,
133
            D(k), ldak );
134
#endif
135 136
#endif
        for (m = k; m < Q->mt; m++) {
137 138
            tempmm = m == Q->mt-1 ? Q->m-m*Q->mb : Q->mb;
            ldqm = BLKLDD(Q, m);
139 140 141 142

            RUNTIME_data_migrate( sequence, Q(m, k),
                                  Q->get_rankof( Q, m, k ) );

143 144 145 146
            MORSE_TASK_zunmlq(
                &options,
                MorseRight, MorseNoTrans,
                tempmm, tempkn, tempkmin, ib, T->nb,
147
                D(k), ldak,
148 149 150
                T(k, k), T->mb,
                Q(m, k), ldqm);
        }
Mathieu Faverge's avatar
Mathieu Faverge committed
151 152
        RUNTIME_data_flush( sequence, D(k)    );
        RUNTIME_data_flush( sequence, T(k, k) );
153

154
        RUNTIME_iteration_pop(morse);
155
    }
Mathieu Faverge's avatar
Mathieu Faverge committed
156

157 158 159
    RUNTIME_options_ws_free(&options);
    RUNTIME_options_finalize(&options, morse);
}