ztrmm.c 13.6 KB
Newer Older
1
/**
2 3
 *
 * @file ztrmm.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
 *
10
 ***
11
 *
12
 * @brief Chameleon ztrmm wrappers
13
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
14
 * @version 1.0.0
15
 * @comment This file has been automatically generated
16
 *          from Plasma 2.5.0 for CHAMELEON 1.0.0
17 18 19 20 21 22
 * @author Mathieu Faverge
 * @author Emmanuel Agullo
 * @author Cedric Castagnede
 * @date 2010-11-15
 * @precisions normal z -> s d c
 *
23
 */
24
#include "control/common.h"
25

26 27
/**
 ********************************************************************************
28
 *
29
 * @ingroup CHAMELEON_Complex64_t
30
 *
31
 *  CHAMELEON_ztrmm - Computes B = alpha*op( A )*B or B = alpha*B*op( A ).
32 33 34 35 36
 *
 *******************************************************************************
 *
 * @param[in] side
 *          Specifies whether A appears on the left or on the right of X:
37 38
 *          = ChamLeft:  A*X = B
 *          = ChamRight: X*A = B
39 40 41
 *
 * @param[in] uplo
 *          Specifies whether the matrix A is upper triangular or lower triangular:
42 43
 *          = ChamUpper: Upper triangle of A is stored;
 *          = ChamLower: Lower triangle of A is stored.
44 45 46
 *
 * @param[in] transA
 *          Specifies whether the matrix A is transposed, not transposed or conjugate transposed:
47 48 49
 *          = ChamNoTrans:   A is transposed;
 *          = ChamTrans:     A is not transposed;
 *          = ChamConjTrans: A is conjugate transposed.
50 51 52
 *
 * @param[in] diag
 *          Specifies whether or not A is unit triangular:
53 54
 *          = ChamNonUnit: A is non unit;
 *          = ChamUnit:    A us unit.
55 56 57 58 59 60 61 62 63 64 65
 *
 * @param[in] N
 *          The order of the matrix A. N >= 0.
 *
 * @param[in] NRHS
 *          The number of right hand sides, i.e., the number of columns of the matrix B. NRHS >= 0.
 *
 * @param[in] alpha
 *          alpha specifies the scalar alpha.
 *
 * @param[in] A
66
 *          The triangular matrix A. If uplo = ChamUpper, the leading N-by-N upper triangular
67
 *          part of the array A contains the upper triangular matrix, and the strictly lower
68
 *          triangular part of A is not referenced. If uplo = ChamLower, the leading N-by-N
69
 *          lower triangular part of the array A contains the lower triangular matrix, and the
70
 *          strictly upper triangular part of A is not referenced. If diag = ChamUnit, the
71 72 73 74 75 76 77 78 79 80 81 82 83 84
 *          diagonal elements of A are also not referenced and are assumed to be 1.
 *
 * @param[in] LDA
 *          The leading dimension of the array A. LDA >= max(1,N).
 *
 * @param[in,out] B
 *          On entry, the N-by-NRHS right hand side matrix B.
 *          On exit, if return value = 0, the N-by-NRHS solution matrix X.
 *
 * @param[in] LDB
 *          The leading dimension of the array B. LDB >= max(1,N).
 *
 *******************************************************************************
 *
85 86
 * @retval CHAMELEON_SUCCESS successful exit
 * @retval <0 if -i, the i-th argument had an illegal value
87 88 89
 *
 *******************************************************************************
 *
90 91 92 93 94
 * @sa CHAMELEON_ztrmm_Tile
 * @sa CHAMELEON_ztrmm_Tile_Async
 * @sa CHAMELEON_ctrmm
 * @sa CHAMELEON_dtrmm
 * @sa CHAMELEON_strmm
95
 *
96
 */
97 98 99 100 101
int CHAMELEON_ztrmm( cham_side_t side, cham_uplo_t uplo,
                 cham_trans_t transA, cham_diag_t diag,
                 int N, int NRHS, CHAMELEON_Complex64_t alpha,
                 CHAMELEON_Complex64_t *A, int LDA,
                 CHAMELEON_Complex64_t *B, int LDB )
