zunmqr.c 13.2 KB
Newer Older
1
/**
2 3
 *
 * @file zunmqr.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.
7 8
 * @copyright 2012-2014 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
 *                      Univ. Bordeaux. All rights reserved.
9
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
10
 ***
11 12 13 14 15 16
 *
 *
 *  MORSE computational routines
 *  MORSE is a software package provided by Univ. of Tennessee,
 *  Univ. of California Berkeley and Univ. of Colorado Denver
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
17
 * @version 1.0.0
18 19 20 21 22 23 24 25 26 27 28
 * @comment This file has been automatically generated
 *          from Plasma 2.5.0 for MORSE 1.0.0
 * @author Hatem Ltaief
 * @author Jakub Kurzak
 * @author Mathieu Faverge
 * @author Emmanuel Agullo
 * @author Cedric Castagnede
 * @date 2010-11-15
 * @precisions normal z -> s d c
 *
 **/
29
#include "control/common.h"
30

31 32
/**
 ********************************************************************************
33 34 35 36
 *
 * @ingroup MORSE_Complex64_t
 *
 *  MORSE_zunmqr - Overwrites the general complex M-by-N matrix C with
37
 *
38 39 40
 *                  SIDE = 'L'     SIDE = 'R'
 *  TRANS = 'N':      Q * C          C * Q
 *  TRANS = 'C':      Q**H * C       C * Q**H
41
 *
42 43
 *  where Q is a complex unitary matrix defined as the product of k
 *  elementary reflectors
44
 *
45
 *        Q = H(1) H(2) . . . H(k)
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
 *  as returned by MORSE_zgeqrf. Q is of order M if SIDE = MorseLeft
 *  and of order N if SIDE = MorseRight.
 *
 *******************************************************************************
 *
 * @param[in] side
 *          Intended usage:
 *          = MorseLeft:  apply Q or Q**H from the left;
 *          = MorseRight: apply Q or Q**H from the right.
 *
 * @param[in] trans
 *          Intended usage:
 *          = MorseNoTrans:   no transpose, apply Q;
 *          = MorseConjTrans: conjugate transpose, apply Q**H.
 *
 * @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 elementary reflectors whose product defines
 *          the matrix Q.
 *          If side == MorseLeft,  M >= K >= 0.
 *          If side == MorseRight, N >= K >= 0.
 *
 * @param[in] A
 *          Details of the QR factorization of the original matrix A as returned by MORSE_zgeqrf.
 *
 * @param[in] LDA
78
 *          The leading dimension of the array A.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
 *          If side == MorseLeft,  LDA >= max(1,M).
 *          If side == MorseRight, LDA >= max(1,N).
 *
 * @param[in] descT
 *          Auxiliary factorization data, computed by MORSE_zgeqrf.
 *
 * @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).
 *
 *******************************************************************************
 *
 * @return
 *          \retval MORSE_SUCCESS successful exit
 *          \retval <0 if -i, the i-th argument had an illegal value
 *
 *******************************************************************************
 *
 * @sa MORSE_zunmqr_Tile
 * @sa MORSE_zunmqr_Tile_Async
 * @sa MORSE_cunmqr
 * @sa MORSE_dormqr
 * @sa MORSE_sormqr
 * @sa MORSE_zgeqrf
 *
 ******************************************************************************/
108 109 110 111
int MORSE_zunmqr( MORSE_enum side, MORSE_enum trans, int M, int N, int K,
                  MORSE_Complex64_t *A, int LDA,
                  MORSE_desc_t *descT,
                  MORSE_Complex64_t *C, int LDC )
