zsyr2k.c 14.4 KB
Newer Older
1
/**
2 3
 *
 * @file zsyr2k.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 zsyr2k 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 -> c d s
 *
23
 */
24
#include "control/common.h"
25

26 27
/**
 ********************************************************************************
28
 *
29
 * @ingroup CHAMELEON_Complex64_t
30
 *
31
 *  CHAMELEON_zsyr2k - Performs one of the symmetric rank 2k operations
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
 *
 *    \f[ C = \alpha [ op( A ) \times conjg( op( B )' )] + \alpha [ op( B ) \times conjg( op( A )' )] + \beta C \f],
 *    or
 *    \f[ C = \alpha [ conjg( op( A )' ) \times op( B ) ] + \alpha [ conjg( op( B )' ) \times op( A ) ] + \beta C \f],
 *
 *  where op( X ) is one of
 *
 *    op( X ) = X  or op( X ) = conjg( X' )
 *
 *  where alpha and beta are real scalars, C is an n-by-n symmetric
 *  matrix and A and B are an n-by-k matrices the first case and k-by-n
 *  matrices in the second case.
 *
 *******************************************************************************
 *
 * @param[in] uplo
48 49
 *          = ChamUpper: Upper triangle of C is stored;
 *          = ChamLower: Lower triangle of C is stored.
50 51 52
 *
 * @param[in] trans
 *          Specifies whether the matrix A is transposed or conjugate transposed:
53 54
 *          = ChamNoTrans: \f[ C = \alpha [ op( A ) \times conjg( op( B )' )] + \alpha [ op( B ) \times conjg( op( A )' )] + \beta C \f]
 *          = ChamTrans: \f[ C = \alpha [ conjg( op( A )' ) \times op( B ) ] + \alpha [ conjg( op( B )' ) \times op( A ) ] + \beta C \f]
55 56 57 58 59
 *
 * @param[in] N
 *          N specifies the order of the matrix C. N must be at least zero.
 *
 * @param[in] K
60 61
 *          K specifies the number of columns of the A and B matrices with trans = ChamNoTrans.
 *          K specifies the number of rows of the A and B matrices with trans = ChamTrans.
62 63 64 65 66
 *
 * @param[in] alpha
 *          alpha specifies the scalar alpha.
 *
 * @param[in] A
67
 *          A is a LDA-by-ka matrix, where ka is K when trans = ChamNoTrans,
68 69 70 71 72 73 74
 *          and is N otherwise.
 *
 * @param[in] LDA
 *          The leading dimension of the array A. LDA must be at least
 *          max( 1, N ), otherwise LDA must be at least max( 1, K ).
 *
 * @param[in] B
75
 *          B is a LDB-by-kb matrix, where kb is K when trans = ChamNoTrans,
76 77 78 79 80
 *          and is N otherwise.
 *
 * @param[in] LDB
 *          The leading dimension of the array B. LDB must be at least
 *          max( 1, N ), otherwise LDB must be at least max( 1, K ).
81
 *
82 83 84 85 86 87 88 89 90 91 92 93 94 95
 * @param[in] beta
 *          beta specifies the scalar beta.
 *
 * @param[in,out] C
 *          C is a LDC-by-N matrix.
 *          On exit, the array uplo part of the matrix is overwritten
 *          by the uplo part of the updated matrix.
 *
 * @param[in] LDC
 *          The leading dimension of the array C. LDC >= max( 1, N ).
 *
 *******************************************************************************
 *
 * @return
96
 *          \retval CHAMELEON_SUCCESS successful exit
97 98 99
 *
 *******************************************************************************
 *
100 101 102 103
 * @sa CHAMELEON_zsyr2k_Tile
 * @sa CHAMELEON_csyr2k
 * @sa CHAMELEON_dsyr2k
 * @sa CHAMELEON_ssyr2k
104
 *
105
 */
106 107 108
int CHAMELEON_zsyr2k( cham_uplo_t uplo, cham_trans_t trans, int N, int K,
                 CHAMELEON_Complex64_t alpha, CHAMELEON_Complex64_t *A, int LDA, CHAMELEON_Complex64_t *B, int LDB,
                 CHAMELEON_Complex64_t beta,  CHAMELEON_Complex64_t *C, int LDC )
