zgetrf_incpiv.c 10.4 KB
Newer Older
1
/**
2 3
 *
 * @file zgetrf_incpiv.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 zgetrf_incpiv 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_zgetrf_incpiv - Computes an LU factorization of a general M-by-N matrix A
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
 *  using the tile LU algorithm with partial tile pivoting with row interchanges.
 *
 *******************************************************************************
 *
 * @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 >= 0.
 *
 * @param[in,out] A
 *          On entry, the M-by-N matrix to be factored.
 *          On exit, the tile factors L and U from the factorization.
 *
 * @param[in] LDA
 *          The leading dimension of the array A. LDA >= max(1,M).
 *
 * @param[out] descL
 *          On exit, auxiliary factorization data, related to the tile L factor,
52
 *          required by CHAMELEON_zgetrs_incpiv to solve the system of equations.
53 54 55 56 57 58
 *
 * @param[out] IPIV
 *          The pivot indices that define the permutations (not equivalent to LAPACK).
 *
 *******************************************************************************
 *
59 60 61
 * @retval CHAMELEON_SUCCESS successful exit
 * @retval <0 if -i, the i-th argument had an illegal value
 * @retval >0 if i, U(i,i) is exactly zero. The factorization has been completed,
62 63 64 65 66
 *               but the factor U is exactly singular, and division by zero will occur
 *               if it is used to solve a system of equations.
 *
 *******************************************************************************
 *
67 68 69 70 71 72
 * @sa CHAMELEON_zgetrf_incpiv_Tile
 * @sa CHAMELEON_zgetrf_incpiv_Tile_Async
 * @sa CHAMELEON_cgetrf_incpiv
 * @sa CHAMELEON_dgetrf_incpiv
 * @sa CHAMELEON_sgetrf_incpiv
 * @sa CHAMELEON_zgetrs_incpiv
73
 *
74
 */
75 76 77
int CHAMELEON_zgetrf_incpiv( int M, int N,
                         CHAMELEON_Complex64_t *A, int LDA,
                         CHAM_desc_t *descL, int *IPIV )
78 79 80
{
    int NB;
    int status;
Mathieu Faverge's avatar
Mathieu Faverge committed
81
    CHAM_context_t *chamctxt;
82 83 84
    RUNTIME_sequence_t *sequence = NULL;
    RUNTIME_request_t request = RUNTIME_REQUEST_INITIALIZER;
    CHAM_desc_t descAl, descAt;
85

Mathieu Faverge's avatar
Mathieu Faverge committed
86 87 88
    chamctxt = chameleon_context_self();
    if (chamctxt == NULL) {
        chameleon_fatal_error("CHAMELEON_zgetrf_incpiv", "CHAMELEON not initialized");
89
        return CHAMELEON_ERR_NOT_INITIALIZED;
90 91 92
    }
    /* Check input arguments */
    if (M < 0) {
Mathieu Faverge's avatar
Mathieu Faverge committed
93
        chameleon_error("CHAMELEON_zgetrf_incpiv", "illegal value of M");
94 95 96
        return -1;
    }
    if (N < 0) {
Mathieu Faverge's avatar
Mathieu Faverge committed
97
        chameleon_error("CHAMELEON_zgetrf_incpiv", "illegal value of N");
98 99
        return -2;
    }
100
    if (LDA < chameleon_max(1, M)) {
Mathieu Faverge's avatar
Mathieu Faverge committed
101
        chameleon_error("CHAMELEON_zgetrf_incpiv", "illegal value of LDA");
102 103 104
        return -4;
    }
    /* Quick return */
Mathieu Faverge's avatar
Mathieu Faverge committed
105
    if (chameleon_min(M, N) == 0)
106
        return CHAMELEON_SUCCESS;
107 108

    /* Tune NB & IB depending on M, N & NRHS; Set NBNBSIZE */
Mathieu Faverge's avatar
Mathieu Faverge committed
109
    status = chameleon_tune(CHAMELEON_FUNC_ZGESV, M, N, 0);
110
    if (status != CHAMELEON_SUCCESS) {
Mathieu Faverge's avatar
Mathieu Faverge committed
111
        chameleon_error("CHAMELEON_zgetrf_incpiv", "chameleon_tune() failed");
112 113 114 115
        return status;
    }

    /* Set NT & NTRHS */
116
    NB   = CHAMELEON_NB;
117

Mathieu Faverge's avatar
Mathieu Faverge committed
118
    chameleon_sequence_create( chamctxt, &sequence );
119

120
    /* Submit the matrix conversion */
Mathieu Faverge's avatar
Mathieu Faverge committed
121
    chameleon_zlap2tile( chamctxt, &descAl, &descAt, ChamDescInout, ChamUpperLower,
122
                     A, NB, NB, LDA, N, M, N, sequence, &request );
123 124

    /* Call the tile interface */
125
    CHAMELEON_zgetrf_incpiv_Tile_Async( &descAt, descL, IPIV, sequence, &request );
126

Mathieu Faverge's avatar
Mathieu Faverge committed
127
    /* Submit the matrix conversion back */
Mathieu Faverge's avatar
Mathieu Faverge committed
128
    chameleon_ztile2lap( chamctxt, &descAl, &descAt,
129 130
                     ChamDescInout, ChamUpperLower, sequence, &request );
    CHAMELEON_Desc_Flush( descL, sequence );
Mathieu Faverge's avatar
Mathieu Faverge committed
131

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

Mathieu Faverge's avatar
Mathieu Faverge committed
134
    /* Cleanup the temporary data */
Mathieu Faverge's avatar
Mathieu Faverge committed
135
    chameleon_ztile2lap_cleanup( chamctxt, &descAl, &descAt );
136 137

    status = sequence->status;
Mathieu Faverge's avatar
Mathieu Faverge committed
138
    chameleon_sequence_destroy( chamctxt, sequence );
139 140 141
    return status;
}

