add codes for generating distribution data for new search algorithm
authorjzhou <jzhou>
Mon, 2 Mar 2009 02:06:14 +0000 (02:06 +0000)
committerjzhou <jzhou>
Mon, 2 Mar 2009 02:06:14 +0000 (02:06 +0000)
Robust/src/Analysis/Scheduling/CombinationUtil.java
Robust/src/Analysis/Scheduling/MCImplSynthesis.java
Robust/src/Analysis/Scheduling/ScheduleAnalysis.java
Robust/src/Analysis/Scheduling/ScheduleNode.java
Robust/src/Analysis/Scheduling/ScheduleSimulator.java
Robust/src/Analysis/Scheduling/SchedulingUtil.java
Robust/src/Analysis/Scheduling/SimExecutionEdge.java
Robust/src/Main/Main.java

index 4356cbfaecccfb7a9d81a44751ea55f22113771c..be8f5667918371706879af38354f826ff0288c1d 100644 (file)
@@ -38,6 +38,15 @@ public class CombinationUtil {
       this.node2Combine = null;
       this.rootNodes = null;
     }
+    
+    public void clear() {
+       this.sNodeVecs = null;
+       this.node2Combine.clear();
+       this.node2Combine = null;
+       this.rootNodes.clear();
+       this.rootNodes = null;
+       this.rootNum = 0;
+    }
 
     public boolean nextGen() {
       boolean trial = false;
@@ -215,6 +224,17 @@ public class CombinationUtil {
       this.lastchoices = null;
       this.first4choice = false;
     }
+    
+    public void clear() {
+       this.rootNodes = null;
+       this.rootNStates.clear();
+       this.rootNStates = null;
+       this.node2Combine = null;
+       this.combine.clear(); 
+       this.combine = null;
+       this.lastchoices = null;
+       this.first4choice = false;
+    }
 
     public Vector<Vector<Combine>> getCombine() {
       return combine;
index 1bcb287915492ab40efbde064ff3cb16b389d67f..983af365979473d0061c16404e6a89492a63019b 100644 (file)
@@ -1,7 +1,9 @@
 package Analysis.Scheduling;
 
+import java.io.File;
 import java.io.FileOutputStream;
 import java.io.PrintStream;
+import java.io.PrintWriter;
 import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.Random;
@@ -27,6 +29,9 @@ public class MCImplSynthesis {
     int coreNum;
     int scheduleThreshold;
     int probThreshold;
+    int generateThreshold;
+    
+    //Random rand;
 
     public MCImplSynthesis(State state, 
                           TaskAnalysis ta,
@@ -37,12 +42,14 @@ public class MCImplSynthesis {
        this.ownershipAnalysis = oa;
        this.scheduleAnalysis = new ScheduleAnalysis(state,
                                                     ta);
-       scheduleAnalysis.setCoreNum(this.coreNum);
+       this.scheduleAnalysis.setCoreNum(this.coreNum);
        this.scheduleSimulator = new ScheduleSimulator(this.coreNum,
                                                       state,
                                                       ta);
        this.scheduleThreshold = 1000;
        this.probThreshold = 0;
+       this.generateThreshold = 30;
+       //this.rand = new Random();
     }
 
     public int getCoreNum() {
@@ -65,6 +72,14 @@ public class MCImplSynthesis {
         this.probThreshold = probThreshold;
     }
 
+    public int getGenerateThreshold() {
+        return generateThreshold;
+    }
+
+    public void setGenerateThreshold(int generateThreshold) {
+        this.generateThreshold = generateThreshold;
+    }
+
     public Vector<Schedule> synthesis() {
        // Print stuff to the original output and error streams.
        // The stuff printed through the 'origOut' and 'origErr' references
@@ -107,7 +122,10 @@ public class MCImplSynthesis {
 
        // generate multiple schedulings
        this.scheduleAnalysis.setScheduleThreshold(this.scheduleThreshold);
-       this.scheduleAnalysis.schedule();
+       this.scheduleAnalysis.schedule(this.generateThreshold);
+       if(this.generateThreshold > 5) {
+           this.generateThreshold = 5;
+       }
 
        Vector<Vector<ScheduleNode>> scheduleGraphs = null;
        Vector<Vector<ScheduleNode>> newscheduleGraphs = 
@@ -126,6 +144,7 @@ public class MCImplSynthesis {
                multiparamtds.addElement(td);
            }
        }
+       it_tasks = null;
 
        int tryindex = 1;
        int bestexetime = Integer.MAX_VALUE;
@@ -135,6 +154,18 @@ public class MCImplSynthesis {
            System.out.print("+++++++++++++++++++++++++++++++++++++++++++++++++++\n");
            System.out.print("Simulate and optimize round: #" + tryindex + ": \n");
            gid += newscheduleGraphs.size();
+           if(scheduleGraphs != null) {
+               for(int i = 0; i < scheduleGraphs.size(); i++) {
+                   Vector<ScheduleNode> tmpgraph = scheduleGraphs.elementAt(i);
+                   for(int j = 0; j < tmpgraph.size(); j++) {
+                       tmpgraph.elementAt(j).getEdgeVector().clear();
+                       tmpgraph.elementAt(j).getInedgeVector().clear();
+                   }
+                   tmpgraph.clear();
+                   tmpgraph = null;
+               }
+               scheduleGraphs.clear();
+           }
            scheduleGraphs = newscheduleGraphs;
            schedulings.clear();
            // get scheduling layouts from schedule graphs
@@ -143,16 +174,29 @@ public class MCImplSynthesis {
                Vector<Schedule> tmpscheduling = 
                    generateScheduling(scheduleGraph, multiparamtds);
                schedulings.add(tmpscheduling);
+               scheduleGraph = null;
+               tmpscheduling = null;
            }
            selectedSchedulings.clear();
+           for(int i = 0; i < selectedSimExeGraphs.size(); i++) {
+               selectedSimExeGraphs.elementAt(i).clear();
+           }
            selectedSimExeGraphs.clear();
            int tmpexetime = this.scheduleSimulator.simulate(schedulings, 
                                                             selectedSchedulings, 
                                                             selectedSimExeGraphs);
            if(tmpexetime < bestexetime) {
                bestexetime = tmpexetime;
+               if(scheduling != null) {
+                   scheduling.clear();
+                   for(int j = 0; j < schedulinggraph.size(); j++) {
+                       schedulinggraph.elementAt(j).getEdgeVector().clear();
+                       schedulinggraph.elementAt(j).getInedgeVector().clear();
+                   }
+                   schedulinggraph.clear();
+               }
                scheduling = schedulings.elementAt(selectedSchedulings.elementAt(0));
-               schedulinggraph = newscheduleGraphs.elementAt(selectedSchedulings.elementAt(0));
+               schedulinggraph = scheduleGraphs.elementAt(selectedSchedulings.elementAt(0));
                System.out.print("end of: #" + tryindex + " (bestexetime: " + bestexetime + ")\n");
                System.out.print("+++++++++++++++++++++++++++++++++++++++++++++++++++\n");
                tryindex++;
@@ -173,28 +217,275 @@ public class MCImplSynthesis {
                                                   selectedSimExeGraphs,
                                                   gid,
                                                   this.scheduleThreshold);
+           if(tmpexetime < bestexetime) {
+               scheduleGraphs.remove(selectedSchedulings.elementAt(0));
+           }
        }while(newscheduleGraphs != null); // TODO: could it possibly lead to endless loop?
 
+       if(scheduleGraphs != null) {
+           scheduleGraphs.clear();
+       }
        scheduleGraphs = null;
        newscheduleGraphs = null;
+       schedulings.clear();
        schedulings = null;
+       selectedSchedulings.clear();
        selectedSchedulings = null;
+       for(int i = 0; i < selectedSimExeGraphs.size(); i++) {
+           selectedSimExeGraphs.elementAt(i).clear();
+       }
+       selectedSimExeGraphs.clear();
        selectedSimExeGraphs = null;
+       multiparamtds.clear();
        multiparamtds = null;
-       
+
+       System.out.print("+++++++++++++++++++++++++++++++++++++++++++++++++++\n");
+       System.out.print("selected bestexetime: " + bestexetime + "\n");
        String path = this.state.outputdir + "scheduling_selected.dot";
        SchedulingUtil.printScheduleGraph(path, schedulinggraph);
 
        // Close the streams.
        try {
            stdout.close();
+           stdout = null;
            System.setOut(origOut);
        } catch (Exception e) {
            origOut.println("Redirect:  Unable to close files!");
        }
+       
+       schedulinggraph.clear();
+       schedulinggraph = null;
 
        return scheduling;
     }
+    
+    // for test
+    // get the distribution info of new search algorithm
+    public void distribution() {
+       // Print stuff to the original output and error streams.
+       // The stuff printed through the 'origOut' and 'origErr' references
+       // should go to the console on most systems while the messages
+       // printed through the 'System.out' and 'System.err' will end up in
+       // the files we created for them.
+       //origOut.println ("\nRedirect:  Round #2");
+       //System.out.println ("Test output via 'SimulatorResult.out'.");
+       //origOut.println ("Test output via 'origOut' reference.");
+
+       // Save the current standard input, output, and error streams
+       // for later restoration.
+       PrintStream origOut = System.out;
+
+       // Create a new output stream for the standard output.
+       PrintStream stdout  = null;
+       try {
+           stdout = new PrintStream(
+                   new FileOutputStream(this.state.outputdir + "SimulatorResult_" 
+                                        + this.coreNum + ".out"));
+       } catch (Exception e) {
+           // Sigh.  Couldn't open the file.
+           System.out.println("Redirect:  Unable to open output file!");
+           System.exit(1);
+       }
+
+       // Print stuff to the original output and error streams.
+       // On most systems all of this will end up on your console when you
+       // run this application.
+       //origOut.println ("\nRedirect:  Round #1");
+       //System.out.println ("Test output via 'System.out'.");
+       //origOut.println ("Test output via 'origOut' reference.");
+
+       // Set the System out and err streams to use our replacements.
+       System.setOut(stdout);
+
+       // generate multiple schedulings
+       this.scheduleAnalysis.setScheduleThreshold(1000);
+       this.scheduleAnalysis.schedule(20);
+       this.generateThreshold = 5;
+       this.probThreshold = 0;
+
+       Vector<Vector<ScheduleNode>> scheduleGraphs = null;
+       Vector<Vector<ScheduleNode>> totestscheduleGraphs = 
+           this.scheduleAnalysis.getScheduleGraphs();
+       Vector<Vector<Schedule>> schedulings = new Vector<Vector<Schedule>>();
+       Vector<Integer> selectedSchedulings = new Vector<Integer>();
+       Vector<Vector<SimExecutionEdge>> selectedSimExeGraphs = 
+           new Vector<Vector<SimExecutionEdge>>();
+       
+       // check all multi-parameter tasks
+       Vector<TaskDescriptor> multiparamtds = new Vector<TaskDescriptor>();
+       Iterator it_tasks = this.state.getTaskSymbolTable().getDescriptorsIterator();
+       while(it_tasks.hasNext()) {
+           TaskDescriptor td = (TaskDescriptor)it_tasks.next();
+           if(td.numParameters() > 1) {
+               multiparamtds.addElement(td);
+           }
+       }
+       it_tasks = null;
+       
+       File file=new File(this.state.outputdir + "distributeinfo_s_" + this.coreNum + ".out");
+       FileOutputStream dotstream = null; 
+       File file2=new File(this.state.outputdir + "distributeinfo_o_" + this.coreNum + ".out");
+       FileOutputStream dotstream2 = null; 
+       try {
+           dotstream = new FileOutputStream(file,false);
+           dotstream2 = new FileOutputStream(file2,false);
+       } catch (Exception e) {
+           e.printStackTrace();
+           System.exit(-1);
+       }
+       PrintWriter output = new java.io.PrintWriter(dotstream, true);
+       PrintWriter output2 = new java.io.PrintWriter(dotstream2, true);
+       output.println("start time(1,000,000 cycles): " + totestscheduleGraphs.size());
+       output2.println("optimized time(1,000,000 cycles): " + totestscheduleGraphs.size());
+       for(int ii = 0; ii < 1/*totestscheduleGraphs.size()*/; ii++) {
+           Vector<Vector<ScheduleNode>> newscheduleGraphs = 
+               new Vector<Vector<ScheduleNode>>();
+           newscheduleGraphs.add(totestscheduleGraphs.elementAt(ii));
+           int tryindex = 1;
+           int bestexetime = Integer.MAX_VALUE;
+           int gid = 1;
+           Vector<Schedule> scheduling = null;
+           Vector<ScheduleNode> schedulinggraph = null;
+           boolean isfirst = true;
+           Random rand = new Random();
+           // simulate the generated schedulings and try to optimize it
+           System.out.print("=========================================================\n");
+           System.out.print("# " + ii + ": \n");
+           do {
+               System.out.print("+++++++++++++++++++++++++++++++++++++++++++++++++++\n");
+               System.out.print("Simulate and optimize round: #" + tryindex + ": \n");    
+               gid += newscheduleGraphs.size();
+               if(scheduleGraphs != null) {
+                   for(int i = 0; i < scheduleGraphs.size(); i++) {
+                       Vector<ScheduleNode> tmpgraph = scheduleGraphs.elementAt(i);
+                       for(int j = 0; j < tmpgraph.size(); j++) {
+                           ScheduleNode snode = tmpgraph.elementAt(j);
+                           snode.getEdgeVector().clear();
+                           snode.getInedgeVector().clear();
+                           snode.getScheduleEdges().clear();
+                           snode.getClassNodes().clear();
+                       }
+                       tmpgraph.clear();
+                       tmpgraph = null;
+                   }
+                   scheduleGraphs.clear();
+               }
+               scheduleGraphs = newscheduleGraphs;
+               schedulings.clear();
+               // get scheduling layouts from schedule graphs
+               for(int i = 0; i < scheduleGraphs.size(); i++) {
+                   Vector<ScheduleNode> scheduleGraph = scheduleGraphs.elementAt(i);
+                   Vector<Schedule> tmpscheduling = 
+                       generateScheduling(scheduleGraph, multiparamtds);
+                   schedulings.add(tmpscheduling);
+                   scheduleGraph = null;
+                   tmpscheduling = null;
+               }
+               selectedSchedulings.clear();
+               for(int i = 0; i < selectedSimExeGraphs.size(); i++) {
+                   selectedSimExeGraphs.elementAt(i).clear();
+               }
+               selectedSimExeGraphs.clear();
+               int tmpexetime = this.scheduleSimulator.simulate(schedulings, 
+                                                                selectedSchedulings, 
+                                                                selectedSimExeGraphs);
+               if(isfirst) {
+                   output.println(((float)tmpexetime/1000000));
+                   isfirst = false;
+               }
+               if(tmpexetime < bestexetime) {
+                   bestexetime = tmpexetime;
+                   if(scheduling != null) {
+                       scheduling.clear();
+                       for(int j = 0; j < schedulinggraph.size(); j++) {
+                           ScheduleNode snode = schedulinggraph.elementAt(j);
+                           snode.getEdgeVector().clear();
+                           snode.getInedgeVector().clear();
+                           snode.getScheduleEdges().clear();
+                           snode.getClassNodes().clear();
+                       }
+                       schedulinggraph.clear();
+                   }
+                   scheduling = schedulings.elementAt(selectedSchedulings.elementAt(0));
+                   schedulinggraph = scheduleGraphs.elementAt(selectedSchedulings.elementAt(0));
+                   tryindex++;
+                   System.out.print("end of: #" + tryindex + " (bestexetime: " + bestexetime + ")\n");
+                   System.out.print("+++++++++++++++++++++++++++++++++++++++++++++++++++\n");
+               } else if(tmpexetime == bestexetime) {
+                   System.out.print("end of: #" + tryindex + " (bestexetime: " + bestexetime + ")\n");
+                   System.out.print("+++++++++++++++++++++++++++++++++++++++++++++++++++\n");
+                   tryindex++;
+                   if((Math.abs(rand.nextInt()) % 100) < this.probThreshold) {
+                       break;
+                   }
+               } else {
+                   break;
+               }
+
+               // try to optimize theschedulings best one scheduling
+               newscheduleGraphs = optimizeScheduling(scheduleGraphs, 
+                                                      selectedSchedulings, 
+                                                      selectedSimExeGraphs,
+                                                      gid,
+                                                      this.scheduleThreshold);
+               if(tmpexetime < bestexetime) {
+                   scheduleGraphs.remove(selectedSchedulings.elementAt(0));
+               }
+           }while(newscheduleGraphs != null); // TODO: could it possibly lead to endless loop?
+
+           scheduleGraphs.clear();
+           scheduleGraphs = null;
+           scheduling = null;
+           schedulinggraph = null;
+           if(newscheduleGraphs != null) {
+               newscheduleGraphs.clear();
+           }
+           newscheduleGraphs = null;
+           totestscheduleGraphs.elementAt(ii).clear();
+           for(int i = 0; i < schedulings.size(); i++) {
+               schedulings.elementAt(i).clear();
+           }
+           schedulings.clear();
+           selectedSchedulings.clear();
+           for(int i = 0; i < selectedSimExeGraphs.size(); i++) {
+               selectedSimExeGraphs.elementAt(i).clear();
+           }
+           selectedSimExeGraphs.clear();
+           
+           output2.println(((float)bestexetime/1000000));
+           System.out.print("=========================================================\n");
+       }
+
+       if(scheduleGraphs != null) {
+           scheduleGraphs.clear();
+       }
+       scheduleGraphs = null;
+       totestscheduleGraphs = null;
+       for(int i = 0; i < schedulings.size(); i++) {
+           schedulings.elementAt(i).clear();
+       }
+       schedulings.clear();
+       schedulings = null;
+       selectedSchedulings.clear();
+       selectedSchedulings = null;
+       selectedSimExeGraphs.clear();
+       selectedSimExeGraphs = null;
+       multiparamtds.clear();
+       multiparamtds = null;
+
+       // Close the streams.
+       try {
+           output.close();
+           stdout.close();
+           output = null;
+           stdout = null;
+           System.setOut(origOut);
+       } catch (Exception e) {
+           origOut.println("Redirect:  Unable to close files!");
+       }
+
+       return;
+    }
 
     private Vector<Vector<ScheduleNode>> optimizeScheduling(Vector<Vector<ScheduleNode>> scheduleGraphs,
                                                            Vector<Integer> selectedScheduleGraphs,
@@ -258,7 +549,7 @@ public class MCImplSynthesis {
        for(int i = 0; i < criticalPath.size(); i++) {
            SimExecutionEdge seedge = criticalPath.elementAt(i);
            Vector<SimExecutionEdge> predicates = seedge.getPredicates();
-           if(predicates.size() > 0) {
+           if(predicates != null) {
                // have predicates
                int starttime = 0;
                // check the latest finish time of all the predicates
@@ -486,7 +777,9 @@ public class MCImplSynthesis {
                                    (SimExecutionNode)tmpseedge.getTarget();
                                if(tmpsenode.getTimepoint() > timepoint) {
                                    // update the predicate info
-                                   edge.getPredicates().remove(lastpredicateedge);
+                                   if(edge.getPredicates() != null) {
+                                       edge.getPredicates().remove(lastpredicateedge);
+                                   }
                                    edge.addPredicate(criticalPath.elementAt(index));
                                    break;
                                }
@@ -615,27 +908,33 @@ public class MCImplSynthesis {
 
        CombinationUtil.CombineGenerator cGen = 
            CombinationUtil.allocateCombineGenerator(rootNodes, nodes2combine);
+       Random rand = new Random();
        while ((left > 0) && (cGen.nextGen())) {
-           Vector<Vector<CombinationUtil.Combine>> combine = cGen.getCombine();
-           Vector<ScheduleNode> sNodes = SchedulingUtil.generateScheduleGraph(this.state,
-                                                                              newscheduleGraph,
-                                                                              scheduleEdges,
-                                                                              rootNodes, 
-                                                                              combine, 
-                                                                              lgid++);
-           if(optimizeschedulegraphs == null) {
-               optimizeschedulegraphs = new Vector<Vector<ScheduleNode>>();
+           if(Math.abs(rand.nextInt()) % 100 > this.generateThreshold) {
+               Vector<Vector<CombinationUtil.Combine>> combine = cGen.getCombine();
+               Vector<ScheduleNode> sNodes = SchedulingUtil.generateScheduleGraph(this.state,
+                                                                                  newscheduleGraph,
+                                                                                  scheduleEdges,
+                                                                                  rootNodes, 
+                                                                                  combine, 
+                                                                                  lgid++);
+               if(optimizeschedulegraphs == null) {
+                   optimizeschedulegraphs = new Vector<Vector<ScheduleNode>>();
+               }
+               optimizeschedulegraphs.add(sNodes);
+               combine = null;
+               sNodes = null;
+               left--;
            }
-           optimizeschedulegraphs.add(sNodes);
-           combine = null;
-           sNodes = null;
-           left--;
        }
+       cGen.clear();
        rootNodes = null;
        nodes2combine = null;
        newscheduleGraph = null;
        scheduleEdges.clear();
        scheduleEdges = null;
+       roots = null;
+       tocombines = null;
        
        return optimizeschedulegraphs;
     }
@@ -721,6 +1020,7 @@ public class MCImplSynthesis {
                            setstartupcore = true;
                        }
                    }
+                   it_edges = null;
                }
                it_flags = null;
            }
index 9471e6514de2d067b073489ac9a13eb9a545cee7..2ec42225c9dd19971ffbe009190bf3c21b4cc109 100644 (file)
@@ -66,7 +66,7 @@ public class ScheduleAnalysis {
        return scheduleEdges;
     }
     
-    public void schedule() {
+    public void schedule(int generateThreshold) {
        try {
            Vector<ScheduleEdge> toBreakDown = new Vector<ScheduleEdge>();
            ScheduleNode startupNode = null;
@@ -81,7 +81,8 @@ public class ScheduleAnalysis {
            // as possible
            CFSTGTransform();
            // mappint to real multi-core processor
-           coreMapping();
+           coreMapping(generateThreshold);
+           toBreakDown = null;
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
@@ -139,6 +140,7 @@ public class ScheduleAnalysis {
                                }
                            }
                        }
+                       it_rootnodes = null;
                    }
                    Iterator it_flags = this.taskanalysis.getFlagStates(cd).iterator();
                    while(it_flags.hasNext()) {
@@ -155,10 +157,13 @@ public class ScheduleAnalysis {
                                ((FlagState)edge.getSource()).setByObj(taskinfo.m_byObj);
                            }
                        }
+                       it_edges = null;
                    }
+                   it_flags = null;
                }
            }
            taskinfos = null;
+           it_classes = null;
        } else {
            randomProfileSetting();
        }
@@ -187,13 +192,16 @@ public class ScheduleAnalysis {
                                        edge.setisbackedge(true);
                                    }
                                }
+                               it_edges = null;
                            }
+                           it_fs = null;
                        }
                    }
                }
                fss = null;
            }
        }
