zlacpy.c 9.81 KB
Newer Older
1
/**
2 3
 *
 * @file zlacpy.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 zlacpy 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_zlacpy copies all or part of a two-dimensional matrix A to another
32 33 34 35 36 37
 *  matrix B
 *
 *******************************************************************************
 *
 * @param[in] uplo
 *          Specifies the part of the matrix A to be copied to B.
38 39 40
 *            = ChamUpperLower: All the matrix A
 *            = ChamUpper: Upper triangular part
 *            = ChamLower: Lower triangular part
41 42
 *
 * @param[in] M
Mathieu Faverge's avatar
Mathieu Faverge committed
43
 *          The number of rows of the matrix A. M >= 0.
44 45 46 47 48
 *
 * @param[in] N
 *          The number of columns of the matrix A. N >= 0.
 *
 * @param[in] A
49 50
 *          The M-by-N matrix A. If uplo = ChamUpper, only the upper trapezium
 *          is accessed; if UPLO = ChamLower, only the lower trapezium is
51 52 53 54 55 56 57 58 59 60 61 62 63 64
 *          accessed.
 *
 * @param[in] LDA
 *          The leading dimension of the array A. LDA >= max(1,M).
 *
 * @param[out] B
 *          The M-by-N matrix B.
 *          On exit, B = A in the locations specified by UPLO.
 *
 * @param[in] LDB
 *          The leading dimension of the array B. LDB >= max(1,M).
 *
 *******************************************************************************
 *
65 66 67 68 69
 * @sa CHAMELEON_zlacpy_Tile
 * @sa CHAMELEON_zlacpy_Tile_Async
 * @sa CHAMELEON_clacpy
 * @sa CHAMELEON_dlacpy
 * @sa CHAMELEON_slacpy
70
 *
71
 */
72 73 74
int CHAMELEON_zlacpy( cham_uplo_t uplo, int M, int N,
                  CHAMELEON_Complex64_t *A, int LDA,
                  CHAMELEON_Complex64_t *B, int LDB )
75 76 77
{
    int NB;
    int status;
Mathieu Faverge's avatar
Mathieu Faverge committed
78
    CHAM_context_t *chamctxt;
79 80 81 82
    RUNTIME_sequence_t *sequence = NULL;
    RUNTIME_request_t request = RUNTIME_REQUEST_INITIALIZER;
    CHAM_desc_t descAl, descAt;
    CHAM_desc_t descBl, descBt;
83

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

    /* Quick return */
Mathieu Faverge's avatar
Mathieu Faverge committed
114
    if (chameleon_min(N, M) == 0)
115
        return (double)0.0;
116 117

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

    /* Set NT */
125
    NB   = CHAMELEON_NB;
126

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

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

    /* Call the tile interface */
136
    CHAMELEON_zlacpy_Tile_Async( uplo, &descAt, &descBt, sequence, &request );
137

Mathieu Faverge's avatar
Mathieu Faverge committed
138
    /* Submit the matrix conversion back */
Mathieu Faverge's avatar
Mathieu Faverge committed
139
    chameleon_ztile2lap( chamctxt, &descAl, &descAt,
140
                     ChamDescInput, uplo, sequence, &request );
Mathieu Faverge's avatar
Mathieu Faverge committed
141
    chameleon_ztile2lap( chamctxt, &descBl, &descBt,
142
                     ChamDescInout, uplo, sequence, &request );
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

Mathieu Faverge's avatar
Mathieu Faverge committed
150
    chameleon_sequence_destroy( chamctxt, sequence );
151
    return CHAMELEON_SUCCESS;
152 153
}

