ztrtri.c 10.5 KB
Newer Older
1
/**
2 3
 *
 * @file ztrtri.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 ztrtri 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
 * @author Mathieu Faverge
 * @author Emmanuel Agullo
 * @author Cedric Castagnede
 * @date 2010-11-15
 * @precisions normal z -> s d c
 *
23
 */
24
#include "control/common.h"
25

26 27
/**
 ********************************************************************************
28
 *
29
 * @ingroup CHAMELEON_Complex64_t
30
 *
31
 *  CHAMELEON_ztrtri - Computes the inverse of a complex upper or lower
32 33 34 35 36
 *  triangular matrix A.
 *
 *******************************************************************************
 *
 * @param[in] uplo
37 38
 *          = ChamUpper: Upper triangle of A is stored;
 *          = ChamLower: Lower triangle of A is stored.
39 40
 *
 * @param[in] diag
41 42
 *          = ChamNonUnit: A is non-unit triangular;
 *          = ChamUnit:    A is unit triangular.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
 *
 * @param[in] N
 *          The order of the matrix A. N >= 0.
 *
 * @param[in,out] A
 *          On entry, the triangular matrix A.  If UPLO = 'U', the
 *          leading N-by-N upper triangular part of the array A
 *          contains the upper triangular matrix, and the strictly
 *          lower triangular part of A is not referenced.  If UPLO =
 *          'L', the leading N-by-N lower triangular part of the array
 *          A contains the lower triangular matrix, and the strictly
 *          upper triangular part of A is not referenced.  If DIAG =
 *          'U', the diagonal elements of A are also not referenced and
 *          are assumed to be 1.  On exit, the (triangular) inverse of
 *          the original matrix, in the same storage format.
 *
 * @param[in] LDA
 *          The leading dimension of the array A. LDA >= max(1,N).
 *
 *******************************************************************************
 *
64 65 66
 * @retval CHAMELEON_SUCCESS successful exit
 * @retval <0 if -i, the i-th argument had an illegal value
 * @retval >0 if i, A(i,i) is exactly zero.  The triangular
67 68 69 70
 *               matrix is singular and its inverse can not be computed.
 *
 *******************************************************************************
 *
71 72 73 74 75 76
 * @sa CHAMELEON_ztrtri_Tile
 * @sa CHAMELEON_ztrtri_Tile_Async
 * @sa CHAMELEON_ctrtri
 * @sa CHAMELEON_dtrtri
 * @sa CHAMELEON_strtri
 * @sa CHAMELEON_zpotri
77
 *
78
 */
79 80
int CHAMELEON_ztrtri( cham_uplo_t uplo, cham_diag_t diag, int N,
                  CHAMELEON_Complex64_t *A, int LDA )
