1 /* Copyright 2004,2007-2010,2012,2014 Universite de Bordeaux, INRIA & CNRS
2 **
3 ** This file is part of the Scotch software package for static mapping,
4 ** graph partitioning and sparse matrix ordering.
5 **
6 ** This software is governed by the CeCILL-C license under French law
7 ** and abiding by the rules of distribution of free software. You can
8 ** use, modify and/or redistribute the software under the terms of the
9 ** CeCILL-C license as circulated by CEA, CNRS and INRIA at the following
10 ** URL: "http://www.cecill.info".
11 **
12 ** As a counterpart to the access to the source code and rights to copy,
13 ** modify and redistribute granted by the license, users are provided
14 ** only with a limited warranty and the software's author, the holder of
15 ** the economic rights, and the successive licensors have only limited
16 ** liability.
17 **
18 ** In this respect, the user's attention is drawn to the risks associated
19 ** with loading, using, modifying and/or developing or reproducing the
20 ** software by the user in light of its specific status of free software,
21 ** that may mean that it is complicated to manipulate, and that also
22 ** therefore means that it is reserved for developers and experienced
23 ** professionals having in-depth computer knowledge. Users are therefore
24 ** encouraged to load and test the software's suitability as regards
25 ** their requirements in conditions enabling the security of their
26 ** systems and/or data to be ensured and, more generally, to use and
27 ** operate it in the same conditions as regards security.
28 **
29 ** The fact that you are presently reading this means that you have had
30 ** knowledge of the CeCILL-C license and that you accept its terms.
31 */
32 /************************************************************/
33 /** **/
34 /** NAME : dummysizes.c **/
35 /** **/
36 /** AUTHOR : Francois PELLEGRINI **/
37 /** **/
38 /** FUNCTION : Part of the libScotch compilation job. **/
39 /** This small program processes files that **/
40 /** are in fact pattern header files for **/
41 /** the libScotch library, and replaces **/
42 /** symbolic sizes of the opaque libScotch **/
43 /** by the proper integer values according **/
44 /** to the machine on which it is run. **/
45 /** **/
46 /** DATES : # Version 3.4 : from : 22 oct 2001 **/
47 /** to : 22 nov 2001 **/
48 /** # Version 4.0 : from : 25 nov 2001 **/
49 /** to : 06 jan 2006 **/
50 /** # Version 5.0 : from : 26 apr 2006 **/
51 /** to : 03 apr 2008 **/
52 /** # Version 5.1 : from : 16 jun 2008 **/
53 /** to : 15 aug 2010 **/
54 /** # Version 6.0 : from : 01 dec 2012 **/
55 /** to : 12 nov 2014 **/
56 /** **/
57 /************************************************************/
58
59 /*
60 ** The defines and includes.
61 */
62
63 #define DUMMYSIZES
64
65 #define CHARMAX 2048 /* Maximum line size */
66
67 #define SUBSMAX 48 /* Maximum number of substitutions */
68
69 #define C_FILENBR 2 /* Number of files in list */
70 #define C_FILEARGNBR 2 /* Number of files which can be arguments */
71
72 #define C_filenamehedinp C_fileTab[0].nameptr /* Source graph input file name */
73 #define C_filenamehedout C_fileTab[1].nameptr /* Statistics output file name */
74
75 #define C_filepntrhedinp C_fileTab[0].fileptr /* Source graph input file */
76 #define C_filepntrhedout C_fileTab[1].fileptr /* Statistics output file */
77
78 #define EXPAND(s) EXPANDTWO(s)
79 #define EXPANDTWO(s) #s
80
81 #include "module.h"
82 #include "common.h"
83 #include "parser.h"
84 #include "graph.h"
85 #include "geom.h"
86 #include "mesh.h"
87 #include "arch.h"
88 #include "mapping.h"
89 #include "order.h"
90 #ifdef SCOTCH_PTSCOTCH
91 #include "dgraph.h"
92 #include "dgraph_halo.h"
93 #include "dmapping.h"
94 #include "dorder.h"
95 #include "library_dmapping.h"
96 #endif /* SCOTCH_PTSCOTCH */
97 #include "library_mapping.h"
98 #include "library_order.h"
99
100 /*
101 ** The static definitions.
102 */
103
104 static int C_fileNum = 0; /* Number of file in arg list */
105 static File C_fileTab[C_FILENBR] = { /* The file array */
106 { "r" },
107 { "w" } };
108
109 /******************************/
110 /* */
111 /* This is the main function. */
112 /* */
113 /******************************/
114
115 void
subsFill(char * substab[2],char * origptr,int subsval)116 subsFill (
117 char * substab[2],
118 char * origptr,
119 int subsval)
120 {
121 char * subsptr;
122
123 subsptr = malloc (32 * sizeof (char));
124 sprintf (subsptr, "%d", (int) ((subsval + sizeof (double) - 1) / sizeof (double)));
125
126 substab[0] = origptr;
127 substab[1] = subsptr;
128 }
129
130 /******************************/
131 /* */
132 /* This is the main function. */
133 /* */
134 /******************************/
135
136 int
main(int argc,char * argv[])137 main (
138 int argc,
139 char * argv[])
140 {
141 char chartab[CHARMAX];
142 char chartmp[CHARMAX];
143 char * substab[SUBSMAX][2]; /* Substitution array */
144 int subsnbr;
145 int i;
146
147 if ((argc >= 2) && (argv[1][0] == '?')) { /* If need for help */
148 printf ("Usage is:\ndummysizes [<input pattern header file> [<output header file>]]\n");
149 return (((argv[1][0] == '?') && argv[1][1] == '\0') ? 0 : 1);
150 }
151
152 for (i = 0; i < C_FILENBR; i ++) /* Set default stream pointers */
153 C_fileTab[i].fileptr = (C_fileTab[i].modeptr[0] == 'r') ? stdin : stdout;
154 for (i = 1; i < argc; i ++) { /* Loop for all option codes */
155 if ((argv[i][0] != '+') && /* If found a file name */
156 ((argv[i][0] != '-') || (argv[i][1] == '\0'))) {
157 if (C_fileNum < C_FILEARGNBR) /* A file name has been given */
158 C_fileTab[C_fileNum ++].nameptr = argv[i];
159 else {
160 fprintf (stderr, "dummysizes: ERROR: main: too many file names given");
161 exit (1);
162 }
163 }
164 else { /* If found an option name */
165 switch (argv[i][1]) {
166 case 'H' : /* Give the usage message */
167 case 'h' :
168 printf ("Usage is:\ndummysizes [<input pattern header file> [<output header file>]]\n");
169 exit (0);
170 case 'V' :
171 fprintf (stderr, "dummysizes, version " SCOTCH_VERSION_STRING "\n");
172 fprintf (stderr, "Copyright 2004,2007-2010 ENSEIRB, INRIA & CNRS, France\n");
173 fprintf (stderr, "This software is libre/free software under CeCILL-C -- see the user's manual for more information\n");
174 return (0);
175 default :
176 fprintf (stderr, "dummysizes: ERROR: main: unprocessed option (\"%s\")", argv[i]);
177 exit (1);
178 }
179 }
180 }
181
182 for (i = 0; i < C_FILENBR; i ++) { /* For all file names */
183 if ((C_fileTab[i].nameptr[0] != '-') || /* If not standard stream */
184 (C_fileTab[i].nameptr[1] != '\0')) {
185 if ((C_fileTab[i].fileptr = fopen (C_fileTab[i].nameptr, C_fileTab[i].modeptr)) == NULL) { /* Open the file */
186 fprintf (stderr, "dummysizes: ERROR: main: cannot open file (%d)", i);
187 exit (1);
188 }
189 }
190 }
191
192 #ifdef SCOTCH_PTSCOTCH
193 substab[0][0] = "library_pt.h";
194 substab[0][1] = "ptscotch.h ";
195 substab[1][0] = "library_pt_f.h";
196 substab[1][1] = "ptscotchf.h ";
197 #else /* SCOTCH_PTSCOTCH */
198 substab[0][0] = "library.h";
199 substab[0][1] = "scotch.h ";
200 substab[1][0] = "library_f.h";
201 substab[1][1] = "scotchf.h ";
202 #endif /* SCOTCH_PTSCOTCH */
203 substab[2][0] = "DUMMYIDX";
204 substab[2][1] = EXPAND (IDX);
205 substab[3][0] = "DUMMYINT";
206 substab[3][1] = EXPAND (INT);
207 substab[4][0] = "DUMMYMAXINT";
208 substab[4][1] = EXPAND (INTVALMAX);
209 substab[5][0] = "DUMMYNUMSTRING";
210 substab[5][1] = "\"" GNUMSTRING "\"";
211 substab[6][0] = "DUMMYVERSION";
212 substab[6][1] = EXPAND (SCOTCH_VERSION);
213 substab[7][0] = "DUMMYRELEASE";
214 substab[7][1] = EXPAND (SCOTCH_RELEASE);
215 substab[8][0] = "DUMMYPATCHLEVEL";
216 substab[8][1] = EXPAND (SCOTCH_PATCHLEVEL);
217 subsnbr = 9;
218 subsFill (substab[subsnbr ++], "DUMMYSIZEARCH", sizeof (Arch));
219 subsFill (substab[subsnbr ++], "DUMMYSIZEGEOM", sizeof (Geom));
220 subsFill (substab[subsnbr ++], "DUMMYSIZEGRAPH", sizeof (Graph));
221 subsFill (substab[subsnbr ++], "DUMMYSIZEMESH", sizeof (Mesh));
222 subsFill (substab[subsnbr ++], "DUMMYSIZEMAP", sizeof (LibMapping));
223 subsFill (substab[subsnbr ++], "DUMMYSIZEORDER", sizeof (LibOrder));
224 subsFill (substab[subsnbr ++], "DUMMYSIZESTRAT", sizeof (Strat *));
225 #ifdef SCOTCH_PTSCOTCH
226 subsFill (substab[subsnbr ++], "DUMMYSIZEDGRAPHHALOREQ", sizeof (DgraphHaloRequest)); /* TRICK: before DUMMYSIZEDGRAPH */
227 subsFill (substab[subsnbr ++], "DUMMYSIZEDGRAPH", sizeof (Dgraph));
228 subsFill (substab[subsnbr ++], "DUMMYSIZEDMAP", sizeof (LibDmapping));
229 subsFill (substab[subsnbr ++], "DUMMYSIZEDORDER", sizeof (Dorder));
230 #else /* SCOTCH_PTSCOTCH */
231 subsFill (substab[subsnbr ++], "DUMMYSIZEDGRAPHHALOREQ", 1); /* TRICK: before DUMMYSIZEDGRAPH */
232 subsFill (substab[subsnbr ++], "DUMMYSIZEDGRAPH", 1);
233 subsFill (substab[subsnbr ++], "DUMMYSIZEDMAP", 1);
234 subsFill (substab[subsnbr ++], "DUMMYSIZEDORDER", 1);
235 #endif /* SCOTCH_PTSCOTCH */
236
237 while (fgets (chartab, CHARMAX, C_filepntrhedinp) != NULL) { /* Infinite loop on file lines */
238 int charnbr;
239 int subsnum;
240
241 if (((charnbr = strlen (chartab)) >= (CHARMAX - 1)) && /* If line read is at least as long as maximum size */
242 (chartab[CHARMAX - 1] != '\n')) { /* And last character is not a newline, that is, some is missing */
243 fprintf (stderr, "dummysizes: ERROR: line too long\n");
244 exit (1);
245 }
246
247 for (subsnum = 0; subsnum < subsnbr; subsnum ++) { /* Perform substitutions */
248 char * charptr; /* Place where token found */
249
250 while ((charptr = strstr (chartab, substab[subsnum][0])) != NULL) { /* As long as substitution can be performed */
251 int charnbr;
252 int charnum;
253
254 charnum = charptr - chartab; /* Position where token found */
255 charnbr = strlen (substab[subsnum][0]); /* Length of token */
256
257 strcpy (chartmp, charptr + charnbr); /* Save end of line */
258
259 sprintf (charptr, "%s%s", substab[subsnum][1], chartmp); /* Replace end of line with substituted token */
260 }
261 }
262
263 fputs (chartab, C_filepntrhedout); /* Output possibly updated line */
264 }
265
266 #ifdef SCOTCH_DEBUG_MAIN1
267 for (i = 0; i < C_FILENBR; i ++) { /* For all file names */
268 if ((C_fileTab[i].name[0] != '-') || /* If not standard stream */
269 (C_fileTab[i].name[1] != '\0')) {
270 fclose (C_fileTab[i].pntr); /* Close the stream */
271 }
272 }
273 #endif /* SCOTCH_DEBUG_MAIN1 */
274
275 exit (0);
276 }
277