zgeqrf_param.c 10.9 KB
Newer Older
1
/**
2 3
 *
 * @file zgeqrf_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 zgeqrf_param wrappers
13
 *
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
14
 * @version 1.0.0
15
 * @author Mathieu Faverge
16
 * @author Raphael Boucherie
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
17
 * @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
 * CHAMELEON_zgeqrf_param - Computes the tile QR factorization of a complex M-by-N
29 30 31 32
 * matrix A: A = Q * R.
 *
 *******************************************************************************
 *
33 34 35
 * @param[in] qrtree
 *          The tree used for the factorization
 *
36 37 38 39 40 41
 * @param[in] M
 *          The number of rows of the matrix A. M >= 0.
 *
 * @param[in] N
 *          The number of columns of the matrix A.  N >= 0.
 *
42
 * @param[in, out] A
43 44 45 46 47 48 49 50 51
 *          On entry, the M-by-N matrix A.
 *          On exit, the elements on and above the diagonal of the array contain the min(M,N)-by-N
 *          upper trapezoidal matrix R (R is upper triangular if M >= N); the elements below the
 *          diagonal represent the unitary matrix Q as a product of elementary reflectors stored
 *          by tiles.
 *
 * @param[in] LDA
 *          The leading dimension of the array A. LDA >= max(1,M).
 *
52
 * @param[out] descTS
53
 *          On exit, auxiliary factorization data, required by CHAMELEON_zgeqrs to solve the system
54 55 56
 *          of equations.
 *
 * @param[out] descTT
57
 *          On exit, auxiliary factorization data, required by CHAMELEON_zgeqrs to solve the system
58 59 60 61
 *          of equations.
 *
 *******************************************************************************
 *
62 63
 * @retval CHAMELEON_SUCCESS successful exit
 * @retval <0 if -i, the i-th argument had an illegal value
64 65 66
 *
 *******************************************************************************
 *
67 68 69 70 71 72
 * @sa CHAMELEON_zgeqrf_param_Tile
 * @sa CHAMELEON_zgeqrf_param_Tile_Async
 * @sa CHAMELEON_cgeqrf
 * @sa CHAMELEON_dgeqrf
 * @sa CHAMELEON_sgeqrf
 * @sa CHAMELEON_zgeqrs
73
 *
74
 */
75
int CHAMELEON_zgeqrf_param( const libhqr_tree_t *qrtree, int M, int N,
76 77
                            CHAMELEON_Complex64_t *A, int LDA,
                            CHAM_desc_t *descTS, CHAM_desc_t *descTT )
78 79 80
{
    int NB;
    int status;
Mathieu Faverge's avatar
Mathieu Faverge committed
81
    CHAM_context_t *chamctxt;
82 83 84
    RUNTIME_sequence_t *sequence = NULL;
    RUNTIME_request_t request = RUNTIME_REQUEST_INITIALIZER;
    CHAM_desc_t descAl, descAt;
85

Mathieu Faverge's avatar
Mathieu Faverge committed
86 87 88
    chamctxt = chameleon_context_self();
    if (chamctxt == NULL) {
        chameleon_fatal_error("CHAMELEON_zgeqrf_param", "CHAMELEON not initialized");
89
        return CHAMELEON_ERR_NOT_INITIALIZED;
90 91 92 93
    }

    /* Check input arguments */
    if (M < 0) {
Mathieu Faverge's avatar
Mathieu Faverge committed
94
        chameleon_error("CHAMELEON_zgeqrf_param", "illegal value of M");
95 96 97
        return -1;
    }
    if (N < 0) {
Mathieu Faverge's avatar
Mathieu Faverge committed
98
        chameleon_error("CHAMELEON_zgeqrf_param", "illegal value of N");
99 100 101
        return -2;
    }
    if (LDA < chameleon_max(1, M)) {
Mathieu Faverge's avatar
Mathieu Faverge committed
102
        chameleon_error("CHAMELEON_zgeqrf_param", "illegal value of LDA");
103 104 105 106 107
        return -4;
    }

    /* Quick return */
    if (chameleon_min(M, N) == 0)
108
        return CHAMELEON_SUCCESS;
109 110

    /* Tune NB & IB depending on M, N & NRHS; Set NBNBSIZE */
Mathieu Faverge's avatar
Mathieu Faverge committed
111
    status = chameleon_tune(CHAMELEON_FUNC_ZGELS, M, N, 0);
112
    if (status != CHAMELEON_SUCCESS) {
Mathieu Faverge's avatar
Mathieu Faverge committed
113
        chameleon_error("CHAMELEON_zgeqrf_param", "chameleon_tune() failed");
114 115 116 117
        return status;
    }

    /* Set NT */
118
    NB = CHAMELEON_NB;
119

Mathieu Faverge's avatar
Mathieu Faverge committed
120
    chameleon_sequence_create( chamctxt, &sequence );
121

122
    /* Submit the matrix conversion */
Mathieu Faverge's avatar
Mathieu Faverge committed
123
    chameleon_zlap2tile( chamctxt, &descAl, &descAt, ChamDescInout, ChamUpperLower,
124
                         A, NB, NB, LDA, N, M, N, sequence, &request );
125 126

    /* Call the tile interface */
127
    CHAMELEON_zgeqrf_param_Tile_Async( qrtree, &descAt, descTS, descTT, sequence, &request );
128

Mathieu Faverge's avatar
Mathieu Faverge committed
129
    /* Submit the matrix conversion back */
Mathieu Faverge's avatar
Mathieu Faverge committed
130
    chameleon_ztile2lap( chamctxt, &descAl, &descAt,
131
                         ChamDescInout, ChamUpperLower, sequence, &request );
132 133
    CHAMELEON_Desc_Flush( descTS, sequence );
    CHAMELEON_Desc_Flush( descTT, sequence );
Mathieu Faverge's avatar
Mathieu Faverge committed
134

Mathieu Faverge's avatar
Mathieu Faverge committed
135
    chameleon_sequence_wait( chamctxt, sequence );
Mathieu Faverge's avatar
Mathieu Faverge committed
136

Mathieu Faverge's avatar
Mathieu Faverge committed
137
    /* Cleanup the temporary data */
Mathieu Faverge's avatar
Mathieu Faverge committed
138
    chameleon_ztile2lap_cleanup( chamctxt, &descAl, &descAt );
139 140

    status = sequence->status;
Mathieu Faverge's avatar
Mathieu Faverge committed
141
    chameleon_sequence_destroy( chamctxt, sequence );
142 143 144 145 146 147
    return status;
}

