zungqr.c 10.7 KB
Newer Older
1
/**
2 3
 *
 * @file zungqr.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 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
 * @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
 *
25
 */
26
#include "control/common.h"
27

28 29
/**
 ********************************************************************************
30
 *
31
 * @ingroup CHAMELEON_Complex64_t
32
 *
33 34
 *  CHAMELEON_zungqr - 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.
35 36 37 38 39 40 41 42 43 44 45 46 47 48
 *
 *******************************************************************************
 *
 * @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
49
 *          Details of the QR factorization of the original matrix A as returned by CHAMELEON_zgeqrf.
50 51 52 53 54
 *
 * @param[in] LDA
 *          The leading dimension of the array A. LDA >= max(1,M).
 *
 * @param[in] descT
55
 *          Auxiliary factorization data, computed by CHAMELEON_zgeqrf.
56 57 58 59 60 61 62 63 64
 *
 * @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).
 *
 *******************************************************************************
 *
65 66
 * @retval CHAMELEON_SUCCESS successful exit
 * @retval <0 if -i, the i-th argument had an illegal value
67 68 69
 *
 *******************************************************************************
 *
70 71 72 73 74 75
 * @sa CHAMELEON_zungqr_Tile
 * @sa CHAMELEON_zungqr_Tile_Async
 * @sa CHAMELEON_cungqr
 * @sa CHAMELEON_dorgqr
 * @sa CHAMELEON_sorgqr
 * @sa CHAMELEON_zgeqrf
76
 *
77
 */
78 79 80 81
int CHAMELEON_zungqr( int M, int N, int K,
                  CHAMELEON_Complex64_t *A, int LDA,
                  CHAM_desc_t *descT,
                  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", "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", "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", "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", "illegal value of K");
108 109
        return -3;
    }
110
    if (LDA < chameleon_max(1, M)) {
Mathieu Faverge's avatar
Mathieu Faverge committed
111
        chameleon_error("CHAMELEON_zungqr", "illegal value of LDA");
112 113
        return -5;
    }
114
    if (LDQ < chameleon_max(1, M)) {
Mathieu Faverge's avatar
Mathieu Faverge committed
115
        chameleon_error("CHAMELEON_zungqr", "illegal value of LDQ");
116 117
        return -8;
    }
118
    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", "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_Tile_Async( &descAt, descT, &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
                     ChamDescInout, ChamUpperLower, sequence, &request );
    CHAMELEON_Desc_Flush( descT, sequence );
Mathieu Faverge's avatar
Mathieu Faverge committed
148

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

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

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

160 161
/**
 ********************************************************************************
162
 *
163
 * @ingroup CHAMELEON_Complex64_t_Tile
164
 *
165 166
 *  CHAMELEON_zungqr_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.
167 168 169 170 171
 *  All matrices are passed through descriptors. All dimensions are taken from the descriptors.
 *
 *******************************************************************************
 *
 * @param[in] A
172
 *          Details of the QR factorization of the original matrix A as returned by CHAMELEON_zgeqrf.
173 174
 *
 * @param[in] T
175
 *          Auxiliary factorization data, computed by CHAMELEON_zgeqrf.
176 177 178 179 180 181
 *
 * @param[out] Q
 *          On exit, the M-by-N matrix Q.
 *
 *******************************************************************************
 *
182
 * @retval CHAMELEON_SUCCESS successful exit
183 184 185
 *
 *******************************************************************************
 *
186 187 188 189 190 191
 * @sa CHAMELEON_zungqr
 * @sa CHAMELEON_zungqr_Tile_Async
 * @sa CHAMELEON_cungqr_Tile
 * @sa CHAMELEON_dorgqr_Tile
 * @sa CHAMELEON_sorgqr_Tile
 * @sa CHAMELEON_zgeqrf_Tile
192
 *
193
 */
194
int CHAMELEON_zungqr_Tile( CHAM_desc_t *A, CHAM_desc_t *T, CHAM_desc_t *Q )
195
{
Mathieu Faverge's avatar
Mathieu Faverge committed
196
    CHAM_context_t *chamctxt;
197 198
    RUNTIME_sequence_t *sequence = NULL;
    RUNTIME_request_t request = RUNTIME_REQUEST_INITIALIZER;
199 200
    int status;

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

208
    CHAMELEON_zungqr_Tile_Async( A, T, Q, sequence, &request );
209

210 211 212
    CHAMELEON_Desc_Flush( A, sequence );
    CHAMELEON_Desc_Flush( T, sequence );
    CHAMELEON_Desc_Flush( Q, sequence );
Mathieu Faverge's avatar
Mathieu Faverge committed
213

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

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

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

    /* Check descriptors for correctness */
Mathieu Faverge's avatar
Mathieu Faverge committed
276 277 278
    if (chameleon_desc_check(A) != CHAMELEON_SUCCESS) {
        chameleon_error("CHAMELEON_zungqr_Tile", "invalid first descriptor");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
279
    }
Mathieu Faverge's avatar
Mathieu Faverge committed
280 281 282
    if (chameleon_desc_check(T) != CHAMELEON_SUCCESS) {
        chameleon_error("CHAMELEON_zungqr_Tile", "invalid second descriptor");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
283
    }
Mathieu Faverge's avatar
Mathieu Faverge committed
284 285 286
    if (chameleon_desc_check(Q) != CHAMELEON_SUCCESS) {
        chameleon_error("CHAMELEON_zungqr_Tile", "invalid third descriptor");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
287 288 289
    }
    /* Check input arguments */
    if (A->nb != A->mb || Q->nb != Q->mb) {
Mathieu Faverge's avatar
Mathieu Faverge committed
290 291
        chameleon_error("CHAMELEON_zungqr_Tile", "only square tiles supported");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
292 293
    }
    /* Quick return */
294 295
    /*
     if (N <= 0)
296
     return CHAMELEON_SUCCESS;
297
     */
298 299
#if defined(CHAMELEON_COPY_DIAG)
    {
300
        int n = chameleon_min(A->m, A->n);
Mathieu Faverge's avatar
Mathieu Faverge committed
301
        chameleon_zdesc_alloc(D, A->mb, A->nb, A->m, n, 0, 0, A->m, n, );
302 303 304 305
        Dptr = &D;
    }
#endif

Mathieu Faverge's avatar
Mathieu Faverge committed
306 307
    chameleon_pzlaset( ChamUpperLower, 0., 1., Q, sequence, request );
    if (chamctxt->householder == ChamFlatHouseholder) {
308
        chameleon_pzungqr( 1, A, Q, T, Dptr, sequence, request );
309 310
    }
    else {
311
        chameleon_pzungqrrh( 1, CHAMELEON_RHBLK, A, Q, T, Dptr, sequence, request );
312 313
    }

314
    if (Dptr != NULL) {
315 316 317 318
        CHAMELEON_Desc_Flush( A, sequence );
        CHAMELEON_Desc_Flush( Q, sequence );
        CHAMELEON_Desc_Flush( T, sequence );
        CHAMELEON_Desc_Flush( Dptr, sequence );
Mathieu Faverge's avatar
Mathieu Faverge committed
319
        chameleon_sequence_wait( chamctxt, sequence );
320
        chameleon_desc_destroy( Dptr );
321 322
    }
    (void)D;
323
    return CHAMELEON_SUCCESS;
324
}