109 110 111 112
{
    int NB;
    int Am, An;
    int status;
113 114 115
    CHAM_desc_t descAl, descAt;
    CHAM_desc_t descBl, descBt;
    CHAM_desc_t descCl, descCt;
Mathieu Faverge's avatar
Mathieu Faverge committed
116
    CHAM_context_t *chamctxt;
117 118
    RUNTIME_sequence_t *sequence = NULL;
    RUNTIME_request_t request = RUNTIME_REQUEST_INITIALIZER;
119

Mathieu Faverge's avatar
Mathieu Faverge committed
120 121 122
    chamctxt = chameleon_context_self();
    if (chamctxt == NULL) {
        chameleon_fatal_error("CHAMELEON_zsyr2k", "CHAMELEON not initialized");
123
        return CHAMELEON_ERR_NOT_INITIALIZED;
124 125 126
    }

    /* Check input arguments */
127
    if ((uplo != ChamUpper) && (uplo != ChamLower)) {
Mathieu Faverge's avatar
Mathieu Faverge committed
128
        chameleon_error("CHAMELEON_zsyr2k", "illegal value of uplo");
129 130
        return -1;
    }
131
    if ((trans != ChamNoTrans) && (trans != ChamTrans)) {
Mathieu Faverge's avatar
Mathieu Faverge committed
132
        chameleon_error("CHAMELEON_zsyr2k", "illegal value of trans");
133 134
        return -2;
    }
135
    if ( trans == ChamNoTrans ) {
136 137 138 139 140
        Am = N; An = K;
    } else {
        Am = K; An = N;
    }
    if (N < 0) {
Mathieu Faverge's avatar
Mathieu Faverge committed
141
        chameleon_error("CHAMELEON_zsyr2k", "illegal value of N");
142 143 144
        return -3;
    }
    if (K < 0) {
Mathieu Faverge's avatar
Mathieu Faverge committed
145
        chameleon_error("CHAMELEON_zsyr2k", "illegal value of K");
146 147
        return -4;
    }
148
    if (LDA < chameleon_max(1, Am)) {
Mathieu Faverge's avatar
Mathieu Faverge committed
149
        chameleon_error("CHAMELEON_zsyr2k", "illegal value of LDA");
150 151
        return -7;
    }
152
    if (LDB < chameleon_max(1, Am)) {
Mathieu Faverge's avatar
Mathieu Faverge committed
153
        chameleon_error("CHAMELEON_zsyr2k", "illegal value of LDB");
154 155
        return -9;
    }
156
    if (LDC < chameleon_max(1, N)) {
Mathieu Faverge's avatar
Mathieu Faverge committed
157
        chameleon_error("CHAMELEON_zsyr2k", "illegal value of LDC");
158 159 160 161 162
        return -12;
    }

    /* Quick return */
    if (N == 0 ||
163 164
        ((alpha == (CHAMELEON_Complex64_t)0.0 || K == 0.0) && beta == (CHAMELEON_Complex64_t)1.0))
        return CHAMELEON_SUCCESS;
165 166

    /* Tune NB depending on M, N & NRHS; Set NBNB */
Mathieu Faverge's avatar
Mathieu Faverge committed
167
    status = chameleon_tune(CHAMELEON_FUNC_ZSYRK, N, K, 0);
168
    if (status != CHAMELEON_SUCCESS) {
Mathieu Faverge's avatar
Mathieu Faverge committed
169
        chameleon_error("CHAMELEON_zsyr2k", "chameleon_tune() failed");
170 171 172 173
        return status;
    }

    /* Set MT & NT & KT */
174
    NB = CHAMELEON_NB;
175

Mathieu Faverge's avatar
Mathieu Faverge committed
176
    chameleon_sequence_create( chamctxt, &sequence );
177

178
    /* Submit the matrix conversion */
Mathieu Faverge's avatar
Mathieu Faverge committed
179
    chameleon_zlap2tile( chamctxt, &descAl, &descAt, ChamDescInput, ChamUpperLower,
180
                     A, NB, NB, LDA, An, Am, An, sequence, &request );
Mathieu Faverge's avatar
Mathieu Faverge committed
181
    chameleon_zlap2tile( chamctxt, &descBl, &descBt, ChamDescInput, ChamUpperLower,
182
                     B, NB, NB, LDB, An, Am, An, sequence, &request );
Mathieu Faverge's avatar
Mathieu Faverge committed
183
    chameleon_zlap2tile( chamctxt, &descCl, &descCt, ChamDescInout, uplo,
184
                     C, NB, NB, LDC, N, N,  N, sequence, &request );
185 186

    /* Call the tile interface */
187
    CHAMELEON_zsyr2k_Tile_Async( uplo, trans, alpha, &descAt, &descBt, beta, &descCt, sequence, &request );
188

Mathieu Faverge's avatar
Mathieu Faverge committed
189
    /* Submit the matrix conversion back */
Mathieu Faverge's avatar
Mathieu Faverge committed
190
    chameleon_ztile2lap( chamctxt, &descAl, &descAt,
191
                     ChamDescInput, ChamUpperLower, sequence, &request );
Mathieu Faverge's avatar
Mathieu Faverge committed
192
    chameleon_ztile2lap( chamctxt, &descBl, &descBt,
193
                     ChamDescInput, ChamUpperLower, sequence, &request );
Mathieu Faverge's avatar
Mathieu Faverge committed
194
    chameleon_ztile2lap( chamctxt, &descCl, &descCt,
195
                     ChamDescInout, uplo, sequence, &request );
Mathieu Faverge's avatar
Mathieu Faverge committed
196

Mathieu Faverge's avatar
Mathieu Faverge committed
197
    chameleon_sequence_wait( chamctxt, sequence );
Mathieu Faverge's avatar
Mathieu Faverge committed
198

Mathieu Faverge's avatar
Mathieu Faverge committed
199
    /* Cleanup the temporary data */
Mathieu Faverge's avatar
Mathieu Faverge committed
200 201 202
    chameleon_ztile2lap_cleanup( chamctxt, &descAl, &descAt );
    chameleon_ztile2lap_cleanup( chamctxt, &descBl, &descBt );
    chameleon_ztile2lap_cleanup( chamctxt, &descCl, &descCt );
203 204

    status = sequence->status;
Mathieu Faverge's avatar
Mathieu Faverge committed
205
    chameleon_sequence_destroy( chamctxt, sequence );
206 207 208
    return status;
}