142 143
/**
 ********************************************************************************
144
 *
145
 * @ingroup CHAMELEON_Complex64_t_Tile
146
 *
147 148
 *  CHAMELEON_zgetrf_incpiv_Tile - Computes the tile LU factorization of a matrix.
 *  Tile equivalent of CHAMELEON_zgetrf_incpiv().
149 150 151 152 153 154 155 156 157 158 159 160
 *  Operates on matrices stored by tiles.
 *  All matrices are passed through descriptors.
 *  All dimensions are taken from the descriptors.
 *
 *******************************************************************************
 *
 * @param[in,out] A
 *          On entry, the M-by-N matrix to be factored.
 *          On exit, the tile factors L and U from the factorization.
 *
 * @param[out] L
 *          On exit, auxiliary factorization data, related to the tile L factor,
161
 *          required by CHAMELEON_zgetrs_incpiv to solve the system of equations.
162 163 164 165 166 167
 *
 * @param[out] IPIV
 *          The pivot indices that define the permutations (not equivalent to LAPACK).
 *
 *******************************************************************************
 *
168 169
 * @retval CHAMELEON_SUCCESS successful exit
 * @retval >0 if i, U(i,i) is exactly zero. The factorization has been completed,
170 171 172 173 174
 *               but the factor U is exactly singular, and division by zero will occur
 *               if it is used to solve a system of equations.
 *
 *******************************************************************************
 *
175 176 177 178 179 180
 * @sa CHAMELEON_zgetrf_incpiv
 * @sa CHAMELEON_zgetrf_incpiv_Tile_Async
 * @sa CHAMELEON_cgetrf_incpiv_Tile
 * @sa CHAMELEON_dgetrf_incpiv_Tile
 * @sa CHAMELEON_sgetrf_incpiv_Tile
 * @sa CHAMELEON_zgetrs_incpiv_Tile
181
 *
182
 */
183
int CHAMELEON_zgetrf_incpiv_Tile( CHAM_desc_t *A, CHAM_desc_t *L, int *IPIV )
184
{
Mathieu Faverge's avatar
Mathieu Faverge committed
185
    CHAM_context_t *chamctxt;
186 187
    RUNTIME_sequence_t *sequence = NULL;
    RUNTIME_request_t request = RUNTIME_REQUEST_INITIALIZER;
188 189
    int status;

Mathieu Faverge's avatar
Mathieu Faverge committed
190 191 192
    chamctxt = chameleon_context_self();
    if (chamctxt == NULL) {
        chameleon_fatal_error("CHAMELEON_zgetrf_incpiv_Tile", "CHAMELEON not initialized");
193
        return CHAMELEON_ERR_NOT_INITIALIZED;
194
    }
Mathieu Faverge's avatar
Mathieu Faverge committed
195
    chameleon_sequence_create( chamctxt, &sequence );
196

197
    CHAMELEON_zgetrf_incpiv_Tile_Async( A, L, IPIV, sequence, &request );
Mathieu Faverge's avatar
Mathieu Faverge committed
198

199 200
    CHAMELEON_Desc_Flush( A, sequence );
    CHAMELEON_Desc_Flush( L, sequence );
201

Mathieu Faverge's avatar
Mathieu Faverge committed
202
    chameleon_sequence_wait( chamctxt, sequence );
203
    status = sequence->status;
Mathieu Faverge's avatar
Mathieu Faverge committed
204
    chameleon_sequence_destroy( chamctxt, sequence );
205 206 207
    return status;
}

