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