pztile.c 4.98 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/**
 *
 * @copyright (c) 2009-2014 The University of Tennessee and The University 
 *                          of Tennessee Research Foundation. 
 *                          All rights reserved.
 * @copyright (c) 2012-2014 Inria. All rights reserved.
 * @copyright (c) 2012-2014 IPB. All rights reserved. 
 *
 **/

/**
 *
 * @file ztile.c
 *
 *  MORSE auxiliary routines
 *  MORSE is a software package provided by Univ. of Tennessee,
 *  Univ. of California Berkeley and Univ. of Colorado Denver
 *
19
 * @version 0.9.0
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 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 167 168 169 170 171 172 173 174 175 176 177 178 179 180
 * @author Jakub Kurzak
 * @author Mathieu Faverge
 * @author Cedric Castagnede
 * @date 2010-11-15
 * @precisions normal z -> c d s
 *
 **/
#include "common.h"

#define A(m, n) dA, m, n
#define B(m, n) &dB, m, n

/*******************************************************************************
 *  Conversion from LAPACK F77 matrix layout to tile layout - dynamic scheduling
 **/
void morse_pzlapack_to_tile(MORSE_Complex64_t *Af77, int lda, MORSE_desc_t *dA,
                            MORSE_sequence_t *sequence, MORSE_request_t *request)
{
    MORSE_context_t *morse;
    MORSE_option_t options;
    MORSE_desc_t dB;
    int X1, Y1;
    int X2, Y2;
    int n, m, ldt;

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

    dB = morse_desc_init(
        MorseComplexDouble, dA->mb, dA->nb, dA->bsiz,
        lda, dA->n, dA->i, dA->j, dA->m, dA->n, 1, 1);

    dB.get_blkaddr = morse_getaddr_cm;
    dB.get_blkldd  = morse_getblkldd_cm;
    dB.mat = Af77;
    dB.styp = MorseCM;

    RUNTIME_desc_create( &dB );

    for (m = 0; m < dA->mt; m++)
    {
        ldt = BLKLDD(dA, m);
        for (n = 0; n < dA->nt; n++)
        {
            X1 = n == 0 ? dA->j%dA->nb : 0;
            Y1 = m == 0 ? dA->i%dA->mb : 0;
            X2 = n == dA->nt-1 ? (dA->j+dA->n-1)%dA->nb+1 : dA->nb;
            Y2 = m == dA->mt-1 ? (dA->i+dA->m-1)%dA->mb+1 : dA->mb;

            MORSE_TASK_zlacpy(
                &options,
                MorseUpperLower,
                (Y2-Y1), (X2-X1), dA->mb,
                B(m, n), lda,
                A(m, n), ldt);
        }
    }

    RUNTIME_barrier( morse );
    RUNTIME_options_finalize( &options, morse );
    MORSE_TASK_dataflush_all();
    RUNTIME_desc_getoncpu( &dB );
    RUNTIME_desc_destroy( &dB );
}

/*******************************************************************************
 *  Conversion from LAPACK F77 matrix layout to tile layout - dynamic scheduling
 **/
void morse_pztile_to_lapack(MORSE_desc_t *dA, MORSE_Complex64_t *Af77, int lda,
                            MORSE_sequence_t *sequence, MORSE_request_t *request)
{
    MORSE_context_t *morse;
    MORSE_option_t options;
    MORSE_desc_t dB;
    int X1, Y1;
    int X2, Y2;
    int n, m, ldt;

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

    dB = morse_desc_init(
        MorseComplexDouble, dA->mb, dA->nb, dA->bsiz,
        lda, dA->n, dA->i, dA->j, dA->m, dA->n, 1, 1);

    dB.get_blkaddr = morse_getaddr_cm;
    dB.get_blkldd  = morse_getblkldd_cm;
    dB.mat  = Af77;
    dB.styp = MorseCM;

    RUNTIME_desc_create( &dB );

    for (m = 0; m < dA->mt; m++)
    {
        Y1 = m == 0 ? dA->i%dA->mb : 0;
        Y2 = m == dA->mt-1 ? (dA->i+dA->m-1)%dA->mb+1 : dA->mb;
        ldt = BLKLDD(dA, m);

        for (n = 0; n < dA->nt; n++)
        {
            X1 = n == 0 ? dA->j%dA->nb : 0;
            X2 = n == dA->nt-1 ? (dA->j+dA->n-1)%dA->nb+1 : dA->nb;

            MORSE_TASK_zlacpy(
                &options,
                MorseUpperLower,
                (Y2-Y1), (X2-X1), dA->mb,
                A(m, n), ldt,
                B(m, n), lda);
        }
    }

    RUNTIME_barrier( morse );
    RUNTIME_options_finalize( &options, morse );
    MORSE_TASK_dataflush_all();
    RUNTIME_desc_getoncpu( &dB );
    RUNTIME_desc_destroy( &dB );
}


/*******************************************************************************
 *  Zeroes a submatrix in tile layout - dynamic scheduling
 **/
void morse_pztile_zero(MORSE_desc_t *dA, MORSE_sequence_t *sequence, MORSE_request_t *request)
{
    MORSE_context_t *morse;
    MORSE_option_t options;
    int X1, Y1;
    int X2, Y2;
    int n, m, ldt;

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

    for (m = 0; m < dA->mt; m++)
    {
        Y1 = m == 0 ? dA->i%dA->mb : 0;
        Y2 = m == dA->mt-1 ? (dA->i+dA->m-1)%dA->mb+1 : dA->mb;
        ldt = BLKLDD(dA, m);
        for (n = 0; n < dA->nt; n++)
        {
            X1 = n == 0 ? dA->j%dA->nb : 0;
            X2 = n == dA->nt-1 ? (dA->j+dA->n-1)%dA->nb+1 : dA->nb;

            MORSE_TASK_ztile_zero(
                &options,
                X1, X2, Y1, Y2,
                A(m, n), ldt);
        }
    }

    RUNTIME_barrier( morse );
    RUNTIME_options_finalize( &options, morse );
    MORSE_TASK_dataflush_all();
}