112 113 114 115 116 117
{
    int NB, Am;
    int status;
    MORSE_context_t *morse;
    MORSE_sequence_t *sequence = NULL;
    MORSE_request_t request = MORSE_REQUEST_INITIALIZER;
118 119
    MORSE_desc_t descAl, descAt;
    MORSE_desc_t descCl, descCt;
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153

    morse = morse_context_self();
    if (morse == NULL) {
        morse_fatal_error("MORSE_zunmqr", "MORSE not initialized");
        return MORSE_ERR_NOT_INITIALIZED;
    }

    if ( side == MorseLeft ) {
        Am = M;
    } else {
        Am = N;
    }

    /* Check input arguments */
    if ((side != MorseLeft) && (side != MorseRight)) {
        morse_error("MORSE_zunmqr", "illegal value of side");
        return -1;
    }
    if ((trans != MorseConjTrans) && (trans != MorseNoTrans)){
        morse_error("MORSE_zunmqr", "illegal value of trans");
        return -2;
    }
    if (M < 0) {
        morse_error("MORSE_zunmqr", "illegal value of M");
        return -3;
    }
    if (N < 0) {
        morse_error("MORSE_zunmqr", "illegal value of N");
        return -4;
    }
    if ((K < 0) || (K > Am)) {
        morse_error("MORSE_zunmqr", "illegal value of K");
        return -5;
    }
154
    if (LDA < chameleon_max(1, Am)) {
155 156 157
        morse_error("MORSE_zunmqr", "illegal value of LDA");
        return -7;
    }
158
    if (LDC < chameleon_max(1, M)) {
159 160 161 162 163
        morse_error("MORSE_zunmqr", "illegal value of LDC");
        return -10;
    }
    /* Quick return - currently NOT equivalent to LAPACK's:
     * CALL DLASET( 'Full', MAX( M, N ), NRHS, ZERO, ZERO, C, LDC ) */
164
    if (chameleon_min(M, chameleon_min(N, K)) == 0)
165 166 167 168 169 170 171 172 173 174 175
        return MORSE_SUCCESS;

    /* Tune NB & IB depending on M, K & N; Set NBNB */
    status = morse_tune(MORSE_FUNC_ZGELS, M, K, N);
    if (status != MORSE_SUCCESS) {
        morse_error("MORSE_zunmqr", "morse_tune() failed");
        return status;
    }

    /* Set MT, NT & NTRHS */
    NB   = MORSE_NB;
176
    morse_sequence_create( morse, &sequence );
177

178
    /* Submit the matrix conversion */
179
    morse_zlap2tile( morse, &descAl, &descAt, MorseDescInput, MorseLower,
180
                     A, NB, NB, LDA, K, Am, K, sequence, &request );
181
    morse_zlap2tile( morse, &descCl, &descCt, MorseDescInout, MorseUpperLower,
182
                     C, NB, NB, LDC, N, M,  N, sequence, &request );
183 184

    /* Call the tile interface */
185
    MORSE_zunmqr_Tile_Async(  side, trans, &descAt, descT, &descCt, sequence, &request );
186

Mathieu Faverge's avatar
Mathieu Faverge committed
187
    /* Submit the matrix conversion back */
188 189
    morse_ztile2lap( morse, &descAl, &descAt,
                     MorseDescInput, MorseLower, sequence, &request );
Mathieu Faverge's avatar
Mathieu Faverge committed
190
    morse_ztile2lap( morse, &descCl, &descCt,
191
                     MorseDescInout, MorseUpperLower, sequence, &request );
192
    MORSE_Desc_Flush( descT, sequence );
Mathieu Faverge's avatar
Mathieu Faverge committed
193

194
    morse_sequence_wait( morse, sequence );
Mathieu Faverge's avatar
Mathieu Faverge committed
195

Mathieu Faverge's avatar
Mathieu Faverge committed
196 197 198
    /* Cleanup the temporary data */
    morse_ztile2lap_cleanup( morse, &descAl, &descAt );
    morse_ztile2lap_cleanup( morse, &descCl, &descCt );
199 200

    status = sequence->status;
201
    morse_sequence_destroy( morse, sequence );
202 203 204
    return status;
}

