PaStiX Handbook  6.2.1
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-2021 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
8  * Univ. Bordeaux. All rights reserved.
9  *
10  * @version 6.2.0
11  * @author Xavier Lacoste
12  * @author Pierre Ramet
13  * @author Mathieu Faverge
14  * @author Tony Delarue
15  * @date 2021-01-03
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  }
97  }
98 
99  b->recvcnt = solvmtx->recvcnt;
100  b->fanincnt = solvmtx->fanincnt;
101 
102  return b;
103 }
104 
105 /**
106  *******************************************************************************
107  *
108  * @ingroup blend_dev_solver
109  *
110  * @brief Restore initial values.
111  *
112  * Restore counter values to be able to call a second factorization or solve
113  * step. The amount of information restored depends on the value of
114  * solvmtx->restore. If it is equal to:
115  * - 0: Nothing is restored
116  * - 1: A solve step has been performed and partial information is restored.
117  * - 2: A factorization step has been performed and full information is restored.
118  * The value of solvmtx->restore is noramally initialized to 0 during the
119  * structure creation, and then set to the correct value by the routine
120  * modifying the solvmtx structure.
121  *
122  *******************************************************************************
123  *
124  * @param[inout] solvmtx
125  * The solver matrix structure holding information for factorization
126  * and solve steps.
127  * On exit, the counters have been restored to their original value
128  * stored in the backup structure.
129  *
130  * @param[in] b
131  * The backup structure pointer returned by the call to solverBackupInit().
132  *
133  *******************************************************************************
134  *
135  * @retval PASTIX_SUCCESS if the data has been restored successfuly.
136  * @retval PASTIX_ERR_BADPARAMETER if one of the parameter is incorrect.
137  *
138  *******************************************************************************/
139 int
140 solverBackupRestore( SolverMatrix *solvmtx,
141  const SolverBackup_t *b )
142 {
143  pastix_int_t i;
144 
145  if ( solvmtx == NULL || b == NULL ) {
147  }
148 
149  if ( solvmtx->restore == 0 ) {
150  return PASTIX_SUCCESS;
151  }
152 
153  /* After factorization */
154  if ( solvmtx->restore == 2 ) {
155  if (solvmtx->tasknbr)
156  {
157  Task *task = solvmtx->tasktab;
158 
159  for (i=0; i<solvmtx->tasknbr; i++, task++)
160  {
161  task->ctrbcnt = b->task_ctrbcnt[i];
162  }
163  }
164  }
165 
166  if (solvmtx->bloknbr) {
167  SolverBlok *blok = solvmtx->bloktab;
168 
169  for (i=0; i<solvmtx->bloknbr; i++, blok++) {
170  blok->fcblknm = b->symbol_cblknum[i];
171  blok->gpuid = GPUID_UNDEFINED;
172  }
173  }
174  solvmtx->nodenbr = b->symbol_nodenbr;
175 
176  if (solvmtx->cblknbr) {
177  SolverCblk *cblk = solvmtx->cblktab;
178 
179  for (i=0; i<solvmtx->cblknbr; i++, cblk++) {
180  cblk->gpuid = GPUID_UNDEFINED;
181  }
182  }
183 
184  solvmtx->recvcnt = b->recvcnt;
185  solvmtx->fanincnt = b->fanincnt;
186 
187  return PASTIX_SUCCESS;
188 }
189 
190 /**
191  *******************************************************************************
192  *
193  * @ingroup blend_dev_solver
194  *
195  * @brief Free the solver backup data structure.
196  *
197  * Clean the data structure holding the information backup and free the given
198  * pointer because it has necessarily been allocated in solverBackupInit().
199  *
200  *******************************************************************************
201  *
202  * @param[inout] b
203  * The backup structure to destroy. On exit, b cannot be used anymore.
204  *
205  *******************************************************************************/
206 void
207 solverBackupExit( SolverBackup_t *b )
208 {
209  if (b->task_ctrbcnt)
210  {
211  memFree_null(b->task_ctrbcnt);
212  }
213 
214  if (b->fanin_ctrbnbr)
215  {
216  memFree_null(b->fanin_ctrbnbr);
217  memFree_null(b->fanin_prionum);
218  }
219 
220  if (b->symbol_cblknum) {
221  memFree_null(b->symbol_cblknum);
222  }
223  memFree_null(b);
224 }
solver.h
solverBackupExit
void solverBackupExit(SolverBackup_t *b)
Free the solver backup data structure.
Definition: solver_backup.c:207
solver_blok_s::gpuid
int8_t gpuid
Definition: solver.h:116
solver_cblk_s
Solver column block structure.
Definition: solver.h:127
solver_blok_s
Solver block structure.
Definition: solver.h:107
task_s::ctrbcnt
pastix_int_t volatile ctrbcnt
Definition: solver.h:95
task_s
The task structure for the numerical factorization.
Definition: solver.h:90
PASTIX_SUCCESS
@ PASTIX_SUCCESS
Definition: api.h:346
solver_cblk_s::brownum
pastix_int_t brownum
Definition: solver.h:137
solver_cblk_s::ctrbcnt
volatile int32_t ctrbcnt
Definition: solver.h:129
GPUID_UNDEFINED
#define GPUID_UNDEFINED
Definition: solver.h:101
solver_cblk_s::gpuid
int8_t gpuid
Definition: solver.h:131
solverBackupInit
SolverBackup_t * solverBackupInit(const SolverMatrix *solvmtx)
Initialize the backup structure.
Definition: solver_backup.c:59
solverBackupRestore
int solverBackupRestore(SolverMatrix *solvmtx, const SolverBackup_t *b)
Restore initial values.
Definition: solver_backup.c:140
PASTIX_ERR_BADPARAMETER
@ PASTIX_ERR_BADPARAMETER
Definition: api.h:353
solver_blok_s::fcblknm
pastix_int_t fcblknm
Definition: solver.h:110