zplghe.c 8.85 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.
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
 *
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
 * @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.
 *
 *******************************************************************************
 *
59 60
 * @retval CHAMELEON_SUCCESS successful exit
 * @retval <0 if -i, the i-th argument had an illegal value
61 62 63
 *
 *******************************************************************************
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
64 65 66 67 68 69
 * @sa CHAMELEON_zplghe_Tile
 * @sa CHAMELEON_zplghe_Tile_Async
 * @sa CHAMELEON_cplghe
 * @sa CHAMELEON_dplghe
 * @sa CHAMELEON_splghe
 * @sa CHAMELEON_zplghe
70
 *
71
 */
Mathieu Faverge's avatar
Mathieu Faverge committed
72 73 74
int CHAMELEON_zplghe( double bump, cham_uplo_t uplo, int N,
                      CHAMELEON_Complex64_t *A, int LDA,
                      unsigned long long int seed )
75 76 77
{
    int NB;
    int status;
Mathieu Faverge's avatar
Mathieu Faverge committed
78
    CHAM_context_t *chamctxt;
Mathieu Faverge's avatar
Mathieu Faverge committed
79 80 81
    RUNTIME_sequence_t *sequence = NULL;
    RUNTIME_request_t request = RUNTIME_REQUEST_INITIALIZER;
    CHAM_desc_t descAl, descAt;
82

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

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

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

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

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

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

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

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

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

    return status;
}

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

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

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

Mathieu Faverge's avatar
Mathieu Faverge committed
191
    CHAMELEON_Desc_Flush( A, sequence );
Mathieu Faverge's avatar
Mathieu Faverge committed
192

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

199 200
/**
 ********************************************************************************
201
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
202
 * @ingroup CHAMELEON_Complex64_t_Tile_Async
203
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
204 205
 *  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().
206 207 208 209 210 211 212 213 214 215 216 217 218 219
 *  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
220 221 222 223 224 225
 * @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
226
 *
227
 */
Mathieu Faverge's avatar
Mathieu Faverge committed
228 229 230 231 232 233
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 )
234
{
Mathieu Faverge's avatar
Mathieu Faverge committed
235
    CHAM_context_t *chamctxt;
236

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

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

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

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

Mathieu Faverge's avatar
Mathieu Faverge committed
275
    return CHAMELEON_SUCCESS;
276
}