208 209
/**
 ********************************************************************************
210
 *
211
 * @ingroup CHAMELEON_Complex64_t_Tile_Async
212
 *
213 214
 *  CHAMELEON_zgetrf_incpiv_Tile_Async - Computes the tile LU factorization of a matrix.
 *  Non-blocking equivalent of CHAMELEON_zgetrf_incpiv_Tile().
215 216 217 218 219 220 221 222 223 224 225 226 227 228
 *  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).
 *
 *******************************************************************************
 *
229 230 231 232 233 234
 * @sa CHAMELEON_zgetrf_incpiv
 * @sa CHAMELEON_zgetrf_incpiv_Tile
 * @sa CHAMELEON_cgetrf_incpiv_Tile_Async
 * @sa CHAMELEON_dgetrf_incpiv_Tile_Async
 * @sa CHAMELEON_sgetrf_incpiv_Tile_Async
 * @sa CHAMELEON_zgetrs_incpiv_Tile_Async
235
 *
236
 */
237 238
int CHAMELEON_zgetrf_incpiv_Tile_Async( CHAM_desc_t *A, CHAM_desc_t *L, int *IPIV,
                                    RUNTIME_sequence_t *sequence, RUNTIME_request_t *request )
239
{
Mathieu Faverge's avatar
Mathieu Faverge committed
240
    CHAM_context_t *chamctxt;
241
    CHAM_desc_t D, *Dptr = NULL;
242

Mathieu Faverge's avatar
Mathieu Faverge committed
243 244 245
    chamctxt = chameleon_context_self();
    if (chamctxt == NULL) {
        chameleon_fatal_error("CHAMELEON_zgetrf_incpiv_Tile", "CHAMELEON not initialized");
246
        return CHAMELEON_ERR_NOT_INITIALIZED;
247 248
    }
    if (sequence == NULL) {
Mathieu Faverge's avatar
Mathieu Faverge committed
249
        chameleon_fatal_error("CHAMELEON_zgetrf_incpiv_Tile", "NULL sequence");
250
        return CHAMELEON_ERR_UNALLOCATED;
251 252
    }
    if (request == NULL) {
Mathieu Faverge's avatar
Mathieu Faverge committed
253
        chameleon_fatal_error("CHAMELEON_zgetrf_incpiv_Tile", "NULL request");
254
        return CHAMELEON_ERR_UNALLOCATED;
255 256
    }
    /* Check sequence status */
257 258
    if (sequence->status == CHAMELEON_SUCCESS) {
        request->status = CHAMELEON_SUCCESS;
Mathieu Faverge's avatar
Mathieu Faverge committed
259 260
    }
    else {
Mathieu Faverge's avatar
Mathieu Faverge committed
261
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_SEQUENCE_FLUSHED);
Mathieu Faverge's avatar
Mathieu Faverge committed
262
    }
263 264

    /* Check descriptors for correctness */
Mathieu Faverge's avatar
Mathieu Faverge committed
265 266 267
    if (chameleon_desc_check(A) != CHAMELEON_SUCCESS) {
        chameleon_error("CHAMELEON_zgetrf_incpiv_Tile", "invalid first descriptor");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
268
    }
Mathieu Faverge's avatar
Mathieu Faverge committed
269 270 271
    if (chameleon_desc_check(L) != CHAMELEON_SUCCESS) {
        chameleon_error("CHAMELEON_zgetrf_incpiv_Tile", "invalid second descriptor");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
272 273 274
    }
    /* Check input arguments */
    if (A->nb != A->mb) {
Mathieu Faverge's avatar
Mathieu Faverge committed
275 276
        chameleon_error("CHAMELEON_zgetrf_incpiv_Tile", "only square tiles supported");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
277 278
    }
    /* Quick return */
279 280
    /*
     if (chameleon_min(M, N) == 0)
281
     return CHAMELEON_SUCCESS;
282
     */
283

284 285 286
#if defined(CHAMELEON_COPY_DIAG)
    {
        int n = chameleon_min(A->mt, A->nt) * A->nb;
Mathieu Faverge's avatar
Mathieu Faverge committed
287
        chameleon_zdesc_alloc(D, A->mb, A->nb, A->m, n, 0, 0, A->m, n, );
288 289 290 291
        Dptr = &D;
    }
#endif

Mathieu Faverge's avatar
Mathieu Faverge committed
292
    chameleon_pzgetrf_incpiv( A, L, Dptr, IPIV, sequence, request );
293

294
    if (Dptr != NULL) {
295 296 297
        CHAMELEON_Desc_Flush( A, sequence );
        CHAMELEON_Desc_Flush( L, sequence );
        CHAMELEON_Desc_Flush( Dptr, sequence );
Mathieu Faverge's avatar
Mathieu Faverge committed
298
        chameleon_sequence_wait( chamctxt, sequence );
299
        chameleon_desc_destroy( Dptr );
300 301
    }
    (void)D;
302
    return CHAMELEON_SUCCESS;
303
}