+       it_classes = null;
     }
     
     private void readProfileInfo(java.util.Hashtable<String, TaskInfo> taskinfos) {
@@ -308,6 +316,9 @@ public class ScheduleAnalysis {
                taskinfos.put(inname, tinfo);
                inindex = profiledata.indexOf('\n');
            }
+           inStream.close();
+           inStream = null;
+           b = null;
        } catch(Exception e) {
            e.printStackTrace();
        }
@@ -318,12 +329,14 @@ public class ScheduleAnalysis {
        // Randomly set the newRate and probability of FEdges
        java.util.Random r=new java.util.Random();
        int tint = 0;
-       for(Iterator it_classes=state.getClassSymbolTable().getDescriptorsIterator(); it_classes.hasNext();) {
+       Iterator it_classes=state.getClassSymbolTable().getDescriptorsIterator();
+       for(; it_classes.hasNext();) {
            ClassDescriptor cd=(ClassDescriptor) it_classes.next();
            if(cd.hasFlags()) {
                Vector rootnodes=this.taskanalysis.getRootNodes(cd);
                if(rootnodes!=null) {
-                   for(Iterator it_rootnodes=rootnodes.iterator(); it_rootnodes.hasNext();) {
+                   Iterator it_rootnodes=rootnodes.iterator();
+                   for(; it_rootnodes.hasNext();) {
                        FlagState root=(FlagState)it_rootnodes.next();
                        Vector allocatingTasks = root.getAllocatingTasks();
                        if(allocatingTasks != null) {
@@ -374,6 +387,7 @@ public class ScheduleAnalysis {
                            }
                        }
                    }
+                   it_rootnodes = null;
                }
 
                Iterator it_flags = this.taskanalysis.getFlagStates(cd).iterator();
@@ -413,9 +427,12 @@ public class ScheduleAnalysis {
                            total -= tint;
                        }
                    }
+                   it_edges = null;
                }
+               it_flags = null;
            }
        }
+       it_classes = null;
     }
 
     private ScheduleNode buildCFSTG(Vector<ScheduleEdge> toBreakDown) {
@@ -446,9 +463,11 @@ public class ScheduleAnalysis {
                    cNode.setTransTime(45);
                }
            }
