zgeqrs_param.c 11.7 KB
Newer Older
1
/**
2 3
 *
 * @file zgeqrs_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 zgeqrs_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
#include "control/common.h"
Mathieu Faverge's avatar
Mathieu Faverge committed
22
#include <stdlib.h>
23 24 25 26

/**
 *******************************************************************************
 *
27
 * @ingroup CHAMELEON_Complex64_t
28
 *
29 30
 *  CHAMELEON_zgeqrs_param - Compute a minimum-norm solution min || A*X - B || using the RQ factorization
 *  A = R*Q computed by CHAMELEON_zgeqrf.
31 32 33 34 35 36 37 38 39 40 41 42 43
 *
 *******************************************************************************
 *
 * @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 >= M >= 0.
 *
 * @param[in] NRHS
 *          The number of columns of B. NRHS >= 0.
 *
 * @param[in,out] A
44
 *          Details of the QR factorization of the original matrix A as returned by CHAMELEON_zgeqrf.
45 46 47 48 49
 *
 * @param[in] LDA
 *          The leading dimension of the array A. LDA >= M.
 *
 * @param[in] descT
50
 *          Auxiliary factorization data, computed by CHAMELEON_zgeqrf.
51 52 53 54 55 56 57 58 59 60
 *
 * @param[in,out] B
 *          On entry, the m-by-nrhs right hand side matrix B.
 *          On exit, the n-by-nrhs solution matrix X.
 *
 * @param[in] LDB
 *          The leading dimension of the array B. LDB >= max(1,N).
 *
 *******************************************************************************
 *
61 62
 * @retval CHAMELEON_SUCCESS successful exit
 * @retval <0 if -i, the i-th argument had an illegal value
63 64 65
 *
 *******************************************************************************
 *
66 67 68 69 70 71
 * @sa CHAMELEON_zgeqrs_param_Tile
 * @sa CHAMELEON_zgeqrs_param_Tile_Async
 * @sa CHAMELEON_cgeqrs
 * @sa CHAMELEON_dgeqrs
 * @sa CHAMELEON_sgeqrs
 * @sa CHAMELEON_zgeqrf
72
 *
73
 */
74 75 76 77
int CHAMELEON_zgeqrs_param( const libhqr_tree_t *qrtree, int M, int N, int NRHS,
                        CHAMELEON_Complex64_t *A, int LDA,
                        CHAM_desc_t *descTS, CHAM_desc_t *descTT,
                        CHAMELEON_Complex64_t *B, int LDB )
