source: issm/trunk-jpl-damage/src/c/modules/Scotchx/Scotchx.cpp@ 11417

Last change on this file since 11417 was 11417, checked in by cborstad, 13 years ago

merged src changes 11330:11410 from trunk-jpl

File size: 13.6 KB
Line 
1/* Copyright 2004,2007,2008 ENSEIRB, 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 : gmap.c **/
35/** **/
36/** AUTHOR : Francois PELLEGRINI **/
37/** **/
38/** FUNCTION : Part of a graph mapping software. **/
39/** This module contains the main function. **/
40/** **/
41/** DATES : # Version 0.0 : from : 05 jan 1993 **/
42/** to 12 may 1993 **/
43/** # Version 1.1 : from : 15 oct 1993 **/
44/** to 15 oct 1993 **/
45/** # Version 1.3 : from : 06 apr 1994 **/
46/** to 18 may 1994 **/
47/** # Version 2.0 : from : 06 jun 1994 **/
48/** to 17 nov 1994 **/
49/** # Version 2.1 : from : 07 apr 1995 **/
50/** to 18 jun 1995 **/
51/** # Version 3.0 : from : 01 jul 1995 **/
52/** to 02 oct 1995 **/
53/** # Version 3.1 : from : 07 nov 1995 **/
54/** to 25 apr 1996 **/
55/** # Version 3.2 : from : 24 sep 1996 **/
56/** to 26 may 1998 **/
57/** # Version 3.3 : from : 19 oct 1998 **/
58/** to : 30 mar 1999 **/
59/** # Version 3.4 : from : 03 feb 2000 **/
60/** to : 03 feb 2000 **/
61/** # Version 4.0 : from : 16 jan 2004 **/
62/** to : 27 dec 2004 **/
63/** # Version 5.0 : from : 23 dec 2007 **/
64/** to : 18 jun 2008 **/
65/** **/
66/************************************************************/
67
68#include "./Scotchx.h"
69
70int
71gmapx (
72 int (**pmaptabi)[2],
73 int argcm,
74 char *argvm[],
75 int nvi,
76 int ne2i,
77 int *ir,
78 int *jc,
79 int *vli,
80 int *vwi,
81 int *ewi,
82 char archtyp[],
83 int nai,
84 int *api)
85{
86#ifdef _HAVE_SCOTCH_ //only works if Scotch library has been compiled in.
87
88 SCOTCH_Graph grafdat; /* Source graph */
89 SCOTCH_Num grafflag; /* Source graph properties */
90 SCOTCH_Arch archdat; /* Target architecture */
91 SCOTCH_Strat stradat; /* Mapping strategy */
92 SCOTCH_Mapping mapdat; /* Mapping data */
93 Clock runtime[2]; /* Timing variables */
94 SCOTCH_Num nvert =0;
95 SCOTCH_Num nedge2=0;
96 SCOTCH_Num* adjir =NULL;
97 SCOTCH_Num* adjjc =NULL;
98 SCOTCH_Num* vertlab=NULL;
99 SCOTCH_Num* vertwgt=NULL;
100 SCOTCH_Num* edgewgt=NULL;
101 SCOTCH_Num napar =0;
102 SCOTCH_Num* archpar=NULL;
103 SCOTCH_Num (*maptab)[2]=NULL;
104 int (*maptabi)[2]=NULL;
105 int flagval;
106 int i,j,k;
107
108/* reset static variables from previous runs (jes, 4/27/10) */
109
110 C_partNbr = 2; /* Default number of parts */
111 C_paraNum = 0; /* Number of parameters */
112 C_paraNbr = 0; /* No parameters for mapping */
113 C_fileNum = 0; /* Number of file in arg list */
114 C_fileNbr = 4; /* Number of files for mapping */
115 for (i=0; i<C_FILENBR; i++) {
116 C_fileTab[i].name = "-";
117 C_fileTab[i].pntr = NULL;
118 if (i < 2)
119 C_fileTab[i].mode = "r";
120 else
121 C_fileTab[i].mode = "w";
122 }
123
124/* convert input arguments to scotch data types */
125
126 nvert =(SCOTCH_Num)nvi;
127 nedge2=(SCOTCH_Num)ne2i;
128
129 if (ir && jc) {
130 adjir = (SCOTCH_Num *) malloc(nedge2*sizeof(SCOTCH_Num));
131 for (i=0; i<nedge2; i++)
132 adjir[i]=(SCOTCH_Num)ir[i];
133 adjjc = (SCOTCH_Num *) malloc((nvert+1)*sizeof(SCOTCH_Num));
134 for (i=0; i<(nvert+1); i++)
135 adjjc[i]=(SCOTCH_Num)jc[i];
136 }
137
138 if (vli) {
139 vertlab = (SCOTCH_Num *) malloc(nvert*sizeof(SCOTCH_Num));
140 for (i=0; i<nvert; i++)
141 vertlab[i]=(SCOTCH_Num)vli[i];
142 }
143
144 if (vwi) {
145 vertwgt = (SCOTCH_Num *) malloc(nvert*sizeof(SCOTCH_Num));
146 for (i=0; i<nvert; i++)
147 vertwgt[i]=(SCOTCH_Num)vwi[i];
148 }
149
150 if (ewi) {
151 edgewgt = (SCOTCH_Num *) malloc(nedge2*sizeof(SCOTCH_Num));
152 for (i=0; i<nedge2; i++)
153 edgewgt[i]=(SCOTCH_Num)ewi[i];
154 }
155
156 napar =(SCOTCH_Num)nai;
157
158 if (api) {
159 archpar = (SCOTCH_Num *) malloc(nai*sizeof(SCOTCH_Num));
160 for (i=0; i<nai; i++)
161 archpar[i]=(SCOTCH_Num)api[i];
162 }
163
164/* start scotch processing */
165
166 flagval = C_FLAGNONE; /* Default behavior */
167 i = strlen (argvm[0]);
168 if ((i >= 5) && (strncmp (argvm[0] + i - 5, "gpart", 5) == 0)) {
169 flagval |= C_FLAGPART;
170 C_paraNbr = 1; /* One more parameter */
171 C_fileNbr = 3; /* One less file to provide */
172 errorProg ("gpart");
173 }
174 else
175 errorProg ("gmap");
176
177 intRandResetStatic ();
178 intRandInit ();
179
180 if ((argcm >= 2) && (argvm[1][0] == '?')) { /* If need for help */
181 usagePrint (stdout, C_usageList);
182 return (0);
183 }
184
185 grafflag = 0; /* Use vertex and edge weights */
186 SCOTCH_stratInit (&stradat); /* Set default mapping strategy */
187
188 for (i = 0; i < C_FILENBR; i ++) /* Set default stream pointers */
189 C_fileTab[i].pntr = (C_fileTab[i].mode[0] == 'r') ? stdin : stdout;
190 for (i = 1; i < argcm; i ++) { /* Loop for all option codes */
191 if ((argvm[i][0] != '-') || (argvm[i][1] == '\0') || (argvm[i][1] == '.')) { /* If found a file name */
192 if (C_paraNum < C_paraNbr) { /* If number of parameters not reached */
193 if ((C_partNbr = atoi (argvm[i])) < 1) /* Get the number of parts */
194 errorPrint ("main: invalid number of parts (\"%s\")", argvm[i]);
195 C_paraNum ++;
196 continue; /* Process the other parameters */
197 }
198 if (C_fileNum < C_fileNbr) /* A file name has been given */
199 C_fileTab[C_fileNum ++].name = argvm[i];
200 else
201 errorPrint ("main: too many file names given");
202 }
203 else { /* If found an option name */
204 switch (argvm[i][1]) {
205 case 'H' : /* Give the usage message */
206 case 'h' :
207 usagePrint (stdout, C_usageList);
208 return (0);
209 case 'M' :
210 case 'm' :
211 SCOTCH_stratExit (&stradat);
212 SCOTCH_stratInit (&stradat);
213 SCOTCH_stratGraphMap (&stradat, &argvm[i][2]);
214 break;
215 case 'S' :
216 case 's' : /* Source graph parameters */
217 for (j = 2; argvm[i][j] != '\0'; j ++) {
218 switch (argvm[i][j]) {
219 case 'E' :
220 case 'e' :
221 grafflag |= 2; /* Do not load edge weights */
222 break;
223 case 'V' :
224 case 'v' :
225 grafflag |= 1; /* Do not load vertex weights */
226 break;
227 default :
228 errorPrint ("main: invalid source graph option (\"%c\")", argvm[i][j]);
229 }
230 }
231 break;
232 case 'V' :
233 fprintf (stderr, "gmap/gpart, version %s - F. Pellegrini\n", SCOTCH_VERSION);
234 fprintf (stderr, "Copyright 2004,2007,2008 ENSEIRB, INRIA & CNRS, France\n");
235 fprintf (stderr, "This software is libre/free software under CeCILL-C -- see the user's manual for more information\n");
236 return (0);
237 case 'v' : /* Output control info */
238 for (j = 2; argvm[i][j] != '\0'; j ++) {
239 switch (argvm[i][j]) {
240 case 'M' :
241 case 'm' :
242 flagval |= C_FLAGVERBMAP;
243 break;
244 case 'S' :
245 case 's' :
246 flagval |= C_FLAGVERBSTR;
247 break;
248 case 'T' :
249 case 't' :
250 flagval |= C_FLAGVERBTIM;
251 break;
252 default :
253 errorPrint ("main: unprocessed parameter \"%c\" in \"%s\"", argvm[i][j], argvm[i]);
254 }
255 }
256 break;
257 default :
258 errorPrint ("main: unprocessed option (\"%s\")", argvm[i]);
259 }
260 }
261 }
262 if ((flagval & C_FLAGPART) != 0) { /* If program run as the partitioner */
263 C_fileTab[3].name = C_fileTab[2].name; /* Put provided file names at their right place */
264 C_fileTab[2].name = C_fileTab[1].name;
265 C_fileTab[1].name = "-";
266 }
267
268 fileBlockOpen (C_fileTab, C_FILENBR); /* Open all files */
269
270 clockInit (&runtime[0]);
271 clockStart (&runtime[0]);
272
273 SCOTCH_graphInit (&grafdat); /* Create graph structure */
274 SCOTCH_graphLoad (&grafdat, C_filepntrsrcinp, -1, grafflag, nvert, nedge2, adjir, adjjc, vertlab, vertwgt, edgewgt); /* Read source graph */
275
276 SCOTCH_archInit (&archdat); /* Create architecture structure */
277 if ((flagval & C_FLAGPART) != 0) /* If program run as the partitioner */
278 SCOTCH_archCmplt (&archdat, C_partNbr); /* Create a complete graph of proper size */
279 else
280 SCOTCH_archLoad (&archdat, C_filepntrtgtinp, archtyp, napar, archpar); /* Read target architecture */
281
282 clockStop (&runtime[0]); /* Get input time */
283 clockInit (&runtime[1]);
284 clockStart (&runtime[1]);
285
286 SCOTCH_graphMapInit (&grafdat, &mapdat, &archdat, NULL);
287 SCOTCH_graphMapCompute (&grafdat, &mapdat, &stradat); /* Perform mapping */
288
289 clockStop (&runtime[1]); /* Get computation time */
290 clockStart (&runtime[0]);
291
292 SCOTCH_graphMapSave (&nvert, &maptab, &grafdat, &mapdat, C_filepntrmapout); /* Write mapping */
293
294/* convert output arguments from scotch data types */
295
296 if (maptab) {
297 *pmaptabi = (int (*)[2]) malloc(nvert*2*sizeof(int));
298 maptabi = *pmaptabi;
299 for (j=0; j<2; j++)
300 for (i=0; i<nvert; i++)
301 maptabi[i][j]=(int)maptab[i][j];
302 free(maptab);
303 }
304
305 clockStop (&runtime[0]); /* Get output time */
306
307 if (flagval & C_FLAGVERBSTR) {
308 fprintf (C_filepntrlogout, "S\tStrat=");
309 SCOTCH_stratSave (&stradat, C_filepntrlogout);
310 putc ('\n', C_filepntrlogout);
311 }
312 if (flagval & C_FLAGVERBTIM) {
313 fprintf (C_filepntrlogout, "T\tMapping\t\t%g\nT\tI/O\t\t%g\nT\tTotal\t\t%g\n",
314 (double) clockVal (&runtime[1]),
315 (double) clockVal (&runtime[0]),
316 (double) clockVal (&runtime[0]) +
317 (double) clockVal (&runtime[1]));
318 }
319 if (flagval & C_FLAGVERBMAP)
320 SCOTCH_graphMapView (&grafdat, &mapdat, C_filepntrlogout);
321
322 fileBlockClose (C_fileTab, C_FILENBR); /* Always close explicitely to end eventual (un)compression tasks */
323
324 SCOTCH_graphMapExit (&grafdat, &mapdat);
325 SCOTCH_graphExit (&grafdat);
326 SCOTCH_stratExit (&stradat);
327 SCOTCH_archExit (&archdat);
328
329 if (archpar) free(archpar);
330 if (edgewgt) free(edgewgt);
331 if (vertwgt) free(vertwgt);
332 if (vertlab) free(vertlab);
333 if (adjjc) free(adjjc);
334 if (adjir) free(adjir);
335
336#ifdef COMMON_PTHREAD
337 pthread_exit ((void *) 0); /* Allow potential (un)compression tasks to complete */
338#endif /* COMMON_PTHREAD */
339 return (0);
340
341#else //#ifdef _HAVE_SCOTCH_
342 return(0);
343#endif
344}
Note: See TracBrowser for help on using the repository browser.