+           rootnodes = null;
            fStates = null;
            sFStates = null;
        }
+       it_classes = null;
 
        ScheduleNode startupNode = null;
        // For each ClassNode create a ScheduleNode containing it
@@ -538,7 +557,6 @@ public class ScheduleAnalysis {
            for(i = 0; i < toBreakDown.size(); i++ ) {
                cloneSNodeList(toBreakDown.elementAt(i), false);
            }
-           toBreakDown = null;
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
@@ -576,6 +594,7 @@ public class ScheduleAnalysis {
                while(it_edge.hasNext()) {
                    toVisit.add((ScheduleNode)((ScheduleEdge)it_edge.next()).getTarget());
                }
+               it_edge = null;
            }
        }
        toVisit = null;
@@ -748,6 +767,7 @@ public class ScheduleAnalysis {
                ses = null;
            }
            keys = null;
+           it_keys = null;
        }
        fe2ses.clear();
        sn2fes.clear();
@@ -931,6 +951,7 @@ public class ScheduleAnalysis {
        toClone = null;
        clone = null;
        qcn2cn = null;
+       cn2cn.clear();
        cn2cn = null;
        origins = null;
        sn2sn = null;
@@ -988,6 +1009,7 @@ public class ScheduleAnalysis {
                    sfss.removeElement(temp);
                }
            }
