PaStiX Handbook  6.3.2
solver_copy.c
Go to the documentation of this file.
1 /**
2  *
3  * @file solver_copy.c
4  *
5  * PaStiX solver matrix copy and reallocation functions.
6  *
7  * @copyright 2004-2023 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
8  * Univ. Bordeaux. All rights reserved.
9  *
10  * @version 6.3.2
11  * @author Pascal Henon
12  * @author Mathieu Faverge
13  * @author Tony Delarue
14  * @date 2023-07-21
15  *
16  **/
17 #include "common.h"
18 #include "queue.h"
19 #include "blend/solver.h"
20 
21 /**
22  *******************************************************************************
23  *
24  * @ingroup blend_dev_solver_null
25  *
26  * @brief Copy the solver matrix data structure from solvin to solvout.
27  *
28  * Every data is copied, event the coefficient if they are allocated and
29  * initialized.
30  * It is also used to reallocate the data in a contiguous way after the
31  * initialization that allocates all internal arrays in multiple step which
32  * might results in fragmentation.
33  * @warning This function is not able to copy a solver matrix with low rank
34  * blocks yet.
35  *
36  *******************************************************************************
37  *
38  * @param[in] solvin
39  * The solver matrix structure to duplicate.
40  *
41  * @param[out] solvout
42  * The allocated pointer to the solver matrix structure that will
43  * contain the copy.
44  *
45  * @param[in] flttype
46  * The floating point arithmetic used in the input solver matrix to
47  * know the size of the memory space to duplicate for the coefficients.
48  *
49  *******************************************************************************/
50 static inline void
51 solver_copy( const SolverMatrix *solvin,
52  SolverMatrix *solvout,
53  pastix_coeftype_t flttype )
54 {
55  SolverCblk *solvcblk;
56  SolverBlok *solvblok;
57  pastix_int_t i;
58 
59  /* Copy tasktab */
60  MALLOC_INTERN(solvout->tasktab, solvout->tasknbr, Task);
61  memcpy(solvout->tasktab, solvin->tasktab, solvout->tasknbr*sizeof(Task));
62 
63  /* Copy cblktab and bloktab */
64  MALLOC_INTERN(solvout->cblktab, solvout->cblknbr+1, SolverCblk);
65  memcpy(solvout->cblktab, solvin->cblktab,
66  (solvout->cblknbr+1)*sizeof(SolverCblk));
67 
68  MALLOC_INTERN(solvout->bloktab, solvout->bloknbr+1, SolverBlok);
69  memcpy(solvout->bloktab, solvin->bloktab,
70  (solvout->bloknbr+1)*sizeof(SolverBlok));
71 
72  MALLOC_INTERN(solvout->browtab, solvout->brownbr, pastix_int_t);
73  memcpy(solvout->browtab, solvin->browtab,
74  solvout->brownbr*sizeof(pastix_int_t));
75 
76  if ( solvin->gcbl2loc ) {
77  MALLOC_INTERN(solvout->gcbl2loc, solvout->gcblknbr, pastix_int_t);
78  memcpy(solvout->gcbl2loc, solvin->gcbl2loc,
79  solvout->gcblknbr*sizeof(pastix_int_t));
80  }
81  else {
82  solvout->gcbl2loc = NULL;
83  }
84 
85  solvblok = solvout->bloktab;
86  for (solvcblk = solvout->cblktab; solvcblk < solvout->cblktab + solvout->cblknbr; solvcblk++) {
87  pastix_int_t bloknbr = (solvcblk+1)->fblokptr - solvcblk->fblokptr;
88  solvcblk->fblokptr = solvblok;
89  solvblok += bloknbr;
90 
91  if ( flttype == PastixPattern ) {
92  solvcblk->lcoeftab = NULL;
93  solvcblk->ucoeftab = NULL;
94  }
95  else {
96  if ( solvcblk->cblktype & CBLK_COMPRESSED ) {
97  /* Not handled for now */
98  }
99  else {
100  void *lcoeftab = solvcblk->lcoeftab;
101  void *ucoeftab = solvcblk->ucoeftab;
102  size_t size = cblk_colnbr( solvcblk ) * solvcblk->stride
103  * pastix_size_of( flttype );
104 
105  if ( ucoeftab ) {
106  MALLOC_INTERN( solvcblk->lcoeftab, 2 * size, char );
107  solvcblk->ucoeftab = (char*)lcoeftab + size;
108  memcpy(solvcblk->lcoeftab, lcoeftab, size );
109  memcpy(solvcblk->ucoeftab, ucoeftab, size );
110  }
111  else {
112  MALLOC_INTERN( solvcblk->lcoeftab, size, char );
113  memcpy(solvcblk->lcoeftab, lcoeftab, size );
114  solvcblk->ucoeftab = NULL;
115  }
116  }
117  }
118  }
119  solvcblk->fblokptr = solvblok;
120 
121  /* Copy ttsktab & ttsknbr */
122  if (solvout->bublnbr>0)
123  {
124  MALLOC_INTERN(solvout->ttsknbr, solvout->bublnbr, pastix_int_t);
125  memcpy(solvout->ttsknbr, solvin->ttsknbr, solvout->bublnbr*sizeof(pastix_int_t));
126  MALLOC_INTERN(solvout->ttsktab, solvout->bublnbr, pastix_int_t*);
127 
128  for (i=0;i<solvout->bublnbr;i++)
129  {
130  solvout->ttsktab[i] = NULL;
131  MALLOC_INTERN(solvout->ttsktab[i], solvout->ttsknbr[i], pastix_int_t);
132  memcpy(solvout->ttsktab[i], solvin->ttsktab[i],
133  solvout->ttsknbr[i]*sizeof(pastix_int_t));
134  }
135  }
136  else
137  {
138  solvout->ttsknbr = NULL;
139  solvout->ttsktab = NULL;
140  }
141 }
142 
143 /**
144  *******************************************************************************
145  *
146  * @ingroup blend_dev_solver
147  *
148  * @brief Generate a copy of a solver matrix structure.
149  *
150  * Every data is copied, event the coefficient if they are allocated and
151  * initialized.
152  * @warning This function is not able to copy a solver matrix with low rank
153  * blocks yet.
154  *
155  *******************************************************************************
156  *
157  * @param[in] solvin
158  * The solver matrix structure to duplicate.
159  *
160  * @param[in] flttype
161  * The floating point arithmetic used in the input solver matrix to
162  * know the size of the memory space to duplicate for the coefficients.
163  *
164  *******************************************************************************
165  *
166  * @return The pointer to the solver matrix internally allocated and that is a
167  * copy of the input solver. This pointer is NULL if the copy failed.
168  *
169  *******************************************************************************/
170 SolverMatrix *
171 solverCopy( const SolverMatrix *solvin,
172  pastix_coeftype_t flttype )
173 {
174  SolverMatrix *solvout;
175 
176  MALLOC_INTERN(solvout, 1, SolverMatrix);
177  memcpy(solvout, solvin, sizeof(SolverMatrix));
178 
179  solver_copy( solvin, solvout, flttype );
180 
181  return solvout;
182 }
183 
184 /**
185  *******************************************************************************
186  *
187  * @ingroup blend_dev_solver
188  *
189  * @brief Realloc in a contiguous way a given solver structure.
190  *
191  * All internal data of the solver structure are reallocated in a contiguous
192  * manner to avoid the possible fragmentation from the initialization at
193  * runtime.
194  * @warning This function is not able to copy a solver matrix with low rank
195  * blocks yet.
196  *
197  *******************************************************************************
198  *
199  * @param[inout] solvmtx
200  * On entry, the solver matrix to reallocate.
201  * On exit, the solver matrix with all internal data reallocated.
202  *
203  *******************************************************************************/
204 void
206 {
207  SolverMatrix *tmp;
208 
209  MALLOC_INTERN(tmp, 1, SolverMatrix);
210  /** copy general info **/
211  memcpy(tmp, solvmtx, sizeof(SolverMatrix));
212 
213  solver_copy( tmp, solvmtx, PastixPattern );
214 
215  /** Free the former solver matrix **/
216  solverExit(tmp);
217  memFree_null(tmp);
218 }
BEGIN_C_DECLS typedef int pastix_int_t
Definition: datatypes.h:51
void solverRealloc(SolverMatrix *solvmtx)
Realloc in a contiguous way a given solver structure.
Definition: solver_copy.c:205
SolverMatrix * solverCopy(const SolverMatrix *solvin, pastix_coeftype_t flttype)
Generate a copy of a solver matrix structure.
Definition: solver_copy.c:171
void solverExit(SolverMatrix *solvmtx)
Free the content of the solver matrix structure.
Definition: solver.c:143
spm_coeftype_t pastix_coeftype_t
Arithmetic types.
Definition: api.h:294
void * ucoeftab
Definition: solver.h:172
pastix_int_t gcblknbr
Definition: solver.h:207
static pastix_int_t cblk_colnbr(const SolverCblk *cblk)
Compute the number of columns in a column block.
Definition: solver.h:324
pastix_int_t cblknbr
Definition: solver.h:208
pastix_int_t * gcbl2loc
Definition: solver.h:228
SolverBlok *restrict bloktab
Definition: solver.h:223
pastix_int_t brownbr
Definition: solver.h:221
SolverBlok * fblokptr
Definition: solver.h:163
pastix_int_t bloknbr
Definition: solver.h:220
pastix_int_t *restrict browtab
Definition: solver.h:224
SolverCblk *restrict cblktab
Definition: solver.h:222
pastix_int_t stride
Definition: solver.h:164
int8_t cblktype
Definition: solver.h:159
void * lcoeftab
Definition: solver.h:171
Solver block structure.
Definition: solver.h:137
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
static void solver_copy(const SolverMatrix *solvin, SolverMatrix *solvout, pastix_coeftype_t flttype)
Copy the solver matrix data structure from solvin to solvout.
Definition: solver_copy.c:51