/**
 *******************************************************************************
 *
148
 * @ingroup CHAMELEON_Complex64_t_Tile
149
 *
150 151
 *  CHAMELEON_zgeqrf_param_Tile - Computes the tile QR factorization of a matrix.
 *  Tile equivalent of CHAMELEON_zgeqrf_param().
152 153 154 155 156 157 158 159 160 161 162 163 164
 *  Operates on matrices stored by tiles.
 *  All matrices are passed through descriptors.
 *  All dimensions are taken from the descriptors.
 *
 *******************************************************************************
 *
 * @param[in,out] A
 *          On entry, the M-by-N matrix A.
 *          On exit, the elements on and above the diagonal of the array contain the min(M,N)-by-N
 *          upper trapezoidal matrix R (R is upper triangular if M >= N); the elements below the
 *          diagonal represent the unitary matrix Q as a product of elementary reflectors stored
 *          by tiles.
 *
165
 * @param[out] TS
166
 *          On exit, auxiliary factorization data, required by CHAMELEON_zgeqrs to solve the system
167 168 169
 *          of equations.
 *
 * @param[out] TT
170
 *          On exit, auxiliary factorization data, required by CHAMELEON_zgeqrs to solve the system
171 172 173 174
 *          of equations.
 *
 *******************************************************************************
 *
175
 * @retval CHAMELEON_SUCCESS successful exit
176 177 178
 *
 *******************************************************************************
 *
179 180 181 182 183 184
 * @sa CHAMELEON_zgeqrf_param
 * @sa CHAMELEON_zgeqrf_param_Tile_Async
 * @sa CHAMELEON_cgeqrf_param_Tile
 * @sa CHAMELEON_dgeqrf_param_Tile
 * @sa CHAMELEON_sgeqrf_param_Tile
 * @sa CHAMELEON_zgeqrs_param_Tile
185
 *
186
 */
187 188
int CHAMELEON_zgeqrf_param_Tile( const libhqr_tree_t *qrtree, CHAM_desc_t *A,
                                 CHAM_desc_t *TS, CHAM_desc_t *TT )
