PaStiX Handbook 6.4.0
Loading...
Searching...
No Matches
starpu_rhs.c
Go to the documentation of this file.
1/**
2 *
3 * @file starpu_rhs.c
4 *
5 * PaStiX dense matrix descriptor for StarPU.
6 *
7 * @copyright 2016-2024 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
8 * Univ. Bordeaux. All rights reserved.
9 *
10 * @version 6.4.0
11 * @author Mathieu Faverge
12 * @author Pierre Ramet
13 * @author Alycia Lisito
14 * @date 2024-07-05
15 *
16 * @ingroup pastix_starpu
17 * @{
18 *
19 **/
20#include "common.h"
21#include "blend/solver.h"
22#include "pastix_starpu.h"
23#include <starpu_data.h>
24
25/**
26 *******************************************************************************
27 *
28 * @brief Generate the StarPU descriptor of the dense matrix.
29 *
30 * This function creates the StarPU descriptor that will provide tha data
31 * mapping and memory location to StarPU for the computation.
32 *
33 *******************************************************************************
34 *
35 * @param[inout] solvmtx
36 * The solver matrix structure that describes the dense matrix for
37 * PaStiX.
38 *
39 * @param[inout] mpitag
40 * The mpitag.
41 *
42 * @param[inout] clustnum
43 * The clustnum.
44 *
45 * @param[in] ncol
46 * The number of columns of the given matrix. The number of rows is
47 * given by the solvmtx structure.
48 *
49 * @param[in] A
50 * The pointer to the matrix.
51 *
52 * @param[in] lda
53 * The leading dimension of the matrix A.
54 *
55 * @param[in] typesize
56 * The memory size of the arithmetic used to store the matrix
57 * coefficients.
58 *
59 * @param[in] nodes
60 * The number of processes used to solve the problem.
61 *
62 * @param[in] myrank
63 * The rank of the calling process.
64 *
65 ******************************************************************************/
66void
67pastix_starpu_rhs_data_register( starpu_data_handle_t *handleptr,
68 int64_t mpitag,
69 int clustnum,
70 const SolverCblk *cblk,
71 size_t typesize,
74 char *A,
75 pastix_int_t lda )
76{
77 int home_node = STARPU_MAIN_RAM;
78 uintptr_t ptr = (uintptr_t)A;
79 int64_t tag_cblk = -1;
80
81 if ( cblk->cblktype & ( CBLK_FANIN | CBLK_RECV ) ) {
82 home_node = -1;
83 lda = m;
84 ptr = 0;
85 }
86 else {
87 assert( ptr != 0 );
88 }
89
90 /* The default StarPU dense matrix type is used to describe the rhs. */
91 starpu_matrix_data_register( handleptr, home_node, ptr, lda, m, n, typesize );
92
93#if defined(PASTIX_WITH_MPI)
94 if ( cblk->cblktype & CBLK_FANIN ) {
95 starpu_data_set_reduction_methods( *handleptr, NULL, &cl_rhs_init_cpu );
96 tag_cblk = mpitag + cblk->gfaninnum;
97 starpu_mpi_data_register( *handleptr, tag_cblk, clustnum );
98 }
99 else {
100 if ( cblk->cblktype & CBLK_RECV ) {
101 starpu_data_set_reduction_methods( *handleptr, NULL, &cl_rhs_init_cpu );
102 tag_cblk = mpitag + cblk->gfaninnum;
103 }
104 else {
105 tag_cblk = mpitag + cblk->gcblknum;
106 }
107 starpu_mpi_data_register( *handleptr, tag_cblk, cblk->ownerid );
108 }
109#endif
110
111#if defined(PASTIX_DEBUG_STARPU)
112 fprintf( stderr, "[%2d][pastix][%s] Solve cblk=%d, owner=%d, tag=%ld, size=%ld\n",
113 clustnum, __func__, cblk->gcblknum, cblk->ownerid, tag_cblk,
114 n * cblk_colnbr( cblk ) * pastix_size_of( solvmtx->flttype ) );
115#endif
116
117 (void)mpitag;
118 (void)clustnum;
119 (void)tag_cblk;
120}
121
122/**
123 *******************************************************************************
124 *
125 * @brief Generate the StarPU descriptor of the dense matrix.
126 *
127 * This function creates the StarPU descriptor that will provide tha data
128 * mapping and memory location to StarPU for the computation.
129 *
130 *******************************************************************************
131 *
132 * @param[inout] solvmtx
133 * The solver matrix structure that describes the dense matrix for
134 * PaStiX.
135 *
136 * @param[inout] rhsb
137 * The pointer to the rhs data structure that holds the vectors of the
138 * right hand side.
139 *
140 * @param[in] typesize
141 * The memory size of the arithmetic used to store the matrix
142 * coefficients.
143 *
144 * @param[in] nodes
145 * The number of processes used to solve the problem.
146 *
147 * @param[in] myrank
148 * The rank of the calling process.
149 *
150 ******************************************************************************/
151void
153 pastix_rhs_t rhsb,
154 int typesize,
155 int nodes,
156 int myrank )
157{
158 starpu_data_handle_t *handler;
159 SolverCblk *cblk;
160 pastix_int_t cblknbr, cblknum, nrow;
161 pastix_int_t ncol = rhsb->n;
162 starpu_rhs_desc_t *rhsdesc = rhsb->starpu_desc;
163
164 if ( rhsdesc != NULL ) {
165 if ( ( ncol == rhsdesc->ncol ) &&
166 ( rhsb->b == rhsdesc->dataptr ) ) {
167 return;
168 }
169 starpu_rhs_destroy( rhsdesc );
170 }
171 else {
172 rhsdesc = (starpu_rhs_desc_t*)malloc(sizeof(starpu_rhs_desc_t));
173 }
174
175 cblknbr = solvmtx->cblknbr;
176
177#if defined(PASTIX_WITH_MPI)
178 {
179 int64_t tag_desc = ( (int64_t) ( solvmtx->gcblknbr + solvmtx->gfanincblknbr ) );
180 rhsdesc->mpitag = pastix_starpu_tag_book( tag_desc );
181 }
182#endif
183 rhsdesc->ncol = ncol;
184 rhsdesc->typesze = pastix_size_of( typesize );
185 rhsdesc->solvmtx = solvmtx;
186 rhsdesc->handletab = malloc( cblknbr * sizeof(starpu_data_handle_t) );
187 rhsdesc->dataptr = rhsb->b;
188
189 /* Initialize 1D cblk handlers */
190 cblk = rhsdesc->solvmtx->cblktab;
191 handler = rhsdesc->handletab;
192 for( cblknum = 0; cblknum < cblknbr; cblknum++, cblk++, handler++ ) {
193 nrow = cblk_colnbr( cblk );
194
195 pastix_starpu_rhs_data_register( handler, rhsdesc->mpitag, solvmtx->clustnum, cblk, rhsdesc->typesze,
196 nrow, ncol, (char*)rhsb->b + (cblk->lcolidx * rhsdesc->typesze), rhsb->ld );
197 }
198
199 rhsb->starpu_desc = rhsdesc;
200
201 (void)nodes;
202 (void)myrank;
203}
204
205/**
206 *******************************************************************************
207 *
208 * @brief Submit asynchronous calls to retrieve the data on main memory.
209 *
210 *******************************************************************************
211 *
212 * @param[inout] rhsdesc
213 * The dense matrix descriptor to retrieve on main memory.
214 *
215 ******************************************************************************/
216void
218{
219 starpu_data_handle_t *handler = rhsdesc->handletab;
220 SolverCblk *cblk;
221 pastix_int_t cblknbr, cblknum;
222
223 cblk = rhsdesc->solvmtx->cblktab;
224 cblknbr = rhsdesc->solvmtx->cblknbr;
225 for(cblknum=0; cblknum<cblknbr; cblknum++, cblk++, handler++)
226 {
227 assert( handler );
228
229#if defined(PASTIX_WITH_MPI)
230 starpu_mpi_cache_flush( rhsdesc->solvmtx->solv_comm, *handler );
231#endif
232 if ( cblk->ownerid == rhsdesc->solvmtx->clustnum ) {
233 starpu_data_acquire_cb( *handler, STARPU_R,
234 (void (*)(void*))&starpu_data_release,
235 *handler );
236 }
237 }
238}
239
240/**
241 *******************************************************************************
242 *
243 * @brief Free the StarPU descriptor of the dense matrix.
244 *
245 * This function destroys the StarPU descriptor, but do not free the matrix data
246 * that are managed by PaStiX.
247 *
248 *******************************************************************************
249 *
250 * @param[inout] rhsdesc
251 * The descriptor to free.
252 *
253 ******************************************************************************/
254void
256{
257 starpu_data_handle_t *handler = rhsdesc->handletab;
258 SolverCblk *cblk;
259 pastix_int_t cblknbr, cblknum;
260
261 cblk = rhsdesc->solvmtx->cblktab;
262 cblknbr = rhsdesc->solvmtx->cblknbr;
263 for( cblknum = 0; cblknum < cblknbr; cblknum++, cblk++, handler++ ) {
264 assert( handler );
265 starpu_data_unregister( *handler );
266 }
267
268 free( rhsdesc->handletab );
269 rhsdesc->handletab = NULL;
270
272}
273
274/**
275 * @}
276 */
BEGIN_C_DECLS typedef int pastix_int_t
Definition datatypes.h:51
SolverMatrix * solvmtx
starpu_data_handle_t * handletab
struct starpu_codelet cl_rhs_init_cpu
Main structure for all tasks of rhs_init type.
void starpu_rhs_getoncpu(starpu_rhs_desc_t *rhsdesc)
Submit asynchronous calls to retrieve the data on main memory.
Definition starpu_rhs.c:217
int64_t pastix_starpu_tag_book(int64_t nbtags)
Book a range of StarPU unique tags of size nbtags.
void starpu_rhs_init(SolverMatrix *solvmtx, pastix_rhs_t rhsb, int typesize, int nodes, int myrank)
Generate the StarPU descriptor of the dense matrix.
Definition starpu_rhs.c:152
void pastix_starpu_tag_release(int64_t min)
Release the set of tags starting by min.
void starpu_rhs_destroy(starpu_rhs_desc_t *rhsdesc)
Free the StarPU descriptor of the dense matrix.
Definition starpu_rhs.c:255
StarPU descriptor for the vectors linked to a given sparse matrix.
pastix_int_t ld
Definition pastixdata.h:160
pastix_int_t n
Definition pastixdata.h:159
Main PaStiX RHS structure.
Definition pastixdata.h:155
pastix_int_t gfanincblknbr
Definition solver.h:212
pastix_int_t gcblknbr
Definition solver.h:210
static pastix_int_t cblk_colnbr(const SolverCblk *cblk)
Compute the number of columns in a column block.
Definition solver.h:329
pastix_int_t gfaninnum
Definition solver.h:176
pastix_int_t cblknbr
Definition solver.h:211
pastix_int_t gcblknum
Definition solver.h:174
pastix_int_t lcolidx
Definition solver.h:170
SolverCblk *restrict cblktab
Definition solver.h:228
int8_t cblktype
Definition solver.h:164
Solver column block structure.
Definition solver.h:161
Solver column block structure.
Definition solver.h:203
void pastix_starpu_rhs_data_register(starpu_data_handle_t *handleptr, int64_t mpitag, int clustnum, const SolverCblk *cblk, size_t typesize, pastix_int_t m, pastix_int_t n, char *A, pastix_int_t lda)
Generate the StarPU descriptor of the dense matrix.
Definition starpu_rhs.c:67