Une nouvelle version du portail de gestion des comptes externes sera mise en production lundi 09 août. Elle permettra d'allonger la validité d'un compte externe jusqu'à 3 ans. Pour plus de détails sur cette version consulter : https://doc-si.inria.fr/x/FCeS

zbuild.c 9.99 KB
Newer Older
1
/**
2 3
 *
 * @file zbuild.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.
Mathieu Faverge's avatar
Mathieu Faverge committed
7
 * @copyright 2012-2018 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
8
 *                      Univ. Bordeaux. All rights reserved.
9
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
10
 * @brief Chameleon zbuild wrappers
11
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
12
 * @version 1.0.0
13
 * @comment This file has been automatically generated
Mathieu Faverge's avatar
Mathieu Faverge committed
14
 *          from Plasma 2.5.0 for CHAMELEON 1.0.0
15 16 17 18 19 20 21
 * @author Mathieu Faverge
 * @author Emmanuel Agullo
 * @author Cedric Castagnede
 * @author Guillaume Sylvand
 * @date 2016-09-05
 * @precisions normal z -> s d c
 *
22
 */
23 24
#include "control/common.h"

25 26
/**
 ********************************************************************************
27
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
28
 * @ingroup CHAMELEON_Complex64_t
29
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
30
 *  CHAMELEON_zbuild - Generate a matrix by calling user provided function.
31 32 33 34 35
 *
 *******************************************************************************
 *
 * @param[in] uplo
 *          Specifies the part of the matrix A to be copied to B.
Mathieu Faverge's avatar
Mathieu Faverge committed
36 37 38
 *            = ChamUpperLower: All the matrix A
 *            = ChamUpper: Upper triangular part
 *            = ChamLower: Lower triangular part
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
 *
 * @param[in] M
 *          The number of rows of A.
 *
 * @param[in] N
 *          The order of the matrix A. N >= 0.
 *
 * @param[out] A
 *          On exit, The matrix A generated.
 *
 * @param[in] LDA
 *          The leading dimension of the array A. LDA >= max(1,M).
 *
 * @param[in] user_data
 *          The user data used in the matrix generation, it will be passed by chameleon
 *          to the build callback function (see below).
 *
 * @param[in] user_build_callback
 *          The user function to call to generate tiles.
 *          The prototype of the callback is :
 *          void myFcn(int row_min, int row_max, int col_min, int col_max, void *buffer, int ld, void *user_data)
 *          It is expected to build the block of matrix [row_min, row_max] x [col_min, col_max]
 *          (with both min and max values included in the intervals,
 *          index start at 0 like in C, NOT 1 like in Fortran)
 *          and store it at the adresse 'buffer' with leading dimension 'ld'
 *          The argument 'user_data' is an opaque pointer on any user data, it is passed by
Mathieu Faverge's avatar
Mathieu Faverge committed
65
 *          the user to Cham_zbuild (see above) and transmitted by chameleon to the callback.
66 67 68 69
 *
 *******************************************************************************
 *
 * @return
Mathieu Faverge's avatar
Mathieu Faverge committed
70
 *          \retval CHAMELEON_SUCCESS successful exit
71 72 73 74
 *          \retval <0 if -i, the i-th argument had an illegal value
 *
 *******************************************************************************
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
75 76 77 78 79
 * @sa CHAMELEON_zbuild_Tile
 * @sa CHAMELEON_zbuild_Tile_Async
 * @sa CHAMELEON_cbuild
 * @sa CHAMELEON_dbuild
 * @sa CHAMELEON_sbuild
80
 *
81
 */
Mathieu Faverge's avatar
Mathieu Faverge committed
82 83
int CHAMELEON_zbuild( cham_uplo_t uplo, int M, int N,
                  CHAMELEON_Complex64_t *A, int LDA,
Mathieu Faverge's avatar
Minor  
Mathieu Faverge committed
84
                  void *user_data, void* user_build_callback )
