PaStiX Handbook 6.4.0
Loading...
Searching...
No Matches
solver_io.c
Go to the documentation of this file.
1/**
2 *
3 * @file solver_io.c
4 *
5 * PaStiX solver structure I/O 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 * @date 2024-07-05
15 *
16 **/
17#include "common.h"
18#include "symbol/symbol.h"
19#include "queue.h"
20#include "blend/solver.h"
21
22/**
23 *******************************************************************************
24 *
25 * @ingroup blend_dev_solver
26 *
27 * @brief Load a solver matrix structure from a file.
28 *
29 *******************************************************************************
30 *
31 * @param[inout] solvptr
32 * The allocated pointer to a solver structure initialized. No need to
33 * initialized it with solverInit().
34 *
35 * @param[in] stream
36 * The stream where to read the informations.
37 *
38 *******************************************************************************
39 *
40 * @retval PASTIX_SUCCESS on successful exit,
41 * @retval PASTIX_ERR_FILE if a problem occurs during the read.
42 *
43 *******************************************************************************/
44int
46 FILE *stream )
47{
48 pastix_int_t i,j;
49 pastix_int_t clustnbr, clustnum;
50 SolverCblk *cblkptr;
51 SolverCblk *cblktnd;
52 SolverBlok *blokptr;
53 SolverBlok *bloktnd;
54 Task *taskptr;
55 Task *tasknd;
56
57 pastix_int_t versval;
58 pastix_int_t baseval;
59 pastix_int_t nodenbr;
60 pastix_int_t cblknbr;
61 pastix_int_t cblknum;
62 pastix_int_t bloknbr;
63 pastix_int_t bloknum;
64 pastix_int_t tmp;
65
66 solverInit(solvptr);
67
68 /** Load the symbol matrix **/
69 if ((intLoad (stream, &versval) + /* Read header */
70 intLoad (stream, &cblknbr) +
71 intLoad (stream, &bloknbr) +
72 intLoad (stream, &nodenbr) +
73 intLoad (stream, &baseval) != 5) ||
74 (versval < 0) || /* Version should be 0 or 1 */
75 (versval > 2) ||
76 (bloknbr < cblknbr) ||
77 (nodenbr < cblknbr)) {
78 pastix_print_error( "solverLoad: bad input (1)" );
79 return PASTIX_ERR_FILE;
80 }
81
82 if ( versval > 1 ) {
83 pastix_print_error( "solverLoad: Version 0 and 1 of the solver files are not supported anymore" );
84 return PASTIX_ERR_FILE;
85 }
86
87 MALLOC_INTERN(solvptr->cblktab, cblknbr + 1, SolverCblk);
88 MALLOC_INTERN(solvptr->bloktab, bloknbr, SolverBlok);
89 if (solvptr->cblktab == NULL || solvptr->bloktab == NULL) {
90 pastix_print_error( "solverLoad: out of memory" );
91 solverExit (solvptr);
92 solverInit (solvptr);
93 return PASTIX_ERR_FILE;
94 }
95 solvptr->baseval = baseval;
96 solvptr->cblknbr = cblknbr;
97 solvptr->bloknbr = bloknbr;
98 solvptr->nodenbr = nodenbr;
99
100 for (cblknum = 0; cblknum < cblknbr; cblknum ++) {
101 if ((intLoad (stream, &solvptr->cblktab[cblknum].fcolnum) + /* Read column blocks */
102 intLoad (stream, &solvptr->cblktab[cblknum].lcolnum) +
103 intLoad (stream, &bloknum) != 3) ||
104 (solvptr->cblktab[cblknum].fcolnum > solvptr->cblktab[cblknum].lcolnum)) {
105 pastix_print_error( "solverLoad: bad input (2)" );
106 /* solverExit (solvptr); */
107 /* solverInit (solvptr); */
108 return PASTIX_ERR_FILE;
109 }
110 solvptr->cblktab[cblknum].fblokptr = solvptr->bloktab+bloknum;
111 }
112 solvptr->cblktab[cblknbr].fcolnum = /* Set last column block */
113 solvptr->cblktab[cblknbr].lcolnum = nodenbr + baseval;
114 solvptr->cblktab[cblknbr].fblokptr = solvptr->bloktab + bloknbr;
115
116 for (bloknum = 0; bloknum < bloknbr; bloknum ++) {
117 if ((intLoad (stream, &solvptr->bloktab[bloknum].frownum) + /* Read column blocks */
118 intLoad (stream, &solvptr->bloktab[bloknum].lrownum) +
119 intLoad (stream, &solvptr->bloktab[bloknum].fcblknm) != 3) ||
120 (solvptr->bloktab[bloknum].frownum > solvptr->bloktab[bloknum].lrownum)) {
121 pastix_print_error( "solverLoad: bad input (3)" );
122 solverExit (solvptr);
123 solverInit (solvptr);
124 return PASTIX_ERR_FILE;
125 }
126
127 {
128 pastix_int_t levfval;
129 if ((versval == 0) &&
130 ((intLoad (stream, &levfval) != 1) ||
131 (levfval < 0))) {
132 pastix_print_error( "solverLoad: bad input (4)" );
133 solverExit (solvptr);
134 solverInit (solvptr);
135 return PASTIX_ERR_FILE;
136 }
137 }
138 }
139
140
141 if( intLoad (stream, &solvptr->coefnbr) +
142 intLoad (stream, &solvptr->gemmmax) +
143 intLoad (stream, &tmp) +
144 intLoad (stream, &tmp) +
145 intLoad (stream, &clustnum) +
146 intLoad (stream, &clustnbr) +
147 intLoad (stream, &solvptr->tasknbr) +
148 intLoad (stream, &solvptr->procnbr) +
149 intLoad (stream, &solvptr->thrdnbr)
150 != 11 )
151 {
152 pastix_print_error( "solverLoad: bad input (1)" );
153 return PASTIX_ERR_FILE;
154 }
155
156 solvptr->clustnbr = (pastix_int_t)clustnbr;
157 solvptr->clustnum = (pastix_int_t)clustnum;
158
159 if (((solvptr->cblktab = (SolverCblk *) memAlloc((solvptr->cblknbr + 1) * sizeof(SolverCblk) )) == NULL) ||
160 ((solvptr->bloktab = (SolverBlok *) memAlloc( solvptr->bloknbr * sizeof(SolverBlok) )) == NULL) ||
161 ((solvptr->tasktab = (Task *) memAlloc((solvptr->tasknbr+1) * sizeof(Task) )) == NULL) ||
162 ((solvptr->ttsknbr = (pastix_int_t *) memAlloc((solvptr->thrdnbr) * sizeof(pastix_int_t) )) == NULL) ||
163 ((solvptr->ttsktab = (pastix_int_t **)memAlloc((solvptr->thrdnbr) * sizeof(pastix_int_t *))) == NULL) )
164 {
165 pastix_print_error( "solverLoad: out of memory (1)" );
166 if (solvptr->cblktab != NULL) {
167 memFree_null (solvptr->cblktab);
168 }
169 if (solvptr->bloktab != NULL) {
170 memFree_null (solvptr->bloktab);
171 }
172 if (solvptr->tasktab != NULL) {
173 memFree_null (solvptr->tasktab);
174 }
175 return PASTIX_ERR_FILE;
176 }
177
178 for (cblkptr = solvptr->cblktab, /* Read column block data */
179 cblktnd = cblkptr + solvptr->cblknbr;
180 cblkptr < cblktnd; cblkptr ++)
181 {
182 if (intLoad (stream, &cblkptr->stride) != 1)
183 {
184 pastix_print_error( "solverlLoad: bad input (2)" );
185 solverExit (solvptr);
186 return PASTIX_ERR_FILE;
187 }
188 }
189
190 for (blokptr = solvptr->bloktab, /* Read block data */
191 bloktnd = blokptr + solvptr->bloknbr;
192 blokptr < bloktnd; blokptr ++)
193 {
194 if (intLoad (stream, &blokptr->coefind) != 1)
195 {
196 pastix_print_error( "solverLoad: bad input (3)" );
197 solverExit (solvptr);
198 return PASTIX_ERR_FILE;
199 }
200
201 }
202
203 for (taskptr = solvptr->tasktab, /** Read Task data **/
204 tasknd = taskptr + solvptr->tasknbr +1;
205 (taskptr < tasknd); taskptr ++)
206 {
207 pastix_int_t temp;
208
209 intLoad(stream, &(taskptr->taskid));
210 intLoad(stream, &(taskptr->prionum));
211 intLoad(stream, &(taskptr->cblknum));
212 intLoad(stream, &(taskptr->bloknum));
213 {
214 /* volatile pb alpha */
215 intLoad(stream, &temp);
216 taskptr->ctrbcnt = temp;
217 }
218 }
219
220 for(i=0;i<solvptr->thrdnbr;i++) /** Read task by thread data **/
221 {
222 intLoad(stream, &(solvptr->ttsknbr[i]));
223 MALLOC_INTERN(solvptr->ttsktab[i], solvptr->ttsknbr[i], pastix_int_t);
224 if (solvptr->ttsktab[i] == NULL)
225 {
226 pastix_print_error( "solverLoad: out of memory (1)" );
227 return 1;
228 }
229 for (j=0;j<solvptr->ttsknbr[i];j++)
230 {
231 intLoad(stream, &(solvptr->ttsktab[i][j]));
232 }
233 }
234
235 return PASTIX_SUCCESS;
236}
237
238/**
239 *******************************************************************************
240 *
241 * @ingroup blend_dev_solver
242 *
243 * @brief Save a solver matrix structure into a file.
244 *
245 *******************************************************************************
246 *
247 * @param[inout] solvptr
248 * The solver matrix structure to dump to disk.
249 *
250 * @param[in] stream
251 * The stream where to write the ordering.
252 *
253 *******************************************************************************
254 *
255 * @retval PASTIX_SUCCESS on successful exit,
256 * @retval PASTIX_ERR_BADPARAMETER if the ordeptr structure is incorrect,
257 * @retval PASTIX_ERR_FILE if a problem occurs during the write.
258 *
259 *******************************************************************************/
260int
261solverSave( const SolverMatrix *solvptr,
262 FILE *stream )
263{
264 pastix_int_t i, j, o;
265 SolverCblk *cblkptr;
266 SolverCblk *cblktnd;
267 SolverBlok *blokptr;
268 SolverBlok *bloktnd;
269 Task *taskptr;
270
271 /* Save the solver matrix */
272 {
273 const SolverCblk *cblktnd;
274 const SolverCblk *cblkptr;
275 const SolverBlok *bloktnd;
276 const SolverBlok *blokptr;
277
278 o = (fprintf (stream, "2\n%ld\t%ld\t%ld\t%ld\n", /* Write file header */
279 (long) solvptr->cblknbr,
280 (long) solvptr->bloknbr,
281 (long) solvptr->nodenbr,
282 (long) solvptr->baseval) == EOF);
283 for (cblkptr = solvptr->cblktab, cblktnd = cblkptr + solvptr->cblknbr;
284 (cblkptr < cblktnd) && (o == 0); cblkptr ++) {
285 o = (fprintf (stream, "%ld\t%ld\t%ld\n",
286 (long) cblkptr->fcolnum,
287 (long) cblkptr->lcolnum,
288 (long) (cblkptr->fblokptr - solvptr->bloktab)) == EOF);
289 }
290 for (blokptr = solvptr->bloktab, bloktnd = blokptr + solvptr->bloknbr;
291 (blokptr < bloktnd) && (o == 0); blokptr ++) {
292 o = (fprintf (stream, "%ld\t%ld\t%ld\n",/* "%ld\t%ld\t%ld\t%ld\n", */
293 (long) blokptr->frownum,
294 (long) blokptr->lrownum,
295 (long) blokptr->fcblknm/* , */
296 /* (long) blokptr->levfval */) == EOF);
297 }
298 }
299
300 /* Write file header */
301 o = (fprintf (stream, "\n%ld\t%ld\t%ld\t%ld\t%ld\t%ld\t%ld\t%ld\t%ld\n",
302 (long) solvptr->coefnbr,
303 (long) solvptr->gemmmax,
304 (long) 0, /*solvptr->nbftmax,*/
305 (long) 0, /*solvptr->arftmax,*/
306 (long) solvptr->clustnum,
307 (long) solvptr->clustnbr,
308 (long) solvptr->tasknbr,
309 (long) solvptr->procnbr,
310 (long) solvptr->thrdnbr
311 ) == EOF);
312
313 /* write cblk data */
314 for (cblkptr = solvptr->cblktab, cblktnd = cblkptr + solvptr->cblknbr;
315 (cblkptr < cblktnd) && (o == 0); cblkptr ++)
316 {
317 o = (fprintf (stream, "%ld\n",
318 (long) cblkptr->stride) == EOF);
319 }
320
321 /* write blok data */
322 for (blokptr = solvptr->bloktab,
323 bloktnd = blokptr + solvptr->bloknbr;
324 (blokptr < bloktnd) && (o == 0); blokptr ++)
325 {
326 o = (fprintf (stream, "%ld\n",(long) blokptr->coefind) == EOF);
327 }
328
329 fprintf(stream, "\n");
330 fprintf(stream, "\n");
331
332 /* Write Task data */
333 {
334 Task *taskend = solvptr->tasktab + solvptr->tasknbr;
335 for (taskptr = solvptr->tasktab;
336 (taskptr < taskend) && (o==0); taskptr ++)
337 {
338 fprintf(stream, "%ld\t%ld\t%ld\t%ld\t%ld\n",
339 (long)taskptr->taskid, (long)taskptr->prionum, (long)taskptr->cblknum, (long)taskptr->bloknum,
340 (long)taskptr->ctrbcnt);
341 }
342 }
343
344 /* Write ttsktab */
345 for (i=0; i<solvptr->thrdnbr; i++)
346 {
347 fprintf(stream, "%ld\n", (long)solvptr->ttsknbr[i]);
348 for (j=0; j<solvptr->ttsknbr[i]; j++)
349 {
350 fprintf(stream, "%ld\n", (long)solvptr->ttsktab[i][j]);
351 }
352 }
353
354 return o ? PASTIX_ERR_FILE : PASTIX_SUCCESS;
355}
BEGIN_C_DECLS typedef int pastix_int_t
Definition datatypes.h:51
int solverSave(const SolverMatrix *solvptr, FILE *stream)
Save a solver matrix structure into a file.
Definition solver_io.c:261
int solverLoad(SolverMatrix *solvptr, FILE *stream)
Load a solver matrix structure from a file.
Definition solver_io.c:45
void solverInit(SolverMatrix *solvmtx)
Initialize the solver structure.
Definition solver.c:118
void solverExit(SolverMatrix *solvmtx)
Free the content of the solver matrix structure.
Definition solver.c:143
@ PASTIX_SUCCESS
Definition api.h:367
@ PASTIX_ERR_FILE
Definition api.h:375
pastix_int_t nodenbr
Definition solver.h:208
pastix_int_t baseval
Definition solver.h:207
pastix_int_t taskid
Definition solver.h:123
pastix_int_t cblknum
Definition solver.h:125
pastix_int_t lrownum
Definition solver.h:148
pastix_int_t fcblknm
Definition solver.h:144
pastix_int_t cblknbr
Definition solver.h:211
SolverBlok *restrict bloktab
Definition solver.h:229
pastix_int_t frownum
Definition solver.h:147
pastix_int_t prionum
Definition solver.h:124
pastix_int_t coefind
Definition solver.h:149
SolverBlok * fblokptr
Definition solver.h:168
pastix_int_t bloknbr
Definition solver.h:224
pastix_int_t volatile ctrbcnt
Definition solver.h:127
SolverCblk *restrict cblktab
Definition solver.h:228
pastix_int_t stride
Definition solver.h:169
pastix_int_t lcolnum
Definition solver.h:167
pastix_int_t bloknum
Definition solver.h:126
pastix_int_t fcolnum
Definition solver.h:166
pastix_int_t coefnbr
Definition solver.h:209
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