ztile.c 5.44 KB
Newer Older
1
/**
2 3
 *
 * @file ztile.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 auxiliary routines
13
 *
Mathieu Faverge's avatar
Mathieu Faverge committed
14
 * @version 1.0.0
15 16 17 18 19 20
 * @author Jakub Kurzak
 * @author Mathieu Faverge
 * @author Cedric Castagnede
 * @date 2010-11-15
 * @precisions normal z -> s d c
 *
21
 */
22
#include "control/common.h"
23

24 25
/**
 ********************************************************************************
26
 *
27
 * @ingroup CHAMELEON_Complex64_t
28
 *
29
 *  CHAMELEON_zLapack_to_Tile - Conversion from LAPACK layout to tile layout.
30 31 32 33 34 35 36 37 38 39
 *
 *******************************************************************************
 *
 * @param[in] Af77
 *          LAPACK matrix.
 *
 * @param[in] LDA
 *          The leading dimension of the matrix Af77.
 *
 * @param[in,out] A
40 41
 *          Descriptor of the CHAMELEON matrix in tile layout.
 *          If CHAMELEON_TRANSLATION_MODE is set to ChamInPlace,
42
 *          A->mat is not used and set to Af77 when returns, else if
43
 *          CHAMELEON_TRANSLATION_MODE is set to ChamOutOfPlace,
44 45 46 47
 *          A->mat has to be allocated before.
 *
 *******************************************************************************
 *
48
 * @retval CHAMELEON_SUCCESS successful exit
49 50 51
 *
 *******************************************************************************
 *
52 53 54 55
 * @sa CHAMELEON_zTile_to_Lapack
 * @sa CHAMELEON_cLapack_to_Tile
 * @sa CHAMELEON_dLapack_to_Tile
 * @sa CHAMELEON_sLapack_to_Tile
56
 *
57
 */
58
int CHAMELEON_zLapack_to_Tile( CHAMELEON_Complex64_t *Af77, int LDA, CHAM_desc_t *A )
59
{
Mathieu Faverge's avatar
Mathieu Faverge committed
60
    CHAM_context_t *chamctxt;
61 62 63
    RUNTIME_sequence_t *sequence = NULL;
    RUNTIME_request_t request;
    CHAM_desc_t *B;
64 65
    int status;

Mathieu Faverge's avatar
Mathieu Faverge committed
66 67 68
    chamctxt = chameleon_context_self();
    if (chamctxt == NULL) {
        chameleon_fatal_error("CHAMELEON_zLapack_to_Tile", "CHAMELEON not initialized");
69
        return CHAMELEON_ERR_NOT_INITIALIZED;
70 71
    }
    /* Check descriptor for correctness */
Mathieu Faverge's avatar
Mathieu Faverge committed
72 73
    if (chameleon_desc_check( A ) != CHAMELEON_SUCCESS) {
        chameleon_error("CHAMELEON_zLapack_to_Tile", "invalid descriptor");
74
        return CHAMELEON_ERR_ILLEGAL_VALUE;
75
    }
76 77

    /* Create the B descriptor to handle the Lapack format matrix */
78
    CHAMELEON_Desc_Create_User( &B, Af77, ChamComplexDouble, A->mb, A->nb, A->bsiz,
79 80
                                LDA, A->n, 0, 0, A->m, A->n, 1, 1,
                                chameleon_getaddr_cm, chameleon_getblkldd_cm, NULL );
81 82

    /* Start the computation */
Mathieu Faverge's avatar
Mathieu Faverge committed
83
    chameleon_sequence_create( chamctxt, &sequence );
84

Mathieu Faverge's avatar
Mathieu Faverge committed
85
    chameleon_pzlacpy( ChamUpperLower, B, A, sequence, &request );
86

87 88
    CHAMELEON_Desc_Flush( B, sequence );
    CHAMELEON_Desc_Flush( A, sequence );
Mathieu Faverge's avatar
Mathieu Faverge committed
89

Mathieu Faverge's avatar
Mathieu Faverge committed
90
    chameleon_sequence_wait( chamctxt, sequence );
91

92
    /* Destroy temporary B descriptor */
93
    CHAMELEON_Desc_Destroy( &B );
94

95
    status = sequence->status;
Mathieu Faverge's avatar
Mathieu Faverge committed
96
    chameleon_sequence_destroy( chamctxt, sequence );
97 98 99
    return status;
}

