zunmlq.c 13.1 KB
Newer Older
1
/**
2 3
 *
 * @file zunmlq.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 zunmlq 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 23 24 25
 * @author Hatem Ltaief
 * @author Jakub Kurzak
 * @author Dulceneia Becker
 * @author Mathieu Faverge
 * @author Emmanuel Agullo
 * @author Cedric Castagnede
 * @date 2010-11-15
 * @precisions normal z -> s d c
 *
26
 */
27
#include "control/common.h"
28

BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
29 30
/**
 *******************************************************************************
31
 *
32
 * @ingroup CHAMELEON_Complex64_t
33
 *
34
 *  CHAMELEON_zunmlq - Overwrites the general complex M-by-N matrix C with
35
 *
36 37 38
 *                  SIDE = 'L'     SIDE = 'R'
 *  TRANS = 'N':      Q * C          C * Q
 *  TRANS = 'C':      Q**H * C       C * Q**H
39
 *
40 41
 *  where Q is a complex unitary matrix defined as the product of k
 *  elementary reflectors
42
 *
43
 *        Q = H(1) H(2) . . . H(k)
44
 *
45 46
 *  as returned by CHAMELEON_zgeqrf. Q is of order M if SIDE = ChamLeft
 *  and of order N if SIDE = ChamRight.
47 48 49 50 51
 *
 *******************************************************************************
 *
 * @param[in] side
 *          Intended usage:
52 53
 *          = ChamLeft:  apply Q or Q**H from the left;
 *          = ChamRight: apply Q or Q**H from the right.
54 55 56
 *
 * @param[in] trans
 *          Intended usage:
57 58
 *          = ChamNoTrans:   no transpose, apply Q;
 *          = ChamConjTrans: conjugate transpose, apply Q**H.
59 60 61 62 63 64 65 66 67
 *
 * @param[in] M
 *          The number of rows of the matrix C. M >= 0.
 *
 * @param[in] N
 *          The number of columns of the matrix C. N >= 0.
 *
 * @param[in] K
 *          The number of rows of elementary tile reflectors whose product defines the matrix Q.
68 69
 *          If side == ChamLeft,  M >= K >= 0.
 *          If side == ChamRight, N >= K >= 0.
70 71
 *
 * @param[in] A
72
 *          Details of the LQ factorization of the original matrix A as returned by CHAMELEON_zgelqf.
73 74 75 76 77
 *
 * @param[in] LDA
 *          The leading dimension of the array A. LDA >= max(1,K).
 *
 * @param[in] descT
78
 *          Auxiliary factorization data, computed by CHAMELEON_zgelqf.
79 80 81 82 83 84 85 86 87 88
 *
 * @param[in,out] C
 *          On entry, the M-by-N matrix C.
 *          On exit, C is overwritten by Q*C or Q**H*C.
 *
 * @param[in] LDC
 *          The leading dimension of the array C. LDC >= max(1,M).
 *
 *******************************************************************************
 *
89 90
 * @retval CHAMELEON_SUCCESS successful exit
 * @retval <0 if -i, the i-th argument had an illegal value
91 92 93
 *
 *******************************************************************************
 *
94 95 96 97 98 99
 * @sa CHAMELEON_zunmlq_Tile
 * @sa CHAMELEON_zunmlq_Tile_Async
 * @sa CHAMELEON_cunmlq
 * @sa CHAMELEON_dormlq
 * @sa CHAMELEON_sormlq
 * @sa CHAMELEON_zgelqf
100
 *
101
 */
102 103 104 105
int CHAMELEON_zunmlq( cham_side_t side, cham_trans_t trans, int M, int N, int K,
                  CHAMELEON_Complex64_t *A, int LDA,
                  CHAM_desc_t *descT,
                  CHAMELEON_Complex64_t *C, int LDC )
