PaStiX Handbook 6.4.0
Loading...
Searching...
No Matches
solver_draw.c
Go to the documentation of this file.
1/**
2 *
3 * @file solver_draw.c
4 *
5 * PaStiX solver structure drawing function.
6 *
7 * @copyright 2004-2025 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
8 * Univ. Bordeaux. All rights reserved.
9 *
10 * @version 6.4.0
11 * @author Gregoire Pichon
12 * @author Mathieu Faverge
13 * @author Pierre Ramet
14 * @date 2024-07-05
15 *
16 **/
17#include "common.h"
18#include "symbol/symbol.h"
19#include "blend/solver.h"
20
21#ifndef DOXYGEN_SHOULD_SKIP_THIS
22/*+ Generic PostScript (tm) output definitions. +*/
23#define SOLVER_PSDPI 72 /*+ PostScript dots-per-inch +*/
24#define SOLVER_PSPICTSIZE 6.6 /*+ PostScript picture size (in inches) +*/
25#endif /* DOXYGEN_SHOULD_SKIP_THIS */
26
27/**
28 *******************************************************************************
29 *
30 * @ingroup blend_dev_solver
31 *
32 * @brief Writes a PostScript picture of the low-rank solver matrix.
33 *
34 *******************************************************************************
35 *
36 * @param[in] solvptr
37 * The solver structure of PaStiX
38 *
39 * @param[inout] stream
40 * File to write the PostScript
41 *
42 * @param[in] verbose
43 * Level of verbosity. If verbose > 4, the number of updates is printed
44 * on each low-rank block.
45 *
46 * @param[in] directory
47 * Tempory directory for output files
48 *
49 *******************************************************************************
50 *
51 * @retval 0 if success
52 * @retval != 0, otherwise
53 *
54 *******************************************************************************/
55int
56solverDraw ( const SolverMatrix * const solvptr,
57 FILE * const stream,
58 int verbose,
59 const char *directory )
60{
61 pastix_int_t cblknum; /* Number of current column block */
62 time_t picttime; /* Creation time */
63 double pictsize; /* Number of distinct coordinates */
64 int o;
65
66 time (&picttime); /* Get current time */
67 pictsize = (double) (solvptr->nodenbr + 1); /* Get matrix size */
68
69 fprintf (stream, "%%!PS-Adobe-2.0 EPSF-2.0\n"); /* Write header */
70 fprintf (stream, "%%%%Title: pastixSymbolmatrix (%ld,%ld,%ld)\n",
71 (long) solvptr->cblknbr, (long) solvptr->bloknbr, (long)solvptr->nodenbr);
72 fprintf (stream, "%%%%Creator: pastixSymbolDraw (LaBRI, Universite Bordeaux I)\n");
73 fprintf (stream, "%%%%CreationDate: %s", ctime (&picttime));
74 fprintf (stream, "%%%%BoundingBox: 0 0 %ld %ld\n",
75 (long) (SOLVER_PSPICTSIZE * SOLVER_PSDPI),
76 (long) (SOLVER_PSPICTSIZE * SOLVER_PSDPI));
77 fprintf (stream, "%%%%Pages: 0\n");
78 fprintf (stream, "%%%%EndComments\n"); /* Write shortcuts */
79 fprintf (stream, "/c { 4 2 roll pop pop newpath 2 copy 2 copy moveto dup lineto dup lineto closepath fill } bind def\n");
80 fprintf (stream, "/d { 4 2 roll pop pop newpath 2 copy 2 copy moveto dup lineto dup lineto closepath } bind def\n");
81 fprintf (stream, "/b { 4 copy 2 index exch moveto lineto dup 3 index lineto exch lineto closepath fill pop } bind def\n");
82 fprintf (stream, "/a { 4 copy 2 index exch moveto lineto dup 3 index lineto exch lineto closepath pop } bind def\n");
83 fprintf (stream, "/r { setrgbcolor } bind def\n");
84 fprintf (stream, "/g { setgray } bind def\n");
85
86 fprintf (stream, "0 setlinecap\n"); /* Use miter caps */
87 fprintf (stream, "%f dup scale\n", /* Print scaling factor */
88 (double) SOLVER_PSDPI * SOLVER_PSPICTSIZE / pictsize);
89 fprintf (stream, "/Times-Roman 70 selectfont\n"); /* activate text in eps file */
90 fprintf (stream, "[ 1 0 0 -1 0 %d ] concat\n", /* Reverse Y coordinate */
91 (int) (solvptr->nodenbr + 1));
92
93 fprintf (stream, "0 0\n"); /* Output fake column block */
94 for (cblknum = 0; cblknum < solvptr->cblknbr; cblknum ++) {
95 float coloval[3]; /* Color of diagonal block and previous color */
96 SolverCblk *cblk = &solvptr->cblktab[cblknum];
97 pastix_int_t ncols = cblk_colnbr( cblk );
98 SolverBlok *blok = cblk[0].fblokptr+1;
99 SolverBlok *lblok = cblk[1].fblokptr;
100
101
102 coloval[0] = 0.5;
103 coloval[1] = 0.5;
104 coloval[2] = 0.5;
105 if ((coloval[0] == coloval[1]) &&
106 (coloval[1] == coloval[2])) {
107 fprintf (stream, "%.2g g ",
108 (float) coloval[0]);
109 }
110 else {
111 fprintf (stream, "%.2g %.2g %.2g r \n",
112 (float) coloval[0], (float) coloval[1], (float) coloval[2]);
113 }
114
115 fprintf (stream, "%ld\t%ld\tc\n", /* Begin new column block */
116 (long) (cblk->fcolnum - solvptr->baseval),
117 (long) (cblk->lcolnum - solvptr->baseval + 1));
118
119
120 for (; blok<lblok; blok++)
121 {
122 if ( !(cblk->cblktype & CBLK_COMPRESSED) ) {
123 fprintf (stream, "%.2g %.2g %.2g r \n",
124 0.5, 0.5, 0.5);
125 }
126 else{
127 pastix_int_t nrows = blok_rownbr( blok );
128 pastix_int_t conso_dense = 2*nrows*ncols;
129 pastix_int_t conso_LR = 0;
130 double gain;
131
132 if (blok->LRblock[0]->rk != -1){
133 conso_LR += (((nrows+ncols) * blok->LRblock[0]->rk));
134 }
135 else{
136 conso_LR += nrows*ncols;
137 }
138 if (blok->LRblock[1]->rk != -1){
139 conso_LR += (((nrows+ncols) * blok->LRblock[1]->rk));
140 }
141 else{
142 conso_LR += nrows*ncols;
143 }
144
145 gain = 1.0 * conso_dense / conso_LR;
146
147 /* There is no compression */
148 if (gain == 1.){
149 fprintf(stream, "%.2g %.2g %.2g r \n",
150 0., 0., 0.);
151 }
152 /* Small amount of compression: red */
153 else if (gain < 5.) {
154 fprintf(stream, "%.2g %.2g %.2g r \n",
155 gain / 5., 0., 0.);
156 }
157 /* Huge amount of compression */
158 else {
159 float color = 0.5 + (gain-5) / 10.;
160 if (color > 1) {
161 color = 1.;
162 }
163 fprintf(stream, "%.2g %.2g %.2g r \n",
164 0., color, 0.);
165 }
166 }
167
168 fprintf (stream, "%ld\t%ld\tb\n", /* Write block in column block */
169 (long) (blok->frownum - solvptr->baseval),
170 (long) (blok->lrownum - solvptr->baseval + 1));
171 }
172 }
173
174 /* Plot numbers */
175 if (verbose > 4){
176 FILE *fd1, *fd2, *fd3;
177 int original_cblk = 1;
178 double color = 0.2;
179 int factoLU = (solvptr->factotype == PastixFactLU) ? 1 : 0;
180
181 fd1 = pastix_fopenw( directory, "contribblok.txt", "r" );
182 fd2 = pastix_fopenw( directory, "contribcblk.txt", "r" );
183 fd3 = pastix_fopenw( directory, "stats.txt", "w" );
184
185 fprintf(fd3, "%ld\n", (long)(solvptr->bloknbr-solvptr->cblknbr));
186
187 fprintf (stream, "0 0\n"); /* Output fake column block */
188 for (cblknum = 0; cblknum < solvptr->cblknbr; cblknum ++) {
189 int unused, nb_contrib;
190 SolverCblk *cblk = &solvptr->cblktab[cblknum];
191 pastix_int_t ncols = cblk_colnbr( cblk );
192 SolverBlok *blok = cblk[0].fblokptr+1;
193 SolverBlok *lblok = cblk[1].fblokptr;
194 if ( 3 != fscanf(fd2, "%d %d %d\n", &unused, &nb_contrib, &original_cblk) ) {
195 fclose(fd1); fclose(fd2); fclose(fd3);
196 return PASTIX_ERR_FILE;
197 }
198 fprintf (stream, "%.2g g %ld\t%ld\tc\n", /* Begin new column block */
199 color,
200 (long) (cblk->fcolnum - solvptr->baseval),
201 (long) (cblk->lcolnum - solvptr->baseval + 1));
202 if ( cblk->cblktype & CBLK_COMPRESSED ) {
203 fprintf (stream, "%ld\t%ld\t4 copy 3 index exch moveto [ 1 0 0 -1 0 0 ] concat 0.0 0.0 0.0 setrgbcolor (%d) show [ 1 0 0 -1 0 0 ] concat pop\n",
204 (long) (cblk->fcolnum - solvptr->baseval),
205 (long) (cblk->lcolnum - solvptr->baseval + 1),
206 nb_contrib);
207 }
208
209
210 for (; blok<lblok; blok++)
211 {
212 int unused, nb_contrib;
213 double gain = 0;
214
215 if ( 2 != fscanf(fd1, "%d %d\n", &unused, &nb_contrib) ) {
216 fclose(fd1); fclose(fd2); fclose(fd3);
217 return PASTIX_ERR_FILE;
218 }
219 fprintf (stream, "%ld\t%ld\ta\n", /* Write block in column block */
220 (long) (blok->frownum - solvptr->baseval),
221 (long) (blok->lrownum - solvptr->baseval + 1));
222 if ( cblk->cblktype & CBLK_COMPRESSED ) {
223 pastix_int_t nrows = blok_rownbr( blok );
224 pastix_int_t conso_dense = 2*nrows*ncols;
225 pastix_int_t conso_LR = 0;
226 fprintf (stream, "%ld\t%ld\t4 copy 3 index exch moveto [ 1 0 0 -1 0 0 ] concat 1.0 1.0 1.0 setrgbcolor (%d) show [ 1 0 0 -1 0 0 ] concat pop\n",
227 (long) (blok->frownum - solvptr->baseval),
228 (long) (blok->lrownum - solvptr->baseval + 1),
229 nb_contrib);
230
231 if (blok->LRblock[0]->rk != -1){
232 conso_LR += (((nrows+ncols) * blok->LRblock[0]->rk));
233 }
234 else{
235 conso_LR += nrows*ncols;
236 }
237 if (factoLU){
238 if (blok->LRblock[1]->rk != -1){
239 conso_LR += (((nrows+ncols) * blok->LRblock[1]->rk));
240 }
241 else{
242 conso_LR += nrows*ncols;
243 }
244 }
245
246 gain = 1.0 * conso_dense / conso_LR;
247 }
248 fprintf(fd3, "%d\n%f\n", nb_contrib, gain);
249 }
250
251 if (original_cblk == 0){
252 if (color < 0.3) {
253 color = 0.8;
254 }
255 else {
256 color = 0.2;
257 }
258 }
259 }
260 fclose(fd1);
261 fclose(fd2);
262 fclose(fd3);
263 }
264
265 fprintf (stream, "pop pop\n"); /* Purge last column block indexes */
266 o = fprintf (stream, "showpage\n"); /* Restore context */
267
268
269 return ((o != EOF) ? 0 : 1);
270}
BEGIN_C_DECLS typedef int pastix_int_t
Definition datatypes.h:51
int solverDraw(const SolverMatrix *const solvptr, FILE *const stream, int verbose, const char *directory)
Writes a PostScript picture of the low-rank solver matrix.
Definition solver_draw.c:56
FILE * pastix_fopenw(const char *dirname, const char *filename, const char *mode)
Open a file in the unique directory of the pastix instance.
Definition api.c:251
@ PastixFactLU
Definition api.h:317
@ PASTIX_ERR_FILE
Definition api.h:375
pastix_int_t nodenbr
Definition solver.h:208
static pastix_int_t blok_rownbr(const SolverBlok *blok)
Compute the number of rows of a block.
Definition solver.h:395
pastix_int_t baseval
Definition solver.h:207
pastix_int_t lrownum
Definition solver.h:148
static pastix_int_t cblk_colnbr(const SolverCblk *cblk)
Compute the number of columns in a column block.
Definition solver.h:329
pastix_int_t cblknbr
Definition solver.h:211
pastix_int_t frownum
Definition solver.h:147
pastix_factotype_t factotype
Definition solver.h:237
SolverBlok * fblokptr
Definition solver.h:168
pastix_int_t bloknbr
Definition solver.h:224
pastix_lrblock_t * LRblock[2]
Definition solver.h:155
SolverCblk *restrict cblktab
Definition solver.h:228
int8_t cblktype
Definition solver.h:164
pastix_int_t lcolnum
Definition solver.h:167
pastix_int_t fcolnum
Definition solver.h:166
Solver block structure.
Definition solver.h:141
Solver column block structure.
Definition solver.h:161
Solver column block structure.
Definition solver.h:203