+           it_edges = null;
        }
        sfss = null;
        Vector<FlagState> sFStates = FlagState.DFS.topology(fStates, null);
@@ -1021,6 +1043,7 @@ public class ScheduleAnalysis {
                    toiterate.add(temp);
                }
            }
+           it_inedges = null;
        }
        toiterate = null;
 
@@ -1063,6 +1086,7 @@ public class ScheduleAnalysis {
                }
            }
        }
+       it_isEdges = null;
        oldSNode.getScheduleEdges().removeAll(toremove);
        toremove.clear();
        // redirect ScheudleEdges out of this subtree to the new ScheduleNode
@@ -1080,6 +1104,7 @@ public class ScheduleAnalysis {
                }
            }
        }
+       it_sEdges = null;
        se.getSource().getEdgeVector().removeAll(toremove);
        toremove = null;
        rCNodes = null;
@@ -1115,7 +1140,7 @@ public class ScheduleAnalysis {
 
     // TODO: restrict the number of generated scheduling according to the setted
     // scheduleThreshold
-    private void coreMapping() throws Exception {
+    private void coreMapping(int generateThreshold) throws Exception {
        if(this.coreNum == -1) {
            throw new Exception("Error: un-initialized coreNum when doing scheduling.");
        }
@@ -1148,6 +1173,7 @@ public class ScheduleAnalysis {
                                                       this.coreNum);
 
            int gid = 1;
+           Random rand = new Random();
            while((gid <= this.scheduleThreshold) && (rGen.nextGen())) {
                // first get the chosen rootNodes
                Vector<Vector<ScheduleNode>> rootNodes = rGen.getRootNodes();
@@ -1157,20 +1183,25 @@ public class ScheduleAnalysis {
                    CombinationUtil.allocateCombineGenerator(rootNodes, 
                                                             nodes2combine);
                while((gid <= this.scheduleThreshold) && cGen.nextGen()) {
-                   Vector<Vector<CombinationUtil.Combine>> combine = cGen.getCombine();
-                   Vector<ScheduleNode> sNodes = SchedulingUtil.generateScheduleGraph(this.state,
-                                                                                      this.scheduleNodes,
-                                                                                      this.scheduleEdges,
-                                                                                      rootNodes, 
-                                                                                      combine, 
-                                                                                      gid++);
-                   this.scheduleGraphs.add(sNodes);
-                   combine = null;
-                   sNodes = null;
+                   if(Math.abs(rand.nextInt()) % 100 > generateThreshold) {
+                       Vector<Vector<CombinationUtil.Combine>> combine = cGen.getCombine();
+                       Vector<ScheduleNode> sNodes = 
+                           SchedulingUtil.generateScheduleGraph(this.state,
+                                                                this.scheduleNodes,
+                                                                this.scheduleEdges,
+                                                                rootNodes, 
+                                                                combine, 
+                                                                gid++);
+                       this.scheduleGraphs.add(sNodes);
+                       combine = null;
+                       sNodes = null;
+                   }
                }
+               cGen.clear();
                rootNodes = null;
                nodes2combine = null;
            }
+           rGen.clear();
            sNodeVecs = null;
        }
     }
index b8d993bbd282026c14139bec57f4cc494630bdb2..2c2d2c24f97b1a2902a9d7b8277eece009e09264 100644 (file)
@@ -134,6 +134,7 @@ public class ScheduleNode extends GraphNode implements Cloneable {
       for(int i = 0; i < mergedcids.size(); i++) {
          this.hashcid = this.hashcid * 31 + mergedcids.elementAt(i);
       }
+      mergedcids = null;
   }
 
   public int getExeTime() {
@@ -332,6 +333,7 @@ public class ScheduleNode extends GraphNode implements Cloneable {
            toiterate.add(temp);
          }
        }
+       it_inedges = null;
       }
       toiterate = null;
 
@@ -354,6 +356,7 @@ public class ScheduleNode extends GraphNode implements Cloneable {
        }
        this.edges.addElement(tse);
       }
