ztrsmpl.c 10.4 KB
Newer Older
1
/**
2 3
 *
 * @file ztrsmpl.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 ztrsmpl 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"
26

27 28
/**
 ********************************************************************************
29
 *
30
 * @ingroup CHAMELEON_Complex64_t
31
 *
32
 *  CHAMELEON_ztrsmpl - Performs the forward substitution step of solving a system of linear equations
33 34 35 36 37 38 39 40 41 42 43
 *  after the tile LU factorization of the matrix.
 *
 *******************************************************************************
 *
 * @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
44
 *          The tile factor L from the factorization, computed by CHAMELEON_zgetrf_incpiv.
45 46 47 48 49
 *
 * @param[in] LDA
 *          The leading dimension of the array A. LDA >= max(1,N).
 *
 * @param[in] descL
50
 *          Auxiliary factorization data, related to the tile L factor, computed by CHAMELEON_zgetrf_incpiv.
51 52
 *
 * @param[in] IPIV
53
 *          The pivot indices from CHAMELEON_zgetrf_incpiv (not equivalent to LAPACK).
54 55 56 57 58 59 60 61 62 63
 *
 * @param[in,out] B
 *          On entry, the N-by-NRHS right hand side matrix B.
 *          On exit, if return value = 0, the N-by-NRHS solution matrix X.
 *
 * @param[in] LDB
 *          The leading dimension of the array B. LDB >= max(1,N).
 *
 *******************************************************************************
 *
64 65
 * @retval CHAMELEON_SUCCESS successful exit
 * @retval <0 if -i, the i-th argument had an illegal value
66 67 68
 *
 *******************************************************************************
 *
69 70 71 72 73 74
 * @sa CHAMELEON_ztrsmpl_Tile
 * @sa CHAMELEON_ztrsmpl_Tile_Async
 * @sa CHAMELEON_ctrsmpl
 * @sa CHAMELEON_dtrsmpl
 * @sa CHAMELEON_strsmpl
 * @sa CHAMELEON_zgetrf_incpiv
75
 *
76
 */
77 78 79 80
int CHAMELEON_ztrsmpl( int N, int NRHS,
                   CHAMELEON_Complex64_t *A, int LDA,
                   CHAM_desc_t *descL, int *IPIV,
                   CHAMELEON_Complex64_t *B, int LDB )
81 82 83
{
    int NB;
    int status;
Mathieu Faverge's avatar
Mathieu Faverge committed
84
    CHAM_context_t *chamctxt;
85 86 87 88
    RUNTIME_sequence_t *sequence = NULL;
    RUNTIME_request_t request = RUNTIME_REQUEST_INITIALIZER;
    CHAM_desc_t descAl, descAt;
    CHAM_desc_t descBl, descBt;
89

Mathieu Faverge's avatar
Mathieu Faverge committed
90 91 92
    chamctxt = chameleon_context_self();
    if (chamctxt == NULL) {
        chameleon_fatal_error("CHAMELEON_ztrsmpl", "CHAMELEON not initialized");
93
        return CHAMELEON_ERR_NOT_INITIALIZED;
94 95 96
    }
    /* Check input arguments */
    if (N < 0) {
Mathieu Faverge's avatar
Mathieu Faverge committed
97
        chameleon_error("CHAMELEON_ztrsmpl", "illegal value of N");
98 99 100
        return -1;
    }
    if (NRHS < 0) {
Mathieu Faverge's avatar
Mathieu Faverge committed
101
        chameleon_error("CHAMELEON_ztrsmpl", "illegal value of NRHS");
102 103
        return -2;
    }
104
    if (LDA < chameleon_max(1, N)) {
Mathieu Faverge's avatar
Mathieu Faverge committed
105
        chameleon_error("CHAMELEON_ztrsmpl", "illegal value of LDA");
106 107
        return -4;
    }
108
    if (LDB < chameleon_max(1, N)) {
Mathieu Faverge's avatar
Mathieu Faverge committed
109
        chameleon_error("CHAMELEON_ztrsmpl", "illegal value of LDB");
110 111 112
        return -8;
    }
    /* Quick return */
Mathieu Faverge's avatar
Mathieu Faverge committed
113
    if (chameleon_min(N, NRHS) == 0)
114
        return CHAMELEON_SUCCESS;
115 116

    /* Tune NB & IB depending on N & NRHS; Set NBNB */
Mathieu Faverge's avatar
Mathieu Faverge committed
117
    status = chameleon_tune(CHAMELEON_FUNC_ZGESV, N, N, NRHS);
118
    if (status != CHAMELEON_SUCCESS) {
Mathieu Faverge's avatar
Mathieu Faverge committed
119
        chameleon_error("CHAMELEON_ztrsmpl", "chameleon_tune() failed");
120 121 122 123
        return status;
    }

    /* Set Mt, NT & NTRHS */
124
    NB    = CHAMELEON_NB;
125

Mathieu Faverge's avatar
Mathieu Faverge committed
126
    chameleon_sequence_create( chamctxt, &sequence );
127

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

    /* Call the tile interface */
135
    CHAMELEON_ztrsmpl_Tile_Async( &descAt, descL, IPIV, &descBt, sequence, &request );
136

Mathieu Faverge's avatar
Mathieu Faverge committed
137
    /* Submit the matrix conversion back */
Mathieu Faverge's avatar
Mathieu Faverge committed
138
    chameleon_ztile2lap( chamctxt, &descAl, &descAt,
139
                     ChamDescInput, ChamLower, sequence, &request );
Mathieu Faverge's avatar
Mathieu Faverge committed
140
    chameleon_ztile2lap( chamctxt, &descBl, &descBt,
141 142
                     ChamDescInout, ChamUpperLower, sequence, &request );
    CHAMELEON_Desc_Flush( descL, sequence );
Mathieu Faverge's avatar
Mathieu Faverge committed
143

Mathieu Faverge's avatar
Mathieu Faverge committed
144
    chameleon_sequence_wait( chamctxt, sequence );
Mathieu Faverge's avatar
Mathieu Faverge committed
145

Mathieu Faverge's avatar
Mathieu Faverge committed
146
    /* Cleanup the temporary data */
Mathieu Faverge's avatar
Mathieu Faverge committed
147 148
    chameleon_ztile2lap_cleanup( chamctxt, &descAl, &descAt );
    chameleon_ztile2lap_cleanup( chamctxt, &descBl, &descBt );
149 150

    status = sequence->status;
Mathieu Faverge's avatar
Mathieu Faverge committed
151
    chameleon_sequence_destroy( chamctxt, sequence );
152 153 154
    return status;
}