205 206
/**
 ********************************************************************************
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
 *
 * @ingroup MORSE_Complex64_t_Tile
 *
 *  MORSE_zunmqr_Tile - overwrites the general M-by-N matrix C with Q*C, where Q is an orthogonal
 *  matrix (unitary in the complex case) defined as the product of elementary reflectors returned
 *  by MORSE_zgeqrf_Tile Q is of order M.
 *  All matrices are passed through descriptors. All dimensions are taken from the descriptors.
 *
 *******************************************************************************
 *
 * @param[in] side
 *          Intended usage:
 *          = MorseLeft:  apply Q or Q**H from the left;
 *          = MorseRight: apply Q or Q**H from the right.
 *          Currently only MorseLeft is supported.
 *
 * @param[in] trans
 *          Intended usage:
 *          = MorseNoTrans:   no transpose, apply Q;
 *          = MorseConjTrans: conjugate transpose, apply Q**H.
 *          Currently only MorseConjTrans is supported.
 *
 * @param[in] A
 *          Details of the QR factorization of the original matrix A as returned by MORSE_zgeqrf.
 *
 * @param[in] T
 *          Auxiliary factorization data, computed by MORSE_zgeqrf.
 *          Can be obtained with MORSE_Alloc_Workspace_zgeqrf
 *
 * @param[in,out] C
 *          On entry, the M-by-N matrix C.
 *          On exit, C is overwritten by Q*C or Q**H*C.
 *
 *******************************************************************************
 *
 * @return
 *          \retval MORSE_SUCCESS successful exit
 *
 *******************************************************************************
 *
 * @sa MORSE_zunmqr
 * @sa MORSE_zunmqr_Tile_Async
 * @sa MORSE_cunmqr_Tile
 * @sa MORSE_dormqr_Tile
 * @sa MORSE_sormqr_Tile
 * @sa MORSE_zgeqrf_Tile
 *
 ******************************************************************************/
255 256
int MORSE_zunmqr_Tile( MORSE_enum side, MORSE_enum trans,
                       MORSE_desc_t *A, MORSE_desc_t *T, MORSE_desc_t *C )
257 258 259 260 261 262 263 264 265 266 267
{
    MORSE_context_t *morse;
    MORSE_sequence_t *sequence = NULL;
    MORSE_request_t request = MORSE_REQUEST_INITIALIZER;
    int status;

    morse = morse_context_self();
    if (morse == NULL) {
        morse_fatal_error("MORSE_zunmqr_Tile", "MORSE not initialized");
        return MORSE_ERR_NOT_INITIALIZED;
    }
268 269
    morse_sequence_create( morse, &sequence );

270
    MORSE_zunmqr_Tile_Async(side, trans, A, T, C, sequence, &request );
271

272
    MORSE_Desc_Flush( A, sequence );
273
    MORSE_Desc_Flush( T, sequence );
274
    MORSE_Desc_Flush( C, sequence );
Mathieu Faverge's avatar
Mathieu Faverge committed
275

276
    morse_sequence_wait( morse, sequence );
277
    status = sequence->status;
278
    morse_sequence_destroy( morse, sequence );
279 280 281
    return status;
}

282 283
/**
 ********************************************************************************
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
 *
 * @ingroup MORSE_Complex64_t_Tile_Async
 *
 *  Non-blocking equivalent of MORSE_zunmqr_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).
 *
 *******************************************************************************
 *
 * @sa MORSE_zunmqr
 * @sa MORSE_zunmqr_Tile
 * @sa MORSE_cunmqr_Tile_Async
 * @sa MORSE_dormqr_Tile_Async
 * @sa MORSE_sormqr_Tile_Async
 * @sa MORSE_zgeqrf_Tile_Async
 *
 ******************************************************************************/
310 311 312
int MORSE_zunmqr_Tile_Async( MORSE_enum side, MORSE_enum trans,
                             MORSE_desc_t *A, MORSE_desc_t *T, MORSE_desc_t *C,
                             MORSE_sequence_t *sequence, MORSE_request_t *request )
