zungqr_param.c 11.3 KB
Newer Older
1
/**
2 3
 *
 * @file zungqr_param.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 zungqr_param wrappers
13
 *
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
14
 * @version 1.0.0
15
 * @author Mathieu Faverge
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
16 17
 * @author Raphael Boucherie
 * @date 2017-05-17
18 19
 * @precisions normal z -> s d c
 *
20
 */
21 22 23 24 25
#include "control/common.h"

/**
 *******************************************************************************
 *
26
 * @ingroup CHAMELEON_Complex64_t
27
 *
28 29
 *  CHAMELEON_zungqr_param - Generates an M-by-N matrix Q with orthonormal columns, which is defined as the
 *  first N columns of a product of the elementary reflectors returned by CHAMELEON_zgeqrf.
30 31 32
 *
 *******************************************************************************
 *
33 34 35
 * @param[in] qrtree
 *          The tree used for the factorization
 *
36 37 38 39 40 41 42 43 44 45 46
 * @param[in] M
 *          The number of rows of the matrix Q. M >= 0.
 *
 * @param[in] N
 *          The number of columns of the matrix Q. N >= M.
 *
 * @param[in] K
 *          The number of columns of elementary tile reflectors whose product defines the matrix Q.
 *          M >= K >= 0.
 *
 * @param[in] A
47
 *          Details of the QR factorization of the original matrix A as returned by CHAMELEON_zgeqrf.
48 49 50 51 52
 *
 * @param[in] LDA
 *          The leading dimension of the array A. LDA >= max(1,M).
 *
 * @param[in] descT
53
 *          Auxiliary factorization data, computed by CHAMELEON_zgeqrf.
54 55 56 57 58 59 60 61 62
 *
 * @param[out] Q
 *          On exit, the M-by-N matrix Q.
 *
 * @param[in] LDQ
 *          The leading dimension of the array Q. LDQ >= max(1,M).
 *
 *******************************************************************************
 *
63 64
 * @retval CHAMELEON_SUCCESS successful exit
 * @retval <0 if -i, the i-th argument had an illegal value
65 66 67
 *
 *******************************************************************************
 *
68 69 70 71 72 73
 * @sa CHAMELEON_zungqr_param_Tile
 * @sa CHAMELEON_zungqr_param_Tile_Async
 * @sa CHAMELEON_cungqr
 * @sa CHAMELEON_dorgqr
 * @sa CHAMELEON_sorgqr
 * @sa CHAMELEON_zgeqrf
74
 *
75
 */
76
int CHAMELEON_zungqr_param( const libhqr_tree_t *qrtree,
77 78 79 80 81
                            int M, int N, int K,
                            CHAMELEON_Complex64_t *A, int LDA,
                            CHAM_desc_t *descTS,
                            CHAM_desc_t *descTT,
                            CHAMELEON_Complex64_t *Q, int LDQ )
