PaStiX Handbook  6.4.0
simu.c
Go to the documentation of this file.
1 /**
2  *
3  * @file simu.c
4  *
5  * PaStiX simulation basic functions.
6  *
7  * @copyright 2004-2024 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
8  * Univ. Bordeaux. All rights reserved.
9  *
10  * @version 6.4.0
11  * @author Pascal Henon
12  * @author Pierre Ramet
13  * @author Mathieu Faverge
14  * @author Gregoire Pichon
15  * @date 2024-07-05
16  *
17  * @addtogroup blend_dev_simu
18  * @{
19  *
20  **/
21 #include <stdio.h>
22 #include <strings.h>
23 #include <math.h>
24 
25 #include "common.h"
26 #include "symbol/symbol.h"
27 #include "blend/elimintree.h"
28 #include "blend/cost.h"
29 #include "blend/cand.h"
30 #include "queue.h"
31 #include "blend/extendVector.h"
32 #include "blend/blendctrl.h"
33 #include "blend/solver.h"
34 #include "blend/simu.h"
35 
36 /**
37  *******************************************************************************
38  *
39  * @brief Initialize the simulation structures.
40  *
41  *******************************************************************************
42  *
43  * @param[inout] simuctrl
44  * The allocated pointer to main control structure for the simulation.
45  *
46  * @param[in] symbptr
47  * The pointer to the symbol matrix structure studied.
48  *
49  * @param[in] candtab
50  * The pointer to the candidate information associated to the symbol
51  * structure and that will guide the simulation.
52  *
53  * @param[in] clustnbr
54  * The number of PaStiX processes involved in the simulation.
55  *
56  * @param[in] procnbr
57  * The total number of workers involved in the simulation.
58  *
59  *******************************************************************************
60  *
61  * @retval PASTIX_SUCCESS if success.
62  * @retval PASTIX_ERR_OUTOFMEMORY if one of the malloc failed.
63  *
64  *******************************************************************************/
66 simuInit( SimuCtrl *simuctrl,
67  const symbol_matrix_t *symbptr,
68  const Cand *candtab,
69  pastix_int_t clustnbr,
70  pastix_int_t procnbr )
71 {
72  pastix_int_t i, j;
73  pastix_int_t p;
74  pastix_int_t ftgtcur;
75  pastix_int_t candnbr;
77  pastix_int_t cblknbr = symbptr->cblknbr;
78  pastix_int_t bloknbr = symbptr->bloknbr;
79 
80  simuctrl->cblknbr = cblknbr;
81  simuctrl->ftgtprio = 0;
82  simuctrl->tasktab = NULL;
83  simuctrl->ftgtcnt = 0;
84 
85  /* Processor initialization */
86  MALLOC_INTERN(simuctrl->proctab, procnbr, SimuProc);
87  for(i=0;i<procnbr;i++)
88  {
89  timerSet(TIMER(i), 0.0); /* for paragraph numeric tolerance */
90  MALLOC_INTERN(simuctrl->proctab[i].futuretask, 1, pastix_queue_t);
91  MALLOC_INTERN(simuctrl->proctab[i].readytask, 1, pastix_queue_t);
92  pqueueInit(simuctrl->proctab[i].futuretask, 100);
93  pqueueInit(simuctrl->proctab[i].readytask, 100);
94 
95  MALLOC_INTERN(simuctrl->proctab[i].tasktab, 1, ExtendVectorINT);
96  extendint_Init(simuctrl->proctab[i].tasktab, bloknbr/procnbr + 1);
97  }
98 
99  /* Cluster initialization */
100  MALLOC_INTERN(simuctrl->clustab, clustnbr, SimuCluster);
101  step = procnbr / clustnbr;
102  for(i=0;i<clustnbr;i++)
103  {
104  simuctrl->clustab[i].fprocnum = i*step;
105  simuctrl->clustab[i].lprocnum = simuctrl->clustab[i].fprocnum + step - 1;
106  MALLOC_INTERN(simuctrl->clustab[i].ftgtsend, clustnbr, ExtendVectorINT);
107  simuctrl->clustab[i].prionum = 0;
108  for(p=0;p<clustnbr;p++) {
109  extendint_Init(&(simuctrl->clustab[i].ftgtsend[p]), cblknbr/(2*clustnbr)+1);
110  }
111  }
112  simuctrl->clustab[clustnbr-1].lprocnum = procnbr-1;
113 
114  MALLOC_INTERN(simuctrl->ownetab, cblknbr, pastix_int_t);
115 
116  /* Affect a negative value to cblk not mapped */
117  for(i=0;i<cblknbr;i++) {
118  simuctrl->ownetab[i] = -1;
119  }
120 
121  MALLOC_INTERN(simuctrl->cblktab, cblknbr+1, SimuCblk);
122  MALLOC_INTERN(simuctrl->bloktab, bloknbr+1, SimuBlok);
123  ftgtcur = 0;
124 
125  for(i=0;i<cblknbr;i++)
126  {
127  candnbr = candtab[i].lccandnum - candtab[i].fccandnum + 1;
128  simuctrl->cblktab[i].owned = 0;
129  simuctrl->cblktab[i].ctrbcnt = 0;
130 
131  for(j=symbptr->cblktab[i].bloknum;j<symbptr->cblktab[i+1].bloknum;j++)
132  {
133  simuctrl->bloktab[j].ftgtnum = ftgtcur;
134  simuctrl->bloktab[j].tasknum = -1;
135  simuctrl->bloktab[j].fccandnum = candtab[i].fccandnum;
136  simuctrl->bloktab[j].ctrbcnt = 0;
137  simuctrl->bloktab[j].ownerclust = -1;
138  /*if(candnbr > 1)*/
139  ftgtcur += candnbr;
140  }
141  }
142  /* One extracblk for avoiding side effect */
143  simuctrl->bloktab[bloknbr].ftgtnum = ftgtcur;
144  simuctrl->ftgtnbr = ftgtcur;
145 
146  if(simuctrl->ftgtnbr > 0)
147  {
148  /* Allocate and Initialize the timer for the reception of each ftgt on a candidate cluster */
149  MALLOC_INTERN(simuctrl->ftgttimetab, simuctrl->ftgtnbr, SimuTimer);
150  for(i=0;i<simuctrl->ftgtnbr;i++) {
151  timerSet(&(simuctrl->ftgttimetab[i]), 0.0);
152  }
153 
154  MALLOC_INTERN(simuctrl->ftgttab, ftgtcur, SimuFtgt);
155  for(i=0;i<simuctrl->ftgtnbr;i++)
156  {
157  simuctrl->ftgttab[i].clustnum = -1;
158  timerSet(&(simuctrl->ftgttab[i].timerecv), 0.0);
159  simuctrl->ftgttab[i].costsend = 0.0;
160  simuctrl->ftgttab[i].costadd = 0.0;
161  memset( simuctrl->ftgttab[i].infotab, 0, FTGT_MAXINFO * sizeof(pastix_int_t) );
162  simuctrl->ftgttab[i].infotab[FTGT_FCOLNUM] = PASTIX_INT_MAX;
163  simuctrl->ftgttab[i].infotab[FTGT_FROWNUM] = PASTIX_INT_MAX;
164  simuctrl->ftgttab[i].infotab[FTGT_CTRBNBR] = 0;
165  simuctrl->ftgttab[i].infotab[FTGT_CTRBCNT] = 0;
166  }
167  }
168  else
169  {
170  simuctrl->ftgttab = NULL;
171  simuctrl->ftgttimetab = NULL;
172  }
173 
174  return PASTIX_SUCCESS;
175 }
176 
177 /**
178  *******************************************************************************
179  *
180  * @brief Reallocate the simulation structures to compact them.
181  *
182  * All data that were globally allocated and replicated on every node is freed,
183  * and only the local information are allocated. This is used only when a second
184  * proportionnal mapping with local information is performed for the dynamic
185  * scheduling.
186  *
187  *******************************************************************************
188  *
189  * @param[inout] simuctrl
190  * The simulation structure to reallocate.
191  *
192  * @param[in] procnbr
193  * The total number of workers.
194  *
195  * @param[in] local_nbthrds
196  * The number of local workers per process.
197  *
198  *******************************************************************************
199  *
200  * @retval PASTIX_SUCCESS if success.
201  * @retval PASTIX_ERR_OUTOFMEMORY if one of the malloc failed.
202  *
203  *******************************************************************************/
206  pastix_int_t procnbr,
207  pastix_int_t local_nbthrds)
208 {
209  pastix_int_t i;
210 
211  /* Free processor structure */
212  for(i=0;i<procnbr;i++)
213  {
214  pqueueExit (simuctrl->proctab[i].readytask);
215  memFree_null (simuctrl->proctab[i].readytask);
216  pqueueExit (simuctrl->proctab[i].futuretask);
217  memFree_null (simuctrl->proctab[i].futuretask);
218  extendint_Exit(simuctrl->proctab[i].tasktab);
219  memFree_null (simuctrl->proctab[i].tasktab);
220  }
221  memFree_null(simuctrl->proctab);
222 
223  /* Initialization for local threads */
224  MALLOC_INTERN(simuctrl->proctab, local_nbthrds, SimuProc);
225  for(i=0;i<local_nbthrds;i++)
226  {
227  MALLOC_INTERN(simuctrl->proctab[i].tasktab, 1, ExtendVectorINT);
228  }
229 
230  return PASTIX_SUCCESS;
231 }
232 
233 /**
234  *******************************************************************************
235  *
236  * @brief Free the simulation structure.
237  *
238  *******************************************************************************
239  *
240  * @param[inout] simuctrl
241  * The simulation structure to free.
242  *
243  * @param[in] clustnbr
244  * The total number of PaStiX processes.
245  *
246  * @param[in] procnbr
247  * The total number of workers.
248  *
249  * @param[in] local_nbthrds
250  * The number of local workers per process.
251  *
252  *******************************************************************************/
253 void
254 simuExit(SimuCtrl *simuctrl,
255  pastix_int_t clustnbr,
256  pastix_int_t procnbr,
257  pastix_int_t local_nbthrds)
258 {
259  pastix_int_t i,j;
260  (void)local_nbthrds; (void)procnbr;
261 
262 #ifndef PASTIX_DYNSCHED
263  for(i=0;i<procnbr;i++)
264  {
265  pqueueExit (simuctrl->proctab[i].readytask);
266  memFree_null (simuctrl->proctab[i].readytask);
267  pqueueExit (simuctrl->proctab[i].futuretask);
268  memFree_null (simuctrl->proctab[i].futuretask);
269  extendint_Exit(simuctrl->proctab[i].tasktab);
270  memFree_null (simuctrl->proctab[i].tasktab);
271  }
272 #else
273  for(i=0;i<local_nbthrds;i++)
274  {
275  extendint_Exit(simuctrl->proctab[i].tasktab);
276  memFree_null(simuctrl->proctab[i].tasktab);
277  }
278 #endif
279 
280  for(i=0;i<clustnbr;i++)
281  {
282  for(j=0;j<clustnbr;j++) {
283  extendint_Exit(&(simuctrl->clustab[i].ftgtsend[j]));
284  }
285  memFree_null(simuctrl->clustab[i].ftgtsend);
286  }
287 
288  if(simuctrl->ftgttab != NULL)
289  {
290  memFree_null(simuctrl->ftgttab);
291  memFree_null(simuctrl->ftgttimetab);
292  }
293  memFree_null(simuctrl->tasktab);
294  memFree_null(simuctrl->proctab);
295  memFree_null(simuctrl->clustab);
296  memFree_null(simuctrl->ownetab);
297  memFree_null(simuctrl->cblktab);
298  memFree_null(simuctrl->bloktab);
299  memFree_null(simuctrl);
300 }
301 
302 /**
303  *@}
304  */
BEGIN_C_DECLS typedef int pastix_int_t
Definition: datatypes.h:51
pastix_int_t lccandnum
Definition: cand.h:34
pastix_int_t fccandnum
Definition: cand.h:33
Processor candidate group to own a column blok.
Definition: cand.h:28
pastix_int_t * extendint_Init(ExtendVectorINT *, pastix_int_t)
Initialize the extendVector structure with the initial size given.
Definition: extendVector.c:45
void extendint_Exit(ExtendVectorINT *)
Free the extendVector structure.
Definition: extendVector.c:66
The extend integer array structure.
Definition: extendVector.h:29
void pqueueExit(pastix_queue_t *)
Free the structure associated to the queue.
Definition: queue.c:110
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
pastix_int_t tasknum
Definition: simu.h:87
pastix_int_t clustnum
Definition: simu.h:69
pastix_int_t infotab[FTGT_MAXINFO]
Definition: simu.h:68
SimuCluster * clustab
Definition: simu.h:123
SimuFtgt * ftgttab
Definition: simu.h:127
SimuProc * proctab
Definition: simu.h:122
pastix_int_t ftgtprio
Definition: simu.h:118
pastix_queue_t * readytask
Definition: simu.h:58
pastix_int_t prionum
Definition: simu.h:50
pastix_queue_t * futuretask
Definition: simu.h:59
int8_t owned
Definition: simu.h:80
SimuTask * tasktab
Definition: simu.h:121
int ownerclust
Definition: simu.h:93
pastix_int_t ftgtcnt
Definition: simu.h:120
SimuTimer * ftgttimetab
Definition: simu.h:129
ExtendVectorINT * tasktab
Definition: simu.h:60
double costadd
Definition: simu.h:72
pastix_int_t lprocnum
Definition: simu.h:48
SimuBlok * bloktab
Definition: simu.h:126
pastix_int_t fprocnum
Definition: simu.h:47
SimuCblk * cblktab
Definition: simu.h:125
pastix_int_t ctrbcnt
Definition: simu.h:91
pastix_int_t ftgtnbr
Definition: simu.h:128
pastix_int_t * ownetab
Definition: simu.h:124
pastix_int_t ftgtnum
Definition: simu.h:88
pastix_int_t ctrbcnt
Definition: simu.h:79
pastix_int_t cblknbr
Definition: simu.h:117
SimuTimer timerecv
Definition: simu.h:70
double costsend
Definition: simu.h:71
int fccandnum
Definition: simu.h:92
ExtendVectorINT * ftgtsend
Definition: simu.h:49
void simuExit(SimuCtrl *, pastix_int_t, pastix_int_t, pastix_int_t)
Free the simulation structure.
Definition: simu.c:254
pastix_int_t simuRealloc(SimuCtrl *, pastix_int_t, pastix_int_t)
Reallocate the simulation structures to compact them.
Definition: simu.c:205
static void timerSet(SimuTimer *timer, double t)
Set the timer value.
Definition: simu_timer.h:84
pastix_int_t simuInit(SimuCtrl *, const symbol_matrix_t *, const Cand *, pastix_int_t, pastix_int_t)
Initialize the simulation structures.
Definition: simu.c:66
@ FTGT_CTRBNBR
Definition: simu.h:30
@ FTGT_FCOLNUM
Definition: simu.h:36
@ FTGT_CTRBCNT
Definition: simu.h:31
@ FTGT_FROWNUM
Definition: simu.h:38
Block structure for the simulation.
Definition: simu.h:86
Column block structure for the simulation.
Definition: simu.h:78
Process structure for the simulation.
Definition: simu.h:46
Fan-in structure for the simulation.
Definition: simu.h:67
Thread structure for the simulation.
Definition: simu.h:56
Timer for the simulation.
Definition: simu_timer.h:25
Control structure for the simulation.
Definition: simu.h:116
@ PASTIX_SUCCESS
Definition: api.h:367
pastix_int_t bloknbr
Definition: symbol.h:80
symbol_cblk_t * cblktab
Definition: symbol.h:83
pastix_int_t bloknum
Definition: symbol.h:48
pastix_int_t cblknbr
Definition: symbol.h:79
Symbol matrix structure.
Definition: symbol.h:77
-by-step