78 79 80
{
    int NB;
    int status;
Mathieu Faverge's avatar
Mathieu Faverge committed
81
    CHAM_context_t *chamctxt;
82 83 84 85
    RUNTIME_sequence_t *sequence = NULL;
    RUNTIME_request_t request = RUNTIME_REQUEST_INITIALIZER;
    CHAM_desc_t descAl, descAt;
    CHAM_desc_t descBl, descBt;
86

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

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

    /* Tune NB & IB depending on M, N & NRHS; Set NBNBSIZE */
Mathieu Faverge's avatar
Mathieu Faverge committed
120
    status = chameleon_tune(CHAMELEON_FUNC_ZGELS, M, N, NRHS);
121
    if (status != CHAMELEON_SUCCESS) {
Mathieu Faverge's avatar
Mathieu Faverge committed
122
        chameleon_error("CHAMELEON_zgeqrs_param", "chameleon_tune() failed");
123 124 125 126
        return status;
    }

    /* Set NT */
127
    NB = CHAMELEON_NB;
128

Mathieu Faverge's avatar
Mathieu Faverge committed
129
    chameleon_sequence_create( chamctxt, &sequence );
130

131
    /* Submit the matrix conversion */
Mathieu Faverge's avatar
Mathieu Faverge committed
132
    chameleon_zlap2tile( chamctxt, &descAl, &descAt, ChamDescInput, ChamUpperLower,
133
                     A, NB, NB, LDA, N, M, N, sequence, &request );
Mathieu Faverge's avatar
Mathieu Faverge committed
134
    chameleon_zlap2tile( chamctxt, &descBl, &descBt, ChamDescInout, ChamUpperLower,
135
                     B, NB, NB, LDB, NRHS, M, NRHS, sequence, &request );
136 137

    /* Call the tile interface */
138
    CHAMELEON_zgeqrs_param_Tile_Async( qrtree, &descAt, descTS, descTT, &descBt, sequence, &request );
139

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

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

Mathieu Faverge's avatar
Mathieu Faverge committed
150
    /* Cleanup the temporary data */
Mathieu Faverge's avatar
Mathieu Faverge committed
151 152
    chameleon_ztile2lap_cleanup( chamctxt, &descAl, &descAt );
    chameleon_ztile2lap_cleanup( chamctxt, &descBl, &descBt );
153 154

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

/**
 *******************************************************************************
 *
162
 * @ingroup CHAMELEON_Complex64_t_Tile
163
 *
164 165
 *  CHAMELEON_zgeqrs_param_Tile - Computes a minimum-norm solution using the tile QR factorization.
 *  Tile equivalent of CHAMELEON_zgeqrf().
166 167 168 169 170 171 172
 *  Operates on matrices stored by tiles.
 *  All matrices are passed through descriptors.
 *  All dimensions are taken from the descriptors.
 *
 *******************************************************************************
 *
 * @param[in,out] 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 183
 *
 * @param[in,out] B
 *          On entry, the m-by-nrhs right hand side matrix B.
 *          On exit, the n-by-nrhs solution matrix X.
 *
 *******************************************************************************
 *
184
 * @retval CHAMELEON_SUCCESS successful exit
185 186 187
 *
 *******************************************************************************
 *
188 189 190 191 192 193
 * @sa CHAMELEON_zgeqrs_param
 * @sa CHAMELEON_zgeqrs_param_Tile_Async
 * @sa CHAMELEON_cgeqrs_Tile
 * @sa CHAMELEON_dgeqrs_Tile
 * @sa CHAMELEON_sgeqrs_Tile
 * @sa CHAMELEON_zgeqrf_Tile
194
 *
195
 */
196 197
int CHAMELEON_zgeqrs_param_Tile( const libhqr_tree_t *qrtree, CHAM_desc_t *A,
                             CHAM_desc_t *TS, CHAM_desc_t *TT, CHAM_desc_t *B )
198
{
Mathieu Faverge's avatar
Mathieu Faverge committed
199
    CHAM_context_t *chamctxt;
200 201
    RUNTIME_sequence_t *sequence = NULL;
    RUNTIME_request_t request = RUNTIME_REQUEST_INITIALIZER;
202 203
    int status;

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

211
    CHAMELEON_zgeqrs_param_Tile_Async( qrtree, A, TS, TT, B, sequence, &request );
212

213 214 215 216
    CHAMELEON_Desc_Flush( A, sequence );
    CHAMELEON_Desc_Flush( TS, sequence );
    CHAMELEON_Desc_Flush( TT, sequence );
    CHAMELEON_Desc_Flush( B, sequence );
Mathieu Faverge's avatar
Mathieu Faverge committed
217

Mathieu Faverge's avatar
Mathieu Faverge committed
218
    chameleon_sequence_wait( chamctxt, sequence );
219
    status = sequence->status;
Mathieu Faverge's avatar
Mathieu Faverge committed
220
    chameleon_sequence_destroy( chamctxt, sequence );
221 222 223 224 225 226
    return status;
}

/**
 *******************************************************************************
 *
227
 * @ingroup CHAMELEON_Complex64_t_Tile_Async
228
 *
229
 *  CHAMELEON_zgeqrs_param_Tile_Async - Computes a minimum-norm solution using the tile
230
 *  QR factorization.
231
 *  Non-blocking equivalent of CHAMELEON_zgeqrs_param_Tile().
232 233 234 235 236 237 238 239 240 241 242 243 244 245
 *  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).
 *
 *******************************************************************************
 *
246 247 248 249 250 251
 * @sa CHAMELEON_zgeqrs_param
 * @sa CHAMELEON_zgeqrs_param_Tile
 * @sa CHAMELEON_cgeqrs_Tile_Async
 * @sa CHAMELEON_dgeqrs_Tile_Async
 * @sa CHAMELEON_sgeqrs_Tile_Async
 * @sa CHAMELEON_zgeqrf_Tile_Async
252
 *
253
 */
254 255 256
int CHAMELEON_zgeqrs_param_Tile_Async( const libhqr_tree_t *qrtree,
                                   CHAM_desc_t *A, CHAM_desc_t *TS, CHAM_desc_t *TT, CHAM_desc_t *B,
                                   RUNTIME_sequence_t *sequence, RUNTIME_request_t *request )
257
{
258 259
    CHAM_desc_t *subA;
    CHAM_desc_t *subB;
Mathieu Faverge's avatar
Mathieu Faverge committed
260
    CHAM_context_t *chamctxt;
261
    CHAM_desc_t D, *Dptr = NULL;
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
262

Mathieu Faverge's avatar
Mathieu Faverge committed
263 264 265
    chamctxt = chameleon_context_self();
    if (chamctxt == NULL) {
        chameleon_fatal_error("CHAMELEON_zgeqrs_param_Tile", "CHAMELEON not initialized");
266
        return CHAMELEON_ERR_NOT_INITIALIZED;
267 268
    }
    if (sequence == NULL) {
Mathieu Faverge's avatar
Mathieu Faverge committed
269
        chameleon_fatal_error("CHAMELEON_zgeqrs_param_Tile", "NULL sequence");
270
        return CHAMELEON_ERR_UNALLOCATED;
271 272
    }
    if (request == NULL) {
Mathieu Faverge's avatar
Mathieu Faverge committed
273
        chameleon_fatal_error("CHAMELEON_zgeqrs_param_Tile", "NULL request");
274
        return CHAMELEON_ERR_UNALLOCATED;
275 276
    }
    /* Check sequence status */
277 278
    if (sequence->status == CHAMELEON_SUCCESS) {
        request->status = CHAMELEON_SUCCESS;
Mathieu Faverge's avatar
Mathieu Faverge committed
279 280
    }
    else {
Mathieu Faverge's avatar
Mathieu Faverge committed
281
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_SEQUENCE_FLUSHED);
Mathieu Faverge's avatar
Mathieu Faverge committed
282
    }
283 284

    /* Check descriptors for correctness */
Mathieu Faverge's avatar
Mathieu Faverge committed
285 286 287
    if (chameleon_desc_check(A) != CHAMELEON_SUCCESS) {
        chameleon_error("CHAMELEON_zgeqrs_param_Tile", "invalid first descriptor");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
288
    }
Mathieu Faverge's avatar
Mathieu Faverge committed
289 290 291
    if (chameleon_desc_check(TS) != CHAMELEON_SUCCESS) {
        chameleon_error("CHAMELEON_zgeqrs_param_Tile", "invalid second descriptor");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
292
    }
Mathieu Faverge's avatar
Mathieu Faverge committed
293 294 295
    if (chameleon_desc_check(TT) != CHAMELEON_SUCCESS) {
        chameleon_error("CHAMELEON_zgeqrs_param_Tile", "invalid third descriptor");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
296
    }
Mathieu Faverge's avatar
Mathieu Faverge committed
297 298 299
    if (chameleon_desc_check(B) != CHAMELEON_SUCCESS) {
        chameleon_error("CHAMELEON_zgeqrs_param_Tile", "invalid fourth descriptor");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
300 301 302
    }
    /* Check input arguments */
    if (A->nb != A->mb || B->nb != B->mb) {
Mathieu Faverge's avatar
Mathieu Faverge committed
303 304
        chameleon_error("CHAMELEON_zgeqrs_param_Tile", "only square tiles supported");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
305 306 307 308
    }
    /* Quick return */
    /*
     if (chameleon_min(M, chameleon_min(N, NRHS)) == 0) {
309
     return CHAMELEON_SUCCESS;
310 311
     }
     */
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
312
#if defined(CHAMELEON_COPY_DIAG)
Mathieu Faverge's avatar
Mathieu Faverge committed
313
    {
314
        int n = chameleon_min(A->m, A->n);
Mathieu Faverge's avatar
Mathieu Faverge committed
315
        chameleon_zdesc_alloc(D, A->mb, A->nb, A->m, n, 0, 0, A->m, n, );
Mathieu Faverge's avatar
Mathieu Faverge committed
316 317
        Dptr = &D;
    }
BOUCHERIE Raphael's avatar
BOUCHERIE Raphael committed
318
#endif
319

Mathieu Faverge's avatar
Mathieu Faverge committed
320 321
    subB = chameleon_desc_submatrix(B, 0, 0, A->n, B->n);
    subA = chameleon_desc_submatrix(A, 0, 0, A->n, A->n);
Mathieu Faverge's avatar
Mathieu Faverge committed
322

323
    chameleon_pzunmqr_param( 1, qrtree, ChamLeft, ChamConjTrans, A, B, TS, TT, Dptr, sequence, request );
Mathieu Faverge's avatar
Mathieu Faverge committed
324
    chameleon_pztrsm( ChamLeft, ChamUpper, ChamNoTrans, ChamNonUnit, 1.0, subA, subB, sequence, request );
Mathieu Faverge's avatar
Mathieu Faverge committed
325

326 327
    free(subA);
    free(subB);
Mathieu Faverge's avatar
Mathieu Faverge committed
328 329

    if (Dptr != NULL) {
330 331 332 333 334
        CHAMELEON_Desc_Flush( A, sequence );
        CHAMELEON_Desc_Flush( B, sequence );
        CHAMELEON_Desc_Flush( TS, sequence );
        CHAMELEON_Desc_Flush( TT, sequence );
        CHAMELEON_Desc_Flush( Dptr, sequence );
Mathieu Faverge's avatar
Mathieu Faverge committed
335
        chameleon_sequence_wait( chamctxt, sequence );
336
        chameleon_desc_destroy( Dptr );
Mathieu Faverge's avatar
Mathieu Faverge committed
337
    }
338
    (void)D;
339
    return CHAMELEON_SUCCESS;
340
}