1 package Analysis.Scheduling;
4 import java.io.FileOutputStream;
5 import java.io.PrintWriter;
6 import java.util.Collection;
7 import java.util.Enumeration;
8 import java.util.HashSet;
9 import java.util.Hashtable;
10 import java.util.Iterator;
12 import java.util.Vector;
13 import java.util.Map.Entry;
15 import Analysis.Scheduling.ScheduleSimulator.Action;
16 import Analysis.Scheduling.ScheduleSimulator.CheckPoint;
17 import Analysis.TaskStateAnalysis.Allocations;
18 import Analysis.TaskStateAnalysis.FEdge;
19 import Analysis.TaskStateAnalysis.FlagState;
20 import Analysis.TaskStateAnalysis.FEdge.NewObjInfo;
21 import IR.ClassDescriptor;
24 import IR.Tree.FlagExpressionNode;
25 import IR.Tree.FlagNode;
26 import IR.Tree.FlagOpNode;
28 import Util.GraphNode;
31 public class SchedulingUtil {
33 public static Vector<ScheduleNode> generateScheduleGraph(State state,
34 Vector<ScheduleNode> scheduleNodes,
35 Vector<ScheduleEdge> scheduleEdges,
36 Vector<Vector<ScheduleNode>> mapping,
38 Vector<ScheduleNode> result = new Vector<ScheduleNode>();
40 // clone the ScheduleNodes
41 Hashtable<ScheduleNode, Hashtable<ClassNode, ClassNode>> sn2hash =
42 new Hashtable<ScheduleNode, Hashtable<ClassNode, ClassNode>>();
43 Hashtable<ScheduleNode, ScheduleNode> sn2sn =
44 new Hashtable<ScheduleNode, ScheduleNode>();
45 cloneScheduleGraph(scheduleNodes,
52 // combine those nodes in combine with corresponding rootnodes
53 for(int i = 0; i < mapping.size(); i++) {
54 Vector<ScheduleNode> sNodes = mapping.elementAt(i);
56 ScheduleNode rootnode = sNodes.elementAt(0);
57 for(int j = 1; j < sNodes.size(); j++) {
58 ScheduleNode tocombine = sn2sn.get(sNodes.elementAt(j));
59 ScheduleNode root = sn2sn.get(rootnode);
60 ScheduleEdge se = (ScheduleEdge)tocombine.inedges().next();
62 if(root.equals(((ScheduleNode)se.getSource()))) {
64 if(ScheduleEdge.NEWEDGE == se.getType()) {
65 // As se has been changed into an internal edge inside a ScheduleNode,
66 // change the source and target of se from original ScheduleNodes into ClassNodes.
67 se.setTarget(se.getTargetCNode());
68 //se.setSource(se.getSourceCNode());
69 //se.getTargetCNode().addEdge(se);
70 se.getSourceCNode().addEdge(se);
73 root.mergeSNode(tocombine);
75 } catch(Exception e) {
79 result.removeElement(tocombine);
91 if(state.PRINTSCHEDULING) {
92 String path = state.outputdir + "scheduling_" + gid + ".dot";
93 SchedulingUtil.printScheduleGraph(path, result);
99 public static Vector<ScheduleNode> generateScheduleGraph(State state,
100 Vector<ScheduleNode> scheduleNodes,
101 Vector<ScheduleEdge> scheduleEdges,
102 Vector<Vector<ScheduleNode>> rootnodes,
103 Vector<Vector<CombinationUtil.Combine>> combine,
105 Vector<ScheduleNode> result = new Vector<ScheduleNode>();
107 // clone the ScheduleNodes
108 Hashtable<ScheduleNode, Hashtable<ClassNode, ClassNode>> sn2hash =
109 new Hashtable<ScheduleNode, Hashtable<ClassNode, ClassNode>>();
110 Hashtable<ScheduleNode, ScheduleNode> sn2sn =
111 new Hashtable<ScheduleNode, ScheduleNode>();
112 cloneScheduleGraph(scheduleNodes,
119 // combine those nodes in combine with corresponding rootnodes
120 for(int i = 0; i < combine.size(); i++) {
121 if(combine.elementAt(i) != null) {
122 for(int j = 0; j < combine.elementAt(i).size(); j++) {
123 CombinationUtil.Combine tmpcombine = combine.elementAt(i).elementAt(j);
124 ScheduleNode tocombine = sn2sn.get(tmpcombine.node);
125 ScheduleNode root = sn2sn.get(rootnodes.elementAt(tmpcombine.root).elementAt(tmpcombine.index));
126 ScheduleEdge se = (ScheduleEdge)tocombine.inedges().next();
128 if(root.equals(((ScheduleNode)se.getSource()))) {
130 if(ScheduleEdge.NEWEDGE == se.getType()) {
131 // As se has been changed into an internal edge inside a ScheduleNode,
132 // change the source and target of se from original ScheduleNodes into ClassNodes.
133 se.setTarget(se.getTargetCNode());
134 //se.setSource(se.getSourceCNode());
135 //se.getTargetCNode().addEdge(se);
136 se.getSourceCNode().addEdge(se);
139 root.mergeSNode(tocombine);
141 } catch(Exception e) {
145 result.removeElement(tocombine);
157 if(state.PRINTSCHEDULING) {
158 String path = state.outputdir + "scheduling_" + gid + ".dot";
159 SchedulingUtil.printScheduleGraph(path, result);
165 public static void cloneScheduleGraph(Vector<ScheduleNode> scheduleNodes,
166 Vector<ScheduleEdge> scheduleEdges,
167 Hashtable<ScheduleNode, Hashtable<ClassNode, ClassNode>> sn2hash,
168 Hashtable<ScheduleNode, ScheduleNode> sn2sn,
169 Vector<ScheduleNode> result,
171 for(int i = 0; i < scheduleNodes.size(); i++) {
172 Hashtable<ClassNode, ClassNode> cn2cn = new Hashtable<ClassNode, ClassNode>();
173 ScheduleNode tocopy = scheduleNodes.elementAt(i);
174 ScheduleNode temp = (ScheduleNode)tocopy.clone(cn2cn, gid);
176 sn2hash.put(temp, cn2cn);
177 sn2sn.put(tocopy, temp);
180 // clone the ScheduleEdges
181 for(int i = 0; i < scheduleEdges.size(); i++) {
182 ScheduleEdge sse = scheduleEdges.elementAt(i);
183 ScheduleNode csource = sn2sn.get(sse.getSource());
184 ScheduleNode ctarget = sn2sn.get(sse.getTarget());
185 Hashtable<ClassNode, ClassNode> sourcecn2cn = sn2hash.get(csource);
186 Hashtable<ClassNode, ClassNode> targetcn2cn = sn2hash.get(ctarget);
187 ScheduleEdge se = null;
188 switch(sse.getType()) {
189 case ScheduleEdge.NEWEDGE: {
190 se = new ScheduleEdge(ctarget, "new", sse.getFstate(), sse.getType(), gid); //new ScheduleEdge(ctarget, "new", sse.getClassDescriptor(), sse.getIsNew(), gid);
191 se.setProbability(sse.getProbability());
192 se.setNewRate(sse.getNewRate());
196 case ScheduleEdge.TRANSEDGE: {
197 se = new ScheduleEdge(ctarget, "transmit", sse.getFstate(), sse.getType(), gid); //new ScheduleEdge(ctarget, "transmit", sse.getClassDescriptor(), false, gid);
201 se.setSourceCNode(sourcecn2cn.get(sse.getSourceCNode()));
202 se.setTargetCNode(targetcn2cn.get(sse.getTargetCNode()));
203 se.setFEdge(sse.getFEdge());
204 se.setTargetFState(sse.getTargetFState());
212 public static void assignCids(Vector<ScheduleNode> result) {
213 Hashtable<Integer, Integer> hcid2cid = new Hashtable<Integer, Integer>();
215 for(int i = 0; i < result.size(); i++) {
216 ScheduleNode tmpnode = result.elementAt(i);
217 tmpnode.computeHashcid();
218 int hcid = tmpnode.getHashcid();
219 if(hcid2cid.containsKey(hcid)) {
220 // already have a cid for this node
221 tmpnode.setCid(hcid2cid.get(hcid));
223 // generate a new cid for such node
224 tmpnode.setCid(ncid);
225 hcid2cid.put(hcid, ncid);
233 // Organize the scheduleNodes in order of their cid
234 public static Vector<Vector<ScheduleNode>>
235 rangeScheduleNodes(Vector<ScheduleNode> scheduleNodes) {
237 Vector<Vector<ScheduleNode>> sNodeVecs = new Vector<Vector<ScheduleNode>>();
239 for(int i = 0; i < scheduleNodes.size(); i++) {
240 ScheduleNode tmpn = scheduleNodes.elementAt(i);
241 int tmpcid = tmpn.getCid();
243 for(index = 0; index < sNodeVecs.size(); index++) {
244 if(sNodeVecs.elementAt(index).elementAt(0).getCid() > tmpcid) {
245 // find the place to insert
246 sNodeVecs.insertElementAt(new Vector<ScheduleNode>(), index);
247 /*sNodeVecs.add(sNodeVecs.lastElement());
248 for(int j = sNodeVecs.size() - 2; j > index; j--) {
249 sNodeVecs.setElementAt(sNodeVecs.elementAt(j - 1), j);
251 sNodeVecs.setElementAt(new Vector<ScheduleNode>(), index);*/
253 } else if(sNodeVecs.elementAt(index).elementAt(0).getCid() == tmpcid) {
257 if(index == sNodeVecs.size()) {
258 sNodeVecs.add(new Vector<ScheduleNode>());
261 /*int index = tmpcid;
262 while(sNodeVecs.size() <= index) {
265 if(sNodeVecs.elementAt(index) == null) {
266 sNodeVecs.setElementAt(new Vector<ScheduleNode>(), index);
268 if(!sNodeVecs.elementAt(index).contains(tmpn)) {
269 sNodeVecs.elementAt(index).addElement(tmpn);
275 System.err.println("Error in rangeScheduleNodes: " + scheduleNodes.size());
282 /*public static int maxDivisor(int l, int r) {
294 if(((a&1)==0) && ((b&1)==0)) {
295 // a and b are both even
299 } else if(((a&1)==0) && ((b&1)!=0)) {
300 // a is even, b is odd
302 } else if (((a&1)!=0) && ((b&1)==0)) {
303 // a is odd, b is even
305 } else if (((a&1)!=0) && ((b&1)!=0)) {
306 // a and b are both odd
308 a = a>b ? (a-b):(b-a);
314 public static boolean isTaskTrigger_flag(FlagExpressionNode fen,
318 else if (fen instanceof FlagNode)
319 return fs.get(((FlagNode)fen).getFlag());
321 switch (((FlagOpNode)fen).getOp().getOp()) {
322 case Operation.LOGIC_AND:
323 return ((isTaskTrigger_flag(((FlagOpNode)fen).getLeft(),fs)) && (isTaskTrigger_flag(((FlagOpNode)fen).getRight(),fs)));
325 case Operation.LOGIC_OR:
326 return ((isTaskTrigger_flag(((FlagOpNode)fen).getLeft(),fs)) || (isTaskTrigger_flag(((FlagOpNode)fen).getRight(),fs)));
328 case Operation.LOGIC_NOT:
329 return !(isTaskTrigger_flag(((FlagOpNode)fen).getLeft(),fs));
336 public static void printScheduleGraph(String path,
337 Vector<ScheduleNode> sNodes) {
339 File file=new File(path);
340 FileOutputStream dotstream=new FileOutputStream(file,false);
341 PrintWriter output = new java.io.PrintWriter(dotstream, true);
342 output.println("digraph G {");
343 output.println("\tcompound=true;\n");
344 traverseSNodes(output, sNodes);
345 output.println("}\n");
347 } catch (Exception e) {
353 private static void traverseSNodes(PrintWriter output,
354 Vector<ScheduleNode> sNodes) {
355 //Draw clusters representing ScheduleNodes
356 Iterator it = sNodes.iterator();
357 while (it.hasNext()) {
358 ScheduleNode gn = (ScheduleNode) it.next();
359 Iterator edges = gn.edges();
360 output.println("\tsubgraph " + gn.getLabel() + "{");
361 output.println("\t\tlabel=\"" + gn.getTextLabel() + "\";");
362 Iterator it_cnodes = gn.getClassNodesIterator();
363 traverseCNodes(output, it_cnodes);
365 //Draw the internal 'new' edges
366 Iterator it_edges =gn.getScheduleEdgesIterator();
367 while(it_edges.hasNext()) {
368 ScheduleEdge se = (ScheduleEdge)it_edges.next();
370 if(se.getSourceCNode().isclone()) {
371 output.print(se.getSourceCNode().getLabel());
373 if(se.getSourceFState() == null) {
374 output.print(se.getSourceCNode().getClusterLabel());
376 output.print(se.getSourceFState().getLabel());
380 output.print(" -> ");
382 if(se.getTargetCNode().isclone()) {
383 output.print(se.getTargetCNode().getLabel());
385 output.print(se.getTargetCNode().getClusterLabel());
387 output.println(" [label=\"" + se.getLabel() + "\", color=red];");
389 output.print(se.getTargetFState().getLabel() + " [label=\"" + se.getLabel() + "\", color=red, ltail=");
390 if(se.getSourceCNode().isclone()) {
391 output.println(se.getSourceCNode().getLabel() + "];");
393 output.println(se.getSourceCNode().getClusterLabel() + "];");
397 output.println("\t}\n");
399 //Draw 'new' edges of this ScheduleNode
400 while(edges.hasNext()) {
401 ScheduleEdge se = (ScheduleEdge)edges.next();
403 if(se.getSourceCNode().isclone()) {
404 output.print(se.getSourceCNode().getLabel());
406 if(se.getSourceFState() == null) {
407 output.print(se.getSourceCNode().getClusterLabel());
409 output.print(se.getSourceFState().getLabel());
413 output.print(" -> ");
415 if(se.getTargetCNode().isclone()) {
416 output.print(se.getTargetCNode().getLabel());
418 output.print(se.getTargetCNode().getClusterLabel());
420 output.println(" [label=\"" + se.getLabel() + "\", color=red, style=dashed];");
422 output.println(se.getTargetFState().getLabel() + " [label=\"" + se.getLabel() + "\", color=red, style=dashed];");
430 private static void traverseCNodes(PrintWriter output,
432 //Draw clusters representing ClassNodes
433 while (it.hasNext()) {
434 ClassNode gn = (ClassNode) it.next();
436 output.println("\t\t" + gn.getLabel() + " [style=dashed, label=\"" + gn.getTextLabel() + "\", shape=box];");
438 output.println("\tsubgraph " + gn.getClusterLabel() + "{");
439 output.println("\t\tstyle=dashed;");
440 output.println("\t\tlabel=\"" + gn.getTextLabel() + "\";");
441 traverseFlagStates(output, gn.getFlagStates());
442 output.println("\t}\n");
447 private static void traverseFlagStates(PrintWriter output,
449 Set cycleset=GraphNode.findcycles(nodes);
450 Vector namers=new Vector();
451 namers.add(new Namer());
452 namers.add(new Allocations());
454 Iterator it = nodes.iterator();
455 while (it.hasNext()) {
456 GraphNode gn = (GraphNode) it.next();
457 Iterator edges = gn.edges();
459 String dotnodeparams="";
461 for(int i=0; i<namers.size(); i++) {
462 Namer name=(Namer) namers.get(i);
463 String newlabel=name.nodeLabel(gn);
464 String newparams=name.nodeOption(gn);
466 if (!newlabel.equals("") && !label.equals("")) {
469 if (!newparams.equals("")) {
470 dotnodeparams+=", " + name.nodeOption(gn);
472 label+=name.nodeLabel(gn);
474 label += ":[" + ((FlagState)gn).getExeTime() + "]";
477 output.println("\t" + gn.getLabel() + " [label=\"" + label + "\"" + dotnodeparams + "];");
480 while (edges.hasNext()) {
481 Edge edge = (Edge) edges.next();
482 GraphNode node = edge.getTarget();
483 if (nodes.contains(node)) {
484 Iterator nodeit=nonmerge(node, nodes).iterator();
485 for(; nodeit.hasNext(); ) {
486 GraphNode node2=(GraphNode)nodeit.next();
487 String edgelabel = "";
488 String edgedotnodeparams="";
490 for(int i=0; i<namers.size(); i++) {
491 Namer name=(Namer) namers.get(i);
492 String newlabel=name.edgeLabel(edge);
493 String newoption=name.edgeOption(edge);
494 if (!newlabel.equals("")&& !edgelabel.equals(""))
497 if (!newoption.equals(""))
498 edgedotnodeparams+=", "+newoption;
500 edgelabel+=":[" + ((FEdge)edge).getExeTime() + "]";
501 edgelabel+=":(" + ((FEdge)edge).getProbability() + "%)";
502 Hashtable<ClassDescriptor, NewObjInfo> hashtable = ((FEdge)edge).getNewObjInfoHashtable();
503 if(hashtable != null) {
504 Set<ClassDescriptor> keys = hashtable.keySet();
505 Iterator it_keys = keys.iterator();
506 while(it_keys.hasNext()) {
507 ClassDescriptor cd = (ClassDescriptor)it_keys.next();
508 NewObjInfo noi = hashtable.get(cd);
509 edgelabel += ":{ class " + cd.getSymbol() + " | " + noi.getNewRate() + " | (" + noi.getProbability() + "%) }";
514 output.println("\t" + gn.getLabel() + " -> " + node2.getLabel() + " [" + "label=\"" + edgelabel + "\"" + edgedotnodeparams + "];");
526 private static Set nonmerge(GraphNode gn,
528 HashSet newset=new HashSet();
529 HashSet toprocess=new HashSet();
531 while(!toprocess.isEmpty()) {
532 GraphNode gn2=(GraphNode)toprocess.iterator().next();
533 toprocess.remove(gn2);
537 Iterator edges = gn2.edges();
538 while (edges.hasNext()) {
539 Edge edge = (Edge) edges.next();
540 GraphNode node = edge.getTarget();
541 if (!newset.contains(node)&&nodes.contains(node))
551 public static void printSimulationResult(String path,
554 Vector<CheckPoint> checkpoints) {
556 File file=new File(path);
557 FileOutputStream dotstream=new FileOutputStream(file,false);
558 PrintWriter output = new java.io.PrintWriter(dotstream, true);
559 output.println("digraph simulation{");
561 output.println("node [shape=plaintext];");
563 output.println("edge [dir=none];");
565 output.println("ranksep=.05;");
571 output.print("{rank=source; \"Time\"; ");
572 for(j = 0; j < coreNum; j++) {
573 output.print("\"core " + j + "\"; ");
576 // time coordinate nodes
577 Vector<String> timeNodes = new Vector<String>();
578 String[] lastTaskNodes = new String[coreNum];
579 String[] lastTasks = new String[coreNum];
580 boolean[] isTaskFinish = new boolean[coreNum];
581 for(j = 0; j < coreNum; j++) {
582 lastTaskNodes[j] = "first";
583 isTaskFinish[j] = true;
587 for(j = 0; j < checkpoints.size(); j++) {
588 CheckPoint tcp = checkpoints.elementAt(j);
589 Hashtable<Integer, String> tmplastTasks = new Hashtable<Integer, String>();
590 Vector<Integer> tmpisTaskFinish = new Vector<Integer>();
591 Vector<Integer> tmpisset = new Vector<Integer>();
592 String tnode = String.valueOf(tcp.getTimepoint());
593 if(!timeNodes.contains(tnode)) {
594 timeNodes.add(tnode);
596 Vector<Action> actions = tcp.getActions();
597 Hashtable<String, StringBuffer> tmpTaskNodes = new Hashtable<String, StringBuffer>();
598 for(int i = 0; i < actions.size(); i++) {
599 Action taction = actions.elementAt(i);
600 int cNum = taction.getCoreNum();
601 if(!tmplastTasks.containsKey(cNum)) {
602 tmplastTasks.put(cNum, lastTasks[cNum]);
604 if(!(tmpisset.contains(cNum))
605 && (isTaskFinish[cNum])
606 && !(tmpisTaskFinish.contains(cNum))) {
607 tmpisTaskFinish.add(cNum); // records those with task finished the first time visit it
609 String tmpTaskNode = "\"" + tnode + "core" + cNum + "\"";
610 StringBuffer tmpLabel = null;
611 boolean isfirst = false;
612 if(!tmpTaskNodes.containsKey(tmpTaskNode)) {
613 tmpTaskNodes.put(tmpTaskNode, new StringBuffer(tnode + ":"));
616 tmpLabel = tmpTaskNodes.get(tmpTaskNode);
617 switch(taction.getType()) {
618 case Action.ADDOBJ: {
620 tmpLabel.append("\\n");
622 tmpLabel.append("(" + taction.getTransObj().getSymbol() + ")arrives;");
623 if(!(lastTaskNodes[cNum].equals(tmpTaskNode))) {
625 if(lastTaskNodes[cNum].equals("first")) {
626 output.print("\"core " + cNum + "\"->" + tmpTaskNode);
628 output.print(lastTaskNodes[cNum] + "->" + tmpTaskNode);
630 if(tmpisTaskFinish.contains(cNum)) {
631 output.print(" [style=invis]");
634 lastTaskNodes[cNum] = tmpTaskNode;
639 case Action.TASKFINISH: {
641 tmpLabel.append("\\n");
643 tmpLabel.append("<" + taction.getTd().getSymbol() + "(");
644 /*Vector<Integer> taskparams = taction.getTaskParams();
645 for(int ii = 0; ii < taskparams.size(); ii++) {
646 tmpLabel.append(taskparams.elementAt(ii));
647 if(ii < taskparams.size() - 1) {
648 tmpLabel.append(",");
651 tmpLabel.append(")>finishes;");
652 if(!(lastTaskNodes[cNum].equals("first"))) {
653 if(!(lastTaskNodes[cNum].equals(tmpTaskNode))) {
655 output.println(lastTaskNodes[cNum] + "->" + tmpTaskNode + ";");
656 lastTaskNodes[cNum] = tmpTaskNode;
658 if(tmpisset.contains(cNum)) {
659 isTaskFinish[cNum] &= true;
661 isTaskFinish[cNum] = true;
664 lastTasks[cNum] = "";
666 throw new Exception("Error: unexpected task finish");
671 case Action.TFWITHOBJ: {
673 tmpLabel.append("\\n");
675 tmpLabel.append("<" + taction.getTd().getSymbol() + "(");
676 /*Vector<Integer> taskparams = taction.getTaskParams();
677 for(int ii = 0; ii < taskparams.size(); ii++) {
678 tmpLabel.append(taskparams.elementAt(ii));
679 if(ii < taskparams.size() - 1) {
680 tmpLabel.append(",");
683 tmpLabel.append(")>finishes;");
684 Iterator<Entry<ClassDescriptor, Integer>> it_entry = (Iterator<Entry<ClassDescriptor, Integer>>)taction.getNObjs().entrySet().iterator();
685 while(it_entry.hasNext()) {
686 Entry<ClassDescriptor, Integer> entry = it_entry.next();
687 tmpLabel.append(entry.getValue() + "(" + entry.getKey().getSymbol() + ")");
688 if(it_entry.hasNext()) {
689 tmpLabel.append(",");
691 tmpLabel.append(";");
696 if(!(lastTaskNodes[cNum].equals("first"))) {
697 if (!(lastTaskNodes[cNum].equals(tmpTaskNode))) {
699 output.println(lastTaskNodes[cNum] + "->" + tmpTaskNode + ";");
700 lastTaskNodes[cNum] = tmpTaskNode;
702 if(tmpisset.contains(cNum)) {
703 isTaskFinish[cNum] &= true;
705 isTaskFinish[cNum] = true;
708 lastTasks[cNum] = "";
710 throw new Exception("Error: unexpected task finish");
715 case Action.TASKSTART: {
717 tmpLabel.append("\\n");
719 tmpLabel.append("<" + taction.getTd().getSymbol() + "(");
720 /*Vector<Integer> taskparams = taction.getTaskParams();
721 for(int ii = 0; ii < taskparams.size(); ii++) {
722 tmpLabel.append(taskparams.elementAt(ii));
723 if(ii < taskparams.size() - 1) {
724 tmpLabel.append(",");
727 tmpLabel.append(")>starts;");
728 lastTasks[cNum] = taction.getTd().getSymbol();
730 if (!(lastTaskNodes[cNum].equals(tmpTaskNode))) {
732 if(lastTaskNodes[cNum].equals("first")) {
733 output.print("\"core " + cNum + "\"->" + tmpTaskNode);
735 output.print(lastTaskNodes[cNum] + "->" + tmpTaskNode);
737 if(tmpisTaskFinish.contains(cNum)) {
738 output.print(" [style=invis]");
741 lastTaskNodes[cNum] = tmpTaskNode;
743 isTaskFinish[cNum] &= false;
747 case Action.TASKABORT: {
749 tmpLabel.append("\\n");
751 tmpLabel.append("<" + taction.getTd().getSymbol() + "(");
752 /*Vector<Integer> taskparams = taction.getTaskParams();
753 for(int ii = 0; ii < taskparams.size(); ii++) {
754 tmpLabel.append(taskparams.elementAt(ii));
755 if(ii < taskparams.size() - 1) {
756 tmpLabel.append(",");
759 tmpLabel.append(")>aborts;");
760 if(!(lastTaskNodes[cNum].equals("first")) &&
761 (tmplastTasks.get(cNum).equals(taction.getTd().getSymbol()))) {
762 if(!(lastTaskNodes[cNum].equals(tmpTaskNode))) {
764 output.println(lastTaskNodes[cNum] + "->" + tmpTaskNode + ";");
765 lastTaskNodes[cNum] = tmpTaskNode;
767 if(tmpisset.contains(cNum)) {
768 isTaskFinish[cNum] &= true;
770 isTaskFinish[cNum] = true;
773 lastTasks[cNum] = "";
775 throw new Exception("Error: unexpected task aborts");
780 case Action.TASKREMOVE: {
782 tmpLabel.append("\\n");
784 tmpLabel.append("<" + taction.getTd().getSymbol() + "(");
785 /*Vector<Integer> taskparams = taction.getTaskParams();
786 for(int ii = 0; ii < taskparams.size(); ii++) {
787 tmpLabel.append(taskparams.elementAt(ii));
788 if(ii < taskparams.size() - 1) {
789 tmpLabel.append(",");
792 tmpLabel.append(")>removes;");
793 if(!(lastTaskNodes[cNum].equals("first")) &&
794 (tmplastTasks.get(cNum).equals(taction.getTd().getSymbol()))) {
795 if(!(lastTaskNodes[cNum].equals(tmpTaskNode))) {
797 output.println(lastTaskNodes[cNum] + "->" + tmpTaskNode + ";");
798 lastTaskNodes[cNum] = tmpTaskNode;
800 if(tmpisset.contains(cNum)) {
801 isTaskFinish[cNum] &= true;
803 isTaskFinish[cNum] = true;
806 lastTasks[cNum] = "";
808 throw new Exception("Error: unexpected task remove");
814 Enumeration<String> keys = tmpTaskNodes.keys();
815 while(keys.hasMoreElements()) {
816 String tmpTaskNode = keys.nextElement();
818 output.println(tmpTaskNode + "[label=\"" + tmpTaskNodes.get(tmpTaskNode).toString() + "\"]");
821 output.print("{rank=same; rankdir=LR; " + tnode + "; ");
822 keys = tmpTaskNodes.keys();
823 while(keys.hasMoreElements()) {
824 String tmpTaskNode = keys.nextElement();
825 output.print(tmpTaskNode);
832 tmpisTaskFinish = null;
839 long prev = Long.parseLong(timeNodes.elementAt(0));
843 for(j = 1; j < timeNodes.size(); j++) {
844 next = Long.parseLong(timeNodes.elementAt(j));
845 long delta = next - prev;
849 } else if((max != delta) && (max2 < delta)) {
856 } else if(max/max2 > 100) {
859 output.println("\"Time\"->" + timeNodes.elementAt(0) + "[style=invis];");
860 prev = Long.parseLong(timeNodes.elementAt(0));
862 for(j = 1; j < timeNodes.size(); j++) {
863 next = Long.parseLong(timeNodes.elementAt(j));
864 if(next - prev > max2) {
866 output.print(prev + "->");
868 } while(next - prev > max2);
869 output.println(next + ";");
871 output.println("{rank=same; rankdir=LR; " + prev + "; " + next + "}");
872 output.println(prev + "->" + next + "[style=invis];");
877 /*for(j = 0; j < time; j++) {
878 output.print(j + "->");
880 output.println(timeNodes.lastElement() + ";");*/
884 lastTaskNodes = null;
887 } catch (Exception e) {
893 public static void printCriticalPath(String path,
894 Vector<SimExecutionEdge> criticalPath) {
896 File file=new File(path);
897 FileOutputStream dotstream=new FileOutputStream(file,false);
898 PrintWriter output = new java.io.PrintWriter(dotstream, true);
899 output.println("digraph simulation{");
901 output.println("node [shape=plaintext];");
903 output.println("edge [dir=none];");
905 output.println("ranksep=.05;");
908 Vector<SimExecutionNode> nodes = new Vector<SimExecutionNode>();
910 String dotnodeparams="";
912 for(int i = 0; i < criticalPath.size(); i++) {
913 SimExecutionEdge seedge = criticalPath.elementAt(i);
914 SimExecutionNode startnode = (SimExecutionNode)seedge.getSource();
915 SimExecutionNode endnode = (SimExecutionNode)seedge.getTarget();
916 if(!nodes.contains(startnode)) {
917 label = startnode.getCoreNum() + ":" + startnode.getTimepoint();
918 output.println("\t" + startnode.getLabel() + " [label=\""
920 nodes.addElement(startnode);
922 if(!nodes.contains(endnode)) {
923 label = endnode.getCoreNum() + ":" + endnode.getTimepoint();
924 output.println("\t" + endnode.getLabel() + " [label=\""
926 nodes.addElement(endnode);
928 output.println("\t" + startnode.getLabel() + " -> " + endnode.getLabel()
929 + " [" + "label=\"" + seedge.getLabel() + "\"];");
935 } catch (Exception e) {