209 210
/**
 ********************************************************************************
211
 *
212
 * @ingroup CHAMELEON_Complex64_t_Tile
213
 *
214 215
 *  CHAMELEON_zsyr2k_Tile - Performs symmetric rank k update.
 *  Tile equivalent of CHAMELEON_zsyr2k().
216 217 218 219 220 221 222
 *  Operates on matrices stored by tiles.
 *  All matrices are passed through descriptors.
 *  All dimensions are taken from the descriptors.
 *
 *******************************************************************************
 *
 * @param[in] uplo
223 224
 *          = ChamUpper: Upper triangle of C is stored;
 *          = ChamLower: Lower triangle of C is stored.
225 226 227
 *
 * @param[in] trans
 *          Specifies whether the matrix A is transposed or conjugate transposed:
228 229
 *          = ChamNoTrans:   A is not transposed;
 *          = ChamTrans: A is conjugate transposed.
230 231 232 233 234
 *
 * @param[in] alpha
 *          alpha specifies the scalar alpha.
 *
 * @param[in] A
235
 *          A is a LDA-by-ka matrix, where ka is K when trans = ChamNoTrans,
236 237 238
 *          and is N otherwise.
 *
 * @param[in] B
239
 *          B is a LDB-by-kb matrix, where kb is K when trans = ChamNoTrans,
240 241 242 243 244 245 246 247 248 249 250 251 252
 *          and is N otherwise.
 *
 * @param[in] beta
 *          beta specifies the scalar beta
 *
 * @param[in,out] C
 *          C is a LDC-by-N matrix.
 *          On exit, the array uplo part of the matrix is overwritten
 *          by the uplo part of the updated matrix.
 *
 *******************************************************************************
 *
 * @return
253
 *          \retval CHAMELEON_SUCCESS successful exit
254 255 256
 *
 *******************************************************************************
 *
257 258 259 260
 * @sa CHAMELEON_zsyr2k_Tile
 * @sa CHAMELEON_csyr2k
 * @sa CHAMELEON_dsyr2k
 * @sa CHAMELEON_ssyr2k
261
 *
262
 */
263 264 265
int CHAMELEON_zsyr2k_Tile( cham_uplo_t uplo, cham_trans_t trans,
                      CHAMELEON_Complex64_t alpha, CHAM_desc_t *A, CHAM_desc_t *B,
                      CHAMELEON_Complex64_t beta,  CHAM_desc_t *C )
