zgeqrs.c 11.2 KB
Newer Older
1
/**
2 3
 *
 * @file zgeqrs.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 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
 * @author Jakub Kurzak
 * @author Mathieu Faverge
 * @author Emmanuel Agullo
 * @author Cedric Castagnede
 * @date 2010-11-15
 * @precisions normal z -> s d c
 *
24
 */
25
#include "control/common.h"
Mathieu Faverge's avatar
Mathieu Faverge committed
26
#include <stdlib.h>
27

28 29
/**
 ********************************************************************************
30
 *
31
 * @ingroup CHAMELEON_Complex64_t
32
 *
33 34
 *  CHAMELEON_zgeqrs - Compute a minimum-norm solution min || A*X - B || using the RQ factorization
 *  A = R*Q computed by CHAMELEON_zgeqrf.
35 36 37 38 39 40 41 42 43 44 45 46 47
 *
 *******************************************************************************
 *
 * @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
48
 *          Details of the QR factorization of the original matrix A as returned by CHAMELEON_zgeqrf.
49 50 51 52 53
 *
 * @param[in] LDA
 *          The leading dimension of the array A. LDA >= M.
 *
 * @param[in] descT
54
 *          Auxiliary factorization data, computed by CHAMELEON_zgeqrf.
55 56 57 58 59 60 61 62 63 64
 *
 * @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).
 *
 *******************************************************************************
 *
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_zgeqrs_Tile
 * @sa CHAMELEON_zgeqrs_Tile_Async
 * @sa CHAMELEON_cgeqrs
 * @sa CHAMELEON_dgeqrs
 * @sa CHAMELEON_sgeqrs
 * @sa CHAMELEON_zgeqrf
76
 *
77
 */
78 79 80 81
int CHAMELEON_zgeqrs( int M, int N, int NRHS,
                  CHAMELEON_Complex64_t *A, int LDA,
                  CHAM_desc_t *descT,
                  CHAMELEON_Complex64_t *B, int LDB )
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 descBl, descBt;
90

Mathieu Faverge's avatar
Mathieu Faverge committed
91 92 93
    chamctxt = chameleon_context_self();
    if (chamctxt == NULL) {
        chameleon_fatal_error("CHAMELEON_zgeqrs", "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_zgeqrs", "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_zgeqrs", "illegal value of N");
104 105 106
        return -2;
    }
    if (NRHS < 0) {
Mathieu Faverge's avatar
Mathieu Faverge committed
107
        chameleon_error("CHAMELEON_zgeqrs", "illegal value of N");
108 109
        return -3;
    }
110
    if (LDA < chameleon_max(1, M)) {
Mathieu Faverge's avatar
Mathieu Faverge committed
111
        chameleon_error("CHAMELEON_zgeqrs", "illegal value of LDA");
112 113
        return -5;
    }
114
    if (LDB < chameleon_max(1, chameleon_max(1, M))) {
Mathieu Faverge's avatar
Mathieu Faverge committed
115
        chameleon_error("CHAMELEON_zgeqrs", "illegal value of LDB");
116 117 118
        return -8;
    }
    /* Quick return */
119
    if (chameleon_min(M, chameleon_min(N, NRHS)) == 0) {
120
        return CHAMELEON_SUCCESS;
121 122 123
    }

    /* Tune NB & IB depending on M, N & NRHS; Set NBNBSIZE */
Mathieu Faverge's avatar
Mathieu Faverge committed
124
    status = chameleon_tune(CHAMELEON_FUNC_ZGELS, M, N, NRHS);
125
    if (status != CHAMELEON_SUCCESS) {
Mathieu Faverge's avatar
Mathieu Faverge committed
126
        chameleon_error("CHAMELEON_zgeqrs", "chameleon_tune() failed");
127 128 129 130
        return status;
    }

    /* Set NT */
131
    NB = CHAMELEON_NB;
132

Mathieu Faverge's avatar
Mathieu Faverge committed
133
    chameleon_sequence_create( chamctxt, &sequence );
134

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

    /* Call the tile interface */
142
    CHAMELEON_zgeqrs_Tile_Async( &descAt, descT, &descBt, sequence, &request );
143

Mathieu Faverge's avatar
Mathieu Faverge committed
144
    /* Submit the matrix conversion back */
Mathieu Faverge's avatar
Mathieu Faverge committed
145
    chameleon_ztile2lap( chamctxt, &descAl, &descAt,
146
                     ChamDescInput, ChamUpperLower, sequence, &request );
Mathieu Faverge's avatar
Mathieu Faverge committed
147
    chameleon_ztile2lap( chamctxt, &descBl, &descBt,
148 149
                     ChamDescInout, ChamUpperLower, sequence, &request );
    CHAMELEON_Desc_Flush( descT, sequence );
Mathieu Faverge's avatar
Mathieu Faverge committed
150

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

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

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

