codelet_zplssq.c 3.94 KB
Newer Older
1 2 3 4 5 6 7 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 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
/**
 *
 * @copyright (c) 2009-2015 The University of Tennessee and The University
 *                          of Tennessee Research Foundation.
 *                          All rights reserved.
 * @copyright (c) 2012-2015 Inria. All rights reserved.
 * @copyright (c) 2012-2015 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria, Univ. Bordeaux. All rights reserved.
 *
 **/

/**
 * @file codelet_zplssq.c
 *
 *  MORSE codelets kernel
 *  MORSE is a software package provided by Univ. of Tennessee,
 *  Univ. of California Berkeley and Univ. of Colorado Denver
 *
 * @version 2.5.0
 * @author Reazul Hoque
 * @precisions normal z -> c d s
 *
 **/
#include <math.h>
#include "runtime/parsec/include/morse_parsec.h"

/*****************************************************************************
 *
 * @ingroup CORE_MORSE_Complex64_t
 *
 *  MORSE_TASK_zplssq returns: scl * sqrt(ssq)
 *
 * with scl and ssq such that
 *
 *    ( scl**2 )*ssq = sum( A( 2*i )**2 * A( 2*i+1 ) )
 *                      i
 *
 * The values of A(2*i+1) are assumed to be at least unity.
 * The values of A(2*i) are assumed to be non-negative and scl is
 *
 *    scl = max( A( 2*i ) ),
 *           i
 *
 * The routine makes only one pass through the matrix A.
 *
 *******************************************************************************
 *
 *  @param[in] M
 *          The number of couple (scale, sumsq) in the matrix A.
 *
 *  @param[in] A
 *          The 2-by-M matrix.
 *
 *  @param[out] result
 *          On exit, result contains scl * sqrt( ssq )
 *
 */
static int
CORE_zplssq_parsec(dague_execution_unit_t *context, dague_execution_context_t *this_task)
{
    dague_data_copy_t *gSCALESUMSQ;
    dague_data_copy_t *gSCLSSQ;

    dague_dtd_unpack_args(this_task,
                          UNPACK_DATA,  &gSCALESUMSQ,
                          UNPACK_DATA,  &gSCLSSQ
                          );


    double *SCALESUMSQ = (double *) DAGUE_DATA_COPY_GET_PTR((dague_data_copy_t *)gSCALESUMSQ);
    double *SCLSSQ     = (double *) DAGUE_DATA_COPY_GET_PTR((dague_data_copy_t *)gSCLSSQ);

    if( SCLSSQ[0] < SCALESUMSQ[0] ) {
        SCLSSQ[1] = SCALESUMSQ[1] + (SCLSSQ[1]     * (( SCLSSQ[0] / SCALESUMSQ[0] ) * ( SCLSSQ[0] / SCALESUMSQ[0] )));
        SCLSSQ[0] = SCALESUMSQ[0];
    } else {
        SCLSSQ[1] = SCLSSQ[1]     + (SCALESUMSQ[1] * (( SCALESUMSQ[0] / SCLSSQ[0] ) * ( SCALESUMSQ[0] / SCLSSQ[0] )));
    }

    return 0;
}

void MORSE_TASK_zplssq( MORSE_option_t *options,
                        MORSE_desc_t *SCALESUMSQ, int SCALESUMSQm, int SCALESUMSQn,
                        MORSE_desc_t *SCLSSQ,     int SCLSSQm,     int SCLSSQn )
{
    dague_dtd_handle_t* DAGUE_dtd_handle = (dague_dtd_handle_t *)(options->sequence->schedopt);

    insert_task_generic_fptr(DAGUE_dtd_handle,      CORE_zplssq_parsec,               "plssq",
                             PASSED_BY_REF,         RTBLKADDR( SCALESUMSQ, MORSE_Complex64_t, SCALESUMSQm, SCALESUMSQn ),    INPUT | REGION_FULL,
                             PASSED_BY_REF,         RTBLKADDR( SCLSSQ, MORSE_Complex64_t, SCLSSQm, SCLSSQn ),                INOUT | REGION_FULL,
                             0);
}

static int
CORE_zplssq2_parsec(dague_execution_unit_t *context, dague_execution_context_t *this_task)
{
    dague_data_copy_t *gRESULT;

    dague_dtd_unpack_args(this_task,
                          UNPACK_DATA,  &gRESULT
                          );

    double *RESULT = DAGUE_DATA_COPY_GET_PTR((dague_data_copy_t *)gRESULT);

    RESULT[0] = RESULT[0] * sqrt( RESULT[1] );

    return 0;
}

void MORSE_TASK_zplssq2( MORSE_option_t *options,
                         MORSE_desc_t *RESULT, int RESULTm, int RESULTn )
{
    dague_dtd_handle_t* DAGUE_dtd_handle = (dague_dtd_handle_t *)(options->sequence->schedopt);

    insert_task_generic_fptr(DAGUE_dtd_handle,      CORE_zplssq2_parsec,               "plssq2",
                             PASSED_BY_REF,         RTBLKADDR( RESULT, MORSE_Complex64_t, RESULTm, RESULTn ),     INOUT | REGION_FULL,
                             0);
}