189
{
Mathieu Faverge's avatar
Mathieu Faverge committed
190
    CHAM_context_t *chamctxt;
191 192
    RUNTIME_sequence_t *sequence = NULL;
    RUNTIME_request_t request = RUNTIME_REQUEST_INITIALIZER;
193 194
    int status;

Mathieu Faverge's avatar
Mathieu Faverge committed
195 196 197
    chamctxt = chameleon_context_self();
    if (chamctxt == NULL) {
        chameleon_fatal_error("CHAMELEON_zgeqrf_param_Tile", "CHAMELEON not initialized");
198
        return CHAMELEON_ERR_NOT_INITIALIZED;
199
    }
Mathieu Faverge's avatar
Mathieu Faverge committed
200
    chameleon_sequence_create( chamctxt, &sequence );
201

202
    CHAMELEON_zgeqrf_param_Tile_Async( qrtree, A, TS, TT, sequence, &request );
Mathieu Faverge's avatar
Mathieu Faverge committed
203

204 205 206
    CHAMELEON_Desc_Flush( A, sequence );
    CHAMELEON_Desc_Flush( TS, sequence );
    CHAMELEON_Desc_Flush( TT, sequence );
207

Mathieu Faverge's avatar
Mathieu Faverge committed
208
    chameleon_sequence_wait( chamctxt, sequence );
209
    status = sequence->status;
Mathieu Faverge's avatar
Mathieu Faverge committed
210
    chameleon_sequence_destroy( chamctxt, sequence );
211 212 213 214 215 216
    return status;
}

/**
 *****************************************************************************
 *
217
 * @ingroup CHAMELEON_Complex64_t_Tile_Async
218
 *
219 220
 *  CHAMELEON_zgeqrf_param_Tile_Async - Computes the tile QR factorization of a matrix.
 *  Non-blocking equivalent of CHAMELEON_zgeqrf_param_Tile().
221 222 223 224 225 226 227 228 229 230 231 232 233 234
 *  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).
 *
 *******************************************************************************
 *
235 236 237 238 239 240
 * @sa CHAMELEON_zgeqrf_param
 * @sa CHAMELEON_zgeqrf_param_Tile
 * @sa CHAMELEON_cgeqrf_param_Tile_Async
 * @sa CHAMELEON_dgeqrf_param_Tile_Async
 * @sa CHAMELEON_sgeqrf_param_Tile_Async
 * @sa CHAMELEON_zgeqrs_param_Tile_Async
241
 *
242
 */
243 244 245
int CHAMELEON_zgeqrf_param_Tile_Async( const libhqr_tree_t *qrtree, CHAM_desc_t *A,
                                       CHAM_desc_t *TS, CHAM_desc_t *TT,
                                       RUNTIME_sequence_t *sequence, RUNTIME_request_t *request )
246
{
Mathieu Faverge's avatar
Mathieu Faverge committed
247
    CHAM_context_t *chamctxt;
248
    CHAM_desc_t D, *Dptr = NULL;
249
    int KT;
250

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

    /* Check descriptors for correctness */
Mathieu Faverge's avatar
Mathieu Faverge committed
273 274 275
    if (chameleon_desc_check(A) != CHAMELEON_SUCCESS) {
        chameleon_error("CHAMELEON_zgeqrf_param_Tile", "invalid first descriptor");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
276
    }
Mathieu Faverge's avatar
Mathieu Faverge committed
277 278 279
    if (chameleon_desc_check(TS) != CHAMELEON_SUCCESS) {
        chameleon_error("CHAMELEON_zgeqrf_param_Tile", "invalid second descriptor");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
280
    }
Mathieu Faverge's avatar
Mathieu Faverge committed
281 282 283
    if (chameleon_desc_check(TT) != CHAMELEON_SUCCESS) {
        chameleon_error("CHAMELEON_zgeqrf_param_Tile", "invalid second descriptor");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
284 285 286
    }
    /* Check input arguments */
    if (A->nb != A->mb) {
Mathieu Faverge's avatar
Mathieu Faverge committed
287 288
        chameleon_error("CHAMELEON_zgeqrf_param_Tile", "only square tiles supported");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
289 290
    }
    /* Quick return */
291 292
    /*
     if (chameleon_min(M, N) == 0)
293
     return CHAMELEON_SUCCESS;
294
     */
295 296 297 298 299 300 301 302

    if ( A->m < A->n ) {
        KT = A->mt;
    }
    else {
        KT = A->nt;
    }

BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
303
#if defined(CHAMELEON_COPY_DIAG)
Mathieu Faverge's avatar
Mathieu Faverge committed
304
    {
305
        int n = chameleon_min(A->m, A->n);
Mathieu Faverge's avatar
Mathieu Faverge committed
306
        chameleon_zdesc_alloc(D, A->mb, A->nb, A->m, n, 0, 0, A->m, n, );
Mathieu Faverge's avatar
Mathieu Faverge committed
307 308
        Dptr = &D;
    }
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
309
#endif
Mathieu Faverge's avatar
Mathieu Faverge committed
310

311 312
    chameleon_pzgeqrf_param( 1, KT, qrtree, A,
                             TS, TT, Dptr, sequence, request );
Mathieu Faverge's avatar
Mathieu Faverge committed
313 314

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