PaStiX Handbook  6.3.2
starpu_dense_matrix.c
Go to the documentation of this file.
1 /**
2  *
3  * @file starpu_dense_matrix.c
4  *
5  * PaStiX dense matrix descriptor for StarPU.
6  *
7  * @copyright 2016-2023 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
8  * Univ. Bordeaux. All rights reserved.
9  *
10  * @version 6.3.2
11  * @author Mathieu Faverge
12  * @author Pierre Ramet
13  * @date 2023-07-21
14  *
15  * @ingroup pastix_starpu
16  * @{
17  *
18  **/
19 #include "common.h"
20 #include "blend/solver.h"
21 #include "pastix_starpu.h"
22 #include <starpu_data.h>
23 
24 /**
25  *******************************************************************************
26  *
27  * @brief Generate the StarPU descriptor of the dense matrix.
28  *
29  * This function creates the StarPU descriptor that will provide tha data
30  * mapping and memory location to StarPU for the computation.
31  *
32  *******************************************************************************
33  *
34  * @param[inout] solvmtx
35  * The solver matrix structure that describes the dense matrix for
36  * PaStiX.
37  *
38  * @param[in] ncol
39  * The number of columns of the given matrix. The number of rows is
40  * given by the solvmtx structure.
41  *
42  * @param[in] A
43  * The pointer to the matrix.
44  *
45  * @param[in] lda
46  * The leading dimension of the matrix A.
47  *
48  * @param[in] typesize
49  * The memory size of the arithmetic used to store the matrix
50  * coefficients.
51  *
52  * @param[in] nodes
53  * The number of processes used to solve the problem.
54  *
55  * @param[in] myrank
56  * The rank of the calling process.
57  *
58  ******************************************************************************/
59 void
61  pastix_int_t ncol, char *A, pastix_int_t lda,
62  int typesize, int nodes, int myrank )
63 {
64  starpu_data_handle_t *handler;
65  SolverCblk *cblk;
66  pastix_int_t cblknbr, cblknum;
67  pastix_int_t nrow;
68 
69  starpu_dense_matrix_desc_t *spmtx = solvmtx->starpu_desc_rhs;
70  if ( spmtx != NULL ) {
71  if ( (ncol == spmtx->ncol) &&
72  (A == spmtx->dataptr) ) {
73  return;
74  }
76  }
77  else {
79  }
80 
81  cblknbr = solvmtx->cblknbr;
82 
83  spmtx->mpitag = pastix_starpu_tag_book( solvmtx->gcblknbr );
84  spmtx->ncol = ncol;
85  spmtx->typesze = typesize;
86  spmtx->solvmtx = solvmtx;
87  spmtx->handletab = malloc( cblknbr * sizeof(starpu_data_handle_t) );
88  spmtx->dataptr = A;
89 
90  /* Initialize 1D cblk handlers */
91  cblk = spmtx->solvmtx->cblktab;
92  handler = spmtx->handletab;
93  for( cblknum = 0;
94  cblknum < cblknbr;
95  cblknum++, cblk++, handler++ )
96  {
97  nrow = cblk_colnbr( cblk );
98 
99  if( cblk->ownerid == myrank ) {
100  starpu_matrix_data_register( handler, STARPU_MAIN_RAM,
101  (uintptr_t)(A + (cblk->lcolidx * typesize)),
102  lda, nrow, ncol, typesize );
103  }
104  else {
105  starpu_matrix_data_register( handler, -1, 0,
106  lda, nrow, ncol, typesize );
107  }
108 #if defined(PASTIX_WITH_MPI)
109  starpu_mpi_data_register( *handler, spmtx->mpitag + ((int64_t)cblknum), cblk->ownerid );
110 #endif
111  }
112 
113  solvmtx->starpu_desc_rhs = spmtx;
114 
115  (void)nodes;
116  (void)myrank;
117 }
118 
119 /**
120  *******************************************************************************
121  *
122  * @brief Submit asynchronous calls to retrieve the data on main memory.
123  *
124  *******************************************************************************
125  *
126  * @param[inout] spmtx
127  * The dense matrix descriptor to retrieve on main memory.
128  *
129  ******************************************************************************/
130 void
132 {
133  starpu_data_handle_t *handler = spmtx->handletab;
134  SolverCblk *cblk;
135  pastix_int_t cblknbr, cblknum;
136 
137  cblk = spmtx->solvmtx->cblktab;
138  cblknbr = spmtx->solvmtx->cblknbr;
139  for(cblknum=0; cblknum<cblknbr; cblknum++, cblk++, handler++)
140  {
141  assert( handler );
142 
143 #if defined(PASTIX_WITH_MPI)
144  starpu_mpi_cache_flush( spmtx->solvmtx->solv_comm, *handler );
145 #endif
146  if ( cblk->ownerid == spmtx->solvmtx->clustnum ) {
147  starpu_data_acquire_cb( *handler, STARPU_R,
148  (void (*)(void*))&starpu_data_release,
149  *handler );
150  }
151  }
152 }
153 
154 /**
155  *******************************************************************************
156  *
157  * @brief Free the StarPU descriptor of the dense matrix.
158  *
159  * This function destroys the StarPU descriptor, but do not free the matrix data
160  * that are managed by PaStiX.
161  *
162  *******************************************************************************
163  *
164  * @param[inout] spmtx
165  * The descriptor to free.
166  *
167  ******************************************************************************/
168 void
170 {
171  starpu_data_handle_t *handler = spmtx->handletab;
172  SolverCblk *cblk;
173  pastix_int_t cblknbr, cblknum;
174 
175  cblk = spmtx->solvmtx->cblktab;
176  cblknbr = spmtx->solvmtx->cblknbr;
177  for(cblknum=0; cblknum<cblknbr; cblknum++, cblk++, handler++)
178  {
179  assert( handler );
180  starpu_data_unregister( *handler );
181  }
182 
183  free( spmtx->handletab );
184  spmtx->handletab = NULL;
185 
187 }
188 
189 /**
190  * @}
191  */
BEGIN_C_DECLS typedef int pastix_int_t
Definition: datatypes.h:51
starpu_data_handle_t * handletab
void starpu_dense_matrix_init(SolverMatrix *solvmtx, pastix_int_t ncol, char *A, pastix_int_t lda, int typesize, int nodes, int myrank)
Generate the StarPU descriptor of the dense matrix.
int64_t pastix_starpu_tag_book(int64_t nbtags)
Book a range of StarPU unique tags of size nbtags.
Definition: starpu_tags.c:246
void pastix_starpu_tag_release(int64_t min)
Release the set of tags starting by min.
Definition: starpu_tags.c:264
void starpu_dense_matrix_destroy(starpu_dense_matrix_desc_t *spmtx)
Free the StarPU descriptor of the dense matrix.
void starpu_dense_matrix_getoncpu(starpu_dense_matrix_desc_t *spmtx)
Submit asynchronous calls to retrieve the data on main memory.
StarPU descriptor for the vectors linked to a given sparse matrix.
pastix_int_t gcblknbr
Definition: solver.h:207
static pastix_int_t cblk_colnbr(const SolverCblk *cblk)
Compute the number of columns in a column block.
Definition: solver.h:324
pastix_int_t cblknbr
Definition: solver.h:208
pastix_int_t lcolidx
Definition: solver.h:165
SolverCblk *restrict cblktab
Definition: solver.h:222
int ownerid
Definition: solver.h:175
Solver column block structure.
Definition: solver.h:156
Solver column block structure.
Definition: solver.h:200