85
{
Mathieu Faverge's avatar
Mathieu Faverge committed
86 87
    int NB;
    int status;
Mathieu Faverge's avatar
Mathieu Faverge committed
88
    CHAM_context_t *chamctxt;
Mathieu Faverge's avatar
Mathieu Faverge committed
89 90 91
    RUNTIME_sequence_t *sequence = NULL;
    RUNTIME_request_t request = RUNTIME_REQUEST_INITIALIZER;
    CHAM_desc_t descAl, descAt;
92

Mathieu Faverge's avatar
Mathieu Faverge committed
93 94 95
    chamctxt = chameleon_context_self();
    if (chamctxt == NULL) {
        chameleon_fatal_error("CHAMELEON_zbuild", "CHAMELEON not initialized");
Mathieu Faverge's avatar
Mathieu Faverge committed
96
        return CHAMELEON_ERR_NOT_INITIALIZED;
Mathieu Faverge's avatar
Mathieu Faverge committed
97 98 99
    }
    /* Check input arguments */
    if (M < 0) {
Mathieu Faverge's avatar
Mathieu Faverge committed
100
        chameleon_error("CHAMELEON_zbuild", "illegal value of M");
Mathieu Faverge's avatar
Mathieu Faverge committed
101 102 103
        return -1;
    }
    if (N < 0) {
Mathieu Faverge's avatar
Mathieu Faverge committed
104
        chameleon_error("CHAMELEON_zbuild", "illegal value of N");
Mathieu Faverge's avatar
Mathieu Faverge committed
105 106 107
        return -2;
    }
    if (LDA < chameleon_max(1, M)) {
Mathieu Faverge's avatar
Mathieu Faverge committed
108
        chameleon_error("CHAMELEON_zbuild", "illegal value of LDA");
Mathieu Faverge's avatar
Mathieu Faverge committed
109 110 111 112
        return -4;
    }
    /* Quick return */
    if (chameleon_min(M, N) == 0)
Mathieu Faverge's avatar
Mathieu Faverge committed
113
        return CHAMELEON_SUCCESS;
114

Mathieu Faverge's avatar
Mathieu Faverge committed
115
    /* Tune NB depending on M, N & NRHS; Set NBNB */
Mathieu Faverge's avatar
Mathieu Faverge committed
116
    status = chameleon_tune(CHAMELEON_FUNC_ZGEMM, M, N, 0);
Mathieu Faverge's avatar
Mathieu Faverge committed
117
    if (status != CHAMELEON_SUCCESS) {
Mathieu Faverge's avatar
Mathieu Faverge committed
118
        chameleon_error("CHAMELEON_zbuild", "chameleon_tune() failed");
Mathieu Faverge's avatar
Mathieu Faverge committed
119 120
        return status;
    }
121

Mathieu Faverge's avatar
Mathieu Faverge committed
122
    /* Set NT */
Mathieu Faverge's avatar
Mathieu Faverge committed
123
    NB = CHAMELEON_NB;
Mathieu Faverge's avatar
Mathieu Faverge committed
124
    chameleon_sequence_create( chamctxt, &sequence );
125 126

    /* Submit the matrix conversion */
Mathieu Faverge's avatar
Mathieu Faverge committed
127
    chameleon_zlap2tile( chamctxt, &descAl, &descAt, ChamDescOutput, uplo,
128
                     A, NB, NB, LDA, N, M, N, sequence, &request );
129

Mathieu Faverge's avatar
Mathieu Faverge committed
130
    /* Call the tile interface */
Mathieu Faverge's avatar
Mathieu Faverge committed
131
    CHAMELEON_zbuild_Tile_Async( uplo, &descAt, user_data, user_build_callback, sequence, &request );
132

Mathieu Faverge's avatar
Mathieu Faverge committed
133
    /* Submit the matrix conversion back */
Mathieu Faverge's avatar
Mathieu Faverge committed
134
    chameleon_ztile2lap( chamctxt, &descAl, &descAt,
Mathieu Faverge's avatar
Mathieu Faverge committed
135
                     ChamDescOutput, uplo, sequence, &request );
Mathieu Faverge's avatar
Mathieu Faverge committed
136

Mathieu Faverge's avatar
Mathieu Faverge committed
137
    chameleon_sequence_wait( chamctxt, sequence );
Mathieu Faverge's avatar
Mathieu Faverge committed
138

Mathieu Faverge's avatar
Mathieu Faverge committed
139
    /* Cleanup the temporary data */
Mathieu Faverge's avatar
Mathieu Faverge committed
140
    chameleon_ztile2lap_cleanup( chamctxt, &descAl, &descAt );
141

Mathieu Faverge's avatar
Mathieu Faverge committed
142
    status = sequence->status;
Mathieu Faverge's avatar
Mathieu Faverge committed
143
    chameleon_sequence_destroy( chamctxt, sequence );
144

Mathieu Faverge's avatar
Mathieu Faverge committed
145
    return status;
146 147
}