102 103 104
{
    int NB, NA;
    int status;
Mathieu Faverge's avatar
Mathieu Faverge committed
105
    CHAM_context_t *chamctxt;
106 107 108 109
    RUNTIME_sequence_t *sequence = NULL;
    RUNTIME_request_t request = RUNTIME_REQUEST_INITIALIZER;
    CHAM_desc_t descAl, descAt;
    CHAM_desc_t descBl, descBt;
110

Mathieu Faverge's avatar
Mathieu Faverge committed
111 112 113
    chamctxt = chameleon_context_self();
    if (chamctxt == NULL) {
        chameleon_fatal_error("CHAMELEON_ztrmm", "CHAMELEON not initialized");
114
        return CHAMELEON_ERR_NOT_INITIALIZED;
115 116
    }

117
    if (side == ChamLeft) {
118
        NA = N;
119
    } else {
120
        NA = NRHS;
121 122 123
    }

    /* Check input arguments */
124
    if (side != ChamLeft && side != ChamRight) {
Mathieu Faverge's avatar
Mathieu Faverge committed
125
        chameleon_error("CHAMELEON_ztrmm", "illegal value of side");
126 127
        return -1;
    }
128
    if ((uplo != ChamUpper) && (uplo != ChamLower)) {
Mathieu Faverge's avatar
Mathieu Faverge committed
129
        chameleon_error("CHAMELEON_ztrmm", "illegal value of uplo");
130 131
        return -2;
    }
132 133 134
    if (transA != ChamConjTrans &&
        transA != ChamNoTrans   &&
        transA != ChamTrans )
135
    {
Mathieu Faverge's avatar
Mathieu Faverge committed
136
        chameleon_error("CHAMELEON_ztrmm", "illegal value of transA");
137 138
        return -3;
    }
139
    if ((diag != ChamUnit) && (diag != ChamNonUnit)) {
Mathieu Faverge's avatar
Mathieu Faverge committed
140
        chameleon_error("CHAMELEON_ztrmm", "illegal value of diag");
141 142 143
        return -4;
    }
    if (N < 0) {
Mathieu Faverge's avatar
Mathieu Faverge committed
144
        chameleon_error("CHAMELEON_ztrmm", "illegal value of N");
145 146 147
        return -5;
    }
    if (NRHS < 0) {
Mathieu Faverge's avatar
Mathieu Faverge committed
148
        chameleon_error("CHAMELEON_ztrmm", "illegal value of NRHS");
149 150
        return -6;
    }
151
    if (LDA < chameleon_max(1, NA)) {
Mathieu Faverge's avatar
Mathieu Faverge committed
152
        chameleon_error("CHAMELEON_ztrmm", "illegal value of LDA");
153 154
        return -8;
    }
155
    if (LDB < chameleon_max(1, N)) {
Mathieu Faverge's avatar
Mathieu Faverge committed
156
        chameleon_error("CHAMELEON_ztrmm", "illegal value of LDB");
157 158 159
        return -10;
    }
    /* Quick return */
Mathieu Faverge's avatar
Mathieu Faverge committed
160
    if (chameleon_min(N, NRHS) == 0)
161
        return CHAMELEON_SUCCESS;
162 163

    /* Tune NB depending on M, N & NRHS; Set NBNB */
Mathieu Faverge's avatar
Mathieu Faverge committed
164
    status = chameleon_tune(CHAMELEON_FUNC_ZPOSV, N, N, NRHS);
165
    if (status != CHAMELEON_SUCCESS) {
Mathieu Faverge's avatar
Mathieu Faverge committed
166
        chameleon_error("CHAMELEON_ztrmm", "chameleon_tune() failed");
167 168 169 170
        return status;
    }

    /* Set NT & NTRHS */
171
    NB = CHAMELEON_NB;
172

Mathieu Faverge's avatar
Mathieu Faverge committed
173
    chameleon_sequence_create( chamctxt, &sequence );
174

175
    /* Submit the matrix conversion */
Mathieu Faverge's avatar
Mathieu Faverge committed
176
    chameleon_zlap2tile( chamctxt, &descAl, &descAt, ChamDescInput, uplo,
177
                     A, NB, NB, LDA, NA, NA, NA, sequence, &request );
Mathieu Faverge's avatar
Mathieu Faverge committed
178
    chameleon_zlap2tile( chamctxt, &descBl, &descBt, ChamDescInout, ChamUpperLower,
179
                     B, NB, NB, LDB, NRHS, N, NRHS, sequence, &request );
180 181

    /* Call the tile interface */
182
    CHAMELEON_ztrmm_Tile_Async(  side, uplo, transA, diag, alpha, &descAt, &descBt, sequence, &request );
183

Mathieu Faverge's avatar
Mathieu Faverge committed
184
    /* Submit the matrix conversion back */
Mathieu Faverge's avatar
Mathieu Faverge committed
185
    chameleon_ztile2lap( chamctxt, &descAl, &descAt,
186
                     ChamDescInput, uplo, sequence, &request );
Mathieu Faverge's avatar
Mathieu Faverge committed
187
    chameleon_ztile2lap( chamctxt, &descBl, &descBt,
188
                     ChamDescInout, ChamUpperLower, sequence, &request );
Mathieu Faverge's avatar
Mathieu Faverge committed
189

Mathieu Faverge's avatar
Mathieu Faverge committed
190
    chameleon_sequence_wait( chamctxt, sequence );
Mathieu Faverge's avatar
Mathieu Faverge committed
191

Mathieu Faverge's avatar
Mathieu Faverge committed
192
    /* Cleanup the temporary data */
Mathieu Faverge's avatar
Mathieu Faverge committed
193 194
    chameleon_ztile2lap_cleanup( chamctxt, &descAl, &descAt );
    chameleon_ztile2lap_cleanup( chamctxt, &descBl, &descBt );
195 196

    status = sequence->status;
Mathieu Faverge's avatar
Mathieu Faverge committed
197
    chameleon_sequence_destroy( chamctxt, sequence );
198 199
    return status;
}
200 201
/**
 ********************************************************************************
202
 *
203
 * @ingroup CHAMELEON_Complex64_t_Tile
204
 *
205 206
 *  CHAMELEON_ztrmm_Tile - Computes triangular solve.
 *  Tile equivalent of CHAMELEON_ztrmm().
207 208 209 210 211 212 213 214
 *  Operates on matrices stored by tiles.
 *  All matrices are passed through descriptors.
 *  All dimensions are taken from the descriptors.
 *
 *******************************************************************************
 *
 * @param[in] side
 *          Specifies whether A appears on the left or on the right of X:
215 216
 *          = ChamLeft:  A*X = B
 *          = ChamRight: X*A = B
217 218 219
 *
 * @param[in] uplo
 *          Specifies whether the matrix A is upper triangular or lower triangular:
220 221
 *          = ChamUpper: Upper triangle of A is stored;
 *          = ChamLower: Lower triangle of A is stored.
222 223 224
 *
 * @param[in] transA
 *          Specifies whether the matrix A is transposed, not transposed or conjugate transposed:
225 226 227
 *          = ChamNoTrans:   A is transposed;
 *          = ChamTrans:     A is not transposed;
 *          = ChamConjTrans: A is conjugate transposed.
228 229 230
 *
 * @param[in] diag
 *          Specifies whether or not A is unit triangular:
231 232
 *          = ChamNonUnit: A is non unit;
 *          = ChamUnit:    A us unit.
233 234 235 236 237
 *
 * @param[in] alpha
 *          alpha specifies the scalar alpha.
 *
 * @param[in] A
238
 *          The triangular matrix A. If uplo = ChamUpper, the leading N-by-N upper triangular
239
 *          part of the array A contains the upper triangular matrix, and the strictly lower
240
 *          triangular part of A is not referenced. If uplo = ChamLower, the leading N-by-N
241
 *          lower triangular part of the array A contains the lower triangular matrix, and the
242
 *          strictly upper triangular part of A is not referenced. If diag = ChamUnit, the
243 244 245 246 247 248 249 250
 *          diagonal elements of A are also not referenced and are assumed to be 1.
 *
 * @param[in,out] B
 *          On entry, the N-by-NRHS right hand side matrix B.
 *          On exit, if return value = 0, the N-by-NRHS solution matrix X.
 *
 *******************************************************************************
 *
251
 * @retval CHAMELEON_SUCCESS successful exit
252 253 254
 *
 *******************************************************************************
 *
255 256 257 258 259
 * @sa CHAMELEON_ztrmm
 * @sa CHAMELEON_ztrmm_Tile_Async
 * @sa CHAMELEON_ctrmm_Tile
 * @sa CHAMELEON_dtrmm_Tile
 * @sa CHAMELEON_strmm_Tile
260
 *
261
 */