100 101
/**
 ********************************************************************************
102
 *
103
 * @ingroup CHAMELEON_Complex64_t
104
 *
105
 *  CHAMELEON_Tile_to_Lapack - Conversion from tile layout to LAPACK layout.
106 107 108 109
 *
 *******************************************************************************
 *
 * @param[in] A
110
 *          Descriptor of the CHAMELEON matrix in tile layout.
111 112 113
 *
 * @param[in,out] Af77
 *          LAPACK matrix.
114
 *          If CHAMELEON_TRANSLATION_MODE is set to ChamInPlace,
115
 *          Af77 has to be A->mat, else if
116
 *          CHAMELEON_TRANSLATION_MODE is set to ChamOutOfPlace,
117 118 119 120 121 122 123
 *          Af77 has to be allocated before.
 *
 * @param[in] LDA
 *          The leading dimension of the matrix Af77.
 *
 *******************************************************************************
 *
124
 * @retval CHAMELEON_SUCCESS successful exit
125 126 127
 *
 *******************************************************************************
 *
128 129 130 131
 * @sa CHAMELEON_zLapack_to_Tile
 * @sa CHAMELEON_cTile_to_Lapack
 * @sa CHAMELEON_dTile_to_Lapack
 * @sa CHAMELEON_sTile_to_Lapack
132
 *
133
 */
134
int CHAMELEON_zTile_to_Lapack( CHAM_desc_t *A, CHAMELEON_Complex64_t *Af77, int LDA )
135
{
Mathieu Faverge's avatar
Mathieu Faverge committed
136
    CHAM_context_t *chamctxt;
137 138 139
    RUNTIME_sequence_t *sequence = NULL;
    RUNTIME_request_t request;
    CHAM_desc_t *B;
140 141
    int status;

Mathieu Faverge's avatar
Mathieu Faverge committed
142 143 144
    chamctxt = chameleon_context_self();
    if (chamctxt == NULL) {
        chameleon_fatal_error("CHAMELEON_zTile_to_Lapack", "CHAMELEON not initialized");
145
        return CHAMELEON_ERR_NOT_INITIALIZED;
146 147
    }
    /* Check descriptor for correctness */
Mathieu Faverge's avatar
Mathieu Faverge committed
148 149
    if (chameleon_desc_check( A ) != CHAMELEON_SUCCESS) {
        chameleon_error("CHAMELEON_zTile_to_Lapack", "invalid descriptor");
150
        return CHAMELEON_ERR_ILLEGAL_VALUE;
151
    }
152 153

    /* Create the B descriptor to handle the Lapack format matrix */
154
    CHAMELEON_Desc_Create_User( &B, Af77, ChamComplexDouble, A->mb, A->nb, A->bsiz,
155 156
                                LDA, A->n, 0, 0, A->m, A->n, 1, 1,
                                chameleon_getaddr_cm, chameleon_getblkldd_cm, NULL );
157 158

    /* Start the computation */
Mathieu Faverge's avatar
Mathieu Faverge committed
159
    chameleon_sequence_create( chamctxt, &sequence );
160

Mathieu Faverge's avatar
Mathieu Faverge committed
161
    chameleon_pzlacpy( ChamUpperLower, A, B, sequence, &request );
162

163 164
    CHAMELEON_Desc_Flush( A, sequence );
    CHAMELEON_Desc_Flush( B, sequence );
165

Mathieu Faverge's avatar
Mathieu Faverge committed
166
    chameleon_sequence_wait( chamctxt, sequence );
167

168
    CHAMELEON_Desc_Destroy( &B );
169

170
    status = sequence->status;
Mathieu Faverge's avatar
Mathieu Faverge committed
171
    chameleon_sequence_destroy( chamctxt, sequence );
172 173
    return status;
}