PaStiX Handbook  6.3.2
symbol_io.c
Go to the documentation of this file.
1 /**
2  *
3  * @file symbol_io.c
4  *
5  * PaStiX symbol structure IO 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 David Goudin
12  * @author Pascal Henon
13  * @author Francois Pellegrini
14  * @author Pierre Ramet
15  * @author Mathieu Faverge
16  * @date 2023-07-21
17  *
18  * Dates:
19  * Version 0.0 - from 23 aug 1998 to 07 oct 1998
20  * Version 0.1 - from 21 mar 2002 to 21 mar 2002
21  * Version 1.0 - from 03 jun 2002 to 08 sep 2003
22  * Version 3.0 - from 29 feb 2004 to 29 feb 2004
23  *
24  * @addtogroup pastix_symbol
25  * @{
26  *
27  */
28 #include "common.h"
29 #include "symbol/symbol.h"
30 
31 /**
32  *******************************************************************************
33  *
34  * @brief Load the given block matrix structure from the given stream.
35  *
36  *******************************************************************************
37  *
38  * @param[inout] symbptr
39  * The symbolic matrix structure to fill in.
40  *
41  * @param[inout] stream
42  * The stream from which to read the structure.
43  *
44  *******************************************************************************
45  *
46  * @retval 0 on success.
47  * @retval !0 on failure.
48  *
49  *******************************************************************************/
50 int
52  FILE * const stream )
53 {
54  pastix_int_t versval;
55  pastix_int_t baseval;
56  pastix_int_t nodenbr;
57  pastix_int_t cblknbr;
58  pastix_int_t cblknum;
59  pastix_int_t bloknbr;
60  pastix_int_t bloknum;
61 
62  if ((intLoad (stream, &versval) + /* Read header */
63  intLoad (stream, &cblknbr) +
64  intLoad (stream, &bloknbr) +
65  intLoad (stream, &nodenbr) +
66  intLoad (stream, &baseval) != 5) ||
67  (versval < 0) || /* Version should be 0 or 1 */
68  (versval > 1) ||
69  (bloknbr < cblknbr) ||
70  (nodenbr < cblknbr)) {
71  pastix_print_error( "symbolLoad: bad input (1)" );
72  return (1);
73  }
74 
75  if (((symbptr->cblktab = (symbol_cblk_t *) memAlloc ((cblknbr + 1) * sizeof (symbol_cblk_t))) == NULL) ||
76  ((symbptr->bloktab = (symbol_blok_t *) memAlloc ( bloknbr * sizeof (symbol_blok_t))) == NULL)) {
77  pastix_print_error( "symbolLoad: out of memory" );
78  pastixSymbolExit (symbptr);
79  return (1);
80  }
81  symbptr->baseval = baseval;
82  symbptr->cblknbr = cblknbr;
83  symbptr->bloknbr = bloknbr;
84  symbptr->nodenbr = nodenbr;
85 
86  for (cblknum = 0; cblknum < cblknbr; cblknum ++) {
87  if ((intLoad (stream, &symbptr->cblktab[cblknum].fcolnum) + /* Read column blocks */
88  intLoad (stream, &symbptr->cblktab[cblknum].lcolnum) +
89  intLoad (stream, &symbptr->cblktab[cblknum].bloknum) != 3) ||
90  (symbptr->cblktab[cblknum].fcolnum > symbptr->cblktab[cblknum].lcolnum)) {
91  pastix_print_error( "symbolLoad: bad input (2)" );
92  pastixSymbolExit (symbptr);
93  return (1);
94  }
95  }
96  symbptr->cblktab[cblknbr].fcolnum = /* Set last column block */
97  symbptr->cblktab[cblknbr].lcolnum = nodenbr + baseval;
98  symbptr->cblktab[cblknbr].bloknum = bloknbr + baseval;
99 
100  for (bloknum = 0; bloknum < bloknbr; bloknum ++) {
101  if ((intLoad (stream, &symbptr->bloktab[bloknum].frownum) + /* Read column blocks */
102  intLoad (stream, &symbptr->bloktab[bloknum].lrownum) +
103  intLoad (stream, &symbptr->bloktab[bloknum].fcblknm) != 3) ||
104  (symbptr->bloktab[bloknum].frownum > symbptr->bloktab[bloknum].lrownum)) {
105  pastix_print_error( "symbolLoad: bad input (3)" );
106  pastixSymbolExit (symbptr);
107  return (1);
108  }
109 
110  /* This block is required for old file compatibility: will be removed */
111  if (0)
112  {
113  pastix_int_t tmp;
114  if ((versval > 0) && (intLoad (stream, &tmp) != 1)) {
115  pastix_print_error( "symbolLoad: bad input (4)" );
116  pastixSymbolExit (symbptr);
117  return (1);
118  }
119  }
120  }
121 
122  // TODO: store the value and read it
123  symbptr->dof = 1;
124  return (0);
125 }
126 
127 /**
128  *******************************************************************************
129  *
130  * @brief Save the given block matrix structure to the given stream.
131  *
132  *******************************************************************************
133  *
134  * @param[inout] symbptr
135  * The symbolic matrix structure to write.
136  *
137  * @param[inout] stream
138  * The stream to which to write the structure.
139  *
140  *******************************************************************************
141  *
142  * @retval 0 on success.
143  * @retval !0 on failure.
144  *
145  *******************************************************************************/
146 int
147 pastixSymbolSave( const symbol_matrix_t * const symbptr,
148  FILE * const stream )
149 {
150  const symbol_cblk_t *cblktnd;
151  const symbol_cblk_t *cblkptr;
152  const symbol_blok_t *bloktnd;
153  const symbol_blok_t *blokptr;
154  int o;
155 
156  o = (fprintf (stream, "1\n%ld\t%ld\t%ld\t%ld\n", /* Write file header */
157  (long) symbptr->cblknbr,
158  (long) symbptr->bloknbr,
159  (long) symbptr->nodenbr,
160  (long) symbptr->baseval) == EOF);
161  for (cblkptr = symbptr->cblktab, cblktnd = cblkptr + symbptr->cblknbr;
162  (cblkptr < cblktnd) && (o == 0); cblkptr ++) {
163  o = (fprintf (stream, "%ld\t%ld\t%ld\n",
164  (long) cblkptr->fcolnum,
165  (long) cblkptr->lcolnum,
166  (long) cblkptr->bloknum) == EOF);
167  }
168  for (blokptr = symbptr->bloktab, bloktnd = blokptr + symbptr->bloknbr;
169  (blokptr < bloktnd) && (o == 0); blokptr ++) {
170  o = (fprintf (stream, "%ld\t%ld\t%ld\n",
171  (long) blokptr->frownum,
172  (long) blokptr->lrownum,
173  (long) blokptr->fcblknm ) == EOF);
174  }
175 
176  return (o);
177 }
178 
179 /**
180  *******************************************************************************
181  *
182  * @brief Print the given block matrix structure in human readable format.
183  *
184  *******************************************************************************
185  *
186  * @param[inout] symbptr
187  * The symbolic matrix structure to write.
188  *
189  * @param[inout] file
190  * The file stream to which to write the structure.
191  *
192  *******************************************************************************/
193 void
195  FILE *file )
196 {
197  pastix_int_t i, j;
198  for(i=0;i<symbptr->cblknbr;i++)
199  {
200  fprintf(file, "CBLK %ld [%ld : %ld ] \n",
201  (long)i,
202  (long)symbptr->cblktab[i].fcolnum,
203  (long)symbptr->cblktab[i].lcolnum );
204  for(j=symbptr->cblktab[i].bloknum;
205  j<symbptr->cblktab[i+1].bloknum;j++) {
206  fprintf(file, "--BLOK %ld [%ld : %ld ]\n",
207  (long)j,
208  (long)symbptr->bloktab[j].frownum,
209  (long)symbptr->bloktab[j].lrownum );
210  }
211  fprintf(file, "\n");
212  }
213 }
214 
215 /**
216  * @}
217  */
BEGIN_C_DECLS typedef int pastix_int_t
Definition: datatypes.h:51
pastix_int_t fcblknm
Definition: symbol.h:63
pastix_int_t frownum
Definition: symbol.h:60
pastix_int_t lrownum
Definition: symbol.h:61
pastix_int_t bloknbr
Definition: symbol.h:80
pastix_int_t baseval
Definition: symbol.h:78
symbol_cblk_t * cblktab
Definition: symbol.h:83
pastix_int_t bloknum
Definition: symbol.h:48
pastix_int_t fcolnum
Definition: symbol.h:46
pastix_int_t lcolnum
Definition: symbol.h:47
pastix_int_t dof
Definition: symbol.h:87
symbol_blok_t * bloktab
Definition: symbol.h:84
pastix_int_t nodenbr
Definition: symbol.h:81
pastix_int_t cblknbr
Definition: symbol.h:79
void pastixSymbolPrint(const symbol_matrix_t *symbptr, FILE *file)
Print the given block matrix structure in human readable format.
Definition: symbol_io.c:194
int pastixSymbolSave(const symbol_matrix_t *symbptr, FILE *stream)
Save the given block matrix structure to the given stream.
Definition: symbol_io.c:147
int pastixSymbolLoad(symbol_matrix_t *symbptr, FILE *stream)
Load the given block matrix structure from the given stream.
Definition: symbol_io.c:51
void pastixSymbolExit(symbol_matrix_t *symbptr)
Free the content of symbolic matrix.
Definition: symbol.c:137
Symbol block structure.
Definition: symbol.h:59
Symbol column block structure.
Definition: symbol.h:45
Symbol matrix structure.
Definition: symbol.h:77