zgeqrs.c 11.3 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.
7 8
 * @copyright 2012-2014 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
 *                      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 65
 *
 * @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).
 *
 *******************************************************************************
 *
 * @return
66
 *          \retval CHAMELEON_SUCCESS successful exit
67 68 69 70
 *          \retval <0 if -i, the i-th argument had an illegal value
 *
 *******************************************************************************
 *
71 72 73 74 75 76
 * @sa CHAMELEON_zgeqrs_Tile
 * @sa CHAMELEON_zgeqrs_Tile_Async
 * @sa CHAMELEON_cgeqrs
 * @sa CHAMELEON_dgeqrs
 * @sa CHAMELEON_sgeqrs
 * @sa CHAMELEON_zgeqrf
77
 *
78
 */
79 80 81 82
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 )
83 84 85
{
    int NB;
    int status;
Mathieu Faverge's avatar
Mathieu Faverge committed
86
    CHAM_context_t *chamctxt;
87 88 89 90
    RUNTIME_sequence_t *sequence = NULL;
    RUNTIME_request_t request = RUNTIME_REQUEST_INITIALIZER;
    CHAM_desc_t descAl, descAt;
    CHAM_desc_t descBl, descBt;
91

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

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

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

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

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

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

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

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

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

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

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

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

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

215
    CHAMELEON_zgeqrs_Tile_Async( A, T, B, sequence, &request );
216

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

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

227 228
/**
 ********************************************************************************
229
 *
230
 * @ingroup CHAMELEON_Complex64_t_Tile_Async
231
 *
232
 *  CHAMELEON_zgeqrs_Tile_Async - Computes a minimum-norm solution using the tile
233
 *  QR factorization.
234
 *  Non-blocking equivalent of CHAMELEON_zgeqrs_Tile().
235 236 237 238 239 240 241 242 243 244 245 246 247 248
 *  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).
 *
 *******************************************************************************
 *
249 250 251 252 253 254
 * @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
255
 *
256
 */
257 258
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 )
259
{
260 261
    CHAM_desc_t *subA;
    CHAM_desc_t *subB;
Mathieu Faverge's avatar
Mathieu Faverge committed
262
    CHAM_context_t *chamctxt;
263
    CHAM_desc_t D, *Dptr = NULL;
264

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

    /* Check descriptors for correctness */
Mathieu Faverge's avatar
Mathieu Faverge committed
287 288 289
    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);
290
    }
Mathieu Faverge's avatar
Mathieu Faverge committed
291 292 293
    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);
294
    }
Mathieu Faverge's avatar
Mathieu Faverge committed
295 296 297
    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);
298 299 300
    }
    /* Check input arguments */
    if (A->nb != A->mb || B->nb != B->mb) {
Mathieu Faverge's avatar
Mathieu Faverge committed
301 302
        chameleon_error("CHAMELEON_zgeqrs_Tile", "only square tiles supported");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
303 304
    }
    /* Quick return */
305 306
    /*
     if (chameleon_min(M, chameleon_min(N, NRHS)) == 0) {
307
     return CHAMELEON_SUCCESS;
308 309
     }
     */
310 311 312
#if defined(CHAMELEON_COPY_DIAG)
    {
        int n = chameleon_min(A->mt, A->nt) * A->nb;
Mathieu Faverge's avatar
Mathieu Faverge committed
313
        chameleon_zdesc_alloc(D, A->mb, A->nb, A->m, n, 0, 0, A->m, n, );
314 315 316 317
        Dptr = &D;
    }
#endif

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

Mathieu Faverge's avatar
Mathieu Faverge committed
325 326 327
    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 );
328 329 330
    free(subA);
    free(subB);

331
    if (Dptr != NULL) {
332 333 334 335
        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
336
        chameleon_sequence_wait( chamctxt, sequence );
337
        RUNTIME_desc_destroy( Dptr );
Mathieu Faverge's avatar
Mathieu Faverge committed
338
        chameleon_desc_mat_free( Dptr );
339 340
    }
    (void)D;
341
    return CHAMELEON_SUCCESS;
342
}