148 149
/**
 ********************************************************************************
150
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
151
 * @ingroup CHAMELEON_Complex64_t_Tile
152
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
153 154
 *  CHAMELEON_zbuild_Tile - Generate a matrix by tiles by calling user provided function.
 *  Tile equivalent of CHAMELEON_zbuild().
155 156 157 158 159 160 161 162
 *  Operates on matrices stored by tiles.
 *  All matrices are passed through descriptors.
 *  All dimensions are taken from the descriptors.
 *
 *******************************************************************************
 *
 * @param[in] uplo
 *          Specifies the part of the matrix A to be copied to B.
Mathieu Faverge's avatar
Mathieu Faverge committed
163 164 165
 *            = ChamUpperLower: All the matrix A
 *            = ChamUpper: Upper triangular part
 *            = ChamLower: Lower triangular part
166 167 168 169 170 171 172 173
 *
 * @param[in] A
 *          On exit, The matrix A generated.
 *
 * @param[in] user_data
 *          The data used in the matrix generation.
 *
 * @param[in] user_build_callback
Mathieu Faverge's avatar
Mathieu Faverge committed
174
 *          The function called by the codelet to fill the tiles (see CHAMELEON_zbuild)
175 176 177 178
 *
 *******************************************************************************
 *
 * @return
Mathieu Faverge's avatar
Mathieu Faverge committed
179
 *          \retval CHAMELEON_SUCCESS successful exit
180 181 182
 *
 *******************************************************************************
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
183 184 185 186 187
 * @sa CHAMELEON_zbuild
 * @sa CHAMELEON_zbuild_Tile_Async
 * @sa CHAMELEON_cbuild_Tile
 * @sa CHAMELEON_dbuild_Tile
 * @sa CHAMELEON_sbuild_Tile
188
 *
189
 */
Mathieu Faverge's avatar
Mathieu Faverge committed
190
int CHAMELEON_zbuild_Tile( cham_uplo_t uplo, CHAM_desc_t *A,
191 192
                       void *user_data, void* user_build_callback )
{
Mathieu Faverge's avatar
Mathieu Faverge committed
193
    CHAM_context_t *chamctxt;
Mathieu Faverge's avatar
Mathieu Faverge committed
194 195
    RUNTIME_sequence_t *sequence = NULL;
    RUNTIME_request_t request = RUNTIME_REQUEST_INITIALIZER;
Mathieu Faverge's avatar
Mathieu Faverge committed
196
    int status;
197

Mathieu Faverge's avatar
Mathieu Faverge committed
198 199 200
    chamctxt = chameleon_context_self();
    if (chamctxt == NULL) {
        chameleon_fatal_error("CHAMELEON_zbuild_Tile", "CHAMELEON not initialized");
Mathieu Faverge's avatar
Mathieu Faverge committed
201
        return CHAMELEON_ERR_NOT_INITIALIZED;
Mathieu Faverge's avatar
Mathieu Faverge committed
202
    }
Mathieu Faverge's avatar
Mathieu Faverge committed
203
    chameleon_sequence_create( chamctxt, &sequence );
204

Mathieu Faverge's avatar
Mathieu Faverge committed
205
    CHAMELEON_zbuild_Tile_Async( uplo, A, user_data, user_build_callback, sequence, &request );
Mathieu Faverge's avatar
Mathieu Faverge committed
206

Mathieu Faverge's avatar
Mathieu Faverge committed
207
    CHAMELEON_Desc_Flush( A, sequence );
Mathieu Faverge's avatar
Mathieu Faverge committed
208

Mathieu Faverge's avatar
Mathieu Faverge committed
209
    chameleon_sequence_wait( chamctxt, sequence );
Mathieu Faverge's avatar
Mathieu Faverge committed
210
    status = sequence->status;
Mathieu Faverge's avatar
Mathieu Faverge committed
211
    chameleon_sequence_destroy( chamctxt, sequence );
Mathieu Faverge's avatar
Mathieu Faverge committed
212
    return status;
213 214
}

