PaStiX Handbook  6.4.0
sequential_cdiag.c
Go to the documentation of this file.
1 /**
2  *
3  * @file sequential_cdiag.c
4  *
5  * @copyright 2012-2024 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
6  * Univ. Bordeaux. All rights reserved.
7  *
8  * @version 6.4.0
9  * @author Pascal Henon
10  * @author Xavier Lacoste
11  * @author Pierre Ramet
12  * @author Mathieu Faverge
13  * @author Tony Delarue
14  * @author Vincent Bridonneau
15  * @author Alycia Lisito
16  * @date 2024-07-05
17  *
18  * @generated from /builds/solverstack/pastix/sopalin/sequential_zdiag.c, normal z -> c, Tue Oct 8 14:17:57 2024
19  *
20  **/
21 #include "common.h"
22 #include "blend/solver.h"
23 #include "sopalin/sopalin_data.h"
24 #include "pastix_ccores.h"
25 
26 #if defined(PASTIX_WITH_STARPU)
27 #include "starpu/pastix_cstarpu.h"
28 #endif
29 
30 /**
31  *******************************************************************************
32  *
33  * @brief Apply the diagonal solve (sequential version)
34  *
35  *******************************************************************************
36  *
37  * @param[in] pastix_data
38  * The pastix_data structure.
39  *
40  * @param[in] sopalin_data
41  * The SolverMatrix structure from PaStiX.
42  *
43  * @param[in] rhsb
44  * The pointer to the rhs data structure that holds the vectors of the
45  * right hand side.
46  *
47  *******************************************************************************/
48 void
50  sopalin_data_t *sopalin_data,
51  pastix_rhs_t rhsb )
52 {
53  SolverMatrix *datacode = sopalin_data->solvmtx;
54  SolverCblk *cblk;
55  pastix_complex32_t *b = rhsb->b;
56  pastix_int_t i, cblknbr;
57  pastix_solv_mode_t mode = pastix_data->iparm[IPARM_SCHUR_SOLV_MODE];
58 
59  cblk = datacode->cblktab;
60  cblknbr = (mode == PastixSolvModeSchur) ? datacode->cblknbr : datacode->cblkschur;
61  for ( i = 0; i < cblknbr; i++, cblk++ ) {
62  if ( cblk->ownerid != datacode->clustnum ) {
63  continue;
64  }
65  solve_cblk_cdiag( cblk, cblk_getdataL( cblk ),
66  rhsb->n, b + cblk->lcolidx, rhsb->ld, NULL );
67  }
68 }
69 
70 /**
71  * @brief Arguments for the diagonal solve.
72  */
73 struct args_cdiag_t
74 {
75  pastix_data_t *pastix_data;
76  sopalin_data_t *sopalin_data;
77  pastix_rhs_t rhsb;
78  volatile int32_t taskcnt;
79 };
80 
81 /**
82  *******************************************************************************
83  *
84  * @brief Applies the diagonal solve.
85  *
86  *******************************************************************************
87  *
88  * @param[in] ctx
89  * Thread structure of the execution context of one instance of the
90  * scheduler.
91  *
92  * @param[in] args
93  * Arguments for the kernel diagonal call.
94  *
95  *******************************************************************************/
96 void
97 thread_cdiag_static( isched_thread_t *ctx,
98  void *args )
99 {
100  struct args_cdiag_t *arg = (struct args_cdiag_t*)args;
101  pastix_data_t *pastix_data = arg->pastix_data;
102  sopalin_data_t *sopalin_data = arg->sopalin_data;
103  SolverMatrix *datacode = sopalin_data->solvmtx;
104  pastix_complex32_t *b = arg->rhsb->b;
105  pastix_int_t nrhs = arg->rhsb->n;
106  pastix_int_t ldb = arg->rhsb->ld;
107  SolverCblk *cblk;
108  Task *t;
109  pastix_int_t i, ii, cblknbr;
110  pastix_int_t tasknbr, *tasktab;
111  pastix_solv_mode_t mode = pastix_data->iparm[IPARM_SCHUR_SOLV_MODE];
112  int rank = ctx->rank;
113 
114  tasknbr = datacode->ttsknbr[rank];
115  tasktab = datacode->ttsktab[rank];
116  cblknbr = (mode == PastixSolvModeSchur) ? datacode->cblknbr : datacode->cblkschur;
117 
118  for (ii=0; ii<tasknbr; ii++) {
119  i = tasktab[ii];
120  t = datacode->tasktab + i;
121 
122  if ( t->cblknum >= cblknbr ) {
123  continue;
124  }
125  cblk = datacode->cblktab + t->cblknum;
126  if ( cblk->ownerid != datacode->clustnum ) {
127  continue;
128  }
129  solve_cblk_cdiag( cblk, cblk_getdataL( cblk ),
130  nrhs, b + cblk->lcolidx, ldb, NULL );
131  }
132 }
133 
134 /**
135  *******************************************************************************
136  *
137  * @brief Apply the diagonal solve (static version)
138  *
139  *******************************************************************************
140  *
141  * @param[in] pastix_data
142  * The pastix_data structure.
143  *
144  * @param[in] sopalin_data
145  * The SolverMatrix structure from PaStiX.
146  *
147  * @param[in] rhsb
148  * The pointer to the rhs data structure that holds the vectors of the
149  * right hand side.
150  *
151  *******************************************************************************/
152 void
154  sopalin_data_t *sopalin_data,
155  pastix_rhs_t rhsb )
156 {
157  struct args_cdiag_t args_cdiag = {pastix_data, sopalin_data, rhsb, 0};
158  isched_parallel_call( pastix_data->isched, thread_cdiag_static, &args_cdiag );
159 }
160 
161 /**
162  *******************************************************************************
163  *
164  * @brief Applies the diagonal solve.
165  *
166  *******************************************************************************
167  *
168  * @param[in] ctx
169  * Thread structure of the execution context of one instance of the
170  * scheduler.
171  *
172  * @param[in] args
173  * Arguments for the kernel diagonal call.
174  *
175  *******************************************************************************/
176 void
177 thread_cdiag_dynamic( isched_thread_t *ctx,
178  void *args )
179 {
180  struct args_cdiag_t *arg = (struct args_cdiag_t*)args;
181  pastix_data_t *pastix_data = arg->pastix_data;
182  sopalin_data_t *sopalin_data = arg->sopalin_data;
183  SolverMatrix *datacode = sopalin_data->solvmtx;
184  pastix_complex32_t *b = arg->rhsb->b;
185  pastix_int_t nrhs = arg->rhsb->n;
186  pastix_int_t ldb = arg->rhsb->ld;
187  int32_t local_taskcnt = 0;
188  pastix_queue_t *computeQueue;
189  pastix_int_t i, ii, cblknbr;//, lcblknbr;
190  pastix_int_t tasknbr, *tasktab, cblknum;
191  SolverCblk *cblk;
192  Task *t;
193  pastix_solv_mode_t mode = pastix_data->iparm[IPARM_SCHUR_SOLV_MODE];
194  int rank = ctx->rank;
195 
196  MALLOC_INTERN( datacode->computeQueue[rank], 1, pastix_queue_t );
197 
198  tasknbr = datacode->ttsknbr[rank];
199  tasktab = datacode->ttsktab[rank];
200  computeQueue = datacode->computeQueue[rank];
201  pqueueInit( computeQueue, tasknbr );
202  cblknbr = (mode == PastixSolvModeSchur) ? datacode->cblknbr : datacode->cblkschur;
203 
204  for ( ii = 0; ii < tasknbr; ii++ ) {
205  i = tasktab[ii];
206  t = datacode->tasktab + i;
207 
208  if ( t->cblknum >= cblknbr ) {
209  continue;
210  }
211  cblk = datacode->cblktab + t->cblknum;
212  pqueuePush1( computeQueue, t->cblknum, cblk->priority );
213  }
214 
215  /* Make sure that all computeQueues are allocated */
216  isched_barrier_wait( &(ctx->global_ctx->barrier) );
217 
218  /* When distributed -> only locals cblks, changes necessay */
219  while( arg->taskcnt > 0 ) {
220  cblknum = pqueuePop(computeQueue);
221 
222  if( cblknum == -1 ) {
223  if ( local_taskcnt ) {
224  pastix_atomic_sub_32b( &(arg->taskcnt), local_taskcnt );
225  local_taskcnt = 0;
226  }
227  cblknum = stealQueue( datacode, rank,
228  ctx->global_ctx->world_size );
229  }
230  if( cblknum != -1 ) {
231  cblk = datacode->cblktab + cblknum;
232  solve_cblk_cdiag( cblk, cblk_getdataL( cblk ),
233  nrhs, b + cblk->lcolidx, ldb, NULL );
234  local_taskcnt++;
235  }
236  }
237  /* Make sure that everyone is done before freeing */
238  isched_barrier_wait( &(ctx->global_ctx->barrier) );
239  pqueueExit( computeQueue );
240  memFree_null( computeQueue );
241 }
242 
243 /**
244  *******************************************************************************
245  *
246  * @brief Apply the diagonal solve (dynamic version)
247  *
248  *******************************************************************************
249  *
250  * @param[in] pastix_data
251  * The pastix_data structure.
252  *
253  * @param[in] sopalin_data
254  * The SolverMatrix structure from PaStiX.
255  *
256  * @param[in] rhsb
257  * The pointer to the rhs data structure that holds the vectors of the
258  * right hand side.
259  *
260  *******************************************************************************/
261 void
263  sopalin_data_t *sopalin_data,
264  pastix_rhs_t rhsb )
265 {
266  pastix_solv_mode_t mode = pastix_data->iparm[IPARM_SCHUR_SOLV_MODE];
267  pastix_int_t tasknbr = (mode == PastixSolvModeSchur) ?
268  sopalin_data->solvmtx->cblknbr : sopalin_data->solvmtx->cblkschur;
269  struct args_cdiag_t args_cdiag = { pastix_data, sopalin_data, rhsb, tasknbr };
270  /* Allocate the computeQueue */
271  MALLOC_INTERN( sopalin_data->solvmtx->computeQueue,
272  pastix_data->isched->world_size, pastix_queue_t * );
273 
274  isched_parallel_call( pastix_data->isched, thread_cdiag_static, &args_cdiag );
275  memFree_null( sopalin_data->solvmtx->computeQueue );
276 }
277 
278 #ifndef DOXYGEN_SHOULD_SKIP_THIS
279 static void (*cdiag_table[5])(pastix_data_t *, sopalin_data_t *, pastix_rhs_t) = {
281  static_cdiag,
282 #if defined(PASTIX_WITH_PARSEC)
283  NULL, /* parsec_cdiag not yet implemented */
284 #else
285  NULL,
286 #endif
287 #if defined(PASTIX_WITH_STARPU)
288  starpu_cdiag,
289 #else
290  NULL,
291 #endif
293 };
294 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
295 
296 /**
297  *******************************************************************************
298  *
299  * @brief Apply the diagonal solve
300  *
301  *******************************************************************************
302  *
303  * @param[in] pastix_data
304  * The pastix_data structure.
305  *
306  * @param[in] sopalin_data
307  * The SolverMatrix structure from PaStiX.
308  *
309  * @param[in] rhsb
310  * The pointer to the rhs data structure that holds the vectors of the
311  * right hand side.
312  *
313  *******************************************************************************/
314 void
316  sopalin_data_t *sopalin_data,
317  pastix_rhs_t rhsb )
318 {
319  int sched = pastix_data->iparm[IPARM_SCHEDULER];
320  void (*cdiag)(pastix_data_t *, sopalin_data_t *, pastix_rhs_t ) = cdiag_table[ sched ];
321 
322  if (cdiag == NULL) {
323  cdiag = static_cdiag;
324  }
325  cdiag( pastix_data, sopalin_data, rhsb );
326 }
BEGIN_C_DECLS typedef int pastix_int_t
Definition: datatypes.h:51
float _Complex pastix_complex32_t
Definition: datatypes.h:76
static void pqueuePush1(pastix_queue_t *q, pastix_int_t elt, double key1)
Push an element with a single key.
Definition: queue.h:64
void pqueueExit(pastix_queue_t *)
Free the structure associated to the queue.
Definition: queue.c:110
static pastix_int_t pqueuePop(pastix_queue_t *q)
Pop the head of the queue whithout returning the keys.
Definition: queue.h:75
int pqueueInit(pastix_queue_t *, pastix_int_t)
Initialize the queue structure with an initial space to store the elements.
Definition: queue.c:81
Queue structure.
Definition: queue.h:38
void solve_cblk_cdiag(const SolverCblk *cblk, const void *dataA, int nrhs, pastix_complex32_t *b, int ldb, pastix_complex32_t *work)
Apply the diagonal solve related to one cblk to all the right hand side.
enum pastix_solv_mode_e pastix_solv_mode_t
Solve Schur modes.
@ IPARM_SCHEDULER
Definition: api.h:117
@ IPARM_SCHUR_SOLV_MODE
Definition: api.h:107
pastix_int_t * iparm
Definition: pastixdata.h:70
pastix_int_t ld
Definition: pastixdata.h:160
isched_t * isched
Definition: pastixdata.h:86
pastix_int_t n
Definition: pastixdata.h:159
Main PaStiX data structure.
Definition: pastixdata.h:68
Main PaStiX RHS structure.
Definition: pastixdata.h:155
void starpu_cdiag(pastix_data_t *pastix_data, sopalin_data_t *sopalin_data, pastix_rhs_t rhsb)
Apply the diagonal solve (StarPU version)
Definition: starpu_cdiag.c:88
void sequential_cdiag(pastix_data_t *pastix_data, sopalin_data_t *sopalin_data, pastix_rhs_t rhsb)
Apply the diagonal solve (sequential version)
void static_cdiag(pastix_data_t *pastix_data, sopalin_data_t *sopalin_data, pastix_rhs_t rhsb)
Apply the diagonal solve (static version)
void thread_cdiag_static(isched_thread_t *ctx, void *args)
Applies the diagonal solve.
void dynamic_cdiag(pastix_data_t *pastix_data, sopalin_data_t *sopalin_data, pastix_rhs_t rhsb)
Apply the diagonal solve (dynamic version)
void thread_cdiag_dynamic(isched_thread_t *ctx, void *args)
Applies the diagonal solve.
void sopalin_cdiag(pastix_data_t *pastix_data, sopalin_data_t *sopalin_data, pastix_rhs_t rhsb)
Apply the diagonal solve.
pastix_int_t cblknum
Definition: solver.h:125
pastix_int_t priority
Definition: solver.h:183
static pastix_int_t stealQueue(SolverMatrix *solvmtx, int rank, int nbthreads)
Task stealing method.
Definition: solver.h:471
pastix_int_t cblknbr
Definition: solver.h:211
static void * cblk_getdataL(const SolverCblk *cblk)
Get the pointer to the data associated to the lower part of the cblk.
Definition: solver.h:342
pastix_int_t lcolidx
Definition: solver.h:170
SolverCblk *restrict cblktab
Definition: solver.h:228
int ownerid
Definition: solver.h:181
pastix_int_t cblkschur
Definition: solver.h:221
Solver column block structure.
Definition: solver.h:161
Solver column block structure.
Definition: solver.h:203
The task structure for the numerical factorization.
Definition: solver.h:122