+      it_edges = null;
 
       targetSEdges = null;
 
@@ -378,6 +381,7 @@ public class ScheduleNode extends GraphNode implements Cloneable {
        tse.setSource(this);
        this.edges.addElement(tse);
       }
+      it_edges = null;
 
       // As all tasks inside one ScheduleNode are executed sequentially,
       // simply add the execution time of all the ClassNodes inside one ScheduleNode.
@@ -424,6 +428,7 @@ public class ScheduleNode extends GraphNode implements Cloneable {
       tse.setTarget(this);
       this.inedges.addElement(tse);
     }
+    it_edges = null;
 
     // As all tasks inside one ScheduleNode are executed sequentially,
     // simply add the execution time of all the ClassNodes inside one ScheduleNode.
@@ -456,6 +461,7 @@ public class ScheduleNode extends GraphNode implements Cloneable {
              }
          }
       }
+      it_innersEdges = null;
       this.scheduleEdges.removeAll(toremove);
       for(int i = 0; i < toremove.size(); i++) {
          ScheduleEdge tse = toremove.elementAt(i);
@@ -479,6 +485,7 @@ public class ScheduleNode extends GraphNode implements Cloneable {
              sNode.addEdge(tse);
          }
       }
+      it_exsEdges = null;
       // redirect inedges whose target is this Classnode to new ScheduleNode
       Iterator it_insEdges = this.inedges();
       while(it_insEdges.hasNext()) {
@@ -488,6 +495,7 @@ public class ScheduleNode extends GraphNode implements Cloneable {
              tse.setTarget(sNode);
          }
       }