106 107 108
{
    int NB, An;
    int status;
Mathieu Faverge's avatar
Mathieu Faverge committed
109
    CHAM_context_t *chamctxt;
110 111 112 113
    RUNTIME_sequence_t *sequence = NULL;
    RUNTIME_request_t request = RUNTIME_REQUEST_INITIALIZER;
    CHAM_desc_t descAl, descAt;
    CHAM_desc_t descCl, descCt;
114

Mathieu Faverge's avatar
Mathieu Faverge committed
115 116 117
    chamctxt = chameleon_context_self();
    if (chamctxt == NULL) {
        chameleon_fatal_error("CHAMELEON_zunmlq", "CHAMELEON not initialized");
118
        return CHAMELEON_ERR_NOT_INITIALIZED;
119 120
    }

121
    if (side == ChamLeft) {
122
        An = M;
123 124
    }
    else {
125
        An = N;
126
    }
127 128

    /* Check input arguments */
129
    if ((side != ChamLeft) && (side != ChamRight)) {
Mathieu Faverge's avatar
Mathieu Faverge committed
130
        chameleon_error("CHAMELEON_zunmlq", "illegal value of side");
131 132
        return -1;
    }
133
    if ((trans != ChamConjTrans) && (trans != ChamNoTrans)){
Mathieu Faverge's avatar
Mathieu Faverge committed
134
        chameleon_error("CHAMELEON_zunmlq", "illegal value of trans");
135 136 137
        return -2;
    }
    if (M < 0) {
Mathieu Faverge's avatar
Mathieu Faverge committed
138
        chameleon_error("CHAMELEON_zunmlq", "illegal value of M");
139 140 141
        return -3;
    }
    if (N < 0) {
Mathieu Faverge's avatar
Mathieu Faverge committed
142
        chameleon_error("CHAMELEON_zunmlq", "illegal value of N");
143 144 145
        return -4;
    }
    if ((K < 0) || (K > An)) {
Mathieu Faverge's avatar
Mathieu Faverge committed
146
        chameleon_error("CHAMELEON_zunmlq", "illegal value of K");
147 148
        return -5;
    }
149
    if (LDA < chameleon_max(1, K)) {
Mathieu Faverge's avatar
Mathieu Faverge committed
150
        chameleon_error("CHAMELEON_zunmlq", "illegal value of LDA");
151 152
        return -7;
    }
153
    if (LDC < chameleon_max(1, M)) {
Mathieu Faverge's avatar
Mathieu Faverge committed
154
        chameleon_error("CHAMELEON_zunmlq", "illegal value of LDC");
155 156 157 158
        return -10;
    }
    /* Quick return - currently NOT equivalent to LAPACK's:
     * CALL DLASET( 'Full', MAX( M, N ), NRHS, ZERO, ZERO, C, LDC ) */
159
    if (chameleon_min(M, chameleon_min(N, K)) == 0)
160
        return CHAMELEON_SUCCESS;
161 162

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

    /* Set MT, NT & NTRHS */
170
    NB   = CHAMELEON_NB;
Mathieu Faverge's avatar
Mathieu Faverge committed
171
    chameleon_sequence_create( chamctxt, &sequence );
172

173
    /* Submit the matrix conversion */
Mathieu Faverge's avatar
Mathieu Faverge committed
174
    chameleon_zlap2tile( chamctxt, &descAl, &descAt, ChamDescInput, ChamUpper,
175
                     A, NB, NB, LDA, An, K, An, sequence, &request );
Mathieu Faverge's avatar
Mathieu Faverge committed
176
    chameleon_zlap2tile( chamctxt, &descCl, &descCt, ChamDescInout, ChamUpperLower,
177
                     C, NB, NB, LDC, N, M,  N, sequence, &request );
178 179

    /* Call the tile interface */
180
    CHAMELEON_zunmlq_Tile_Async(  side, trans, &descAt, descT, &descCt, sequence, &request );
181

Mathieu Faverge's avatar
Mathieu Faverge committed
182
    /* Submit the matrix conversion back */
Mathieu Faverge's avatar
Mathieu Faverge committed
183
    chameleon_ztile2lap( chamctxt, &descAl, &descAt,
184
                     ChamDescInput, ChamUpper, sequence, &request );
Mathieu Faverge's avatar
Mathieu Faverge committed
185
    chameleon_ztile2lap( chamctxt, &descCl, &descCt,
186 187
                     ChamDescInout, ChamUpperLower, sequence, &request );
    CHAMELEON_Desc_Flush( descT, sequence );
Mathieu Faverge's avatar
Mathieu Faverge committed
188

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

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

    status = sequence->status;
Mathieu Faverge's avatar
Mathieu Faverge committed
196
    chameleon_sequence_destroy( chamctxt, sequence );
197 198 199
    return status;
}

BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
200 201
/**
 *******************************************************************************
202
 *
203
 * @ingroup CHAMELEON_Complex64_t_Tile
204
 *
205
 *  CHAMELEON_zunmlq_Tile - overwrites the general M-by-N matrix C with Q*C, where Q is an orthogonal
206
 *  matrix (unitary in the complex case) defined as the product of elementary reflectors returned
207
 *  by CHAMELEON_zgelqf_Tile Q is of order M.
208 209 210 211 212 213
 *  All matrices are passed through descriptors. All dimensions are taken from the descriptors.
 *
 *******************************************************************************
 *
 * @param[in] side
 *          Intended usage:
214 215 216
 *          = ChamLeft:  apply Q or Q**H from the left;
 *          = ChamRight: apply Q or Q**H from the right.
 *          Currently only ChamLeft is supported.
217 218 219
 *
 * @param[in] trans
 *          Intended usage:
220 221 222
 *          = ChamNoTrans:   no transpose, apply Q;
 *          = ChamConjTrans: conjugate transpose, apply Q**H.
 *          Currently only ChamConjTrans is supported.
223 224
 *
 * @param[in] A
225
 *          Details of the LQ factorization of the original matrix A as returned by CHAMELEON_zgelqf.
226 227
 *
 * @param[in] T
228
 *          Auxiliary factorization data, computed by CHAMELEON_zgelqf.
229 230 231 232 233 234 235
 *
 * @param[in,out] C
 *          On entry, the M-by-N matrix C.
 *          On exit, C is overwritten by Q*C or Q**H*C.
 *
 *******************************************************************************
 *
236
 * @retval CHAMELEON_SUCCESS successful exit
237 238 239
 *
 *******************************************************************************
 *
240 241 242 243 244 245
 * @sa CHAMELEON_zunmlq
 * @sa CHAMELEON_zunmlq_Tile_Async
 * @sa CHAMELEON_cunmlq_Tile
 * @sa CHAMELEON_dormlq_Tile
 * @sa CHAMELEON_sormlq_Tile
 * @sa CHAMELEON_zgelqf_Tile
246
 *
247
 */
248 249
int CHAMELEON_zunmlq_Tile( cham_side_t side, cham_trans_t trans,
                       CHAM_desc_t *A, CHAM_desc_t *T, CHAM_desc_t *C )
250
{
Mathieu Faverge's avatar
Mathieu Faverge committed
251
    CHAM_context_t *chamctxt;
252 253
    RUNTIME_sequence_t *sequence = NULL;
    RUNTIME_request_t request = RUNTIME_REQUEST_INITIALIZER;
254 255
    int status;

Mathieu Faverge's avatar
Mathieu Faverge committed
256 257 258
    chamctxt = chameleon_context_self();
    if (chamctxt == NULL) {
        chameleon_fatal_error("CHAMELEON_zunmlq_Tile", "CHAMELEON not initialized");
259
        return CHAMELEON_ERR_NOT_INITIALIZED;
260
    }
Mathieu Faverge's avatar
Mathieu Faverge committed
261
    chameleon_sequence_create( chamctxt, &sequence );
262

263
    CHAMELEON_zunmlq_Tile_Async(side, trans, A, T, C, sequence, &request );
264

265 266 267
    CHAMELEON_Desc_Flush( A, sequence );
    CHAMELEON_Desc_Flush( T, sequence );
    CHAMELEON_Desc_Flush( C, sequence );
Mathieu Faverge's avatar
Mathieu Faverge committed
268

Mathieu Faverge's avatar
Mathieu Faverge committed
269
    chameleon_sequence_wait( chamctxt, sequence );
270
    status = sequence->status;
Mathieu Faverge's avatar
Mathieu Faverge committed
271
    chameleon_sequence_destroy( chamctxt, sequence );
272 273 274
    return status;
}

BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
275 276
/**
 *******************************************************************************
277
 *
278
 * @ingroup CHAMELEON_Complex64_t_Tile_Async
279
 *
280
 *  Non-blocking equivalent of CHAMELEON_zunmlq_Tile().
281 282 283 284 285 286 287 288 289 290 291 292 293 294
 *  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).
 *
 *******************************************************************************
 *
295 296 297 298 299 300
 * @sa CHAMELEON_zunmlq
 * @sa CHAMELEON_zunmlq_Tile
 * @sa CHAMELEON_cunmlq_Tile_Async
 * @sa CHAMELEON_dormlq_Tile_Async
 * @sa CHAMELEON_sormlq_Tile_Async
 * @sa CHAMELEON_zgelqf_Tile_Async
301
 *
302
 */
303 304 305
int CHAMELEON_zunmlq_Tile_Async( cham_side_t side, cham_trans_t trans,
                             CHAM_desc_t *A, CHAM_desc_t *T, CHAM_desc_t *C,
                             RUNTIME_sequence_t *sequence, RUNTIME_request_t *request )