82 83 84
{
    int NB;
    int status;
Mathieu Faverge's avatar
Mathieu Faverge committed
85
    CHAM_context_t *chamctxt;
86 87 88 89
    RUNTIME_sequence_t *sequence = NULL;
    RUNTIME_request_t request = RUNTIME_REQUEST_INITIALIZER;
    CHAM_desc_t descAl, descAt;
    CHAM_desc_t descQl, descQt;
90

Mathieu Faverge's avatar
Mathieu Faverge committed
91 92 93
    chamctxt = chameleon_context_self();
    if (chamctxt == NULL) {
        chameleon_fatal_error("CHAMELEON_zungqr_param", "CHAMELEON not initialized");
94
        return CHAMELEON_ERR_NOT_INITIALIZED;
95 96 97 98
    }

    /* Check input arguments */
    if (M < 0) {
Mathieu Faverge's avatar
Mathieu Faverge committed
99
        chameleon_error("CHAMELEON_zungqr_param", "illegal value of M");
100 101 102
        return -1;
    }
    if (N < 0 || N > M) {
Mathieu Faverge's avatar
Mathieu Faverge committed
103
        chameleon_error("CHAMELEON_zungqr_param", "illegal value of N");
104 105 106
        return -2;
    }
    if (K < 0 || K > N) {
Mathieu Faverge's avatar
Mathieu Faverge committed
107
        chameleon_error("CHAMELEON_zungqr_param", "illegal value of K");
108 109 110
        return -3;
    }
    if (LDA < chameleon_max(1, M)) {
Mathieu Faverge's avatar
Mathieu Faverge committed
111
        chameleon_error("CHAMELEON_zungqr_param", "illegal value of LDA");
112 113 114
        return -5;
    }
    if (LDQ < chameleon_max(1, M)) {
Mathieu Faverge's avatar
Mathieu Faverge committed
115
        chameleon_error("CHAMELEON_zungqr_param", "illegal value of LDQ");
116 117 118
        return -8;
    }
    if (chameleon_min(M, chameleon_min(N, K)) == 0)
119
        return CHAMELEON_SUCCESS;
120 121

    /* Tune NB & IB depending on M & N; Set NBNB */
Mathieu Faverge's avatar
Mathieu Faverge committed
122
    status = chameleon_tune(CHAMELEON_FUNC_ZGELS, M, N, 0);
123
    if (status != CHAMELEON_SUCCESS) {
Mathieu Faverge's avatar
Mathieu Faverge committed
124
        chameleon_error("CHAMELEON_zungqr_param", "chameleon_tune() failed");
125 126 127 128
        return status;
    }

    /* Set NT */
129
    NB = CHAMELEON_NB;
130

Mathieu Faverge's avatar
Mathieu Faverge committed
131
    chameleon_sequence_create( chamctxt, &sequence );
132

133
    /* Submit the matrix conversion */
Mathieu Faverge's avatar
Mathieu Faverge committed
134
    chameleon_zlap2tile( chamctxt, &descAl, &descAt, ChamDescInput, ChamLower,
135
                     A, NB, NB, LDA, N, M, K, sequence, &request );
Mathieu Faverge's avatar
Mathieu Faverge committed
136
    chameleon_zlap2tile( chamctxt, &descQl, &descQt, ChamDescInout, ChamUpperLower,
137
                     Q, NB, NB, LDQ, N, M, N, sequence, &request );
138 139

    /* Call the tile interface */
140
    CHAMELEON_zungqr_param_Tile_Async( qrtree, &descAt, descTS, descTT, &descQt, sequence, &request );
141

Mathieu Faverge's avatar
Mathieu Faverge committed
142
    /* Submit the matrix conversion back */
Mathieu Faverge's avatar
Mathieu Faverge committed
143
    chameleon_ztile2lap( chamctxt, &descAl, &descAt,
144
                     ChamDescInput, ChamLower, sequence, &request );
Mathieu Faverge's avatar
Mathieu Faverge committed
145
    chameleon_ztile2lap( chamctxt, &descQl, &descQt,
146 147 148
                     ChamDescInout, ChamUpperLower, sequence, &request );
    CHAMELEON_Desc_Flush( descTS, sequence );
    CHAMELEON_Desc_Flush( descTT, sequence );
Mathieu Faverge's avatar
Mathieu Faverge committed
149

Mathieu Faverge's avatar
Mathieu Faverge committed
150
    chameleon_sequence_wait( chamctxt, sequence );
Mathieu Faverge's avatar
Mathieu Faverge committed
151

Mathieu Faverge's avatar
Mathieu Faverge committed
152
    /* Cleanup the temporary data */
Mathieu Faverge's avatar
Mathieu Faverge committed
153 154
    chameleon_ztile2lap_cleanup( chamctxt, &descAl, &descAt );
    chameleon_ztile2lap_cleanup( chamctxt, &descQl, &descQt );
155 156

    status = sequence->status;
Mathieu Faverge's avatar
Mathieu Faverge committed
157
    chameleon_sequence_destroy( chamctxt, sequence );
158 159 160
    return status;
}