266
{
Mathieu Faverge's avatar
Mathieu Faverge committed
267
    CHAM_context_t *chamctxt;
268 269
    RUNTIME_sequence_t *sequence = NULL;
    RUNTIME_request_t request = RUNTIME_REQUEST_INITIALIZER;
270 271
    int status;

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

279
    CHAMELEON_zsyr2k_Tile_Async( uplo, trans, alpha, A, B, beta, C, sequence, &request );
280

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

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

291 292
/**
 ********************************************************************************
293
 *
294
 * @ingroup CHAMELEON_Complex64_t_Tile_Async
295
 *
296 297
 *  CHAMELEON_zsyr2k_Tile_Async - Performs symmetric rank-k update.
 *  Non-blocking equivalent of CHAMELEON_zsyr2k_Tile().
298 299 300 301 302 303 304 305 306 307 308 309 310 311
 *  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).
 *
 *******************************************************************************
 *
312 313 314 315 316
 * @sa CHAMELEON_zsyr2k
 * @sa CHAMELEON_zsyr2k_Tile
 * @sa CHAMELEON_csyr2k_Tile_Async
 * @sa CHAMELEON_dsyr2k_Tile_Async
 * @sa CHAMELEON_ssyr2k_Tile_Async
317
 *
318
 */
319 320 321 322
int CHAMELEON_zsyr2k_Tile_Async( cham_uplo_t uplo, cham_trans_t trans,
                            CHAMELEON_Complex64_t alpha, CHAM_desc_t *A, CHAM_desc_t *B,
                            CHAMELEON_Complex64_t beta,  CHAM_desc_t *C,
                            RUNTIME_sequence_t *sequence, RUNTIME_request_t *request )
323
{
Mathieu Faverge's avatar
Mathieu Faverge committed
324
    CHAM_context_t *chamctxt;
325 326 327
    int N, K;
    int Am, An, Amb;

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

    /* Check descriptors for correctness */
Mathieu Faverge's avatar
Mathieu Faverge committed
350 351 352
    if (chameleon_desc_check(A) != CHAMELEON_SUCCESS) {
        chameleon_error("CHAMELEON_zsyr2k_Tile_Async", "invalid first descriptor");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
353
    }
Mathieu Faverge's avatar
Mathieu Faverge committed
354 355 356
    if (chameleon_desc_check(B) != CHAMELEON_SUCCESS) {
        chameleon_error("CHAMELEON_zsyr2k_Tile_Async", "invalid second descriptor");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
357
    }
Mathieu Faverge's avatar
Mathieu Faverge committed
358 359 360
    if (chameleon_desc_check(C) != CHAMELEON_SUCCESS) {
        chameleon_error("CHAMELEON_zsyr2k_Tile_Async", "invalid third descriptor");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
361 362
    }
    /* Check input arguments */
363
    if ((uplo != ChamUpper) && (uplo != ChamLower)) {
Mathieu Faverge's avatar
Mathieu Faverge committed
364 365
        chameleon_error("CHAMELEON_zsyr2k", "illegal value of uplo");
        return chameleon_request_fail(sequence, request, -1);
366
    }
367
    if ((trans != ChamNoTrans) && (trans != ChamTrans)) {
Mathieu Faverge's avatar
Mathieu Faverge committed
368 369
        chameleon_error("CHAMELEON_zsyr2k", "illegal value of trans");
        return chameleon_request_fail(sequence, request, -2);
370 371
    }

372
    if ( trans == ChamNoTrans ) {
373 374 375 376 377 378 379 380 381 382
        Am  = A->m;
        An  = A->n;
        Amb = A->mb;
    } else {
        Am  = A->n;
        An  = A->m;
        Amb = A->nb;
    }

    if (C->mb != C->nb) {
Mathieu Faverge's avatar
Mathieu Faverge committed
383 384
        chameleon_error("CHAMELEON_zsyr2k_Tile_Async", "only square tiles for C are supported");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
385 386
    }
    if ( (B->mb != A->mb) || (B->nb != A->nb) || (Amb != C->mb) ){
Mathieu Faverge's avatar
Mathieu Faverge committed
387 388
        chameleon_error("CHAMELEON_zsyr2k_Tile_Async", "tile sizes have to match");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
389 390
    }
    if (C->m != C->n) {
Mathieu Faverge's avatar
Mathieu Faverge committed
391 392
        chameleon_error("CHAMELEON_zsyr2k_Tile_Async", "only square matrix C is supported");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
393 394
    }
    if ( (B->m != A->m) || (B->n != A->n) || (Am != C->m) ){
Mathieu Faverge's avatar
Mathieu Faverge committed
395 396
        chameleon_error("CHAMELEON_zsyr2k_Tile_Async", "sizes of matrices have to match");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
397 398 399 400 401 402 403
    }

    N = C->m;
    K = An;

    /* Quick return */
    if ( N == 0 ||
404 405
         ((alpha == (CHAMELEON_Complex64_t)0.0 || K == 0) && beta == (CHAMELEON_Complex64_t)1.0))
        return CHAMELEON_SUCCESS;
406

Mathieu Faverge's avatar
Mathieu Faverge committed
407
    chameleon_pzsyr2k( uplo, trans, alpha, A, B, beta, C, sequence, request );
408

409
    return CHAMELEON_SUCCESS;
410
}