306
{
Mathieu Faverge's avatar
Mathieu Faverge committed
307
    CHAM_context_t *chamctxt;
308
    CHAM_desc_t D, *Dptr = NULL;
309

Mathieu Faverge's avatar
Mathieu Faverge committed
310 311 312
    chamctxt = chameleon_context_self();
    if (chamctxt == NULL) {
        chameleon_fatal_error("CHAMELEON_zunmlq_Tile", "CHAMELEON not initialized");
313
        return CHAMELEON_ERR_NOT_INITIALIZED;
314 315
    }
    if (sequence == NULL) {
Mathieu Faverge's avatar
Mathieu Faverge committed
316
        chameleon_fatal_error("CHAMELEON_zunmlq_Tile", "NULL sequence");
317
        return CHAMELEON_ERR_UNALLOCATED;
318 319
    }
    if (request == NULL) {
Mathieu Faverge's avatar
Mathieu Faverge committed
320
        chameleon_fatal_error("CHAMELEON_zunmlq_Tile", "NULL request");
321
        return CHAMELEON_ERR_UNALLOCATED;
322 323
    }
    /* Check sequence status */
324 325
    if (sequence->status == CHAMELEON_SUCCESS) {
        request->status = CHAMELEON_SUCCESS;
Mathieu Faverge's avatar
Mathieu Faverge committed
326 327
    }
    else {
Mathieu Faverge's avatar
Mathieu Faverge committed
328
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_SEQUENCE_FLUSHED);
Mathieu Faverge's avatar
Mathieu Faverge committed
329
    }
330 331

    /* Check descriptors for correctness */
Mathieu Faverge's avatar
Mathieu Faverge committed
332 333 334
    if (chameleon_desc_check(A) != CHAMELEON_SUCCESS) {
        chameleon_error("CHAMELEON_zunmlq_Tile", "invalid first descriptor");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
335
    }
Mathieu Faverge's avatar
Mathieu Faverge committed
336 337 338
    if (chameleon_desc_check(T) != CHAMELEON_SUCCESS) {
        chameleon_error("CHAMELEON_zunmlq_Tile", "invalid second descriptor");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
339
    }
Mathieu Faverge's avatar
Mathieu Faverge committed
340 341 342
    if (chameleon_desc_check(C) != CHAMELEON_SUCCESS) {
        chameleon_error("CHAMELEON_zunmlq_Tile", "invalid third descriptor");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
343 344 345
    }
    /* Check input arguments */
    if (A->nb != A->mb || C->nb != C->mb) {
Mathieu Faverge's avatar
Mathieu Faverge committed
346 347
        chameleon_error("CHAMELEON_zunmlq_Tile", "only square tiles supported");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
348
    }
349
    if ((side != ChamLeft) && (side != ChamRight)) {
Mathieu Faverge's avatar
Mathieu Faverge committed
350
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
351
    }
352
    if ((trans != ChamConjTrans) && (trans != ChamNoTrans)){
Mathieu Faverge's avatar
Mathieu Faverge committed
353
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
354 355 356
    }
    /* Quick return - currently NOT equivalent to LAPACK's:
     * CALL DLASET( 'Full', MAX( M, N ), NRHS, ZERO, ZERO, C, LDC ) */
357 358
    /*
     if (chameleon_min(M, chameleon_min(N, K)) == 0)
359
     return CHAMELEON_SUCCESS;
360
     */
361 362
#if defined(CHAMELEON_COPY_DIAG)
    {
363
        int m = chameleon_min(A->m, A->n);
Mathieu Faverge's avatar
Mathieu Faverge committed
364
        chameleon_zdesc_alloc(D, A->mb, A->nb, m, A->n, 0, 0, m, A->n, );
365 366 367 368
        Dptr = &D;
    }
#endif

Mathieu Faverge's avatar
Mathieu Faverge committed
369
    if (chamctxt->householder == ChamFlatHouseholder) {
370
        chameleon_pzunmlq( 1, side, trans, A, C, T, Dptr, sequence, request );
371 372
    }
    else {
373
        chameleon_pzunmlqrh( 1, CHAMELEON_RHBLK, side, trans, A, C, T, Dptr, sequence, request );
374
    }
375 376

    if ( Dptr != NULL ) {
377 378 379 380
        CHAMELEON_Desc_Flush( A, sequence );
        CHAMELEON_Desc_Flush( C, sequence );
        CHAMELEON_Desc_Flush( T, sequence );
        CHAMELEON_Desc_Flush( Dptr, sequence );
Mathieu Faverge's avatar
Mathieu Faverge committed
381
        chameleon_sequence_wait( chamctxt, sequence );
382
        chameleon_desc_destroy( Dptr );
383 384
    }
    (void)D;
385
    return CHAMELEON_SUCCESS;
386
}