zplghe.c 8.9 KB
Newer Older
1
/**
2 3
 *
 * @file zplghe.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.
7 8
 * @copyright 2012-2016 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
 *                      Univ. Bordeaux. All rights reserved.
9
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
10
 ***
11
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
12
 * @brief Chameleon zplghe wrappers
13
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
14
 * @version 1.0.0
15 16
 * @comment This file is a copy of zplghe.c
 *          wich has been automatically generated
Mathieu Faverge's avatar
Mathieu Faverge committed
17
 *          from Plasma 2.5.0 for CHAMELEON 1.0.0
18 19 20
 * @author Mathieu Faverge
 * @author Emmanuel Agullo
 * @author Cedric Castagnede
21 22 23
 * @author Rade Mathis
 * @author Florent Pruvost
 * @date 2016-08-01
24 25
 * @precisions normal z -> c
 *
26
 */
27
#include "control/common.h"
28

29 30
/**
 ********************************************************************************
31
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
32
 * @ingroup CHAMELEON_Complex64_t
33
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
34
 *  CHAMELEON_zplghe - Generate a random hermitian (positive definite if 'bump' is large enough) half-matrix by tiles.
35 36 37 38
 *
 *******************************************************************************
 *
 * @param[in] bump
Mathieu Faverge's avatar
Mathieu Faverge committed
39
 *          The value to add to the diagonal to be sure
40 41 42 43 44
 *          to have a positive definite matrix.
 *
 * @param[in] N
 *          The order of the matrix A. N >= 0.
 *
45 46 47
 * @param[in] uplo
 *          The part of the Matrix wich will be generated.
 *
48 49 50 51 52 53 54 55 56 57 58 59
 * @param[out] A
 *          On exit, The random hermitian matrix A generated.
 *
 * @param[in] LDA
 *          The leading dimension of the array A. LDA >= max(1,M).
 *
 * @param[in] seed
 *          The seed used in the random generation.
 *
 *******************************************************************************
 *
 * @return
Mathieu Faverge's avatar
Mathieu Faverge committed
60
 *          \retval CHAMELEON_SUCCESS successful exit
61 62 63 64
 *          \retval <0 if -i, the i-th argument had an illegal value
 *
 *******************************************************************************
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
65 66 67 68 69 70
 * @sa CHAMELEON_zplghe_Tile
 * @sa CHAMELEON_zplghe_Tile_Async
 * @sa CHAMELEON_cplghe
 * @sa CHAMELEON_dplghe
 * @sa CHAMELEON_splghe
 * @sa CHAMELEON_zplghe
71
 *
72
 */
Mathieu Faverge's avatar
Mathieu Faverge committed
73 74 75
int CHAMELEON_zplghe( double bump, cham_uplo_t uplo, int N,
                      CHAMELEON_Complex64_t *A, int LDA,
                      unsigned long long int seed )