313 314
{
    MORSE_context_t *morse;
315
    MORSE_desc_t D, *Dptr = NULL;
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330

    morse = morse_context_self();
    if (morse == NULL) {
        morse_fatal_error("MORSE_zunmqr_Tile", "MORSE not initialized");
        return MORSE_ERR_NOT_INITIALIZED;
    }
    if (sequence == NULL) {
        morse_fatal_error("MORSE_zunmqr_Tile", "NULL sequence");
        return MORSE_ERR_UNALLOCATED;
    }
    if (request == NULL) {
        morse_fatal_error("MORSE_zunmqr_Tile", "NULL request");
        return MORSE_ERR_UNALLOCATED;
    }
    /* Check sequence status */
Mathieu Faverge's avatar
Mathieu Faverge committed
331
    if (sequence->status == MORSE_SUCCESS) {
332
        request->status = MORSE_SUCCESS;
Mathieu Faverge's avatar
Mathieu Faverge committed
333 334
    }
    else {
335
        return morse_request_fail(sequence, request, MORSE_ERR_SEQUENCE_FLUSHED);
Mathieu Faverge's avatar
Mathieu Faverge committed
336
    }
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363

    /* Check descriptors for correctness */
    if (morse_desc_check(A) != MORSE_SUCCESS) {
        morse_error("MORSE_zunmqr_Tile", "invalid first descriptor");
        return morse_request_fail(sequence, request, MORSE_ERR_ILLEGAL_VALUE);
    }
    if (morse_desc_check(T) != MORSE_SUCCESS) {
        morse_error("MORSE_zunmqr_Tile", "invalid second descriptor");
        return morse_request_fail(sequence, request, MORSE_ERR_ILLEGAL_VALUE);
    }
    if (morse_desc_check(C) != MORSE_SUCCESS) {
        morse_error("MORSE_zunmqr_Tile", "invalid third descriptor");
        return morse_request_fail(sequence, request, MORSE_ERR_ILLEGAL_VALUE);
    }
    /* Check input arguments */
    if (A->nb != A->mb || C->nb != C->mb) {
        morse_error("MORSE_zunmqr_Tile", "only square tiles supported");
        return morse_request_fail(sequence, request, MORSE_ERR_ILLEGAL_VALUE);
    }
    if ((side != MorseLeft) && (side != MorseRight)) {
        return morse_request_fail(sequence, request, MORSE_ERR_ILLEGAL_VALUE);
    }
    if ((trans != MorseConjTrans) && (trans != MorseNoTrans)){
        return morse_request_fail(sequence, request, MORSE_ERR_ILLEGAL_VALUE);
    }
    /* Quick return - currently NOT equivalent to LAPACK's:
     * CALL DLASET( 'Full', MAX( M, N ), NRHS, ZERO, ZERO, C, LDC ) */
364 365 366 367
    /*
     if (chameleon_min(M, chameleon_min(N, K)) == 0)
     return MORSE_SUCCESS;
     */
368 369 370 371 372 373 374 375 376

#if defined(CHAMELEON_COPY_DIAG)
    {
        int n = chameleon_min(A->mt, A->nt) * A->nb;
        morse_zdesc_alloc(D, A->mb, A->nb, A->m, n, 0, 0, A->m, n, );
        Dptr = &D;
    }
#endif

377
    if (morse->householder == MORSE_FLAT_HOUSEHOLDER) {
378 379
        if ( (trans == MorseConjTrans) &&
             (side == MorseLeft) ) {
Mathieu Faverge's avatar
Mathieu Faverge committed
380
            morse_pzunmqr( side, trans, A, C, T, Dptr, sequence, request );
381 382
        }
        else {
Mathieu Faverge's avatar
Mathieu Faverge committed
383
            morse_pzunmqr( side, trans, A, C, T, Dptr, sequence, request );
384 385 386
        }
    }
    else {
Mathieu Faverge's avatar
Mathieu Faverge committed
387
        morse_pzunmqrrh( side, trans, A, C, T, Dptr, MORSE_RHBLK, sequence, request );
388 389
    }

390
    if (Dptr != NULL) {
391 392 393 394 395
        MORSE_Desc_Flush( A, sequence );
        MORSE_Desc_Flush( C, sequence );
        MORSE_Desc_Flush( T, sequence );
        MORSE_Desc_Flush( Dptr, sequence );
        morse_sequence_wait( morse, sequence );
Mathieu Faverge's avatar
Mathieu Faverge committed
396
        morse_desc_mat_free( Dptr );
397 398
    }
    (void)D;
399 400
    return MORSE_SUCCESS;
}