154 155
/**
 ********************************************************************************
156
 *
157
 * @ingroup CHAMELEON_Complex64_t_Tile
158
 *
159
 *  CHAMELEON_zlacpy_Tile - Tile equivalent of CHAMELEON_zlacpy().
160 161 162 163 164 165 166 167
 *  Operates on matrices stored by tiles.
 *  All matrices are passed through descriptors.
 *  All dimensions are taken from the descriptors.
 *
 *******************************************************************************
 *
 * @param[in] uplo
 *          Specifies the part of the matrix A to be copied to B.
168 169 170
 *            = ChamUpperLower: All the matrix A
 *            = ChamUpper: Upper triangular part
 *            = ChamLower: Lower triangular part
171 172
 *
 * @param[in] A
173 174
 *          The M-by-N matrix A. If uplo = ChamUpper, only the upper trapezium
 *          is accessed; if UPLO = ChamLower, only the lower trapezium is
175 176 177 178 179 180 181 182
 *          accessed.
 *
 * @param[out] B
 *          The M-by-N matrix B.
 *          On exit, B = A in the locations specified by UPLO.
 *
 *******************************************************************************
 *
183
 * @retval CHAMELEON_SUCCESS successful exit
184 185 186
 *
 *******************************************************************************
 *
187 188 189 190 191
 * @sa CHAMELEON_zlacpy
 * @sa CHAMELEON_zlacpy_Tile_Async
 * @sa CHAMELEON_clacpy_Tile
 * @sa CHAMELEON_dlacpy_Tile
 * @sa CHAMELEON_slacpy_Tile
192
 *
193
 */
194
int CHAMELEON_zlacpy_Tile( cham_uplo_t uplo, CHAM_desc_t *A, CHAM_desc_t *B )
195
{
Mathieu Faverge's avatar
Mathieu Faverge committed
196
    CHAM_context_t *chamctxt;
197 198
    RUNTIME_sequence_t *sequence = NULL;
    RUNTIME_request_t request = RUNTIME_REQUEST_INITIALIZER;
199
    int status;
200

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

208
    CHAMELEON_zlacpy_Tile_Async( uplo, A, B, sequence, &request );
Mathieu Faverge's avatar
Mathieu Faverge committed
209

210 211
    CHAMELEON_Desc_Flush( A, 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
    return status;
217 218
}

219 220
/**
 ********************************************************************************
221
 *
222
 * @ingroup CHAMELEON_Complex64_t_Tile_Async
223
 *
224
 *  CHAMELEON_zlacpy_Tile_Async - Non-blocking equivalent of CHAMELEON_zlacpy_Tile().
225 226 227 228 229 230 231 232 233 234 235 236 237 238
 *  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).
 *
 *******************************************************************************
 *
239 240 241 242 243
 * @sa CHAMELEON_zlacpy
 * @sa CHAMELEON_zlacpy_Tile
 * @sa CHAMELEON_clacpy_Tile_Async
 * @sa CHAMELEON_dlacpy_Tile_Async
 * @sa CHAMELEON_slacpy_Tile_Async
244
 *
245
 */
246 247
int CHAMELEON_zlacpy_Tile_Async( cham_uplo_t uplo, CHAM_desc_t *A, CHAM_desc_t *B,
                             RUNTIME_sequence_t *sequence, RUNTIME_request_t *request )
248
{
Mathieu Faverge's avatar
Mathieu Faverge committed
249
    CHAM_context_t *chamctxt;
250

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

    /* Check descriptors for correctness */
Mathieu Faverge's avatar
Mathieu Faverge committed
273 274 275
    if (chameleon_desc_check(A) != CHAMELEON_SUCCESS) {
        chameleon_error("CHAMELEON_zlacpy_Tile_Async", "invalid first descriptor");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
276
    }
Mathieu Faverge's avatar
Mathieu Faverge committed
277 278 279
    if (chameleon_desc_check(B) != CHAMELEON_SUCCESS) {
        chameleon_error("CHAMELEON_zlacpy_Tile_Async", "invalid second descriptor");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
280 281 282
    }
    /* Check input arguments */
    if (A->nb != A->mb) {
Mathieu Faverge's avatar
Mathieu Faverge committed
283 284
        chameleon_error("CHAMELEON_zlacpy_Tile_Async", "only square tiles supported");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
285 286
    }
    /* Check input arguments */
287 288 289
    if ( (uplo != ChamUpperLower) &&
         (uplo != ChamUpper) &&
         (uplo != ChamLower) ) {
Mathieu Faverge's avatar
Mathieu Faverge committed
290
        chameleon_error("CHAMELEON_zlacpy_Tile_Async", "illegal value of uplo");
291 292 293
        return -1;
    }
    /* Quick return */
Mathieu Faverge's avatar
Mathieu Faverge committed
294
    if (chameleon_min(A->m, A->n) == 0) {
295
        return CHAMELEON_SUCCESS;
296 297
    }

Mathieu Faverge's avatar
Mathieu Faverge committed
298
    chameleon_pzlacpy( uplo, A, B, sequence, request );
299

300
    return CHAMELEON_SUCCESS;
301
}