262 263 264
int CHAMELEON_ztrmm_Tile( cham_side_t side, cham_uplo_t uplo,
                      cham_trans_t transA, cham_diag_t diag,
                      CHAMELEON_Complex64_t alpha, CHAM_desc_t *A, CHAM_desc_t *B )
265
{
Mathieu Faverge's avatar
Mathieu Faverge committed
266
    CHAM_context_t *chamctxt;
267 268
    RUNTIME_sequence_t *sequence = NULL;
    RUNTIME_request_t request = RUNTIME_REQUEST_INITIALIZER;
269 270
    int status;

Mathieu Faverge's avatar
Mathieu Faverge committed
271 272 273
    chamctxt = chameleon_context_self();
    if (chamctxt == NULL) {
        chameleon_fatal_error("CHAMELEON_ztrmm_Tile", "CHAMELEON not initialized");
274
        return CHAMELEON_ERR_NOT_INITIALIZED;
275
    }
Mathieu Faverge's avatar
Mathieu Faverge committed
276
    chameleon_sequence_create( chamctxt, &sequence );
277

278
    CHAMELEON_ztrmm_Tile_Async(side, uplo, transA, diag, alpha, A, B, sequence, &request );
279

280 281
    CHAMELEON_Desc_Flush( A, sequence );
    CHAMELEON_Desc_Flush( B, sequence );
Mathieu Faverge's avatar
Mathieu Faverge committed
282

Mathieu Faverge's avatar
Mathieu Faverge committed
283
    chameleon_sequence_wait( chamctxt, sequence );
284
    status = sequence->status;
Mathieu Faverge's avatar
Mathieu Faverge committed
285
    chameleon_sequence_destroy( chamctxt, sequence );
286 287 288
    return status;
}

