PaStiX Handbook 6.4.0
Loading...
Searching...
No Matches
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-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 Tony Delarue
14 * @date 2024-07-05
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 *******************************************************************************/
51void
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 memset( &sn_pgraph, 0, sizeof(pastix_graph_t) );
93 rc = graphIsolateRange( graph, order, &sn_pgraph,
94 ibeg, iend, 2 );
95 if ( rc != PASTIX_SUCCESS ) {
96 fprintf( stderr, "Failed to isolate graph\n" );
97 return;
98 }
99
100 sn_colptr = sn_pgraph.colptr;
101 sn_rows = sn_pgraph.rowptr;
102
103 if ( !SCOTCH_graphInit(&sn_sgraph) )
104 {
105 SCOTCH_graphBuild( &sn_sgraph,
106 order->baseval,
107 size,
108 sn_colptr,
109 NULL,
110 NULL,
111 NULL,
112 sn_colptr[ size ] - order->baseval,
113 sn_rows,
114 NULL );
115 }
116 else
117 {
118 fprintf( stderr, "Failed to build graph\n" );
119 graphExit( &sn_pgraph );
120 return;
121 }
122
123 rc = asprintf( &fname, "part.%ld.grf", (long)sndeidx);
124 assert( rc != -1 );
125
126 file = pastix_fopenw( pastix_data->dir_global, fname, "w" );
127 SCOTCH_graphSave( &sn_sgraph, file );
128 fclose( file );
129 free(fname);
130
131 fprintf(stderr,"Check: %d\n", SCOTCH_graphCheck( &sn_sgraph ));
132 SCOTCH_graphExit( &sn_sgraph );
133 graphExit( &sn_pgraph );
134 }
135
136 /*
137 * Dump the XYZ file
138 */
139 if ( dump & orderDrawCoordinates )
140 {
141 FILE *filein;
142 long dim, n;
143
144 filein = fopen( "before.xyz", "r" );
145 if ( filein == NULL ) {
146 fprintf( stderr, "Please give before.xyz file\n" );
147 return;
148 }
149
150 /* Read dimensions */
151 rc = fscanf( filein, "%ld %ld", &dim, &n );
152 if ( n != order->vertnbr ){
153 fprintf(stderr, "Cannot proceed part.xyz and part.map files: invalid number of vertices in before.xyz\n");
154 fclose(filein);
155 return;
156 }
157
158 rc = asprintf( &fname, "part.%ld.xyz", (long)sndeidx);
159 assert( rc != -1 );
160 file = pastix_fopenw( pastix_data->dir_global, fname, "w" );
161 free( fname );
162
163 fprintf( file, "%ld %ld\n", (long)dim, (long)size );
164 for(i=0; i<order->vertnbr; i++) {
165 long v, iv;
166 double x, y, z;
167
168 rc = fscanf(filein, "%ld %lf %lf %lf", &v, &x, &y, &z );
169 assert( rc == 4 );
170
171 /* If node within the selected supernode, let's keep it */
172 iv = order->permtab[i];
173 if ( (iv >= ibeg) && (iv < iend) ) {
174 fprintf( file, "%ld %lf %lf %lf\n",
175 (long)(iv - ibeg), x, y, z );
176 }
177 }
178
179 fclose(file);
180 fclose(filein);
181 }
182
183 /*
184 * Dump the mapping file
185 */
186 if ( dump & orderDrawMapping )
187 {
188 pastix_int_t color = 0;
189
190 if ( extname ) {
191 rc = asprintf( &fname, "part.%ld.%s.map",
192 (long)sndeidx, extname );
193 }
194 else {
195 rc = asprintf( &fname, "part.%ld.map",
196 (long)sndeidx );
197 }
198 assert( rc != -1 );
199 file = pastix_fopenw( pastix_data->dir_global, fname, "w" );
200 free( fname );
201
202 fprintf( file, "%ld\n", (long)size );
203
204 /*
205 * Look for the last cblk implied in the original supernode
206 * The search is down backward to have more coherent coloring from one
207 * version to another, and because we usually draw the last supernode
208 * and no more.
209 */
210 i = order->cblknbr;
211 while ( (i > 0) && (order->rangtab[i] > iend) ) {
212 i--;
213 }
214 i--;
215
216 for (; i>0; i--) {
217 pastix_int_t fnode = order->rangtab[i];
218 pastix_int_t lnode = order->rangtab[i+1];
219
220 if ( fnode < ibeg ) {
221 assert( lnode <= ibeg );
222 break;
223 }
224
225 for (j=fnode; j<lnode; j++) {
226 fprintf( file, "%ld %ld\n",
227 (long)(j - ibeg), (long)color );
228 }
229 color++;
230 }
231 fclose(file);
232 }
233 (void)rc;
234}
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:251
void pastix_gendirectories(pastix_data_t *pastix_data)
Generate a unique temporary directory to store output files.
Definition api.c:85
@ PASTIX_SUCCESS
Definition api.h:367
void graphExit(pastix_graph_t *graph)
Free the content of the graph structure.
Definition graph.c:73
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:98
pastix_graph_t * graph
Definition pastixdata.h:92
char * dir_global
Definition pastixdata.h:110
Main PaStiX data structure.
Definition pastixdata.h:68