PaStiX Handbook  6.4.0
solver_backup.c
Go to the documentation of this file.
1 /**
2  *
3  * @file solver_backup.c
4  *
5  * PaStiX solver structure routines.
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 Xavier Lacoste
12  * @author Pierre Ramet
13  * @author Mathieu Faverge
14  * @author Tony Delarue
15  * @date 2024-07-05
16  *
17  **/
18 #include "common.h"
19 #include "blend/solver.h"
20 
21 /**
22  * @ingroup blend_dev_solver
23  * @brief Structure to store backup of counter modified during numerical factorization and solve steps.
24  */
25 struct SolverBackup_s {
26  pastix_int_t *task_ctrbcnt; /**< Number of contribution: the counter is decreased to 0 during factorization */
27  pastix_int_t *fanin_ctrbnbr; /**< Number of contribution to FanIn: decreased during facto and solve */
28  pastix_int_t *fanin_prionum; /**< Replaced by the number of msg packed during factorization sends */
29  pastix_int_t *symbol_cblknum; /**< Replaced by the negative FanIn index during facto and solve */
30  pastix_int_t symbol_nodenbr; /**< ??? */
31  pastix_int_t recvcnt;
32  pastix_int_t fanincnt;
33 };
34 
35 /**
36  *******************************************************************************
37  *
38  * @ingroup blend_dev_solver
39  *
40  * @brief Initialize the backup structure.
41  *
42  * This function saves the initial values of the counters before
43  * modifications. See structure description for more information about what is
44  * saved and why.
45  *
46  *******************************************************************************
47  *
48  * @param[in] solvmtx
49  * The solver matrix structure holding information for factorization
50  * and solve steps.
51  *
52  *******************************************************************************
53  *
54  * @retval Pointer to the allocated backup structure with the copy of
55  * information that might be destroyed.
56  *
57  *******************************************************************************/
58 SolverBackup_t *
59 solverBackupInit( const SolverMatrix *solvmtx )
60 {
61  SolverBackup_t *b;
62  pastix_int_t i;
63 
64  MALLOC_INTERN( b, 1, SolverBackup_t );
65  memset( b, 0, sizeof(SolverBackup_t) );
66 
67  if (solvmtx->tasknbr)
68  {
69  Task *task = solvmtx->tasktab;
70 
71  MALLOC_INTERN(b->task_ctrbcnt, solvmtx->tasknbr, pastix_int_t);
72 
73  for (i=0; i<solvmtx->tasknbr; i++, task++)
74  {
75  b->task_ctrbcnt[i] = task->ctrbcnt;
76  }
77  }
78 
79  if (solvmtx->bloknbr) {
80  SolverBlok *blok = solvmtx->bloktab;
81 
82  MALLOC_INTERN(b->symbol_cblknum, solvmtx->bloknbr, pastix_int_t);
83 
84  for (i=0; i<solvmtx->bloknbr; i++, blok++) {
85  b->symbol_cblknum[i] = blok->fcblknm;
86  }
87  }
88 
89  b->symbol_nodenbr = solvmtx->nodenbr;
90 
91  {
92  SolverCblk *cblk = solvmtx->cblktab;
93  for (i=0; i<solvmtx->cblknbr; i++, cblk++)
94  {
95  cblk->ctrbcnt = cblk[1].brownum - cblk[0].brownum;
96  cblk->partitioned = 0;
97  }
98  }
99 
100  b->recvcnt = solvmtx->recvcnt;
101  b->fanincnt = solvmtx->fanincnt;
102 
103  return b;
104 }
105 
106 /**
107  *******************************************************************************
108  *
109  * @ingroup blend_dev_solver
110  *
111  * @brief Restore initial values.
112  *
113  * Restore counter values to be able to call a second factorization or solve
114  * step. The amount of information restored depends on the value of
115  * solvmtx->restore. If it is equal to:
116  * - 0: Nothing is restored
117  * - 1: A solve step has been performed and partial information is restored.
118  * - 2: A factorization step has been performed and full information is restored.
119  * The value of solvmtx->restore is noramally initialized to 0 during the
120  * structure creation, and then set to the correct value by the routine
121  * modifying the solvmtx structure.
122  *
123  *******************************************************************************
124  *
125  * @param[inout] solvmtx
126  * The solver matrix structure holding information for factorization
127  * and solve steps.
128  * On exit, the counters have been restored to their original value
129  * stored in the backup structure.
130  *
131  * @param[in] b
132  * The backup structure pointer returned by the call to solverBackupInit().
133  *
134  *******************************************************************************
135  *
136  * @retval PASTIX_SUCCESS if the data has been restored successfuly.
137  * @retval PASTIX_ERR_BADPARAMETER if one of the parameter is incorrect.
138  *
139  *******************************************************************************/
140 int
142  const SolverBackup_t *b )
143 {
144  pastix_int_t i;
145 
146  if ( solvmtx == NULL || b == NULL ) {
148  }
149 
150  if ( solvmtx->restore == 0 ) {
151  return PASTIX_SUCCESS;
152  }
153 
154  /* After factorization */
155  if ( solvmtx->restore == 2 ) {
156  if (solvmtx->tasknbr)
157  {
158  Task *task = solvmtx->tasktab;
159 
160  for (i=0; i<solvmtx->tasknbr; i++, task++)
161  {
162  task->ctrbcnt = b->task_ctrbcnt[i];
163  }
164  }
165  }
166 
167  if (solvmtx->bloknbr) {
168  SolverBlok *blok = solvmtx->bloktab;
169 
170  for (i=0; i<solvmtx->bloknbr; i++, blok++) {
171  blok->fcblknm = b->symbol_cblknum[i];
172  }
173  }
174 
175  solvmtx->nodenbr = b->symbol_nodenbr;
176  solvmtx->recvcnt = b->recvcnt;
177  solvmtx->fanincnt = b->fanincnt;
178 
179  return PASTIX_SUCCESS;
180 }
181 
182 /**
183  *******************************************************************************
184  *
185  * @ingroup blend_dev_solver
186  *
187  * @brief Free the solver backup data structure.
188  *
189  * Clean the data structure holding the information backup and free the given
190  * pointer because it has necessarily been allocated in solverBackupInit().
191  *
192  *******************************************************************************
193  *
194  * @param[inout] b
195  * The backup structure to destroy. On exit, b cannot be used anymore.
196  *
197  *******************************************************************************/
198 void
199 solverBackupExit( SolverBackup_t *b )
200 {
201  if (b->task_ctrbcnt)
202  {
203  memFree_null(b->task_ctrbcnt);
204  }
205 
206  if (b->fanin_ctrbnbr)
207  {
208  memFree_null(b->fanin_ctrbnbr);
209  memFree_null(b->fanin_prionum);
210  }
211 
212  if (b->symbol_cblknum) {
213  memFree_null(b->symbol_cblknum);
214  }
215  memFree_null(b);
216 }
BEGIN_C_DECLS typedef int pastix_int_t
Definition: datatypes.h:51
int solverBackupRestore(SolverMatrix *solvmtx, const SolverBackup_t *b)
Restore initial values.
void solverBackupExit(SolverBackup_t *b)
Free the solver backup data structure.
SolverBackup_t * solverBackupInit(const SolverMatrix *solvmtx)
Initialize the backup structure.
Definition: solver_backup.c:59
@ PASTIX_SUCCESS
Definition: api.h:367
@ PASTIX_ERR_BADPARAMETER
Definition: api.h:374
pastix_int_t nodenbr
Definition: solver.h:208
pastix_int_t brownum
Definition: solver.h:171
pastix_int_t fcblknm
Definition: solver.h:144
pastix_int_t recvcnt
Definition: solver.h:217
pastix_int_t cblknbr
Definition: solver.h:211
SolverBlok *restrict bloktab
Definition: solver.h:229
pastix_int_t fanincnt
Definition: solver.h:214
volatile int32_t ctrbcnt
Definition: solver.h:163
pastix_int_t bloknbr
Definition: solver.h:224
pastix_int_t volatile ctrbcnt
Definition: solver.h:127
SolverCblk *restrict cblktab
Definition: solver.h:228
int8_t partitioned
Definition: solver.h:165
Solver block structure.
Definition: solver.h:141
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