289 290
/**
 ********************************************************************************
291
 *
292
 * @ingroup CHAMELEON_Complex64_t_Tile_Async
293
 *
294 295
 *  CHAMELEON_ztrmm_Tile_Async - Performs triangular matrix multiplication.
 *  Non-blocking equivalent of CHAMELEON_ztrmm_Tile().
296 297 298 299 300 301 302 303 304 305 306 307 308 309
 *  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).
 *
 *******************************************************************************
 *
310 311 312 313 314
 * @sa CHAMELEON_ztrmm
 * @sa CHAMELEON_ztrmm_Tile
 * @sa CHAMELEON_ctrmm_Tile_Async
 * @sa CHAMELEON_dtrmm_Tile_Async
 * @sa CHAMELEON_strmm_Tile_Async
315
 *
316
 */
317 318 319 320
int CHAMELEON_ztrmm_Tile_Async( cham_side_t side, cham_uplo_t uplo,
                            cham_trans_t transA, cham_diag_t diag,
                            CHAMELEON_Complex64_t alpha, CHAM_desc_t *A, CHAM_desc_t *B,
                            RUNTIME_sequence_t *sequence, RUNTIME_request_t *request )
321
{
Mathieu Faverge's avatar
Mathieu Faverge committed
322
    CHAM_context_t *chamctxt;
323

Mathieu Faverge's avatar
Mathieu Faverge committed
324 325 326
    chamctxt = chameleon_context_self();
    if (chamctxt == NULL) {
        chameleon_fatal_error("CHAMELEON_ztrmm_Tile", "CHAMELEON not initialized");
327
        return CHAMELEON_ERR_NOT_INITIALIZED;
328 329
    }
    if (sequence == NULL) {
Mathieu Faverge's avatar
Mathieu Faverge committed
330
        chameleon_fatal_error("CHAMELEON_ztrmm_Tile", "NULL sequence");
331
        return CHAMELEON_ERR_UNALLOCATED;
332 333
    }
    if (request == NULL) {
Mathieu Faverge's avatar
Mathieu Faverge committed
334
        chameleon_fatal_error("CHAMELEON_ztrmm_Tile", "NULL request");
335
        return CHAMELEON_ERR_UNALLOCATED;
336 337
    }
    /* Check sequence status */
338 339
    if (sequence->status == CHAMELEON_SUCCESS) {
        request->status = CHAMELEON_SUCCESS;
Mathieu Faverge's avatar
Mathieu Faverge committed
340 341
    }
    else {
Mathieu Faverge's avatar
Mathieu Faverge committed
342
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_SEQUENCE_FLUSHED);
Mathieu Faverge's avatar
Mathieu Faverge committed
343
    }