+      it_insEdges = null;
       this.inedges.removeAll(toremove);
       toremove.clear();
       toremove = null;
index e8b7565e416c175923b368ded98c9fe6971a89b8..754d2356535a651803cdf3770db9f8a4b45fa7d1 100644 (file)
@@ -113,7 +113,9 @@ public class ScheduleSimulator {
                  selectedSimExeGraphs.add(simexegraph);
              }
              scheduling = null;
+             checkpoints.clear();
              checkpoints = null;
+             simexegraph = null;
              index++;
          }
          it_scheduling = null;
@@ -665,6 +667,7 @@ public class ScheduleSimulator {
          tmpentry = null;
          nobjs = null;
       }
+      it_entries = null;
       transObjQueues = null;
       
       return totransObjs;
@@ -891,14 +894,16 @@ public class ScheduleSimulator {
        this.type = type;
        this.td = ts.getTd();
        Vector<Queue<ObjectSimulator>> paraQueues = ts.getParaQueues();
-       this.taskparams = new Vector<Integer>();
-       if((this.type != TASKABORT) && (this.type != TASKREMOVE)) {
+       if(this.type == TASKSTART) {
+           this.taskparams = new Vector<Integer>();
            for(int i = 0; i < paraQueues.size(); i++) {
                ObjectSimulator tpara = paraQueues.elementAt(i).peek();
                this.taskparams.add(tpara.getOid());
            }
-           paraQueues = null;
+       } else {
+           this.taskparams = null;
        }
+       paraQueues = null;
        if(this.type == TFWITHOBJ) {
            this.nObjs = new Hashtable<ClassDescriptor, Integer>();
        } else {
index 2728af34e6a04d8b1bcae6d7770a24bcc634b689..8197cdd229021215548805359f4a1c5f2f3cf45b 100644 (file)
@@ -283,6 +283,7 @@ public class SchedulingUtil {
       output.println("\t\tlabel=\"" + gn.getTextLabel() + "\";");
       Iterator it_cnodes = gn.getClassNodesIterator();
       traverseCNodes(output, it_cnodes);
+      it_cnodes = null;
       //Draw the internal 'new' edges
       Iterator it_edges =gn.getScheduleEdgesIterator();
       while(it_edges.hasNext()) {
@@ -316,6 +317,7 @@ public class SchedulingUtil {
        }
       }
       output.println("\t}\n");
+      it_edges = null;
       //Draw 'new' edges of this ScheduleNode
       while(edges.hasNext()) {
        ScheduleEdge se = (ScheduleEdge)edges.next();
@@ -342,7 +344,9 @@ public class SchedulingUtil {
          output.println(se.getTargetFState().getLabel() + " [label=\"" + se.getLabel() + "\", color=red, style=dashed];");
        }
       }
+      edges = null;
     }
+    it = null;
   }
 
   private static void traverseCNodes(PrintWriter output, 
@@ -399,7 +403,8 @@ public class SchedulingUtil {
          Edge edge = (Edge) edges.next();
          GraphNode node = edge.getTarget();
          if (nodes.contains(node)) {
-           for(Iterator nodeit=nonmerge(node, nodes).iterator(); nodeit.hasNext();) {
+             Iterator nodeit=nonmerge(node, nodes).iterator();
+           for(; nodeit.hasNext();) {
              GraphNode node2=(GraphNode)nodeit.next();
              String edgelabel = "";
              String edgedotnodeparams="";
@@ -425,12 +430,19 @@ public class SchedulingUtil {
                  NewObjInfo noi = hashtable.get(cd);
                  edgelabel += ":{ class " + cd.getSymbol() + " | " + noi.getNewRate() + " | (" + noi.getProbability() + "%) }";
                }
+               keys = null;
+               it_keys = null;
              }
              output.println("\t" + gn.getLabel() + " -> " + node2.getLabel() + " [" + "label=\"" + edgelabel + "\"" + edgedotnodeparams + "];");
            }
+           nodeit = null;
          }
        }
+      edges = null;
     }
+    cycleset = null;
+    namers = null;
+    it = null;
   }
 
   private static Set nonmerge(GraphNode gn, 
@@ -451,8 +463,10 @@ public class SchedulingUtil {
          if (!newset.contains(node)&&nodes.contains(node))
            toprocess.add(node);
        }
+       edges = null;
       }
     }