76 77 78
{
    int NB;
    int status;
Mathieu Faverge's avatar
Mathieu Faverge committed
79
    CHAM_context_t *chamctxt;
Mathieu Faverge's avatar
Mathieu Faverge committed
80 81 82
    RUNTIME_sequence_t *sequence = NULL;
    RUNTIME_request_t request = RUNTIME_REQUEST_INITIALIZER;
    CHAM_desc_t descAl, descAt;
83

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

    /* Tune NB depending on M, N & NRHS; Set NBNB */
Mathieu Faverge's avatar
Mathieu Faverge committed
103
    status = chameleon_tune(CHAMELEON_FUNC_ZGEMM, N, N, 0);
Mathieu Faverge's avatar
Mathieu Faverge committed
104
    if (status != CHAMELEON_SUCCESS) {
Mathieu Faverge's avatar
Mathieu Faverge committed
105
        chameleon_error("CHAMELEON_zplghe", "chameleon_tune() failed");
106 107
        return status;
    }
Mathieu Faverge's avatar
Mathieu Faverge committed
108

109
    /* Set NT */
Mathieu Faverge's avatar
Mathieu Faverge committed
110
    NB = CHAMELEON_NB;
Mathieu Faverge's avatar
Mathieu Faverge committed
111
    chameleon_sequence_create( chamctxt, &sequence );
Mathieu Faverge's avatar
Mathieu Faverge committed
112

113
    /* Submit the matrix conversion */
Mathieu Faverge's avatar
Mathieu Faverge committed
114
    chameleon_zlap2tile( chamctxt, &descAl, &descAt, ChamDescOutput, uplo,
115
                     A, NB, NB, LDA, N, N, N, sequence, &request );
116 117

    /* Call the tile interface */
Mathieu Faverge's avatar
Mathieu Faverge committed
118
    CHAMELEON_zplghe_Tile_Async( bump, uplo, &descAt, seed, sequence, &request );
119

Mathieu Faverge's avatar
Cleanup  
Mathieu Faverge committed
120
    /* Submit the matrix conversion back */
Mathieu Faverge's avatar
Mathieu Faverge committed
121
    chameleon_ztile2lap( chamctxt, &descAl, &descAt,
Mathieu Faverge's avatar
Mathieu Faverge committed
122
                     ChamDescOutput, uplo, sequence, &request );
Mathieu Faverge's avatar
Mathieu Faverge committed
123

Mathieu Faverge's avatar
Mathieu Faverge committed
124
    chameleon_sequence_wait( chamctxt, sequence );
Mathieu Faverge's avatar
Mathieu Faverge committed
125

Mathieu Faverge's avatar
Mathieu Faverge committed
126
    /* Cleanup the temporary data */
Mathieu Faverge's avatar
Mathieu Faverge committed
127
    chameleon_ztile2lap_cleanup( chamctxt, &descAl, &descAt );
128 129

    status = sequence->status;
Mathieu Faverge's avatar
Mathieu Faverge committed
130
    chameleon_sequence_destroy( chamctxt, sequence );
131 132 133 134

    return status;
}

135 136
/**
 ********************************************************************************
137
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
138
 * @ingroup CHAMELEON_Complex64_t_Tile
139
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
140 141
 *  CHAMELEON_zplghe_Tile - Generate a random hermitian (positive definite if 'bump' is large enough) half-matrix by tiles.
 *  Tile equivalent of CHAMELEON_zplghe().
142 143 144 145 146 147 148
 *  Operates on matrices stored by tiles.
 *  All matrices are passed through descriptors.
 *  All dimensions are taken from the descriptors.
 *
 *******************************************************************************
 *
 * @param[in] bump
Mathieu Faverge's avatar
Mathieu Faverge committed
149
 *          The value to add to the diagonal to be sure
150 151
 *          to have a positive definite matrix.
 *
152 153 154
 * @param[in] uplo
 *          The part of the Matrix wich will be generated.
 *
155 156 157 158 159 160 161 162 163
 * @param[in] A
 *          On exit, The random hermitian matrix A generated.
 *
 * @param[in] seed
 *          The seed used in the random generation.
 *
 *******************************************************************************
 *
 * @return
Mathieu Faverge's avatar
Mathieu Faverge committed
164
 *          \retval CHAMELEON_SUCCESS successful exit
165 166 167
 *
 *******************************************************************************
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
168 169 170 171 172 173
 * @sa CHAMELEON_zplghe
 * @sa CHAMELEON_zplghe_Tile_Async
 * @sa CHAMELEON_cplghe_Tile
 * @sa CHAMELEON_dplghe_Tile
 * @sa CHAMELEON_splghe_Tile
 * @sa CHAMELEON_zplghe_Tile
174
 *
175
 */
Mathieu Faverge's avatar
Mathieu Faverge committed
176 177
int CHAMELEON_zplghe_Tile( double bump, cham_uplo_t uplo, CHAM_desc_t *A,
                           unsigned long long int seed )
