1 | /**CFile*********************************************************************** |
---|
2 | |
---|
3 | FileName [partCmd.c] |
---|
4 | |
---|
5 | PackageName [part] |
---|
6 | |
---|
7 | Synopsis [Command interface for the partition package.] |
---|
8 | |
---|
9 | Author [Abelardo Pardo] |
---|
10 | |
---|
11 | Copyright [This file was created at the University of Colorado at |
---|
12 | Boulder. The University of Colorado at Boulder makes no warranty |
---|
13 | about the suitability of this software for any purpose. It is |
---|
14 | presented on an AS IS basis.] |
---|
15 | |
---|
16 | ******************************************************************************/ |
---|
17 | |
---|
18 | #include "partInt.h" |
---|
19 | |
---|
20 | static char rcsid[] UNUSED = "$Id: partCmd.c,v 1.22 2009/04/11 01:47:18 fabio Exp $"; |
---|
21 | |
---|
22 | /*---------------------------------------------------------------------------*/ |
---|
23 | /* Variable declarations */ |
---|
24 | /*---------------------------------------------------------------------------*/ |
---|
25 | /**Variable******************************************************************** |
---|
26 | |
---|
27 | Synopsis [Buffer to store the environment in a setjmp call] |
---|
28 | |
---|
29 | SeeAlso [TimeOutHandle] |
---|
30 | |
---|
31 | ******************************************************************************/ |
---|
32 | static jmp_buf timeOutEnv; |
---|
33 | |
---|
34 | /**AutomaticStart*************************************************************/ |
---|
35 | |
---|
36 | /*---------------------------------------------------------------------------*/ |
---|
37 | /* Static function prototypes */ |
---|
38 | /*---------------------------------------------------------------------------*/ |
---|
39 | |
---|
40 | static int CommandBuildPartitionMdds(Hrc_Manager_t ** hmgr, int argc, char ** argv); |
---|
41 | static int CommandPrintPartition(Hrc_Manager_t **hmgr, int argc, char **argv); |
---|
42 | static int CommandPrintPartitionStats(Hrc_Manager_t **hmgr, int argc, char **argv); |
---|
43 | static void TimeOutHandle(void); |
---|
44 | |
---|
45 | /**AutomaticEnd***************************************************************/ |
---|
46 | |
---|
47 | |
---|
48 | /*---------------------------------------------------------------------------*/ |
---|
49 | /* Definition of exported functions */ |
---|
50 | /*---------------------------------------------------------------------------*/ |
---|
51 | |
---|
52 | /**Function******************************************************************** |
---|
53 | |
---|
54 | Synopsis [Initializes the partitioning package.] |
---|
55 | |
---|
56 | SideEffects [] |
---|
57 | |
---|
58 | SeeAlso [Part_End] |
---|
59 | |
---|
60 | ******************************************************************************/ |
---|
61 | void |
---|
62 | Part_Init(void) |
---|
63 | { |
---|
64 | Cmd_CommandAdd("build_partition_mdds", CommandBuildPartitionMdds, |
---|
65 | 0/* doesn't change network */); |
---|
66 | Cmd_CommandAdd("print_partition", CommandPrintPartition, |
---|
67 | 0/* doesn't change network */); |
---|
68 | Cmd_CommandAdd("print_partition_stats", CommandPrintPartitionStats, |
---|
69 | 0/* doesn't change network*/); |
---|
70 | } /* End of Part_Init */ |
---|
71 | |
---|
72 | |
---|
73 | /**Function******************************************************************** |
---|
74 | |
---|
75 | Synopsis [Ends the partitioning package.] |
---|
76 | |
---|
77 | SideEffects [] |
---|
78 | |
---|
79 | SeeAlso [Part_Init] |
---|
80 | |
---|
81 | ******************************************************************************/ |
---|
82 | void |
---|
83 | Part_End(void) |
---|
84 | { |
---|
85 | } /* End of Part_End */ |
---|
86 | |
---|
87 | /*---------------------------------------------------------------------------*/ |
---|
88 | /* Definition of internal functions */ |
---|
89 | /*---------------------------------------------------------------------------*/ |
---|
90 | |
---|
91 | |
---|
92 | /*---------------------------------------------------------------------------*/ |
---|
93 | /* Definition of static functions */ |
---|
94 | /*---------------------------------------------------------------------------*/ |
---|
95 | |
---|
96 | /**Function******************************************************************** |
---|
97 | |
---|
98 | Synopsis [Implements the build_partition_mdds command.] |
---|
99 | |
---|
100 | Description [The data structure needed to store the information |
---|
101 | related to the partitioning process will be stored in a graph_t |
---|
102 | structure that will become part of the network. This procedure |
---|
103 | checks if the network has already registered this application. If |
---|
104 | not, a new structure is allocated. After this process, depending on |
---|
105 | the type of method specified in the command line, the specific |
---|
106 | routine is executed. The user may set the specific flag |
---|
107 | <tt>partition_method</tt> as the default to be used whenever no |
---|
108 | method is specified in the command line. If no flag is defined, the |
---|
109 | <tt>frontier</tt> method will be used.] |
---|
110 | |
---|
111 | CommandName [build_partition_mdds] |
---|
112 | |
---|
113 | CommandSynopsis [build a partition of MDDs for the flattened network] |
---|
114 | |
---|
115 | CommandArguments [\[-h\] \[-i\] \[-n <list>\] \[-s <num>\] \[-t |
---|
116 | <seconds>\] \[-v\] \[<method>\]] |
---|
117 | |
---|
118 | CommandDescription [Build the MDDs of a flattened network. Depending on the |
---|
119 | <tt>method</tt> selected, the MDDs for the combinational outputs (COs) are |
---|
120 | built in terms of either the combinational inputs (CIs) or in terms of some |
---|
121 | subset of intermediate nodes of the network. The MDDs built are stored in a |
---|
122 | DAG called a "partition". The vertices of a partition correspond to the |
---|
123 | CIs, COs, and any intermediate nodes used. Each vertex has a multi-valued |
---|
124 | function (represented by MDDs) expressing the function of the corresponding |
---|
125 | network node in terms of the partition vertices in its transitive fanin. |
---|
126 | Hence, the MDDs of the partition represent a partial collapsing of the |
---|
127 | network.<p> |
---|
128 | |
---|
129 | This command must be preceded by the commands <tt>flatten_hierarchy</tt> and |
---|
130 | <tt>static_order</tt>. The partition built is stored with the network for |
---|
131 | use by other commands, such as <tt>simulate</tt>, <tt>compute_reach</tt>, |
---|
132 | <tt>model_check</tt>, etc. This command has no affect when invoked on a |
---|
133 | network that already has a partition. To remove the existing partition of a |
---|
134 | network, reinvoke <tt>flatten_hierarchy</tt>.<p> |
---|
135 | |
---|
136 | The choice of <tt>method</tt> determines which intermediate nodes are |
---|
137 | used. The <tt>inout</tt> method represents one extreme where no intermediate |
---|
138 | nodes are used, and <tt>total</tt> represents the other extreme where every |
---|
139 | node in the network has a corresponding vertex in the partition. If no |
---|
140 | <tt>method</tt> is specified on the command line, then the value of the flag |
---|
141 | <tt>partition_method</tt> is used (this flag is set by the command <tt>set |
---|
142 | partition_method</tt>), unless it does not have a value, in which case the |
---|
143 | <tt>forntier</tt> method is used. The different methods available are: |
---|
144 | |
---|
145 | <dl> |
---|
146 | <li> <tt>inout</tt> Expresses the combinational |
---|
147 | outputs in terms of the combinational inputs. |
---|
148 | |
---|
149 | <li> <tt>total</tt> The partition built is isomorphic to the combinational |
---|
150 | part of the network. The function of each node is expressed in terms of its |
---|
151 | immediate fanins. If the <tt>-i</tt> is used the function attached to each |
---|
152 | vertex is computed as a function of the combinational inputs. |
---|
153 | |
---|
154 | <li> <tt>partial</tt> Builds a partition using the intermediate nodes specified |
---|
155 | with the <tt>-n</tt> option or the <tt>-f</tt> option. |
---|
156 | |
---|
157 | <li> <tt>frontier</tt> (default) Builds a partition creating vertices for the intermediate nodes |
---|
158 | as needed in order to control the BDD size. The threshold value for the BDD size can |
---|
159 | be set by the parameter "partition_threshold". This method encompasses both "inout" |
---|
160 | (set partition_threshold parameter to infinity) and |
---|
161 | "total" (set partition_threshold parameter to 0). |
---|
162 | |
---|
163 | <li> <tt>boundary</tt> Builds a partition in a fashion that preserves all nodes that |
---|
164 | are Input/Output nodes of any hnode in the hierarchy rooted at the current hnode. |
---|
165 | |
---|
166 | </dl> |
---|
167 | |
---|
168 | Command options: <p> |
---|
169 | |
---|
170 | <dl> |
---|
171 | |
---|
172 | <dt> -h |
---|
173 | <dd> Print the command usage.<p> |
---|
174 | |
---|
175 | <dt> -i |
---|
176 | <dd> Build the multi-valued functions of each partition vertex in terms of |
---|
177 | the combinational inputs, rather than in terms of its transitive fanin |
---|
178 | vertices.<p> |
---|
179 | |
---|
180 | <dt> -n <list> |
---|
181 | <dd> Used in conjunction with the <tt>partial</tt> method. <tt>List</tt> is |
---|
182 | a comma separated list of network nodes to use as intermediate nodes in the |
---|
183 | partition.<p> |
---|
184 | |
---|
185 | <dt> -s <num> |
---|
186 | <dd> Level of severity of a post-computation check applied to the partition data |
---|
187 | structure (0 by default, meaning no check).<p> |
---|
188 | |
---|
189 | <dt> -t <seconds> |
---|
190 | <dd> Time in seconds allowed to build the partition. If the computation time |
---|
191 | goes above that limit, the process of building the partition is aborted. The |
---|
192 | default is no limit.<p> |
---|
193 | |
---|
194 | <dt> -v |
---|
195 | <dd> Turn on the verbosity.<p> |
---|
196 | |
---|
197 | </ul>] |
---|
198 | |
---|
199 | SideEffects [Registers in the network the partition application with |
---|
200 | the key specified by PART_NETWORK_APPL_KEY] |
---|
201 | |
---|
202 | SeeAlso [Ntk_NetworkAddApplInfo] |
---|
203 | |
---|
204 | ******************************************************************************/ |
---|
205 | static int |
---|
206 | CommandBuildPartitionMdds( |
---|
207 | Hrc_Manager_t ** hmgr, |
---|
208 | int argc, |
---|
209 | char ** argv) |
---|
210 | { |
---|
211 | static Part_PartitionMethod method; |
---|
212 | static boolean inTermsOfLeaves; |
---|
213 | lsList nodeList = lsCreate(); |
---|
214 | graph_t *partition; |
---|
215 | static int verbose; |
---|
216 | static int sanityCheck; |
---|
217 | static int timeOutPeriod; |
---|
218 | int c; |
---|
219 | int length; |
---|
220 | char *methodString; |
---|
221 | char *modelName; |
---|
222 | Hrc_Node_t *currentNode; |
---|
223 | Ntk_Network_t *network = Ntk_HrcManagerReadCurrentNetwork(*hmgr); |
---|
224 | char *nodeName; |
---|
225 | char *tmpNodeName; |
---|
226 | char *realName; |
---|
227 | FILE *nodeFile; |
---|
228 | static boolean fileUsed; |
---|
229 | |
---|
230 | fileUsed = FALSE; |
---|
231 | inTermsOfLeaves = FALSE; |
---|
232 | verbose = 0; |
---|
233 | sanityCheck = 0; |
---|
234 | timeOutPeriod = 0; |
---|
235 | |
---|
236 | nodeFile = NIL(FILE); |
---|
237 | util_getopt_reset(); |
---|
238 | while ((c = util_getopt(argc, argv, "f:hvin:s:t:")) != EOF) { |
---|
239 | switch(c) { |
---|
240 | case 'f': |
---|
241 | fileUsed = TRUE; |
---|
242 | nodeFile = Cmd_FileOpen(util_optarg, "r", &realName, 1); |
---|
243 | FREE(realName); |
---|
244 | if (nodeFile == NIL(FILE)){ |
---|
245 | (void)fprintf(vis_stderr,"Cannot open %s\n", util_optarg); |
---|
246 | lsDestroy(nodeList, (void (*)(lsGeneric))0); |
---|
247 | return 1; |
---|
248 | } |
---|
249 | else{ |
---|
250 | tmpNodeName = ALLOC(char, 512); |
---|
251 | while(fscanf(nodeFile, "%s\n", tmpNodeName) != EOF){ |
---|
252 | if(*tmpNodeName != '#'){ |
---|
253 | nodeName = ALLOC(char, strlen(tmpNodeName) + 2); |
---|
254 | sprintf(nodeName, "%s", tmpNodeName); |
---|
255 | lsNewEnd(nodeList, (lsGeneric)nodeName, NIL(lsHandle)); |
---|
256 | } |
---|
257 | } |
---|
258 | FREE(tmpNodeName); |
---|
259 | } |
---|
260 | break; |
---|
261 | case 'h': |
---|
262 | goto usage; |
---|
263 | case 'i': |
---|
264 | inTermsOfLeaves = TRUE; |
---|
265 | break; |
---|
266 | case 'v': |
---|
267 | verbose = 1; |
---|
268 | break; |
---|
269 | case 's': |
---|
270 | sanityCheck = atoi(util_optarg); |
---|
271 | break; |
---|
272 | case 't': |
---|
273 | timeOutPeriod = atoi(util_optarg); |
---|
274 | break; |
---|
275 | case 'n': |
---|
276 | length = strlen(util_optarg); |
---|
277 | for(c = 0; c < length; c++) { |
---|
278 | if (util_optarg[c] == ',') { |
---|
279 | util_optarg[c] = 0; |
---|
280 | } /* End of if */ |
---|
281 | } /* End of for */ |
---|
282 | c = 0; |
---|
283 | while (c < length) { |
---|
284 | lsNewEnd(nodeList, &util_optarg[c], NIL(lsHandle)); |
---|
285 | while (util_optarg[c++] != 0); |
---|
286 | } /* End of while */ |
---|
287 | break; |
---|
288 | default: |
---|
289 | goto usage; |
---|
290 | } |
---|
291 | } |
---|
292 | |
---|
293 | if (argc == util_optind) { |
---|
294 | /* No method specified. Choosing default */ |
---|
295 | methodString = Cmd_FlagReadByName("partition_method"); |
---|
296 | if (methodString == NIL(char)) { |
---|
297 | methodString = "default"; |
---|
298 | } |
---|
299 | } |
---|
300 | else { |
---|
301 | methodString = argv[util_optind]; |
---|
302 | } |
---|
303 | |
---|
304 | if (strcmp(methodString,"inout") == 0) { |
---|
305 | method = Part_InOut_c; |
---|
306 | if (lsLength(nodeList) != 0) { |
---|
307 | (void) fprintf(vis_stderr, "Ignoring provided list of nodes in <inout>"); |
---|
308 | (void) fprintf(vis_stderr, " method\n"); |
---|
309 | } /* End of if */ |
---|
310 | if (inTermsOfLeaves) { |
---|
311 | (void) fprintf(vis_stderr, "Ignoring -i flag in the <inout> method\n"); |
---|
312 | } /* End of if */ |
---|
313 | } |
---|
314 | else if (strcmp(methodString,"partial") == 0) { |
---|
315 | method = Part_Partial_c; |
---|
316 | /* Make sure a list of nodes has been provided */ |
---|
317 | if (lsLength(nodeList) == 0) { |
---|
318 | (void) fprintf(vis_stderr, "Method <partial> requires a non-empty list"); |
---|
319 | (void) fprintf(vis_stderr, " of nodes\n"); |
---|
320 | |
---|
321 | lsDestroy(nodeList, (void (*)(lsGeneric))0); |
---|
322 | goto usage; |
---|
323 | } /* End of if */ |
---|
324 | } |
---|
325 | else if (strcmp(methodString,"total") == 0) { |
---|
326 | method = Part_Total_c; |
---|
327 | if (lsLength(nodeList) != 0) { |
---|
328 | (void) fprintf(vis_stderr, "Ignoring provided list of nodes in <total>"); |
---|
329 | (void) fprintf(vis_stderr, " method\n"); |
---|
330 | } /* End of if */ |
---|
331 | } |
---|
332 | else if (strcmp(methodString,"frontier") == 0) { |
---|
333 | method = Part_Frontier_c; |
---|
334 | } |
---|
335 | else if (strcmp(methodString,"boundary") == 0) { |
---|
336 | method = Part_Boundary_c; |
---|
337 | } |
---|
338 | else if (strcmp(methodString, "fine") == 0) { |
---|
339 | method = Part_Fine_c; |
---|
340 | } |
---|
341 | else if (strcmp(methodString, "default") == 0) { |
---|
342 | method = Part_Default_c; |
---|
343 | } |
---|
344 | else { |
---|
345 | goto usage; |
---|
346 | } |
---|
347 | |
---|
348 | |
---|
349 | /* Check if the network has been read in */ |
---|
350 | if (network == NIL(Ntk_Network_t)) { |
---|
351 | lsDestroy(nodeList, (void (*)(lsGeneric))0); |
---|
352 | return 1; |
---|
353 | } |
---|
354 | |
---|
355 | /* Check if the network has the variables ordered */ |
---|
356 | if (Ord_NetworkTestAreVariablesOrdered(network, Ord_InputAndLatch_c) == |
---|
357 | FALSE) { |
---|
358 | (void) fprintf(vis_stdout, "The MDD variables have not been ordered. Use static_order.\n"); |
---|
359 | |
---|
360 | lsDestroy(nodeList, (void (*)(lsGeneric))0); |
---|
361 | return 1; |
---|
362 | } |
---|
363 | |
---|
364 | /* Check if there is already a partition attached to the network */ |
---|
365 | partition = (graph_t *) Ntk_NetworkReadApplInfo(network, |
---|
366 | PART_NETWORK_APPL_KEY); |
---|
367 | |
---|
368 | /* If there is, just return. */ |
---|
369 | if (partition != NIL(graph_t)) { |
---|
370 | (void) fprintf(vis_stderr, "partition already built; reinvoke "); |
---|
371 | (void) fprintf(vis_stderr, "flatten_hierarchy to remove the current partition\n"); |
---|
372 | return 1; |
---|
373 | } |
---|
374 | |
---|
375 | /* Read the name of the model to be passed to Part_NetworkCreatePartition */ |
---|
376 | currentNode = Hrc_ManagerReadCurrentNode(*hmgr); |
---|
377 | modelName = Hrc_NodeReadModelName(currentNode); |
---|
378 | |
---|
379 | /* Set the timeout */ |
---|
380 | if (timeOutPeriod > 0) { |
---|
381 | (void) signal(SIGALRM, (void(*)(int))TimeOutHandle); |
---|
382 | (void) alarm(timeOutPeriod); |
---|
383 | if (setjmp(timeOutEnv) > 0) { |
---|
384 | (void) fprintf(vis_stdout, "Partition: timeout occurred after "); |
---|
385 | (void) fprintf(vis_stdout, "%d seconds\n", timeOutPeriod); |
---|
386 | alarm(0); |
---|
387 | |
---|
388 | /* Partial clean up */ |
---|
389 | lsDestroy(nodeList, (void (*)(lsGeneric))0); |
---|
390 | return 1; |
---|
391 | } |
---|
392 | } |
---|
393 | |
---|
394 | /* |
---|
395 | * Execute the partition algorithm. The two nil pointers is to indicate |
---|
396 | * that the graph must represent the complete network. |
---|
397 | */ |
---|
398 | partition = Part_NetworkCreatePartition(network, currentNode, modelName, (lsList)0, |
---|
399 | (lsList)0, NIL(mdd_t), method, nodeList, |
---|
400 | inTermsOfLeaves, verbose, |
---|
401 | sanityCheck); |
---|
402 | |
---|
403 | /* Register the partition in the network if any */ |
---|
404 | Ntk_NetworkAddApplInfo(network, PART_NETWORK_APPL_KEY, |
---|
405 | (Ntk_ApplInfoFreeFn) Part_PartitionFreeCallback, |
---|
406 | (void *) partition); |
---|
407 | |
---|
408 | /* Deactivate the alarm */ |
---|
409 | alarm(0); |
---|
410 | |
---|
411 | /* Clean up */ |
---|
412 | if(fileUsed){ |
---|
413 | lsDestroy(nodeList, PartNameFree); |
---|
414 | } |
---|
415 | else{ |
---|
416 | lsDestroy(nodeList, (void (*)(lsGeneric))0); |
---|
417 | } |
---|
418 | return 0; |
---|
419 | |
---|
420 | usage: |
---|
421 | (void) fprintf(vis_stderr, "usage: build_partition_mdds [options] [method]\n"); |
---|
422 | (void) fprintf(vis_stderr, "Options:\n"); |
---|
423 | (void) fprintf(vis_stderr, " -h\t\tprint the command usage\n"); |
---|
424 | (void) fprintf(vis_stderr, " -i\t\tBuild the functions in the partition in terms of the\n"); |
---|
425 | (void) fprintf(vis_stderr, " \t\tcombinational inputs of the system. This option is redundant if\n"); |
---|
426 | (void) fprintf(vis_stderr, " \t\tthe inout partition is chosen.\n"); |
---|
427 | (void) fprintf(vis_stderr, " -n <list>\tComma separated list of network nodes to preserve in the\n"); |
---|
428 | (void) fprintf(vis_stderr, " \tpartitioning. It only matters if the partial method has been\n"); |
---|
429 | (void) fprintf(vis_stderr, " \tselected.\n"); |
---|
430 | (void) fprintf(vis_stderr, " -f <file>\tSpecifies the file containing names of network nodes\n"); |
---|
431 | (void) fprintf(vis_stderr, " \tto preserve while partitioning. This option matters only \n"); |
---|
432 | (void) fprintf(vis_stderr, " \tif the partial method has been selected. Each node name must\n"); |
---|
433 | (void) fprintf(vis_stderr, " \tbe listed on a new line. Comments in <file> must begin with '#'.\n"); |
---|
434 | (void) fprintf(vis_stderr, " -s <num>\tLevel of severity check applied after computation. 0 being no\n"); |
---|
435 | (void) fprintf(vis_stderr, " \t\tcheck, 1 begin simple check and >1 being exhaustive check.\n"); |
---|
436 | (void) fprintf(vis_stderr, " -t <sec>\tTime in seconds allowed to build the partition. If the\n"); |
---|
437 | (void) fprintf(vis_stderr, " \tcomputation time goes above that limit, the process of building\n"); |
---|
438 | (void) fprintf(vis_stderr, " \tthe partition is aborted.\n"); |
---|
439 | (void) fprintf(vis_stderr, " -v\t\tverbose\n"); |
---|
440 | (void) fprintf(vis_stderr, "Methods\n"); |
---|
441 | (void) fprintf(vis_stderr, " inout\tIt represents the network with one MDD for\n"); |
---|
442 | (void) fprintf(vis_stderr, " \teach combinational output as a function of the combinational\n"); |
---|
443 | (void) fprintf(vis_stderr, " \tinputs\n"); |
---|
444 | (void) fprintf(vis_stderr, " total\tPartitions the network preserving its structure. Every node in\n"); |
---|
445 | (void) fprintf(vis_stderr, " \tthe network will produce a vertex in the partition graph. The\n"); |
---|
446 | (void) fprintf(vis_stderr, " \tflag -i explained above controls the support of\n"); |
---|
447 | (void) fprintf(vis_stderr, " \tthe functions attached to the vertices.\n"); |
---|
448 | (void) fprintf(vis_stderr, " frontier\tThe default method. Partitions the network creating vertices for intermediate nodes\n"); |
---|
449 | (void) fprintf(vis_stderr, " \tas necessary to control the BDD size. The threshold value of the\n"); |
---|
450 | (void) fprintf(vis_stderr, " \tBDD can be specified by partition_threshold.\n"); |
---|
451 | (void) fprintf(vis_stderr, " partial\tPartitions the network preserving certain nodes specified with\n"); |
---|
452 | (void) fprintf(vis_stderr, " \tthe option -n or -f.\n"); |
---|
453 | (void) fprintf(vis_stderr, " boundary\tPartitions the network preserving all nodes that are \n"); |
---|
454 | (void) fprintf(vis_stderr, " \tsubcircuit IOs.\n"); |
---|
455 | |
---|
456 | lsDestroy(nodeList, (void (*)(lsGeneric))0); |
---|
457 | |
---|
458 | return 1; /* Error exit */ |
---|
459 | } /* End of CommandBuildPartitionMdds */ |
---|
460 | |
---|
461 | |
---|
462 | /**Function******************************************************************** |
---|
463 | |
---|
464 | Synopsis [This frees a given char *] |
---|
465 | |
---|
466 | Description [This function frees the memory assocated with a char * that |
---|
467 | is given as input] |
---|
468 | |
---|
469 | SideEffects [ ] |
---|
470 | |
---|
471 | SeeAlso [] |
---|
472 | |
---|
473 | ******************************************************************************/ |
---|
474 | void |
---|
475 | PartNameFree( |
---|
476 | lsGeneric name) |
---|
477 | { |
---|
478 | FREE(name); |
---|
479 | } |
---|
480 | |
---|
481 | |
---|
482 | /**Function******************************************************************** |
---|
483 | |
---|
484 | Synopsis [Command level routine to write a file in dot format of the |
---|
485 | partition DAG.] |
---|
486 | |
---|
487 | SideEffects [] |
---|
488 | |
---|
489 | SeeAlso [CommandBuildPartitionMdds] |
---|
490 | |
---|
491 | CommandName [print_partition] |
---|
492 | |
---|
493 | CommandSynopsis [print the "dot" format describing the partition graph] |
---|
494 | |
---|
495 | CommandArguments [\[-h\] <file>] |
---|
496 | |
---|
497 | CommandDescription [Write a file in the format taken by the tool |
---|
498 | <tt>dot</tt>. Dot is a tool that, given a description of a graph in a |
---|
499 | certain format, produces a postscript print of the graph. For more |
---|
500 | information about <tt>dot</tt> look in <a |
---|
501 | href="http://www.research.att.com/sw/tools/graphviz"> |
---|
502 | http://www.research.att.com/sw/tools/graphviz</a>.<p> |
---|
503 | |
---|
504 | If no argument is specified on the command line, the output is written to |
---|
505 | the standard output.<p> |
---|
506 | |
---|
507 | Command options:<p> |
---|
508 | <dl> |
---|
509 | |
---|
510 | <dt> -h |
---|
511 | <dd> Print the command usage.<p> |
---|
512 | |
---|
513 | <dt> <file> |
---|
514 | <dd> Name of file where the partition is to be written in "dot" format. |
---|
515 | |
---|
516 | </dl>] |
---|
517 | |
---|
518 | ******************************************************************************/ |
---|
519 | static int |
---|
520 | CommandPrintPartition( |
---|
521 | Hrc_Manager_t **hmgr, |
---|
522 | int argc, |
---|
523 | char **argv) |
---|
524 | { |
---|
525 | FILE *fp; |
---|
526 | int c, status; |
---|
527 | graph_t *partition; |
---|
528 | Ntk_Network_t *network = Ntk_HrcManagerReadCurrentNetwork(*hmgr); |
---|
529 | |
---|
530 | util_getopt_reset(); |
---|
531 | while ((c = util_getopt(argc,argv,"h")) != EOF){ |
---|
532 | switch(c){ |
---|
533 | case 'h': |
---|
534 | goto usage; |
---|
535 | default: |
---|
536 | goto usage; |
---|
537 | } |
---|
538 | } |
---|
539 | |
---|
540 | /* Check if the network has been read in */ |
---|
541 | if (network == NIL(Ntk_Network_t)) { |
---|
542 | return 1; |
---|
543 | } |
---|
544 | |
---|
545 | /* Check if there is a partition attached to the network */ |
---|
546 | partition = (graph_t *) Ntk_NetworkReadApplInfo(network, |
---|
547 | PART_NETWORK_APPL_KEY); |
---|
548 | if (partition == NIL(graph_t)) { |
---|
549 | (void) fprintf(vis_stderr, "No partition has been created for this network.\n"); |
---|
550 | return 1; |
---|
551 | } |
---|
552 | |
---|
553 | if (argc == 1) { |
---|
554 | fp = vis_stdout; |
---|
555 | } |
---|
556 | else if (argc == 2) { |
---|
557 | fp = Cmd_FileOpen(*(++argv), "w", NIL(char *), /* silent */ 1); |
---|
558 | if (fp == NIL(FILE)) { |
---|
559 | (void) fprintf(vis_stderr, "Cannot write to %s\n", *argv); |
---|
560 | return 1; |
---|
561 | } |
---|
562 | } |
---|
563 | else { |
---|
564 | goto usage; |
---|
565 | } |
---|
566 | |
---|
567 | error_init(); |
---|
568 | status = PartPartitionPrint(fp, partition); |
---|
569 | (void) fprintf(vis_stderr, "%s", error_string()); |
---|
570 | fflush(fp); |
---|
571 | |
---|
572 | /* If we opened a file before, close it */ |
---|
573 | if (argc == 2) { |
---|
574 | (void) fclose(fp); |
---|
575 | } |
---|
576 | return (status ? 0 : 1); |
---|
577 | |
---|
578 | usage: |
---|
579 | (void) fprintf(vis_stderr, "usage: print_partition [-h] [file]\n"); |
---|
580 | (void) fprintf(vis_stderr, " -h\t\tprint the command usage\n"); |
---|
581 | return 1; |
---|
582 | } /* End of CommandPrintPartition */ |
---|
583 | |
---|
584 | /**Function******************************************************************** |
---|
585 | |
---|
586 | Synopsis [Command level routine to print some stats of the partition DAG.] |
---|
587 | |
---|
588 | SideEffects [] |
---|
589 | |
---|
590 | SeeAlso [CommandBuildPartitionMdds] |
---|
591 | |
---|
592 | CommandName [print_partition_stats] |
---|
593 | |
---|
594 | CommandSynopsis [print statistics about the partition graph] |
---|
595 | |
---|
596 | CommandArguments [\[-h\] \[-n\]] |
---|
597 | |
---|
598 | CommandDescription [Print statistics about the partition currently attached |
---|
599 | to the network, such as: |
---|
600 | |
---|
601 | <dl> |
---|
602 | <li>Method used to build the partition. |
---|
603 | <li>Number of sink vertices. |
---|
604 | <li>Number of source vertices. |
---|
605 | <li>Total number of vertices. |
---|
606 | <li>Number of shared MDD nodes used to represent the functions. |
---|
607 | </dl> |
---|
608 | |
---|
609 | Command options:<p> |
---|
610 | |
---|
611 | <dl> |
---|
612 | |
---|
613 | <dt> -h |
---|
614 | <dd> Print the command usage.<p> |
---|
615 | |
---|
616 | <dt> -n |
---|
617 | <dd> Print the name of the network nodes represented by vertices in the |
---|
618 | partition. |
---|
619 | |
---|
620 | </dl>] |
---|
621 | |
---|
622 | ******************************************************************************/ |
---|
623 | static int |
---|
624 | CommandPrintPartitionStats( |
---|
625 | Hrc_Manager_t **hmgr, |
---|
626 | int argc, |
---|
627 | char **argv) |
---|
628 | { |
---|
629 | int c; |
---|
630 | graph_t *partition; |
---|
631 | Ntk_Network_t *network = Ntk_HrcManagerReadCurrentNetwork(*hmgr); |
---|
632 | boolean printNodeNames = FALSE; |
---|
633 | |
---|
634 | util_getopt_reset(); |
---|
635 | while ((c = util_getopt(argc,argv,"hn")) != EOF){ |
---|
636 | switch(c){ |
---|
637 | case 'n': |
---|
638 | printNodeNames = TRUE; |
---|
639 | break; |
---|
640 | case 'h': |
---|
641 | goto usage; |
---|
642 | default: |
---|
643 | goto usage; |
---|
644 | } |
---|
645 | } |
---|
646 | |
---|
647 | /* Check if the network has been read in */ |
---|
648 | if (network == NIL(Ntk_Network_t)) { |
---|
649 | return 1; |
---|
650 | } |
---|
651 | |
---|
652 | /* Check if there is a partition attached to the network */ |
---|
653 | partition = (graph_t *) Ntk_NetworkReadApplInfo(network, |
---|
654 | PART_NETWORK_APPL_KEY); |
---|
655 | if (partition == NIL(graph_t)) { |
---|
656 | (void) fprintf(vis_stderr, "No partition has been created for this network.\n"); |
---|
657 | return 1; |
---|
658 | } |
---|
659 | |
---|
660 | /* Print the statistics to vis_stdout */ |
---|
661 | Part_PartitionPrintStats(vis_stdout, partition, printNodeNames); |
---|
662 | return 0; |
---|
663 | |
---|
664 | usage: |
---|
665 | (void) fprintf(vis_stderr, "usage: print_partition_stats [-h] [-n]\n"); |
---|
666 | (void) fprintf(vis_stderr, " -h\t\tprint the command usage\n"); |
---|
667 | (void) fprintf(vis_stderr, " -n\t\tprint names of network nodes "); |
---|
668 | (void) fprintf(vis_stderr, "represented by vertices\n"); |
---|
669 | return 1; |
---|
670 | } /* End of CommandPrintPartitionStats */ |
---|
671 | |
---|
672 | |
---|
673 | /**Function******************************************************************** |
---|
674 | |
---|
675 | Synopsis [required] |
---|
676 | |
---|
677 | Description [optional] |
---|
678 | |
---|
679 | SideEffects [required] |
---|
680 | |
---|
681 | SeeAlso [optional] |
---|
682 | |
---|
683 | ******************************************************************************/ |
---|
684 | static void |
---|
685 | TimeOutHandle(void) |
---|
686 | { |
---|
687 | longjmp(timeOutEnv, 1); |
---|
688 | } /* End of TimeOutHandle */ |
---|