+    toprocess = null;
     return newset;
   }
 
@@ -598,7 +612,9 @@ public class SchedulingUtil {
              } else {
                tmpLabel.append(";");
              }
+             entry = null;
            }
+           it_entry = null;
            if(!(lastTaskNodes[cNum].equals("first"))) {
              if (!(lastTaskNodes[cNum].equals(tmpTaskNode))) {
                output.print("\t");
@@ -834,6 +850,7 @@ public class SchedulingUtil {
          }
          output.println("}");
          output.close();
+         nodes = null;
       } catch (Exception e) {
          e.printStackTrace();
          System.exit(-1);
index 533a5b0588aceee0ba8f2b1ab593ed953ce61261..4f0a50143bfd9e3a7786d9992abc74ca9e65f5b2 100644 (file)
@@ -35,7 +35,7 @@ public class SimExecutionEdge extends Edge {
        this.bestStartPoint = -1;
        this.lastpredicatenode = null;
        this.lastpredicateedge = null;
-       this.predicates = new Vector<SimExecutionEdge>();
+       this.predicates = null;
        this.isFixedTime = true;
     }
     
@@ -77,6 +77,9 @@ public class SimExecutionEdge extends Edge {
     }
     
     public void addPredicate(SimExecutionEdge predicate) {
+       if(this.predicates == null) {
+           this.predicates = new Vector<SimExecutionEdge>();
+       }
        if(!this.predicates.contains(predicate)) {
            this.predicates.add(predicate);
        }
index db364b584dca6e2257c404ad8a09332a4679a65e..6a6f6a5273a8552d51e5d5712d1905a29e3814d3 100644 (file)
@@ -55,7 +55,8 @@ public class Main {
     Vector sourcefiles=new Vector();
     state.classpath.add(".");
 
-       String outputdir = null;
+    String outputdir = null;
+    boolean isDistributeInfo = false;
 
     for(int i=0; i<args.length; i++) {
       String option=args[i];
@@ -130,6 +131,8 @@ public class Main {
        state.RAW=true;
       else if (option.equals("-scheduling"))
        state.SCHEDULING=true;
+      else if (option.equals("-distributioninfo"))
+       isDistributeInfo=true;
       else if (option.equals("-useprofile"))
        state.USEPROFILE=true;
       else if (option.equals("-thread"))
@@ -271,23 +274,29 @@ public class Main {
        MCImplSynthesis mcImplSynthesis = new MCImplSynthesis(state,
                                                              ta,
                                                              oa);
-       mcImplSynthesis.setScheduleThreshold(50);
-       mcImplSynthesis.setProbThreshold(0);
-       Vector<Schedule> scheduling = mcImplSynthesis.synthesis();
-       
-       // generate multicore codes
-       if(state.MULTICORE) {
-         BuildCodeMultiCore bcm=new BuildCodeMultiCore(state,
-                                                       bf.getMap(),
-                                                       tu,
-                                                       sa,
-                                                       scheduling,
-                                                       mcImplSynthesis.getCoreNum(),
-                                                       pa);
-         bcm.setOwnershipAnalysis(oa);
-         bcm.buildCode();
+       if(isDistributeInfo) {
+           mcImplSynthesis.distribution();
+       } else {
+           mcImplSynthesis.setScheduleThreshold(50);
+           mcImplSynthesis.setProbThreshold(0);
+           mcImplSynthesis.setGenerateThreshold(30);
+           Vector<Schedule> scheduling = mcImplSynthesis.synthesis();
+
+           // generate multicore codes
+           if(state.MULTICORE) {
+               BuildCodeMultiCore bcm=new BuildCodeMultiCore(state,
+                                                             bf.getMap(),
+                                                             tu,
+                                                             sa,
+                                                             scheduling,
+                                                             mcImplSynthesis.getCoreNum(),
+                                                             pa);
+               bcm.setOwnershipAnalysis(oa);
+               bcm.buildCode();
+           }
+           scheduling.clear();
+           scheduling = null;
        }
-       scheduling = null;
       }
     }