zgetrs_nopiv.c 10.4 KB
Newer Older
1
/**
2 3
 *
 * @file zgetrs_nopiv.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 zgetrs_nopiv 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 Jakub Kurzak
 * @author Mathieu Faverge
 * @author Emmanuel Agullo
 * @author Cedric Castagnede
 * @author Florent Pruvost
 * @date 2014-11-08
 * @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_zgetrs_nopiv - Solves a system of linear equations A * X = B, with a general N-by-N matrix A
 *  using the tile LU factorization computed by CHAMELEON_zgetrf_nopiv.
35 36 37 38 39
 *
 *******************************************************************************
 *
 * @param[in] trans
 *          Intended to specify the the form of the system of equations:
40 41 42 43
 *          = ChamNoTrans:   A * X = B     (No transpose)
 *          = ChamTrans:     A**T * X = B  (Transpose)
 *          = ChamConjTrans: A**H * X = B  (Conjugate transpose)
 *          Currently only ChamNoTrans is supported.
44 45 46 47 48 49 50 51 52
 *
 * @param[in] N
 *          The order of the matrix A.  N >= 0.
 *
 * @param[in] NRHS
 *          The number of right hand sides, i.e., the number of columns of the matrix B.
 *          NRHS >= 0.
 *
 * @param[in] A
53
 *          The tile factors L and U from the factorization, computed by CHAMELEON_zgetrf_nopiv.
54 55 56 57 58 59 60 61 62 63 64 65 66
 *
 * @param[in] LDA
 *          The leading dimension of the array A. LDA >= max(1,N).
 *
 * @param[in,out] B
 *          On entry, the N-by-NRHS matrix of right hand side matrix B.
 *          On exit, the solution matrix X.
 *
 * @param[in] LDB
 *          The leading dimension of the array B. LDB >= max(1,N).
 *
 *******************************************************************************
 *
67 68
 * @retval CHAMELEON_SUCCESS successful exit
 * @return <0 if -i, the i-th argument had an illegal value
69 70 71
 *
 *******************************************************************************
 *
72 73 74 75 76 77
 * @sa CHAMELEON_zgetrs_nopiv_Tile
 * @sa CHAMELEON_zgetrs_nopiv_Tile_Async
 * @sa CHAMELEON_cgetrs_nopiv
 * @sa CHAMELEON_dgetrs_nopiv
 * @sa CHAMELEON_sgetrs_nopiv
 * @sa CHAMELEON_zgetrf_nopiv
78
 *
79
 */
80 81 82
int CHAMELEON_zgetrs_nopiv( cham_trans_t trans, int N, int NRHS,
                        CHAMELEON_Complex64_t *A, int LDA,
                        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_zgetrs_nopiv", "CHAMELEON not initialized");
95
        return CHAMELEON_ERR_NOT_INITIALIZED;
96 97
    }
    /* Check input arguments */
98
    if (trans != ChamNoTrans) {
Mathieu Faverge's avatar
Mathieu Faverge committed
99
        chameleon_error("CHAMELEON_zgetrs_nopiv", "only ChamNoTrans supported");
100
        return CHAMELEON_ERR_NOT_SUPPORTED;
101 102
    }
    if (N < 0) {
Mathieu Faverge's avatar
Mathieu Faverge committed
103
        chameleon_error("CHAMELEON_zgetrs_nopiv", "illegal value of N");
104 105 106
        return -2;
    }
    if (NRHS < 0) {
Mathieu Faverge's avatar
Mathieu Faverge committed
107
        chameleon_error("CHAMELEON_zgetrs_nopiv", "illegal value of NRHS");
108 109
        return -3;
    }
110
    if (LDA < chameleon_max(1, N)) {
Mathieu Faverge's avatar
Mathieu Faverge committed
111
        chameleon_error("CHAMELEON_zgetrs_nopiv", "illegal value of LDA");
112 113
        return -5;
    }
114
    if (LDB < chameleon_max(1, N)) {
Mathieu Faverge's avatar
Mathieu Faverge committed
115
        chameleon_error("CHAMELEON_zgetrs_nopiv", "illegal value of LDB");
116 117 118
        return -9;
    }
    /* Quick return */
Mathieu Faverge's avatar
Mathieu Faverge committed
119
    if (chameleon_min(N, NRHS) == 0)
120
        return CHAMELEON_SUCCESS;
121 122

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

    /* Set NT & NTRHS */
130
    NB    = CHAMELEON_NB;
131

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

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

    /* Call the tile interface */
141
    CHAMELEON_zgetrs_nopiv_Tile_Async( &descAt, &descBt, sequence, &request );
142

Mathieu Faverge's avatar
Mathieu Faverge committed
143
    /* Submit the matrix conversion back */
Mathieu Faverge's avatar
Mathieu Faverge committed
144
    chameleon_ztile2lap( chamctxt, &descAl, &descAt,
145
                     ChamDescInput, ChamUpperLower, sequence, &request );