215 216
/**
 ********************************************************************************
217
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
218
 * @ingroup CHAMELEON_Complex64_t_Tile_Async
219
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
220 221
 *  CHAMELEON_zbuild_Tile_Async - Generate a matrix by tiles by calling user provided function.
 *  Non-blocking equivalent of CHAMELEON_zbuild_Tile().
222 223 224 225 226 227 228
 *  May return before the computation is finished.
 *  Allows for pipelining of operations at runtime.
 *
 *******************************************************************************
 *
 * @param[in] uplo
 *          Specifies the part of the matrix A to be copied to B.
Mathieu Faverge's avatar
Mathieu Faverge committed
229 230 231
 *            = ChamUpperLower: All the matrix A
 *            = ChamUpper: Upper triangular part
 *            = ChamLower: Lower triangular part
232 233 234 235 236 237 238 239
 *
 * @param[in] A
 *          On exit, The matrix A generated.
 *
 * @param[in] user_data
 *          The data used in the matrix generation.
 *
 * @param[in] user_build_callback
Mathieu Faverge's avatar
Mathieu Faverge committed
240
 *          The function called by the codelet to fill the tiles (see CHAMELEON_zbuild)
241 242 243 244 245 246 247 248 249 250
 *
 * @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).
 *
 *******************************************************************************
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
251 252 253 254 255
 * @sa CHAMELEON_zbuild
 * @sa CHAMELEON_zbuild_Tile
 * @sa CHAMELEON_cbuild_Tile_Async
 * @sa CHAMELEON_dbuild_Tile_Async
 * @sa CHAMELEON_sbuild_Tile_Async
256
 *
257
 */
Mathieu Faverge's avatar
Mathieu Faverge committed
258
int CHAMELEON_zbuild_Tile_Async( cham_uplo_t uplo, CHAM_desc_t     *A,
259
                             void *user_data, void* user_build_callback,
Mathieu Faverge's avatar
Mathieu Faverge committed
260 261
                             RUNTIME_sequence_t *sequence,
                             RUNTIME_request_t  *request )
262
{
Mathieu Faverge's avatar
Mathieu Faverge committed
263
    CHAM_context_t *chamctxt;
264

Mathieu Faverge's avatar
Mathieu Faverge committed
265 266 267
    chamctxt = chameleon_context_self();
    if (chamctxt == NULL) {
        chameleon_fatal_error("CHAMELEON_zbuild_Tile", "CHAMELEON not initialized");
Mathieu Faverge's avatar
Mathieu Faverge committed
268
        return CHAMELEON_ERR_NOT_INITIALIZED;
Mathieu Faverge's avatar
Mathieu Faverge committed
269 270
    }
    if (sequence == NULL) {
Mathieu Faverge's avatar
Mathieu Faverge committed
271
        chameleon_fatal_error("CHAMELEON_zbuild_Tile", "NULL sequence");
Mathieu Faverge's avatar
Mathieu Faverge committed
272
        return CHAMELEON_ERR_UNALLOCATED;
Mathieu Faverge's avatar
Mathieu Faverge committed
273 274
    }
    if (request == NULL) {
Mathieu Faverge's avatar
Mathieu Faverge committed
275
        chameleon_fatal_error("CHAMELEON_zbuild_Tile", "NULL request");
Mathieu Faverge's avatar
Mathieu Faverge committed
276
        return CHAMELEON_ERR_UNALLOCATED;
Mathieu Faverge's avatar
Mathieu Faverge committed
277 278
    }
    /* Check sequence status */
Mathieu Faverge's avatar
Mathieu Faverge committed
279 280
    if (sequence->status == CHAMELEON_SUCCESS) {
        request->status = CHAMELEON_SUCCESS;
Mathieu Faverge's avatar
Mathieu Faverge committed
281 282
    }
    else {
Mathieu Faverge's avatar
Mathieu Faverge committed
283
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_SEQUENCE_FLUSHED);
Mathieu Faverge's avatar
Mathieu Faverge committed
284
    }
285

Mathieu Faverge's avatar
Mathieu Faverge committed
286
    /* Check descriptors for correctness */
Mathieu Faverge's avatar
Mathieu Faverge committed
287 288 289
    if (chameleon_desc_check(A) != CHAMELEON_SUCCESS) {
        chameleon_error("CHAMELEON_zbuild_Tile", "invalid descriptor");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
Mathieu Faverge's avatar
Mathieu Faverge committed
290
    }
291

Mathieu Faverge's avatar
Mathieu Faverge committed
292
    /* Quick return */
Mathieu Faverge's avatar
Minor  
Mathieu Faverge committed
293
    if (chameleon_min( A->m, A->n ) == 0) {
Mathieu Faverge's avatar
Mathieu Faverge committed
294
        return CHAMELEON_SUCCESS;
Mathieu Faverge's avatar
Minor  
Mathieu Faverge committed
295
    }
296

Mathieu Faverge's avatar
Mathieu Faverge committed
297
    chameleon_pzbuild( uplo, A, user_data, user_build_callback, sequence, request );
298

Mathieu Faverge's avatar
Mathieu Faverge committed
299
    return CHAMELEON_SUCCESS;
300
}