81 82 83
{
    int NB;
    int status;
Mathieu Faverge's avatar
Mathieu Faverge committed
84
    CHAM_context_t *chamctxt;
85 86 87
    RUNTIME_sequence_t *sequence = NULL;
    RUNTIME_request_t request = RUNTIME_REQUEST_INITIALIZER;
    CHAM_desc_t descAl, descAt;
88

Mathieu Faverge's avatar
Mathieu Faverge committed
89 90 91
    chamctxt = chameleon_context_self();
    if (chamctxt == NULL) {
        chameleon_fatal_error("CHAMELEON_ztrtri", "CHAMELEON not initialized");
92
        return CHAMELEON_ERR_NOT_INITIALIZED;
93 94
    }
    /* Check input arguments */
95
    if ((uplo != ChamUpper) && (uplo != ChamLower)) {
Mathieu Faverge's avatar
Mathieu Faverge committed
96
        chameleon_error("CHAMELEON_ztrtri", "illegal value of uplo");
97 98
        return -1;
    }
99
    if ((diag != ChamUnit) && (diag != ChamNonUnit)) {
Mathieu Faverge's avatar
Mathieu Faverge committed
100
        chameleon_error("CHAMELEON_ztrtri", "illegal value of diag");
101 102 103
        return -2;
    }
    if (N < 0) {
Mathieu Faverge's avatar
Mathieu Faverge committed
104
        chameleon_error("CHAMELEON_ztrtri", "illegal value of N");
105 106
        return -3;
    }
107
    if (LDA < chameleon_max(1, N)) {
Mathieu Faverge's avatar
Mathieu Faverge committed
108
        chameleon_error("CHAMELEON_ztrtri", "illegal value of LDA");
109 110 111
        return -5;
    }
    /* Quick return */
112
    if (chameleon_max(N, 0) == 0)
113
        return CHAMELEON_SUCCESS;
114 115

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

    /* Set NT */
123
    NB = CHAMELEON_NB;
124

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

127
    /* Submit the matrix conversion */
Mathieu Faverge's avatar
Mathieu Faverge committed
128
    chameleon_zlap2tile( chamctxt, &descAl, &descAt, ChamDescInout, uplo,
129
                     A, NB, NB, LDA, N, N, N, sequence, &request );
130 131

    /* Call the tile interface */
132
    CHAMELEON_ztrtri_Tile_Async( uplo, diag, &descAt, sequence, &request );
133

Mathieu Faverge's avatar
Mathieu Faverge committed
134
    /* Submit the matrix conversion back */
Mathieu Faverge's avatar
Mathieu Faverge committed
135
    chameleon_ztile2lap( chamctxt, &descAl, &descAt,
136
                     ChamDescInout, uplo, sequence, &request );
Mathieu Faverge's avatar
Mathieu Faverge committed
137

Mathieu Faverge's avatar
Mathieu Faverge committed
138
    chameleon_sequence_wait( chamctxt, sequence );
Mathieu Faverge's avatar
Mathieu Faverge committed
139

Mathieu Faverge's avatar
Mathieu Faverge committed
140
    /* Cleanup the temporary data */
Mathieu Faverge's avatar
Mathieu Faverge committed
141
    chameleon_ztile2lap_cleanup( chamctxt, &descAl, &descAt );
142 143

    status = sequence->status;
Mathieu Faverge's avatar
Mathieu Faverge committed
144
    chameleon_sequence_destroy( chamctxt, sequence );
145 146 147
    return status;
}

148 149
/**
 ********************************************************************************
150
 *
151
 * @ingroup CHAMELEON_Complex64_t_Tile
152
 *
153
 *  CHAMELEON_ztrtri_Tile - Computes the inverse of a complex upper or
154
 *  lower triangular matrix A.
155
 *  Tile equivalent of CHAMELEON_ztrtri().
156 157 158 159 160 161 162
 *  Operates on matrices stored by tiles.
 *  All matrices are passed through descriptors.
 *  All dimensions are taken from the descriptors.
 *
 *******************************************************************************
 *
 * @param[in] uplo
163 164
 *          = ChamUpper: Upper triangle of A is stored;
 *          = ChamLower: Lower triangle of A is stored.
165 166
 *
 * @param[in] diag
167 168
 *          = ChamNonUnit: A is non-unit triangular;
 *          = ChamUnit:    A us unit triangular.
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
 *
 * @param[in] A
 *          On entry, the triangular matrix A.  If UPLO = 'U', the
 *          leading N-by-N upper triangular part of the array A
 *          contains the upper triangular matrix, and the strictly
 *          lower triangular part of A is not referenced.  If UPLO =
 *          'L', the leading N-by-N lower triangular part of the array
 *          A contains the lower triangular matrix, and the strictly
 *          upper triangular part of A is not referenced.  If DIAG =
 *          'U', the diagonal elements of A are also not referenced and
 *          are assumed to be 1.  On exit, the (triangular) inverse of
 *          the original matrix, in the same storage format.
 *
 *******************************************************************************
 *
184 185
 * @retval CHAMELEON_SUCCESS successful exit
 * @retval >0 if i, A(i,i) is exactly zero.  The triangular
186 187 188 189
 *               matrix is singular and its inverse can not be computed.
 *
 *******************************************************************************
 *
190 191 192 193 194 195
 * @sa CHAMELEON_ztrtri
 * @sa CHAMELEON_ztrtri_Tile_Async
 * @sa CHAMELEON_ctrtri_Tile
 * @sa CHAMELEON_dtrtri_Tile
 * @sa CHAMELEON_strtri_Tile
 * @sa CHAMELEON_zpotri_Tile
196
 *
197
 */