162 163
/**
 ********************************************************************************
164
 *
165
 * @ingroup CHAMELEON_Complex64_t_Tile
166
 *
167 168
 *  CHAMELEON_zgeqrs_Tile - Computes a minimum-norm solution using the tile QR factorization.
 *  Tile equivalent of CHAMELEON_zgeqrf().
169 170 171 172 173 174 175
 *  Operates on matrices stored by tiles.
 *  All matrices are passed through descriptors.
 *  All dimensions are taken from the descriptors.
 *
 *******************************************************************************
 *
 * @param[in,out] A
176
 *          Details of the QR factorization of the original matrix A as returned by CHAMELEON_zgeqrf.
177 178
 *
 * @param[in] T
179
 *          Auxiliary factorization data, computed by CHAMELEON_zgeqrf.
180 181 182 183 184 185 186
 *
 * @param[in,out] B
 *          On entry, the m-by-nrhs right hand side matrix B.
 *          On exit, the n-by-nrhs solution matrix X.
 *
 *******************************************************************************
 *
187
 * @retval CHAMELEON_SUCCESS successful exit
188 189 190
 *
 *******************************************************************************
 *
191 192 193 194 195 196
 * @sa CHAMELEON_zgeqrs
 * @sa CHAMELEON_zgeqrs_Tile_Async
 * @sa CHAMELEON_cgeqrs_Tile
 * @sa CHAMELEON_dgeqrs_Tile
 * @sa CHAMELEON_sgeqrs_Tile
 * @sa CHAMELEON_zgeqrf_Tile
197
 *
198
 */
199
int CHAMELEON_zgeqrs_Tile( CHAM_desc_t *A, CHAM_desc_t *T, CHAM_desc_t *B )
200
{
Mathieu Faverge's avatar
Mathieu Faverge committed
201
    CHAM_context_t *chamctxt;
202 203
    RUNTIME_sequence_t *sequence = NULL;
    RUNTIME_request_t request = RUNTIME_REQUEST_INITIALIZER;
204 205
    int status;

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

213
    CHAMELEON_zgeqrs_Tile_Async( A, T, B, sequence, &request );
214

215 216 217
    CHAMELEON_Desc_Flush( A, sequence );
    CHAMELEON_Desc_Flush( T, sequence );
    CHAMELEON_Desc_Flush( B, sequence );
Mathieu Faverge's avatar
Mathieu Faverge committed
218

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

225 226
/**
 ********************************************************************************
227
 *
228
 * @ingroup CHAMELEON_Complex64_t_Tile_Async
229
 *
230
 *  CHAMELEON_zgeqrs_Tile_Async - Computes a minimum-norm solution using the tile
231
 *  QR factorization.
232
 *  Non-blocking equivalent of CHAMELEON_zgeqrs_Tile().
233 234 235 236 237 238 239 240 241 242 243 244 245 246
 *  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).
 *
 *******************************************************************************
 *
247 248 249 250 251 252
 * @sa CHAMELEON_zgeqrs
 * @sa CHAMELEON_zgeqrs_Tile
 * @sa CHAMELEON_cgeqrs_Tile_Async
 * @sa CHAMELEON_dgeqrs_Tile_Async
 * @sa CHAMELEON_sgeqrs_Tile_Async
 * @sa CHAMELEON_zgeqrf_Tile_Async
253
 *
254
 */
255 256
int CHAMELEON_zgeqrs_Tile_Async( CHAM_desc_t *A, CHAM_desc_t *T, 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;
262

Mathieu Faverge's avatar
Mathieu Faverge committed
263 264 265
    chamctxt = chameleon_context_self();
    if (chamctxt == NULL) {
        chameleon_fatal_error("CHAMELEON_zgeqrs_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_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_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_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(T) != CHAMELEON_SUCCESS) {
        chameleon_error("CHAMELEON_zgeqrs_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(B) != CHAMELEON_SUCCESS) {
        chameleon_error("CHAMELEON_zgeqrs_Tile", "invalid third descriptor");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
296 297 298
    }
    /* Check input arguments */
    if (A->nb != A->mb || B->nb != B->mb) {
Mathieu Faverge's avatar
Mathieu Faverge committed
299 300
        chameleon_error("CHAMELEON_zgeqrs_Tile", "only square tiles supported");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
301 302
    }
    /* Quick return */
303 304
    /*
     if (chameleon_min(M, chameleon_min(N, NRHS)) == 0) {
305
     return CHAMELEON_SUCCESS;
306 307
     }
     */
308 309
#if defined(CHAMELEON_COPY_DIAG)
    {
310
        int n = chameleon_min(A->m, A->n);
Mathieu Faverge's avatar
Mathieu Faverge committed
311
        chameleon_zdesc_alloc(D, A->mb, A->nb, A->m, n, 0, 0, A->m, n, );
312 313 314 315
        Dptr = &D;
    }
#endif

Mathieu Faverge's avatar
Mathieu Faverge committed
316
    if (chamctxt->householder == ChamFlatHouseholder) {
317
        chameleon_pzunmqr( 1, ChamLeft, ChamConjTrans, A, B, T, Dptr, sequence, request );
318 319
    }
    else {
320
        chameleon_pzunmqrrh( 1, CHAMELEON_RHBLK, ChamLeft, ChamConjTrans, A, B, T, Dptr, sequence, request );
321 322
    }

Mathieu Faverge's avatar
Mathieu Faverge committed
323 324 325
    subB = chameleon_desc_submatrix(B, 0, 0, A->n, B->n);
    subA = chameleon_desc_submatrix(A, 0, 0, A->n, A->n);
    chameleon_pztrsm( ChamLeft, ChamUpper, ChamNoTrans, ChamNonUnit, 1.0, subA, subB, sequence, request );
326 327 328
    free(subA);
    free(subB);

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