161 162
/**
 *******************************************************************************
163
 *
164
 * @ingroup CHAMELEON_Complex64_t_Tile
165
 *
166 167
 *  CHAMELEON_zungqr_param_Tile - Generates an M-by-N matrix Q with orthonormal columns, which is defined as the
 *  first N columns of a product of the elementary reflectors returned by CHAMELEON_zgeqrf.
168 169 170 171 172
 *  All matrices are passed through descriptors. All dimensions are taken from the descriptors.
 *
 *******************************************************************************
 *
 * @param[in] A
173
 *          Details of the QR factorization of the original matrix A as returned by CHAMELEON_zgeqrf.
174 175
 *
 * @param[in] T
176
 *          Auxiliary factorization data, computed by CHAMELEON_zgeqrf.
177 178 179 180 181 182
 *
 * @param[out] Q
 *          On exit, the M-by-N matrix Q.
 *
 *******************************************************************************
 *
183
 * @retval CHAMELEON_SUCCESS successful exit
184 185 186
 *
 *******************************************************************************
 *
187 188 189 190 191 192
 * @sa CHAMELEON_zungqr_param
 * @sa CHAMELEON_zungqr_param_Tile_Async
 * @sa CHAMELEON_cungqr_Tile
 * @sa CHAMELEON_dorgqr_Tile
 * @sa CHAMELEON_sorgqr_Tile
 * @sa CHAMELEON_zgeqrf_Tile
193
 *
194
 */
195
int CHAMELEON_zungqr_param_Tile( const libhqr_tree_t *qrtree, CHAM_desc_t *A, CHAM_desc_t *TS, CHAM_desc_t *TT, CHAM_desc_t *Q )
196
{
Mathieu Faverge's avatar
Mathieu Faverge committed
197
    CHAM_context_t *chamctxt;
198 199
    RUNTIME_sequence_t *sequence = NULL;
    RUNTIME_request_t request = RUNTIME_REQUEST_INITIALIZER;
200 201
    int status;

Mathieu Faverge's avatar
Mathieu Faverge committed
202 203 204
    chamctxt = chameleon_context_self();
    if (chamctxt == NULL) {
        chameleon_fatal_error("CHAMELEON_zungqr_param_Tile", "CHAMELEON not initialized");
205
        return CHAMELEON_ERR_NOT_INITIALIZED;
206
    }
Mathieu Faverge's avatar
Mathieu Faverge committed
207
    chameleon_sequence_create( chamctxt, &sequence );
208

209
    CHAMELEON_zungqr_param_Tile_Async( qrtree, A, TS, TT, Q, sequence, &request );
210

211 212 213 214
    CHAMELEON_Desc_Flush( A, sequence );
    CHAMELEON_Desc_Flush( TS, sequence );
    CHAMELEON_Desc_Flush( TT, sequence );
    CHAMELEON_Desc_Flush( Q, sequence );
Mathieu Faverge's avatar
Mathieu Faverge committed
215

Mathieu Faverge's avatar
Mathieu Faverge committed
216
    chameleon_sequence_wait( chamctxt, sequence );
217
    status = sequence->status;
Mathieu Faverge's avatar
Mathieu Faverge committed
218
    chameleon_sequence_destroy( chamctxt, sequence );
219 220 221
    return status;
}

222 223
/**
 *******************************************************************************
224
 *
225
 * @ingroup CHAMELEON_Complex64_t_Tile_Async
226
 *
227
 *  Non-blocking equivalent of CHAMELEON_zungqr_param_Tile().
228 229 230 231 232 233 234 235 236 237 238 239 240 241
 *  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).
 *
 *******************************************************************************
 *
242 243 244 245 246 247
 * @sa CHAMELEON_zungqr_param
 * @sa CHAMELEON_zungqr_param_Tile
 * @sa CHAMELEON_cungqr_Tile_Async
 * @sa CHAMELEON_dorgqr_Tile_Async
 * @sa CHAMELEON_sorgqr_Tile_Async
 * @sa CHAMELEON_zgeqrf_Tile_Async
248
 *
249
 */
250
int CHAMELEON_zungqr_param_Tile_Async( const libhqr_tree_t *qrtree, CHAM_desc_t *A, CHAM_desc_t *TS, CHAM_desc_t *TT, CHAM_desc_t *Q, RUNTIME_sequence_t *sequence, RUNTIME_request_t *request )
251
{
Mathieu Faverge's avatar
Mathieu Faverge committed
252
    CHAM_context_t *chamctxt;
253
    CHAM_desc_t D, *Dptr = NULL;
254 255
    int KT;

Mathieu Faverge's avatar
Mathieu Faverge committed
256 257 258
    chamctxt = chameleon_context_self();
    if (chamctxt == NULL) {
        chameleon_fatal_error("CHAMELEON_zungqr_param_Tile", "CHAMELEON not initialized");
259
        return CHAMELEON_ERR_NOT_INITIALIZED;
260 261
    }
    if (sequence == NULL) {
Mathieu Faverge's avatar
Mathieu Faverge committed
262
        chameleon_fatal_error("CHAMELEON_zungqr_param_Tile", "NULL sequence");
263
        return CHAMELEON_ERR_UNALLOCATED;
264 265
    }
    if (request == NULL) {
Mathieu Faverge's avatar
Mathieu Faverge committed
266
        chameleon_fatal_error("CHAMELEON_zungqr_param_Tile", "NULL request");
267
        return CHAMELEON_ERR_UNALLOCATED;
268 269
    }
    /* Check sequence status */
270 271
    if (sequence->status == CHAMELEON_SUCCESS) {
        request->status = CHAMELEON_SUCCESS;
Mathieu Faverge's avatar
Mathieu Faverge committed
272 273
    }
    else {
Mathieu Faverge's avatar
Mathieu Faverge committed
274
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_SEQUENCE_FLUSHED);
Mathieu Faverge's avatar
Mathieu Faverge committed
275
    }