155 156
/**
 ********************************************************************************
157
 *
158
 * @ingroup CHAMELEON_Complex64_t_Tile
159
 *
160
 * CHAMELEON_ztrsmpl_Tile - Performs the forward substitution step of solving a system of linear equations
161 162 163 164 165 166
 * after the tile LU factorization of the matrix.
 * All matrices are passed through descriptors. All dimensions are taken from the descriptors.
 *
 *******************************************************************************
 *
 * @param[in] A
167
 *          The tile factor L from the factorization, computed by CHAMELEON_zgetrf_incpiv.
168 169
 *
 * @param[in] L
170
 *          Auxiliary factorization data, related to the tile L factor, computed by CHAMELEON_zgetrf_incpiv.
171 172
 *
 * @param[in] IPIV
173
 *          The pivot indices from CHAMELEON_zgetrf_incpiv (not equivalent to LAPACK).
174 175 176 177 178 179 180
 *
 * @param[in,out] B
 *          On entry, the N-by-NRHS right hand side matrix B.
 *          On exit, if return value = 0, the N-by-NRHS solution matrix X.
 *
 *******************************************************************************
 *
181
 * @retval CHAMELEON_SUCCESS successful exit
182 183 184
 *
 *******************************************************************************
 *
185 186 187 188 189 190
 * @sa CHAMELEON_ztrsmpl
 * @sa CHAMELEON_ztrsmpl_Tile_Async
 * @sa CHAMELEON_ctrsmpl_Tile
 * @sa CHAMELEON_dtrsmpl_Tile
 * @sa CHAMELEON_strsmpl_Tile
 * @sa CHAMELEON_zgetrf_incpiv_Tile
191
 *
192
 */
193
int CHAMELEON_ztrsmpl_Tile( CHAM_desc_t *A, CHAM_desc_t *L, int *IPIV, CHAM_desc_t *B )
194
{
Mathieu Faverge's avatar
Mathieu Faverge committed
195
    CHAM_context_t *chamctxt;
196 197
    RUNTIME_sequence_t *sequence = NULL;
    RUNTIME_request_t request = RUNTIME_REQUEST_INITIALIZER;
198 199
    int status;

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

207
    CHAMELEON_ztrsmpl_Tile_Async( A, L, IPIV, B, sequence, &request );
208

209 210 211
    CHAMELEON_Desc_Flush( A, sequence );
    CHAMELEON_Desc_Flush( L, sequence );
    CHAMELEON_Desc_Flush( B, sequence );
Mathieu Faverge's avatar
Mathieu Faverge committed
212

Mathieu Faverge's avatar
Mathieu Faverge committed
213
    chameleon_sequence_wait( chamctxt, sequence );
214
    status = sequence->status;
Mathieu Faverge's avatar
Mathieu Faverge committed
215
    chameleon_sequence_destroy( chamctxt, sequence );
216 217 218
    return status;
}

219 220
/**
 ********************************************************************************
221
 *
222
 * @ingroup CHAMELEON_Complex64_t_Tile_Async
223
 *
224
 *  CHAMELEON_ztrsmpl_Tile - Performs the forward substitution step of solving
225
 *  a system of linear equations after the tile LU factorization of the matrix.
226
 *  Non-blocking equivalent of CHAMELEON_ztrsmpl_Tile().
227 228 229 230 231 232 233 234 235 236 237 238 239 240
 *  Returns control to the user thread before worker threads finish the computation
 *  to allow for pipelined execution of diferent routines.
 *
 *******************************************************************************
 *
 * @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).
 *
 *******************************************************************************
 *
241 242 243 244 245 246
 * @sa CHAMELEON_ztrsmpl
 * @sa CHAMELEON_ztrsmpl_Tile
 * @sa CHAMELEON_ctrsmpl_Tile_Async
 * @sa CHAMELEON_dtrsmpl_Tile_Async
 * @sa CHAMELEON_strsmpl_Tile_Async
 * @sa CHAMELEON_zgetrf_incpiv_Tile_Async
247
 *
248
 */
249 250
int CHAMELEON_ztrsmpl_Tile_Async( CHAM_desc_t *A, CHAM_desc_t *L, int *IPIV, CHAM_desc_t *B,
                              RUNTIME_sequence_t *sequence, RUNTIME_request_t *request )
251
{
Mathieu Faverge's avatar
Mathieu Faverge committed
252
    CHAM_context_t *chamctxt;
253

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

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

300
    return CHAMELEON_SUCCESS;
301
}