PaStiX Handbook  6.3.2
sequential_sdiag.c
Go to the documentation of this file.
1 /**
2  *
3  * @file sequential_sdiag.c
4  *
5  * @copyright 2012-2023 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
6  * Univ. Bordeaux. All rights reserved.
7  *
8  * @version 6.3.2
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 2023-11-07
17  *
18  * @generated from /builds/solverstack/pastix/sopalin/sequential_zdiag.c, normal z -> s, Wed Dec 13 12:09:47 2023
19  *
20  **/
21 #include "common.h"
22 #include "blend/solver.h"
23 #include "sopalin/sopalin_data.h"
24 #include "pastix_scores.h"
25 
26 #if defined(PASTIX_WITH_STARPU)
27 #include "starpu/pastix_sstarpu.h"
28 #endif
29 
30 /**
31  *******************************************************************************
32  *
33  * @brief TODO
34  *
35  *******************************************************************************
36  *
37  * @param[in] pastix_data
38  * TODO
39  *
40  * @param[in] sopalin_data
41  * TODO
42  *
43  * @param[in] nrhs
44  * TODO
45  *
46  * @param[in] b
47  * TODO
48  *
49  * @param[in] ldb
50  * TODO
51  *
52  *******************************************************************************/
53 void
55  sopalin_data_t *sopalin_data,
56  int nrhs,
57  float *b,
58  int ldb )
59 {
60  SolverMatrix *datacode = sopalin_data->solvmtx;
61  SolverCblk *cblk;
62  pastix_int_t i, cblknbr;
63  pastix_solv_mode_t mode = pastix_data->iparm[IPARM_SCHUR_SOLV_MODE];
64 
65  cblk = datacode->cblktab;
66  cblknbr = (mode == PastixSolvModeSchur) ? datacode->cblknbr : datacode->cblkschur;
67  for (i=0; i<cblknbr; i++, cblk++) {
68  if ( cblk->ownerid != datacode->clustnum ) {
69  continue;
70  }
71  solve_cblk_sdiag( cblk, cblk_getdataL( cblk ),
72  nrhs, b + cblk->lcolidx, ldb, NULL );
73  }
74 }
75 
76 /**
77  * @brief TODO
78  */
79 struct args_sdiag_t
80 {
81  pastix_data_t *pastix_data;
82  sopalin_data_t *sopalin_data;
83  int nrhs;
84  float *b;
85  int ldb;
86  volatile int32_t taskcnt;
87 };
88 
89 /**
90  *******************************************************************************
91  *
92  * @brief TODO
93  *
94  *******************************************************************************
95  *
96  * @param[in] ctx
97  * TODO
98  *
99  * @param[in] args
100  * TODO
101  *
102  *******************************************************************************/
103 void
104 thread_sdiag_static( isched_thread_t *ctx,
105  void *args )
106 {
107  struct args_sdiag_t *arg = (struct args_sdiag_t*)args;
108  pastix_data_t *pastix_data = arg->pastix_data;
109  sopalin_data_t *sopalin_data = arg->sopalin_data;
110  SolverMatrix *datacode = sopalin_data->solvmtx;
111  float *b = arg->b;
112  int nrhs = arg->nrhs;
113  int ldb = arg->ldb;
114  SolverCblk *cblk;
115  Task *t;
116  pastix_int_t i, ii, cblknbr;
117  pastix_int_t tasknbr, *tasktab;
118  pastix_solv_mode_t mode = pastix_data->iparm[IPARM_SCHUR_SOLV_MODE];
119  int rank = ctx->rank;
120 
121  tasknbr = datacode->ttsknbr[rank];
122  tasktab = datacode->ttsktab[rank];
123  cblknbr = (mode == PastixSolvModeSchur) ? datacode->cblknbr : datacode->cblkschur;
124 
125  for (ii=0; ii<tasknbr; ii++) {
126  i = tasktab[ii];
127  t = datacode->tasktab + i;
128 
129  if ( t->cblknum >= cblknbr ) {
130  continue;
131  }
132  cblk = datacode->cblktab + t->cblknum;
133  if ( cblk->ownerid != datacode->clustnum ) {
134  continue;
135  }
136  solve_cblk_sdiag( cblk, cblk_getdataL( cblk ),
137  nrhs, b + cblk->lcolidx, ldb, NULL );
138  }
139 }
140 
141 /**
142  *******************************************************************************
143  *
144  * @brief TODO
145  *
146  *******************************************************************************
147  *
148  * @param[in] pastix_data
149  * TODO
150  *
151  * @param[in] sopalin_data
152  * TODO
153  *
154  * @param[in] nrhs
155  * TODO
156  *
157  * @param[in] b
158  * TODO
159  *
160  * @param[in] ldb
161  * TODO
162  *
163  *******************************************************************************/
164 void
166  sopalin_data_t *sopalin_data,
167  int nrhs,
168  float *b,
169  int ldb )
170 {
171  struct args_sdiag_t args_sdiag = {pastix_data, sopalin_data, nrhs, b, ldb, 0};
172  isched_parallel_call( pastix_data->isched, thread_sdiag_static, &args_sdiag );
173 }
174 
175 /**
176  *******************************************************************************
177  *
178  * @brief TODO
179  *
180  *******************************************************************************
181  *
182  * @param[in] ctx
183  * TODO
184  *
185  * @param[in] args
186  * TODO
187  *
188  *******************************************************************************/
189 void
190 thread_sdiag_dynamic( isched_thread_t *ctx,
191  void *args )
192 {
193  struct args_sdiag_t *arg = (struct args_sdiag_t*)args;
194  pastix_data_t *pastix_data = arg->pastix_data;
195  sopalin_data_t *sopalin_data = arg->sopalin_data;
196  SolverMatrix *datacode = sopalin_data->solvmtx;
197  float *b = arg->b;
198  pastix_queue_t *computeQueue;
199  pastix_int_t i, ii, cblknbr;//, lcblknbr;
200  pastix_int_t tasknbr, *tasktab, cblknum;
201  pastix_solv_mode_t mode = pastix_data->iparm[IPARM_SCHUR_SOLV_MODE];
202  SolverCblk *cblk;
203  Task *t;
204  int32_t local_taskcnt = 0;
205  int nrhs = arg->nrhs;
206  int ldb = arg->ldb;
207  int rank = ctx->rank;
208 
209  MALLOC_INTERN( datacode->computeQueue[rank], 1, pastix_queue_t );
210 
211  tasknbr = datacode->ttsknbr[rank];
212  tasktab = datacode->ttsktab[rank];
213  computeQueue = datacode->computeQueue[rank];
214  pqueueInit( computeQueue, tasknbr );
215  cblknbr = (mode == PastixSolvModeSchur) ? datacode->cblknbr : datacode->cblkschur;
216 
217  for (ii=0; ii<tasknbr; ii++) {
218  i = tasktab[ii];
219  t = datacode->tasktab + i;
220 
221  if ( t->cblknum >= cblknbr ) {
222  continue;
223  }
224  cblk = datacode->cblktab + t->cblknum;
225  pqueuePush1( computeQueue, t->cblknum, cblk->priority );
226  }
227 
228  /* Make sure that all computeQueues are allocated */
229  isched_barrier_wait( &(ctx->global_ctx->barrier) );
230 
231  /* When distributed -> only locals cblks, changes necessay */
232  while( arg->taskcnt > 0 ){
233  cblknum = pqueuePop(computeQueue);
234 
235  if( cblknum == -1 ){
236  if ( local_taskcnt ) {
237  pastix_atomic_sub_32b( &(arg->taskcnt), local_taskcnt );
238  local_taskcnt = 0;
239  }
240  cblknum = stealQueue( datacode, rank,
241  ctx->global_ctx->world_size );
242  }
243  if( cblknum != -1 ){
244  cblk = datacode->cblktab + cblknum;
245  solve_cblk_sdiag( cblk, cblk_getdataL( cblk ),
246  nrhs, b + cblk->lcolidx, ldb, NULL );
247  local_taskcnt++;
248  }
249  }
250  /* Make sure that everyone is done before freeing */
251  isched_barrier_wait( &(ctx->global_ctx->barrier) );
252  pqueueExit( computeQueue );
253  memFree_null( computeQueue );
254 }
255 
256 /**
257  *******************************************************************************
258  *
259  * @brief TODO
260  *
261  *******************************************************************************
262  *
263  * @param[in] pastix_data
264  * TODO
265  *
266  * @param[in] sopalin_data
267  * TODO
268  *
269  * @param[in] nrhs
270  * TODO
271  *
272  * @param[in] b
273  * TODO
274  *
275  * @param[in] ldb
276  * TODO
277  *
278  *******************************************************************************/
279 void
281  sopalin_data_t *sopalin_data,
282  int nrhs,
283  float *b,
284  int ldb )
285 {
286  pastix_solv_mode_t mode = pastix_data->iparm[IPARM_SCHUR_SOLV_MODE];
287  pastix_int_t tasknbr = (mode == PastixSolvModeSchur) ?
288  sopalin_data->solvmtx->cblknbr : sopalin_data->solvmtx->cblkschur;
289  struct args_sdiag_t args_sdiag = { pastix_data, sopalin_data, nrhs, b, ldb, tasknbr };
290  /* Allocate the computeQueue */
291  MALLOC_INTERN( sopalin_data->solvmtx->computeQueue,
292  pastix_data->isched->world_size, pastix_queue_t * );
293 
294  isched_parallel_call( pastix_data->isched, thread_sdiag_static, &args_sdiag );
295  memFree_null( sopalin_data->solvmtx->computeQueue );
296 }
297 
298 #ifndef DOXYGEN_SHOULD_SKIP_THIS
299 static void (*sdiag_table[5])(pastix_data_t *, sopalin_data_t *,
300  int, float *, int) = {
302  static_sdiag,
303 #if defined(PASTIX_WITH_PARSEC)
304  NULL, /* parsec_sdiag not yet implemented */
305 #else
306  NULL,
307 #endif
308 #if defined(PASTIX_WITH_STARPU)
309  starpu_sdiag,
310 #else
311  NULL,
312 #endif
314 };
315 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
316 
317 /**
318  *******************************************************************************
319  *
320  * @brief TODO
321  *
322  *******************************************************************************
323  *
324  * @param[in] pastix_data
325  * TODO
326  *
327  * @param[in] sopalin_data
328  * TODO
329  *
330  * @param[in] nrhs
331  * TODO
332  *
333  * @param[in] b
334  * TODO
335  *
336  * @param[in] ldb
337  * TODO
338  *
339  *******************************************************************************/
340 void
342  sopalin_data_t *sopalin_data,
343  int nrhs,
344  float *b,
345  int ldb )
346 {
347  int sched = pastix_data->iparm[IPARM_SCHEDULER];
348  void (*sdiag)(pastix_data_t *, sopalin_data_t *, int, float *, int) = sdiag_table[ sched ];
349 
350  if (sdiag == NULL) {
351  sdiag = static_sdiag;
352  }
353  sdiag( pastix_data, sopalin_data, nrhs, b, ldb );
354 }
BEGIN_C_DECLS typedef int pastix_int_t
Definition: datatypes.h:51
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_sdiag(const SolverCblk *cblk, const void *dataA, int nrhs, float *b, int ldb, float *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:69
isched_t * isched
Definition: pastixdata.h:85
Main PaStiX data structure.
Definition: pastixdata.h:67
void starpu_sdiag(pastix_data_t *pastix_data, sopalin_data_t *sopalin_data, int nrhs, float *b, int ldb)
Apply the diagonal solve (StarPU version)
Definition: starpu_sdiag.c:88
void thread_sdiag_dynamic(isched_thread_t *ctx, void *args)
TODO.
void thread_sdiag_static(isched_thread_t *ctx, void *args)
TODO.
void static_sdiag(pastix_data_t *pastix_data, sopalin_data_t *sopalin_data, int nrhs, float *b, int ldb)
TODO.
void sequential_sdiag(pastix_data_t *pastix_data, sopalin_data_t *sopalin_data, int nrhs, float *b, int ldb)
TODO.
void sopalin_sdiag(pastix_data_t *pastix_data, sopalin_data_t *sopalin_data, int nrhs, float *b, int ldb)
TODO.
void dynamic_sdiag(pastix_data_t *pastix_data, sopalin_data_t *sopalin_data, int nrhs, float *b, int ldb)
TODO.
pastix_int_t cblknum
Definition: solver.h:121
pastix_int_t priority
Definition: solver.h:177
static pastix_int_t stealQueue(SolverMatrix *solvmtx, int rank, int nbthreads)
Task stealing method.
Definition: solver.h:466
pastix_int_t cblknbr
Definition: solver.h:208
static void * cblk_getdataL(const SolverCblk *cblk)
Get the pointer to the data associated to the lower part of the cblk.
Definition: solver.h:337
pastix_int_t lcolidx
Definition: solver.h:165
SolverCblk *restrict cblktab
Definition: solver.h:222
int ownerid
Definition: solver.h:175
pastix_int_t cblkschur
Definition: solver.h:217
Solver column block structure.
Definition: solver.h:156
Solver column block structure.
Definition: solver.h:200
The task structure for the numerical factorization.
Definition: solver.h:118