178
{
Mathieu Faverge's avatar
Mathieu Faverge committed
179
    CHAM_context_t *chamctxt;
Mathieu Faverge's avatar
Mathieu Faverge committed
180 181
    RUNTIME_sequence_t *sequence = NULL;
    RUNTIME_request_t request = RUNTIME_REQUEST_INITIALIZER;
182 183
    int status;

Mathieu Faverge's avatar
Mathieu Faverge committed
184 185 186
    chamctxt = chameleon_context_self();
    if (chamctxt == NULL) {
        chameleon_fatal_error("CHAMELEON_zplghe_Tile", "CHAMELEON not initialized");
Mathieu Faverge's avatar
Mathieu Faverge committed
187
        return CHAMELEON_ERR_NOT_INITIALIZED;
188
    }
Mathieu Faverge's avatar
Mathieu Faverge committed
189
    chameleon_sequence_create( chamctxt, &sequence );
190

Mathieu Faverge's avatar
Mathieu Faverge committed
191
    CHAMELEON_zplghe_Tile_Async( bump, uplo, A, seed, sequence, &request );
Mathieu Faverge's avatar
Mathieu Faverge committed
192

Mathieu Faverge's avatar
Mathieu Faverge committed
193
    CHAMELEON_Desc_Flush( A, sequence );
Mathieu Faverge's avatar
Mathieu Faverge committed
194

Mathieu Faverge's avatar
Mathieu Faverge committed
195
    chameleon_sequence_wait( chamctxt, sequence );
196
    status = sequence->status;
Mathieu Faverge's avatar
Mathieu Faverge committed
197
    chameleon_sequence_destroy( chamctxt, sequence );
198 199 200
    return status;
}

201 202
/**
 ********************************************************************************
203
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
204
 * @ingroup CHAMELEON_Complex64_t_Tile_Async
205
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
206 207
 *  CHAMELEON_zplghe_Tile_Async - Generate a random hermitian (positive definite if 'bump' is large enough) half-matrix by tiles.
 *  Non-blocking equivalent of CHAMELEON_zplghe_Tile().
208 209 210 211 212 213 214 215 216 217 218 219 220 221
 *  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).
 *
 *******************************************************************************
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
222 223 224 225 226 227
 * @sa CHAMELEON_zplghe
 * @sa CHAMELEON_zplghe_Tile
 * @sa CHAMELEON_cplghe_Tile_Async
 * @sa CHAMELEON_dplghe_Tile_Async
 * @sa CHAMELEON_splghe_Tile_Async
 * @sa CHAMELEON_zplghe_Tile_Async
228
 *
229
 */
Mathieu Faverge's avatar
Mathieu Faverge committed
230 231 232 233 234 235
int CHAMELEON_zplghe_Tile_Async( double                 bump,
                                 cham_uplo_t            uplo,
                                 CHAM_desc_t           *A,
                                 unsigned long long int seed,
                                 RUNTIME_sequence_t    *sequence,
                                 RUNTIME_request_t     *request )
236
{
Mathieu Faverge's avatar
Mathieu Faverge committed
237
    CHAM_context_t *chamctxt;
238

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

    /* Check descriptors for correctness */
Mathieu Faverge's avatar
Mathieu Faverge committed
261 262 263
    if (chameleon_desc_check(A) != CHAMELEON_SUCCESS) {
        chameleon_error("CHAMELEON_zplghe_Tile", "invalid descriptor");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
264 265 266
    }
    /* Check input arguments */
    if (A->nb != A->mb) {
Mathieu Faverge's avatar
Mathieu Faverge committed
267 268
        chameleon_error("CHAMELEON_zplghe_Tile", "only square tiles supported");
        return chameleon_request_fail(sequence, request, CHAMELEON_ERR_ILLEGAL_VALUE);
269 270 271
    }

    /* Quick return */
Mathieu Faverge's avatar
Mathieu Faverge committed
272
    if (chameleon_min( A->m, A->n ) == 0)
Mathieu Faverge's avatar
Mathieu Faverge committed
273
        return CHAMELEON_SUCCESS;
274

Mathieu Faverge's avatar
Mathieu Faverge committed
275
    chameleon_pzplghe( bump, uplo, A, seed, sequence, request );
276

Mathieu Faverge's avatar
Mathieu Faverge committed
277
    return CHAMELEON_SUCCESS;
278
}