Mathieu Faverge's avatar
Mathieu Faverge committed
146
    chameleon_ztile2lap( chamctxt, &descBl, &descBt,
147
                     ChamDescInout, ChamUpperLower, sequence, &request );
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, &descBl, &descBt );
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
 *  CHAMELEON_zgetrs_nopiv_Tile - Solves a system of linear equations using previously
166
 *  computed LU factorization.
167
 *  Tile equivalent of CHAMELEON_zgetrs_nopiv().
168 169 170 171 172 173 174
 *  Operates on matrices stored by tiles.
 *  All matrices are passed through descriptors.
 *  All dimensions are taken from the descriptors.
 *
 *******************************************************************************
 *
 * @param[in] A
175
 *          The tile factors L and U from the factorization, computed by CHAMELEON_zgetrf_nopiv.
176 177 178 179 180 181 182
 *
 * @param[in,out] B
 *          On entry, the N-by-NRHS matrix of right hand side matrix B.
 *          On exit, the solution matrix X.
 *
 *******************************************************************************
 *
183
 * @retval CHAMELEON_SUCCESS successful exit
184 185 186
 *
 *******************************************************************************
 *
187 188 189 190 191 192
 * @sa CHAMELEON_zgetrs_nopiv
 * @sa CHAMELEON_zgetrs_nopiv_Tile_Async
 * @sa CHAMELEON_cgetrs_nopiv_Tile
 * @sa CHAMELEON_dgetrs_nopiv_Tile
 * @sa CHAMELEON_sgetrs_nopiv_Tile
 * @sa CHAMELEON_zgetrf_nopiv_Tile
193
 *
194
 */
195
int CHAMELEON_zgetrs_nopiv_Tile( CHAM_desc_t *A, CHAM_desc_t *B )
196
{
Mathieu Faverge's avatar
Mathieu Faverge committed
197
    CHAM_context_t *chamctxt;
198 199
    RUNTIME_sequence_t *sequence = NULL;
    RUNTIME_request_t request = RUNTIME_REQUEST_INITIALIZER;
200 201
    int status;

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

209
    CHAMELEON_zgetrs_nopiv_Tile_Async( A, B, sequence, &request );
210

211 212
    CHAMELEON_Desc_Flush( A, sequence );
    CHAMELEON_Desc_Flush( B, 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
 *  CHAMELEON_zgetrs_nopiv_Tile_Async - Solves a system of linear equations using previously
226
 *  computed LU factorization.
227
 *  Non-blocking equivalent of CHAMELEON_zgetrs_nopiv_Tile().
228 229 230 231 232 233 234 235 236 237 238 239 240 241
 *  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).
 *
 *******************************************************************************
 *
242 243 244 245 246 247
 * @sa CHAMELEON_zgetrs_nopiv
 * @sa CHAMELEON_zgetrs_nopiv_Tile
 * @sa CHAMELEON_cgetrs_nopiv_Tile_Async
 * @sa CHAMELEON_dgetrs_nopiv_Tile_Async
 * @sa CHAMELEON_sgetrs_nopiv_Tile_Async
 * @sa CHAMELEON_zgetrf_nopiv_Tile_Async
248
 *
249
 */
250 251
int CHAMELEON_zgetrs_nopiv_Tile_Async( CHAM_desc_t *A, CHAM_desc_t *B,
                                   RUNTIME_sequence_t *sequence, RUNTIME_request_t *request )
252
{
Mathieu Faverge's avatar
Mathieu Faverge committed
253
    CHAM_context_t *chamctxt;
254

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

    /* Check descriptors for correctness */
Mathieu Faverge's avatar
Mathieu Faverge committed
277 278 279
    if (chameleon_desc_check(A) != CHAMELEON_SUCCESS) {
        chameleon_error("CHAMELEON_zgetrs_nopiv_Tile", "invalid first 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(B) != CHAMELEON_SUCCESS) {
        chameleon_error("CHAMELEON_zgetrs_nopiv_Tile", "invalid third descriptor");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
284 285 286
    }
    /* Check input arguments */
    if (A->nb != A->mb || B->nb != B->mb) {
Mathieu Faverge's avatar
Mathieu Faverge committed
287 288
        chameleon_error("CHAMELEON_zgetrs_nopiv_Tile", "only square tiles supported");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
289 290
    }
    /* Quick return */
291 292
    /*
     if (chameleon_min(N, NRHS) == 0)
293
     return CHAMELEON_SUCCESS;
294
     */
Mathieu Faverge's avatar
Mathieu Faverge committed
295
    chameleon_pztrsm( ChamLeft, ChamLower, ChamNoTrans, ChamUnit, (CHAMELEON_Complex64_t)1.0, A, B, sequence, request );
296

Mathieu Faverge's avatar
Mathieu Faverge committed
297
    chameleon_pztrsm( ChamLeft, ChamUpper, ChamNoTrans, ChamNonUnit, (CHAMELEON_Complex64_t)1.0, A, B, sequence, request );
298

299
    return CHAMELEON_SUCCESS;
300
}