344 345

    /* Check descriptors for correctness */
Mathieu Faverge's avatar
Mathieu Faverge committed
346 347 348
    if (chameleon_desc_check(A) != CHAMELEON_SUCCESS) {
        chameleon_error("CHAMELEON_ztrmm_Tile", "invalid first descriptor");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
349
    }
Mathieu Faverge's avatar
Mathieu Faverge committed
350 351 352
    if (chameleon_desc_check(B) != CHAMELEON_SUCCESS) {
        chameleon_error("CHAMELEON_ztrmm_Tile", "invalid second descriptor");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
353 354 355
    }
    /* Check input arguments */
    if (A->nb != A->mb || B->nb != B->mb) {
Mathieu Faverge's avatar
Mathieu Faverge committed
356 357
        chameleon_error("CHAMELEON_ztrmm_Tile", "only square tiles supported");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
358
    }
359
    if (side != ChamLeft && side != ChamRight) {
Mathieu Faverge's avatar
Mathieu Faverge committed
360 361
        chameleon_error("CHAMELEON_ztrmm_Tile", "illegal value of side");
        return chameleon_request_fail(sequence, request, -1);
362
    }
363
    if ((uplo != ChamUpper) && (uplo != ChamLower)) {
Mathieu Faverge's avatar
Mathieu Faverge committed
364 365
        chameleon_error("CHAMELEON_ztrmm_Tile", "illegal value of uplo");
        return chameleon_request_fail(sequence, request, -2);
366
    }
367
    if ((transA < ChamNoTrans) || (transA > ChamConjTrans)) {
Mathieu Faverge's avatar
Mathieu Faverge committed
368 369
        chameleon_error("CHAMELEON_ztrmm_Tile", "illegal value of transA");
        return chameleon_request_fail(sequence, request, -3);
370
    }
371
    if ((diag != ChamUnit) && (diag != ChamNonUnit)) {
Mathieu Faverge's avatar
Mathieu Faverge committed
372 373
        chameleon_error("CHAMELEON_ztrmm_Tile", "illegal value of diag");
        return chameleon_request_fail(sequence, request, -4);
374 375 376
    }

    /* Quick return */
Mathieu Faverge's avatar
Mathieu Faverge committed
377
    chameleon_pztrmm( side, uplo, transA, diag, alpha, A, B, sequence, request );
378

379
    return CHAMELEON_SUCCESS;
380
}