198
int CHAMELEON_ztrtri_Tile( cham_uplo_t uplo, cham_diag_t diag, CHAM_desc_t *A )
199
{
Mathieu Faverge's avatar
Mathieu Faverge committed
200
    CHAM_context_t *chamctxt;
201 202
    RUNTIME_sequence_t *sequence = NULL;
    RUNTIME_request_t request = RUNTIME_REQUEST_INITIALIZER;
203 204
    int status;

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

212
    CHAMELEON_ztrtri_Tile_Async( uplo, diag, A, sequence, &request );
Mathieu Faverge's avatar
Mathieu Faverge committed
213

214
    CHAMELEON_Desc_Flush( A, sequence );
215

Mathieu Faverge's avatar
Mathieu Faverge committed
216
    chameleon_sequence_wait( chamctxt, sequence );
217
    status = sequence->status;
Mathieu Faverge's avatar
Mathieu Faverge committed
218
    chameleon_sequence_destroy( chamctxt, sequence );
219 220 221
    return status;
}

222 223
/**
 ********************************************************************************
224
 *
225
 * @ingroup CHAMELEON_Complex64_t_Tile_Async
226
 *
227
 *  CHAMELEON_ztrtri_Tile_Async - Computes the inverse of a complex upper or lower
228
 *  triangular matrix A.
229
 *  Non-blocking equivalent of CHAMELEON_ztrtri_Tile().
230 231 232 233 234 235 236 237 238 239 240 241 242 243
 *  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).
 *
 *******************************************************************************
 *
244 245 246 247 248 249
 * @sa CHAMELEON_ztrtri
 * @sa CHAMELEON_ztrtri_Tile
 * @sa CHAMELEON_ctrtri_Tile_Async
 * @sa CHAMELEON_dtrtri_Tile_Async
 * @sa CHAMELEON_strtri_Tile_Async
 * @sa CHAMELEON_zpotri_Tile_Async
250
 *
251
 */
252 253
int CHAMELEON_ztrtri_Tile_Async( cham_uplo_t uplo, cham_diag_t diag, CHAM_desc_t *A,
                             RUNTIME_sequence_t *sequence, RUNTIME_request_t *request )
254
{
Mathieu Faverge's avatar
Mathieu Faverge committed
255
    CHAM_context_t *chamctxt;
256

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

    /* Check descriptors for correctness */
Mathieu Faverge's avatar
Mathieu Faverge committed
279 280 281
    if (chameleon_desc_check(A) != CHAMELEON_SUCCESS) {
        chameleon_error("CHAMELEON_ztrtri_Tile", "invalid descriptor");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
282 283 284
    }
    /* Check input arguments */
    if (A->nb != A->mb) {
Mathieu Faverge's avatar
Mathieu Faverge committed
285 286
        chameleon_error("CHAMELEON_ztrtri_Tile", "only square tiles supported");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
287
    }
288
    if ((uplo != ChamUpper) && (uplo != ChamLower)) {
Mathieu Faverge's avatar
Mathieu Faverge committed
289 290
        chameleon_error("CHAMELEON_ztrtri_Tile", "illegal value of uplo");
        return chameleon_request_fail(sequence, request, -1);
291
    }
292
    if ((diag != ChamUnit) && (diag != ChamNonUnit)) {
Mathieu Faverge's avatar
Mathieu Faverge committed
293 294
        chameleon_error("CHAMELEON_ztrtri_Tile", "illegal value of diag");
        return chameleon_request_fail(sequence, request, -2);
295 296
    }
    /* Quick return */
297 298
    /*
     if (chameleon_max(N, 0) == 0)
299
     return CHAMELEON_SUCCESS;
300
     */
Mathieu Faverge's avatar
Mathieu Faverge committed
301
    chameleon_pztrtri( uplo, diag, A, sequence, request );
302

303
    return CHAMELEON_SUCCESS;
304
}