PaStiX Handbook  6.2.1
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-2021 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
8  * Univ. Bordeaux. All rights reserved.
9  *
10  * @version 6.2.0
11  * @author Gregoire Pichon
12  * @author Mathieu Faverge
13  * @author Pierre Ramet
14  * @date 2021-01-03
15  *
16  **/
17 #include "common.h"
18 #include "symbol/symbol.h"
19 #include "blend/solver.h"
20 
21 /*+ Generic PostScript (tm) output definitions. +*/
22 #define SOLVER_PSDPI 72 /*+ PostScript dots-per-inch +*/
23 #define SOLVER_PSPICTSIZE 6.6 /*+ PostScript picture size (in inches) +*/
24 
25 /**
26  *******************************************************************************
27  *
28  * @ingroup blend_dev_solver
29  *
30  * @brief Writes a PostScript picture of the low-rank solver matrix.
31  *
32  *******************************************************************************
33  *
34  * @param[in] solvptr
35  * The solver structure of PaStiX
36  *
37  * @param[inout] stream
38  * File to write the PostScript
39  *
40  * @param[in] verbose
41  * Level of verbosity. If verbose > 4, the number of updates is printed
42  * on each low-rank block.
43  *
44  * @param[in] directory
45  * Tempory directory for output files
46  *
47  *******************************************************************************
48  *
49  * @retval 0 if success
50  * @retval != 0, otherwise
51  *
52  *******************************************************************************/
53 int
54 solverDraw ( const SolverMatrix * const solvptr,
55  FILE * const stream,
56  int verbose,
57  const char *directory )
58 {
59  pastix_int_t cblknum; /* Number of current column block */
60  time_t picttime; /* Creation time */
61  double pictsize; /* Number of distinct coordinates */
62  int o;
63 
64  time (&picttime); /* Get current time */
65  pictsize = (double) (solvptr->nodenbr + 1); /* Get matrix size */
66 
67  fprintf (stream, "%%!PS-Adobe-2.0 EPSF-2.0\n"); /* Write header */
68  fprintf (stream, "%%%%Title: pastixSymbolmatrix (%ld,%ld,%ld)\n",
69  (long) solvptr->cblknbr, (long) solvptr->bloknbr, (long)solvptr->nodenbr);
70  fprintf (stream, "%%%%Creator: pastixSymbolDraw (LaBRI, Universite Bordeaux I)\n");
71  fprintf (stream, "%%%%CreationDate: %s", ctime (&picttime));
72  fprintf (stream, "%%%%BoundingBox: 0 0 %ld %ld\n",
73  (long) (SOLVER_PSPICTSIZE * SOLVER_PSDPI),
74  (long) (SOLVER_PSPICTSIZE * SOLVER_PSDPI));
75  fprintf (stream, "%%%%Pages: 0\n");
76  fprintf (stream, "%%%%EndComments\n"); /* Write shortcuts */
77  fprintf (stream, "/c { 4 2 roll pop pop newpath 2 copy 2 copy moveto dup lineto dup lineto closepath fill } bind def\n");
78  fprintf (stream, "/d { 4 2 roll pop pop newpath 2 copy 2 copy moveto dup lineto dup lineto closepath } bind def\n");
79  fprintf (stream, "/b { 4 copy 2 index exch moveto lineto dup 3 index lineto exch lineto closepath fill pop } bind def\n");
80  fprintf (stream, "/a { 4 copy 2 index exch moveto lineto dup 3 index lineto exch lineto closepath pop } bind def\n");
81  fprintf (stream, "/r { setrgbcolor } bind def\n");
82  fprintf (stream, "/g { setgray } bind def\n");
83 
84  fprintf (stream, "0 setlinecap\n"); /* Use miter caps */
85  fprintf (stream, "%f dup scale\n", /* Print scaling factor */
86  (double) SOLVER_PSDPI * SOLVER_PSPICTSIZE / pictsize);
87  fprintf (stream, "/Times-Roman 70 selectfont\n"); /* activate text in eps file */
88  fprintf (stream, "[ 1 0 0 -1 0 %d ] concat\n", /* Reverse Y coordinate */
89  (int) (solvptr->nodenbr + 1));
90 
91  fprintf (stream, "0 0\n"); /* Output fake column block */
92  for (cblknum = 0; cblknum < solvptr->cblknbr; cblknum ++) {
93  float coloval[3]; /* Color of diagonal block and previous color */
94  SolverCblk *cblk = &solvptr->cblktab[cblknum];
95  pastix_int_t ncols = cblk_colnbr( cblk );
96  SolverBlok *blok = cblk[0].fblokptr+1;
97  SolverBlok *lblok = cblk[1].fblokptr;
98 
99 
100  coloval[0] = 0.5;
101  coloval[1] = 0.5;
102  coloval[2] = 0.5;
103  if ((coloval[0] == coloval[1]) &&
104  (coloval[1] == coloval[2])) {
105  fprintf (stream, "%.2g g ",
106  (float) coloval[0]);
107  }
108  else {
109  fprintf (stream, "%.2g %.2g %.2g r \n",
110  (float) coloval[0], (float) coloval[1], (float) coloval[2]);
111  }
112 
113  fprintf (stream, "%ld\t%ld\tc\n", /* Begin new column block */
114  (long) (cblk->fcolnum - solvptr->baseval),
115  (long) (cblk->lcolnum - solvptr->baseval + 1));
116 
117 
118  for (; blok<lblok; blok++)
119  {
120  if ( !(cblk->cblktype & CBLK_COMPRESSED) ) {
121  fprintf (stream, "%.2g %.2g %.2g r \n",
122  0.5, 0.5, 0.5);
123  }
124  else{
125  pastix_int_t nrows = blok_rownbr( blok );
126  pastix_int_t conso_dense = 2*nrows*ncols;
127  pastix_int_t conso_LR = 0;
128  double gain;
129 
130  if (blok->LRblock[0]->rk != -1){
131  conso_LR += (((nrows+ncols) * blok->LRblock[0]->rk));
132  }
133  else{
134  conso_LR += nrows*ncols;
135  }
136  if (blok->LRblock[1]->rk != -1){
137  conso_LR += (((nrows+ncols) * blok->LRblock[1]->rk));
138  }
139  else{
140  conso_LR += nrows*ncols;
141  }
142 
143  gain = 1.0 * conso_dense / conso_LR;
144 
145  /* There is no compression */
146  if (gain == 1.){
147  fprintf(stream, "%.2g %.2g %.2g r \n",
148  0., 0., 0.);
149  }
150  /* Small amount of compression: red */
151  else if (gain < 5.) {
152  fprintf(stream, "%.2g %.2g %.2g r \n",
153  gain / 5., 0., 0.);
154  }
155  /* Huge amount of compression */
156  else {
157  float color = 0.5 + (gain-5) / 10.;
158  if (color > 1) {
159  color = 1.;
160  }
161  fprintf(stream, "%.2g %.2g %.2g r \n",
162  0., color, 0.);
163  }
164  }
165 
166  fprintf (stream, "%ld\t%ld\tb\n", /* Write block in column block */
167  (long) (blok->frownum - solvptr->baseval),
168  (long) (blok->lrownum - solvptr->baseval + 1));
169  }
170  }
171 
172  /* Plot numbers */
173  if (verbose > 4){
174  int nb_bloks = 0;
175  int nb_cblks = 0;
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  nb_bloks++;
249 
250  fprintf(fd3, "%d\n%f\n", nb_contrib, gain);
251  }
252 
253  if (original_cblk == 0){
254  if (color < 0.3) {
255  color = 0.8;
256  }
257  else {
258  color = 0.2;
259  }
260  }
261  nb_cblks++;
262  }
263  fclose(fd1);
264  fclose(fd2);
265  fclose(fd3);
266  }
267 
268  fprintf (stream, "pop pop\n"); /* Purge last column block indexes */
269  o = fprintf (stream, "showpage\n"); /* Restore context */
270 
271 
272  return ((o != EOF) ? 0 : 1);
273 }
solver_blok_s::frownum
pastix_int_t frownum
Definition: solver.h:112
solver.h
blok_rownbr
static pastix_int_t blok_rownbr(const SolverBlok *blok)
Compute the number of rows of a block.
Definition: solver.h:313
cblk_colnbr
static pastix_int_t cblk_colnbr(const SolverCblk *cblk)
Compute the number of columns in a column block.
Definition: solver.h:247
solver_cblk_s::fblokptr
SolverBlok * fblokptr
Definition: solver.h:134
solver_cblk_s
Solver column block structure.
Definition: solver.h:127
solver_blok_s
Solver block structure.
Definition: solver.h:107
solver_cblk_s::lcolnum
pastix_int_t lcolnum
Definition: solver.h:133
PASTIX_ERR_FILE
@ PASTIX_ERR_FILE
Definition: api.h:354
solverDraw
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:54
pastix_fopenw
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:232
symbol.h
solver_blok_s::lrownum
pastix_int_t lrownum
Definition: solver.h:113
pastix_lrblock_s::rk
int rk
Definition: pastix_lowrank.h:113
solver_cblk_s::cblktype
int8_t cblktype
Definition: solver.h:130
solver_cblk_s::fcolnum
pastix_int_t fcolnum
Definition: solver.h:132
PastixFactLU
@ PastixFactLU
Definition: api.h:304
solver_blok_s::LRblock
pastix_lrblock_t * LRblock[2]
Definition: solver.h:121