map.c 4.96 KB
Newer Older
Mathieu Faverge's avatar
Mathieu Faverge committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/**
 *
 * @file map.c
 *
 * @copyright 2018-2018 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
 *                      Univ. Bordeaux. All rights reserved.
 *
 ***
 *
 * @brief Chameleon map wrappers
 *
 * @version 1.0.0
 * @author Mathieu Faverge
 * @date 2018-09-24
 *
 */
#include "control/common.h"

/**
 ********************************************************************************
 *
22
 * @ingroup CHAMELEON_Tile
Mathieu Faverge's avatar
Mathieu Faverge committed
23
 *
24 25 26
 *  Apply a given operator on each tile of the given matrix. Operates on
 *  matrices stored by tiles.  All matrices are passed through descriptors.  All
 *  dimensions are taken from the descriptors.
Mathieu Faverge's avatar
Mathieu Faverge committed
27 28 29
 *
 *******************************************************************************
 *
30 31 32 33
 * @param[in,out] uplo
 *          - ChamUpper: Only the upper triangular part of the matrix is touched
 *          - ChamLower: Only the lower triangular part of the matrix is touched
 *          - ChamUpperLower: The entire the matrix is touched
Mathieu Faverge's avatar
Mathieu Faverge committed
34
 *
35 36
 * @param[in,out] A
 *          On exit, the operator has been applied on each tile of the matrix A.
Mathieu Faverge's avatar
Mathieu Faverge committed
37
 *
38 39
 * @param[in] operator
 *          The operator function to apply on each tile of the matrix.
Mathieu Faverge's avatar
Mathieu Faverge committed
40
 *
41 42 43
 * @param[in,out] op_args
 *          The arguments structure passed to the operator function when applied
 *          on each tile. May be updated by the operator function.
Mathieu Faverge's avatar
Mathieu Faverge committed
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
 *
 *******************************************************************************
 *
 * @retval CHAMELEON_SUCCESS successful exit
 *
 *******************************************************************************
 *
 * @sa CHAMELEON_map_Tile_Async
 *
 */
int CHAMELEON_map_Tile( cham_uplo_t           uplo,
                        CHAM_desc_t          *A,
                        cham_unary_operator_t operator,
                        void                 *op_args )
{
    CHAM_context_t     *chamctxt;
    RUNTIME_sequence_t *sequence = NULL;
    RUNTIME_request_t   request = RUNTIME_REQUEST_INITIALIZER;
    int status;

    chamctxt = chameleon_context_self();
    if (chamctxt == NULL) {
        chameleon_fatal_error("CHAMELEON_map_Tile", "CHAMELEON not initialized");
        return CHAMELEON_ERR_NOT_INITIALIZED;
    }
    chameleon_sequence_create( chamctxt, &sequence );

    CHAMELEON_map_Tile_Async( uplo, A, operator, op_args, sequence, &request );

    CHAMELEON_Desc_Flush( A, sequence );

    chameleon_sequence_wait( chamctxt, sequence );
    status = sequence->status;
    chameleon_sequence_destroy( chamctxt, sequence );
    return status;
}

/**
 ********************************************************************************
 *
 * @ingroup CHAMELEON_Tile_Async
 *
86
 *  Apply a given operator on each tile of the given matrix. Non-blocking equivalent of
Mathieu Faverge's avatar
Mathieu Faverge committed
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
 *  CHAMELEON_map_Tile().  May return before the computation is finished.
 *  Allows for pipelining of operations at runtime.
 *
 *******************************************************************************
 *
 * @param[in] sequence
 *          Identifies the sequence of function calls that this call belongs to
 *          (for completion checks and exception handling purposes).
 *
 * @param[out] request
 *          Identifies this function call (for exception handling purposes).
 *
 *******************************************************************************
 *
 * @retval CHAMELEON_SUCCESS successful exit
 *
 *******************************************************************************
 *
 * @sa CHAMELEON_map_Tile
 *
 */
int CHAMELEON_map_Tile_Async( cham_uplo_t           uplo,
                              CHAM_desc_t          *A,
                              cham_unary_operator_t operator,
                              void                 *op_args,
                              RUNTIME_sequence_t   *sequence,
                              RUNTIME_request_t    *request )
{
    CHAM_context_t *chamctxt;

    chamctxt = chameleon_context_self();
    if (chamctxt == NULL) {
Mathieu Faverge's avatar
Mathieu Faverge committed
119
        chameleon_fatal_error("CHAMELEON_map_Tile_Async", "CHAMELEON not initialized");
Mathieu Faverge's avatar
Mathieu Faverge committed
120 121 122
        return CHAMELEON_ERR_NOT_INITIALIZED;
    }
    if (sequence == NULL) {
Mathieu Faverge's avatar
Mathieu Faverge committed
123
        chameleon_fatal_error("CHAMELEON_map_Tile_Async", "NULL sequence");
Mathieu Faverge's avatar
Mathieu Faverge committed
124 125 126
        return CHAMELEON_ERR_UNALLOCATED;
    }
    if (request == NULL) {
Mathieu Faverge's avatar
Mathieu Faverge committed
127
        chameleon_fatal_error("CHAMELEON_map_Tile_Async", "NULL request");
Mathieu Faverge's avatar
Mathieu Faverge committed
128 129 130 131 132 133 134 135 136 137 138 139
        return CHAMELEON_ERR_UNALLOCATED;
    }
    /* Check sequence status */
    if (sequence->status == CHAMELEON_SUCCESS) {
        request->status = CHAMELEON_SUCCESS;
    }
    else {
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_SEQUENCE_FLUSHED);
    }

    /* Check descriptors for correctness */
    if (chameleon_desc_check(A) != CHAMELEON_SUCCESS) {
Mathieu Faverge's avatar
Mathieu Faverge committed
140
        chameleon_error("CHAMELEON_map_Tile_Async", "invalid descriptor");
Mathieu Faverge's avatar
Mathieu Faverge committed
141 142 143 144
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
    }

    /* Quick return */
145
    if (chameleon_min( A->m, A->n ) == 0) {
Mathieu Faverge's avatar
Mathieu Faverge committed
146
        return CHAMELEON_SUCCESS;
147
    }
Mathieu Faverge's avatar
Mathieu Faverge committed
148 149 150 151 152

    chameleon_pmap( uplo, A, operator, op_args, sequence, request );

    return CHAMELEON_SUCCESS;
}