276 277

    /* Check descriptors for correctness */
Mathieu Faverge's avatar
Mathieu Faverge committed
278 279 280
    if (chameleon_desc_check(A) != CHAMELEON_SUCCESS) {
        chameleon_error("CHAMELEON_zungqr_param_Tile", "invalid first descriptor");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
281
    }
Mathieu Faverge's avatar
Mathieu Faverge committed
282 283 284
    if (chameleon_desc_check(TS) != CHAMELEON_SUCCESS) {
        chameleon_error("CHAMELEON_zungqr_param_Tile", "invalid second descriptor");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
285
    }
Mathieu Faverge's avatar
Mathieu Faverge committed
286 287 288
    if (chameleon_desc_check(TT) != CHAMELEON_SUCCESS) {
        chameleon_error("CHAMELEON_zungqr_param_Tile", "invalid third descriptor");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
289
    }
Mathieu Faverge's avatar
Mathieu Faverge committed
290 291 292
    if (chameleon_desc_check(Q) != CHAMELEON_SUCCESS) {
        chameleon_error("CHAMELEON_zungqr_param_Tile", "invalid fourth descriptor");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
293
    }
294 295
    /* Check input arguments */
    if (A->nb != A->mb || Q->nb != Q->mb) {
Mathieu Faverge's avatar
Mathieu Faverge committed
296 297
        chameleon_error("CHAMELEON_zungqr_param_Tile", "only square tiles supported");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
298 299
    }
    /* Quick return */
300 301
    /*
     if (N <= 0)
302
     return CHAMELEON_SUCCESS;
303
     */
304 305 306 307 308 309 310
    if ( A->m < A->n ) {
        KT = A->mt;
    }
    else {
        KT = A->nt;
    }

BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
311
#if defined(CHAMELEON_COPY_DIAG)
Mathieu Faverge's avatar
Mathieu Faverge committed
312
    {
313
        int n = chameleon_min(A->m, A->n);
Mathieu Faverge's avatar
Mathieu Faverge committed
314
        chameleon_zdesc_alloc(D, A->mb, A->nb, A->m, n, 0, 0, A->m, n, );
Mathieu Faverge's avatar
Mathieu Faverge committed
315 316
        Dptr = &D;
    }
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
317
#endif
Mathieu Faverge's avatar
Mathieu Faverge committed
318

Mathieu Faverge's avatar
Mathieu Faverge committed
319
    chameleon_pzlaset( ChamUpperLower, 0., 1., Q, sequence, request );
320
    chameleon_pzungqr_param( 1, KT, qrtree, A, Q, TS, TT, Dptr, sequence, request );
Mathieu Faverge's avatar
Mathieu Faverge committed
321 322

    if (Dptr != NULL) {
323 324 325 326 327
        CHAMELEON_Desc_Flush( A, sequence );
        CHAMELEON_Desc_Flush( Q, sequence );
        CHAMELEON_Desc_Flush( TS, sequence );
        CHAMELEON_Desc_Flush( TT, sequence );
        CHAMELEON_Desc_Flush( Dptr, sequence );
Mathieu Faverge's avatar
Mathieu Faverge committed
328
        chameleon_sequence_wait( chamctxt, sequence );
329
        chameleon_desc_destroy( Dptr );
Mathieu Faverge's avatar
Mathieu Faverge committed
330
    }
331
    (void)D;
332
    return CHAMELEON_SUCCESS;
333
}