PaStiX Handbook  6.2.1
order_draw.c
Go to the documentation of this file.
1 /**
2  *
3  * @file order_draw.c
4  *
5  * PaStiX order routines dedicated to split supernodes thanks to graph connectivity
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 Tony Delarue
14  * @date 2021-01-25
15  *
16  */
17 #define _GNU_SOURCE 1
18 #include "common.h"
19 #include "order_internal.h"
20 #include "graph/graph.h"
21 #include <scotch.h>
22 
23 /**
24  *******************************************************************************
25  *
26  * @ingroup pastix_order
27  *
28  * @brief Dump the last separator into an ivview file.
29  *
30  *******************************************************************************
31  *
32  * @param[inout] pastix_data
33  * The pastix data structure that holds the graph and the ordering.
34  * On exit the output directories may be initialized, if not previously.
35  *
36  * @param[in] extname
37  * Filename extension to specify the .map file if multiple.
38  *
39  * @param[in] sndeidx
40  * The index of the supernode to dump into file.
41  *
42  * @param[in] dump
43  * Define which information to dump:
44  * - (0x1 << 0) dumps the graph file
45  * - (0x1 << 1) dumps the coordinate file
46  * - (0x1 << 2) dumps the color mapping file
47  *
48  *******************************************************************************/
49 void
50 orderDraw( pastix_data_t *pastix_data,
51  const char *extname,
52  pastix_int_t sndeidx,
53  int dump )
54 {
55  char *fname;
56  FILE *file;
57  pastix_graph_t *graph = pastix_data->graph;
58  pastix_order_t *order = pastix_data->ordemesh;
59  pastix_int_t ibeg, iend, size;
60  pastix_int_t i, j;
61  int rc;
62 
63  assert( graph != NULL );
64  assert( order != NULL );
65  assert( order->sndetab != NULL );
66 
67  ibeg = order->sndetab[sndeidx];
68  iend = order->sndetab[sndeidx+1];
69  size = iend - ibeg;
70 
71  if ( dump ) {
72  pastix_gendirectories( pastix_data );
73  }
74 
75  /*
76  * Dump the graph file
77  */
78  if ( dump & orderDrawGraph ) {
79  SCOTCH_Graph sn_sgraph;
80  pastix_graph_t sn_pgraph;
81  pastix_int_t *sn_colptr;
82  pastix_int_t *sn_rows;
83 
84  /**
85  * Extract the subgraph with unknowns of the supernode sndeidx
86  *
87  * 1 is sufficient for the max_distance in most cases, but set to 2 for
88  * corner cases that need extra connexions, and to match order_supernode.
89  */
90  graphIsolateRange( graph, order, &sn_pgraph,
91  ibeg, iend, 2 );
92 
93  sn_colptr = sn_pgraph.colptr;
94  sn_rows = sn_pgraph.rowptr;
95 
96  if ( !SCOTCH_graphInit(&sn_sgraph) )
97  {
98  SCOTCH_graphBuild( &sn_sgraph,
99  order->baseval,
100  size,
101  sn_colptr,
102  NULL,
103  NULL,
104  NULL,
105  sn_colptr[ size ] - order->baseval,
106  sn_rows,
107  NULL );
108  }
109  else
110  {
111  fprintf( stderr, "Failed to build graph\n" );
112  return;
113  }
114 
115  rc = asprintf( &fname, "part.%ld.grf", (long)sndeidx);
116  assert( rc != -1 );
117 
118  file = pastix_fopenw( pastix_data->dir_global, fname, "w" );
119  SCOTCH_graphSave( &sn_sgraph, file );
120  fclose( file );
121  free(fname);
122 
123  fprintf(stderr,"Check: %d\n", SCOTCH_graphCheck( &sn_sgraph ));
124  free(sn_colptr);
125  free(sn_rows);
126  }
127 
128  /*
129  * Dump the XYZ file
130  */
131  if ( dump & orderDrawCoordinates )
132  {
133  FILE *filein;
134  long dim, n;
135 
136  filein = fopen( "before.xyz", "r" );
137  if ( filein == NULL ) {
138  fprintf( stderr, "Please give before.xyz file\n" );
139  return;
140  }
141 
142  /* Read dimensions */
143  rc = fscanf( filein, "%ld %ld", &dim, &n );
144  if ( n != order->vertnbr ){
145  fprintf(stderr, "Cannot proceed part.xyz and part.map files: invalid number of vertices in before.xyz\n");
146  fclose(filein);
147  return;
148  }
149 
150  rc = asprintf( &fname, "part.%ld.xyz", (long)sndeidx);
151  assert( rc != -1 );
152  file = pastix_fopenw( pastix_data->dir_global, fname, "w" );
153  free( fname );
154 
155  fprintf( file, "%ld %ld\n", (long)dim, (long)size );
156  for(i=0; i<order->vertnbr; i++) {
157  long v, iv;
158  double x, y, z;
159 
160  rc = fscanf(filein, "%ld %lf %lf %lf", &v, &x, &y, &z );
161  assert( rc == 4 );
162 
163  /* If node within the selected supernode, let's keep it */
164  iv = order->permtab[i];
165  if ( (iv >= ibeg) && (iv < iend) ) {
166  fprintf( file, "%ld %lf %lf %lf\n",
167  (long)(iv - ibeg), x, y, z );
168  }
169  }
170 
171  fclose(file);
172  fclose(filein);
173  }
174 
175  /*
176  * Dump the mapping file
177  */
178  if ( dump & orderDrawMapping )
179  {
180  pastix_int_t color = 0;
181 
182  if ( extname ) {
183  rc = asprintf( &fname, "part.%ld.%s.map",
184  (long)sndeidx, extname );
185  }
186  else {
187  rc = asprintf( &fname, "part.%ld.map",
188  (long)sndeidx );
189  }
190  assert( rc != -1 );
191  file = pastix_fopenw( pastix_data->dir_global, fname, "w" );
192  free( fname );
193 
194  fprintf( file, "%ld\n", (long)size );
195 
196  /*
197  * Look for the last cblk implied in the original supernode
198  * The search is down backward to have more coherent coloring from one
199  * version to another, and because we usually draw the last supernode
200  * and no more.
201  */
202  i = order->cblknbr;
203  while ( (i > 0) && (order->rangtab[i] > iend) ) {
204  i--;
205  }
206  i--;
207 
208  for (; i>0; i--) {
209  pastix_int_t fnode = order->rangtab[i];
210  pastix_int_t lnode = order->rangtab[i+1];
211 
212  if ( fnode < ibeg ) {
213  assert( lnode <= ibeg );
214  break;
215  }
216 
217  for (j=fnode; j<lnode; j++) {
218  fprintf( file, "%ld %ld\n",
219  (long)(j - ibeg), (long)color );
220  }
221  color++;
222  }
223  fclose(file);
224  }
225  (void)rc;
226 }
orderDraw
void orderDraw(pastix_data_t *pastix_data, const char *extname, pastix_int_t sndeidx, int dump)
Dump the last separator into an ivview file.
Definition: order_draw.c:50
pastix_order_s::cblknbr
pastix_int_t cblknbr
Definition: order.h:48
pastix_order_s::permtab
pastix_int_t * permtab
Definition: order.h:49
pastix_gendirectories
void pastix_gendirectories(pastix_data_t *pastix_data)
Generate a unique temporary directory to store output files.
Definition: api.c:69
pastix_order_s
Order structure.
Definition: order.h:45
pastix_order_s::vertnbr
pastix_int_t vertnbr
Definition: order.h:47
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
pastix_order_s::baseval
pastix_int_t baseval
Definition: order.h:46
graph.h
pastix_order_s::rangtab
pastix_int_t * rangtab
Definition: order.h:51
graphIsolateRange
int graphIsolateRange(const pastix_graph_t *graphIn, const pastix_order_t *order, pastix_graph_t *graphOut, pastix_int_t fnode, pastix_int_t lnode, pastix_int_t distance)
Isolate the subgraph associated to a range of unknowns in the permuted graph.
Definition: graph_isolate.c:455
pastix_order_s::sndetab
pastix_int_t * sndetab
Definition: order.h:55