From: jzhou Date: Fri, 20 Mar 2009 00:44:49 +0000 (+0000) Subject: changes on directed simulated annealing X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=373ae0e9abb897bfd3dd8841996abdf704e1ac6c;p=IRC.git changes on directed simulated annealing --- diff --git a/Robust/src/Analysis/Scheduling/MCImplSynthesis.java b/Robust/src/Analysis/Scheduling/MCImplSynthesis.java index b03d5e3c..19f1900a 100644 --- a/Robust/src/Analysis/Scheduling/MCImplSynthesis.java +++ b/Robust/src/Analysis/Scheduling/MCImplSynthesis.java @@ -27,12 +27,12 @@ public class MCImplSynthesis { ScheduleSimulator scheduleSimulator; int coreNum; - int scheduleThreshold; - int probThreshold; - int generateThreshold; + int scheduleThreshold; // how many starting points generated by schedule analysis + int probThreshold; // the probability to stop when no accelaration achieved in the + // directed simulated annealing + int generateThreshold; // how many optimized implementation generated in each iteration + // of the directed simulated annealing - //Random rand; - public MCImplSynthesis(State state, TaskAnalysis ta, OwnershipAnalysis oa) { @@ -49,7 +49,6 @@ public class MCImplSynthesis { this.scheduleThreshold = 1000; this.probThreshold = 0; this.generateThreshold = 30; - //this.rand = new Random(); } public int getCoreNum() { @@ -94,7 +93,7 @@ public class MCImplSynthesis { // for later restoration. PrintStream origOut = System.out; - // Create a new output stream for the standard output. + // Create a new output stream for the stcriticalPathandard output. PrintStream stdout = null; try { stdout = new PrintStream( @@ -305,84 +304,47 @@ public class MCImplSynthesis { // 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; + if(false) { + this.scheduleAnalysis.setScheduleThreshold(100000); + this.scheduleAnalysis.schedule(-1); - Vector> scheduleGraphs = null; - Vector> totestscheduleGraphs = - this.scheduleAnalysis.getScheduleGraphs(); - Vector> schedulings = new Vector>(); - Vector selectedSchedulings = new Vector(); - Vector> selectedSimExeGraphs = - new Vector>(); - - // check all multi-parameter tasks - Vector multiparamtds = new Vector(); - 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> newscheduleGraphs = - new Vector>(); - newscheduleGraphs.add(totestscheduleGraphs.elementAt(ii)); - int tryindex = 1; - int bestexetime = Integer.MAX_VALUE; - int gid = 1; - Vector scheduling = null; - Vector 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 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(); + Vector> totestscheduleGraphs = + this.scheduleAnalysis.getScheduleGraphs(); + Vector> schedulings = new Vector>(); + Vector selectedSchedulings = new Vector(); + Vector> selectedSimExeGraphs = + new Vector>(); + + // check all multi-parameter tasks + Vector multiparamtds = new Vector(); + Iterator it_tasks = this.state.getTaskSymbolTable().getDescriptorsIterator(); + while(it_tasks.hasNext()) { + TaskDescriptor td = (TaskDescriptor)it_tasks.next(); + if(td.numParameters() > 1) { + multiparamtds.addElement(td); } - scheduleGraphs = newscheduleGraphs; + } + it_tasks = null; + + File file=new File(this.state.outputdir + "distributeinfo_s_" + this.coreNum + ".out"); + FileOutputStream dotstream = null; + try { + dotstream = new FileOutputStream(file,false); + } catch (Exception e) { + e.printStackTrace(); + System.exit(-1); + } + PrintWriter output = new java.io.PrintWriter(dotstream, true); + output.println("start time(1,000,000 cycles): " + totestscheduleGraphs.size()); + for(int ii = 0; ii < totestscheduleGraphs.size(); ii++) { + Vector> newscheduleGraphs = + new Vector>(); + newscheduleGraphs.add(totestscheduleGraphs.elementAt(ii)); + // simulate the generated schedulings and try to optimize it schedulings.clear(); // get scheduling layouts from schedule graphs - for(int i = 0; i < scheduleGraphs.size(); i++) { - Vector scheduleGraph = scheduleGraphs.elementAt(i); + for(int i = 0; i < newscheduleGraphs.size(); i++) { + Vector scheduleGraph = newscheduleGraphs.elementAt(i); Vector tmpscheduling = generateScheduling(scheduleGraph, multiparamtds); schedulings.add(tmpscheduling); @@ -395,101 +357,204 @@ public class MCImplSynthesis { } selectedSimExeGraphs.clear(); int tmpexetime = this.scheduleSimulator.simulate(schedulings, - selectedSchedulings, - selectedSimExeGraphs); - if(isfirst) { - output.println(((float)tmpexetime/1000000)); - isfirst = false; + selectedSchedulings, + selectedSimExeGraphs); + output.println(((float)tmpexetime/1000000)); + } + } else { + // generate multiple schedulings + this.scheduleThreshold = 20; + this.generateThreshold = 30; + this.probThreshold = 0; + this.scheduleAnalysis.setScheduleThreshold(1000); + this.scheduleAnalysis.schedule(this.generateThreshold); + + Vector> scheduleGraphs = null; + Vector> totestscheduleGraphs = + this.scheduleAnalysis.getScheduleGraphs(); + Vector> schedulings = new Vector>(); + Vector selectedSchedulings = new Vector(); + Vector> selectedSimExeGraphs = + new Vector>(); + + // check all multi-parameter tasks + Vector multiparamtds = new Vector(); + Iterator it_tasks = this.state.getTaskSymbolTable().getDescriptorsIterator(); + while(it_tasks.hasNext()) { + TaskDescriptor td = (TaskDescriptor)it_tasks.next(); + if(td.numParameters() > 1) { + multiparamtds.addElement(td); } - 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(); + } + 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 < totestscheduleGraphs.size(); ii++) { + Vector> newscheduleGraphs = + new Vector>(); + newscheduleGraphs.add(totestscheduleGraphs.elementAt(ii)); + int tryindex = 1; + int bestexetime = Integer.MAX_VALUE; + int gid = 1; + Vector scheduling = null; + Vector 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 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; } - schedulinggraph.clear(); + scheduleGraphs.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) { + scheduleGraphs = newscheduleGraphs; + schedulings.clear(); + // get scheduling layouts from schedule graphs + for(int i = 0; i < scheduleGraphs.size(); i++) { + Vector scheduleGraph = scheduleGraphs.elementAt(i); + Vector tmpscheduling = + generateScheduling(scheduleGraph, multiparamtds); + schedulings.add(tmpscheduling); + scheduleGraph = null; + tmpscheduling = null; + } + selectedSchedulings.clear(); + for(int i = 0; i < selectedSimExeGraphs.size(); i++) { + Vector tmpgraph = + selectedSimExeGraphs.elementAt(i); + for(int j = 0; j < tmpgraph.size(); j++) { + tmpgraph.elementAt(j).destroy(); + } + tmpgraph.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; } - } 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)); + // 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(); } - }while(newscheduleGraphs != null); // TODO: could it possibly lead to endless loop? + selectedSimExeGraphs.clear(); - scheduleGraphs.clear(); - scheduleGraphs = null; - scheduling = null; - schedulinggraph = null; - if(newscheduleGraphs != null) { - newscheduleGraphs.clear(); + output2.println(((float)bestexetime/1000000)); + System.out.print("=========================================================\n"); + } + + if(scheduleGraphs != null) { + scheduleGraphs.clear(); } - newscheduleGraphs = null; - totestscheduleGraphs.elementAt(ii).clear(); + scheduleGraphs = null; + totestscheduleGraphs = null; for(int i = 0; i < schedulings.size(); i++) { schedulings.elementAt(i).clear(); } schedulings.clear(); + schedulings = null; selectedSchedulings.clear(); - for(int i = 0; i < selectedSimExeGraphs.size(); i++) { - selectedSimExeGraphs.elementAt(i).clear(); - } + selectedSchedulings = null; selectedSimExeGraphs.clear(); - - output2.println(((float)bestexetime/1000000)); - System.out.print("=========================================================\n"); - } + selectedSimExeGraphs = null; + multiparamtds.clear(); + multiparamtds = null; - 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!"); + // 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; @@ -552,42 +617,6 @@ public class MCImplSynthesis { return criticalPath; } - private void computeBestStartPoint(Vector criticalPath) { - // calculate the earliest start time of each task on the critial path - for(int i = 0; i < criticalPath.size(); i++) { - SimExecutionEdge seedge = criticalPath.elementAt(i); - Vector predicates = seedge.getPredicates(); - if(predicates != null) { - // have predicates - int starttime = 0; - // check the latest finish time of all the predicates - for(int j = 0; j < predicates.size(); j++) { - SimExecutionEdge predicate = predicates.elementAt(j); - int tmptime = predicate.getBestStartPoint() + predicate.getWeight(); - if(tmptime > starttime) { - starttime = tmptime; - seedge.setLastpredicateEdge(predicate); - if(predicate.getTd() != null) { - seedge.setLastpredicateNode((SimExecutionNode)predicate.getTarget()); - } else { - // transfer edge - seedge.setLastpredicateNode((SimExecutionNode)predicate.getSource()); - } - } - } - seedge.setBestStartPoint(starttime); - } else if(seedge.getSource().getInedgeVector().size() > 0) { - // should have only one in edge - int starttime = ((SimExecutionNode)seedge.getSource()).getTimepoint(); - seedge.setBestStartPoint(starttime); - } else { - // no predicates - seedge.setBestStartPoint(0); - } - predicates = null; - } - } - // TODO: currently only get one critical path. It's possible that there are // multiple critical paths and some of them can not be optimized while others // can. Need to fix up for this situation. @@ -624,6 +653,42 @@ public class MCImplSynthesis { subcriticalpath = null; return sum; } + + private void computeBestStartPoint(Vector criticalPath) { + // calculate the earliest start time of each task on the critial path + for(int i = 0; i < criticalPath.size(); i++) { + SimExecutionEdge seedge = criticalPath.elementAt(i); + Vector predicates = seedge.getPredicates(); + if(predicates != null) { + // have predicates + int starttime = 0; + // check the latest finish time of all the predicates + for(int j = 0; j < predicates.size(); j++) { + SimExecutionEdge predicate = predicates.elementAt(j); + int tmptime = predicate.getBestStartPoint() + predicate.getWeight(); + if(tmptime > starttime) { + starttime = tmptime; + seedge.setLastpredicateEdge(predicate); + if(predicate.getTd() != null) { + seedge.setLastpredicateNode((SimExecutionNode)predicate.getTarget()); + } else { + // transfer edge + seedge.setLastpredicateNode((SimExecutionNode)predicate.getSource()); + } + } + } + seedge.setBestStartPoint(starttime); + } else if(seedge.getSource().getInedgeVector().size() > 0) { + // should have only one in edge + int starttime = ((SimExecutionNode)seedge.getSource()).getTimepoint(); + seedge.setBestStartPoint(starttime); + } else { + // no predicates + seedge.setBestStartPoint(0); + } + predicates = null; + } + } private Vector> optimizeCriticalPath(Vector scheduleGraph, Vector criticalPath, @@ -643,10 +708,10 @@ public class MCImplSynthesis { // earliest start time and group them int opcheckpoint = Integer.MAX_VALUE; Vector sparecores = null; - // first group according to core index, - // then group according to task type - Hashtable>> tooptimize = - new Hashtable>>(); + // group according to core index + Hashtable>> toselects = + new Hashtable>>(); + Random rand = new Random(); for(int i = 0; i < criticalPath.size(); i++) { SimExecutionEdge seedge = criticalPath.elementAt(i); int starttime = seedge.getBestStartPoint(); @@ -657,123 +722,138 @@ public class MCImplSynthesis { // consider to optimize it only when its predicates can NOT // be optimized, otherwise first considering optimize its predicates SimExecutionEdge lastpredicateedge = seedge.getLastpredicateEdge(); - if(lastpredicateedge.isFixedTime()) { - if(opcheckpoint >= starttime) { - // only consider the tasks with smallest best start time - if(opcheckpoint > starttime) { - tooptimize.clear(); - opcheckpoint = starttime; - SimExecutionNode lastpredicatenode = seedge.getLastpredicateNode(); - int timepoint = lastpredicatenode.getTimepoint(); - if(lastpredicateedge.getTd() == null) { - // transfer edge - timepoint += lastpredicateedge.getWeight(); - } - // mapping to critical path - for(int index = 0; index < criticalPath.size(); index++) { - SimExecutionEdge tmpseedge = criticalPath.elementAt(index); - SimExecutionNode tmpsenode = - (SimExecutionNode)tmpseedge.getTarget(); - if(tmpsenode.getTimepoint() > timepoint) { - // get the spare core info - sparecores = tmpsenode.getSpareCores(); - break; - } - } - } - int corenum = seedge.getCoreNum(); - if(!tooptimize.containsKey(corenum)) { - tooptimize.put(corenum, - new Hashtable>()); - } - if(!tooptimize.get(corenum).containsKey(seedge.getTd())) { - tooptimize.get(corenum).put(seedge.getTd(), - new Vector()); - } - tooptimize.get(corenum).get(seedge.getTd()).add(seedge); + if(lastpredicateedge.isFixedTime()) { + int corenum = seedge.getCoreNum(); + if(!toselects.containsKey(starttime)) { + toselects.put(starttime, + new Hashtable>()); + } + if(!toselects.get(starttime).containsKey(corenum)) { + toselects.get(starttime).put(corenum, + new Vector()); } + toselects.get(starttime).get(corenum).add(seedge); } } } + + // Randomly choose the tasks to optimize(previously only + // consider the tasks with smallest best start time) + Vector keys = new Vector(toselects.keySet()); + do{ + int length = keys.size(); + if(length == 0) { + return optimizeschedulegraphs; + } + int tochoose = Math.abs(rand.nextInt()) % length; + opcheckpoint = (keys.elementAt(tochoose)).intValue(); + keys.removeElementAt(tochoose); + Hashtable> tooptimize = + toselects.get(opcheckpoint); + SimExecutionEdge seedge = tooptimize.values().iterator().next().elementAt(0); + SimExecutionNode lastpredicatenode = seedge.getLastpredicateNode(); + SimExecutionEdge lastpredicateedge = seedge.getLastpredicateEdge(); + int timepoint = lastpredicatenode.getTimepoint(); + if(lastpredicateedge.getTd() == null) { + // transfer edge + timepoint += lastpredicateedge.getWeight(); + } + // mapping to critical path + for(int index = 0; index < criticalPath.size(); index++) { + SimExecutionEdge tmpseedge = criticalPath.elementAt(index); + SimExecutionNode tmpsenode = + (SimExecutionNode)tmpseedge.getTarget(); + if(tmpsenode.getTimepoint() > timepoint) { + // get the spare core info + sparecores = tmpsenode.getSpareCores(); + break; + } + } - if(tooptimize.size() > 0) { - Iterator it_cores = tooptimize.keySet().iterator(); - // check if it is possible to optimize these tasks - if((sparecores == null) || (sparecores.size() == 0)) { - // lack of spare cores - while(it_cores.hasNext()) { - int corenum = it_cores.next(); - Hashtable> candidatetasks = - tooptimize.get(corenum); - if(candidatetasks.keySet().size() > 1) { - // there are multiple tasks could be optimized to start from - // this timepoint, try to change original execution order - Iterator it_tds = candidatetasks.keySet().iterator(); - TaskDescriptor td = null; - int starttime = Integer.MAX_VALUE; - do { - TaskDescriptor tmptd = it_tds.next(); - Vector seedges = candidatetasks.get(td); - int tmptime = ((SimExecutionNode)seedges.elementAt(0).getSource()).getTimepoint(); - for(int i = 1; i < seedges.size(); i++) { - int ttime = ((SimExecutionNode)seedges.elementAt(i).getSource()).getTimepoint(); - if(ttime < tmptime) { - tmptime = ttime; + if(tooptimize.size() > 0) { + Iterator it_cores = tooptimize.keySet().iterator(); + // check if it is possible to optimize these tasks + if((sparecores == null) || (sparecores.size() == 0)) { + // lack of spare cores + while(it_cores.hasNext()) { + int corenum = it_cores.next(); + Vector tmptasks = tooptimize.get(corenum); + // group the task instantiations according to whether it + // has backward data dependences or not + Vector candidatetasks = new Vector(); + for(int ii= 0; ii < tmptasks.size(); ii++) { + SimExecutionEdge tmpseedge = tmptasks.elementAt(ii); + SimExecutionNode target = (SimExecutionNode)tmpseedge.getTarget(); + Vector children = + (Vector)target.getEdgeVector(); + int jj = 0; + for(; jj < children.size(); jj++) { + SimExecutionEdge tmpedge = children.elementAt(jj); + if(tmpedge.getTd() != null) { + Vector predicates = + tmpedge.getPredicates(); + if((predicates != null) && + (predicates.contains(tmpseedge))) { + break; + } + predicates = null; + } else if(tmpedge.getWeight() != 0) { + // transfer edge + if(((SimExecutionNode)tmpedge.getTarget()).getTimepoint() + == tmpedge.getWeight() + target.getTimepoint()) { + break; + } } } - if(tmptime < starttime) { - starttime = tmptime; - td = tmptd; + if(jj == children.size()) { + candidatetasks.add(tmpseedge); } - seedges = null; - }while(it_tds.hasNext()); - it_tds = null; - // TODO: only consider non-multi-param tasks currently - if(td.numParameters() == 1) { - Hashtable>> tooptimize2 = - new Hashtable>>(); + } + if((candidatetasks.size() > 0) && + (candidatetasks.size() < tmptasks.size())) { + // there are less important tasks which have no backward + // data dependences at this timepoint, try to change + // original execution order + Hashtable> tooptimize2 = + new Hashtable>(); tooptimize2.put(corenum, candidatetasks); Vector> ops = innerOptimizeCriticalPath(scheduleGraph, - tooptimize2, - null, - lgid, - left); + tooptimize2, + null, + lgid, + left); if(ops != null) { if(optimizeschedulegraphs == null) { optimizeschedulegraphs = new Vector>(); } optimizeschedulegraphs.addAll(ops); - lgid += optimizeschedulegraphs.size(); - left -= optimizeschedulegraphs.size(); + lgid += ops.size(); + left -= ops.size(); } - tooptimize2.clear(); tooptimize2 = null; ops = null; } + tmptasks = null; + candidatetasks = null; + } + + if(left == 0) { + it_cores = null; + return optimizeschedulegraphs; } - candidatetasks = null; - } - - if(left == 0) { - it_cores = null; - return optimizeschedulegraphs; - } - // flush the dependences and earliest start time - it_cores = tooptimize.keySet().iterator(); - while(it_cores.hasNext()) { - Hashtable> candidatetasks = - tooptimize.get(it_cores.next()); - Iterator> it_edgevecs = - candidatetasks.values().iterator(); - while(it_edgevecs.hasNext()) { - Vector edgevec = it_edgevecs.next(); + // flush the dependences and earliest start time + it_cores = tooptimize.keySet().iterator(); + while(it_cores.hasNext()) { + int corenum = it_cores.next(); + Vector edgevec = + tooptimize.get(corenum); for(int j = 0; j < edgevec.size(); j++) { SimExecutionEdge edge = edgevec.elementAt(j); - SimExecutionEdge lastpredicateedge = edge.getLastpredicateEdge(); - SimExecutionNode lastpredicatenode = edge.getLastpredicateNode(); + lastpredicateedge = edge.getLastpredicateEdge(); + lastpredicatenode = edge.getLastpredicateNode(); // if(edge.getCoreNum() != lastpredicate.getCoreNum()) // should never hit this - int timepoint = lastpredicatenode.getTimepoint(); + timepoint = lastpredicatenode.getTimepoint(); if(lastpredicateedge.getTd() == null) { // transfer edge timepoint += lastpredicateedge.getWeight(); @@ -795,48 +875,52 @@ public class MCImplSynthesis { } edgevec = null; } - candidatetasks = null; - it_edgevecs = null; - } - it_cores = null; - computeBestStartPoint(criticalPath); - Vector> ops = optimizeCriticalPath(scheduleGraph, - criticalPath, - lgid, - left); - if(ops != null) { - if(optimizeschedulegraphs == null) { - optimizeschedulegraphs = new Vector>(); + it_cores = null; + computeBestStartPoint(criticalPath); + Vector> ops = optimizeCriticalPath(scheduleGraph, + criticalPath, + lgid, + left); + if(ops != null) { + if(optimizeschedulegraphs == null) { + optimizeschedulegraphs = new Vector>(); + } + optimizeschedulegraphs.addAll(ops); + lgid += ops.size(); + left -= ops.size(); } - optimizeschedulegraphs.addAll(ops); - } - ops = null; - } else { - // there are spare cores, try to reorganize the tasks to the spare - // cores - Vector> ops = innerOptimizeCriticalPath(scheduleGraph, - tooptimize, - sparecores, - lgid, - left); - if(ops != null) { - if(optimizeschedulegraphs == null) { - optimizeschedulegraphs = new Vector>(); + ops = null; + } else { + // there are spare cores, try to reorganize the tasks to the spare + // cores + Vector> ops = innerOptimizeCriticalPath(scheduleGraph, + tooptimize, + sparecores, + lgid, + left); + if(ops != null) { + if(optimizeschedulegraphs == null) { + optimizeschedulegraphs = new Vector>(); + } + optimizeschedulegraphs.addAll(ops); + lgid += ops.size(); + left -= ops.size(); } - optimizeschedulegraphs.addAll(ops); + ops = null; } - ops = null; } - } - sparecores = null; - tooptimize.clear(); - tooptimize = null; + sparecores = null; + tooptimize.clear(); + tooptimize = null; + }while(left > 0); + toselects.clear(); + toselects = null; return optimizeschedulegraphs; } private Vector> innerOptimizeCriticalPath(Vector scheduleGraph, - Hashtable>> tooptimize, + Hashtable> tooptimize, Vector sparecores, int gid, int count) { @@ -863,37 +947,32 @@ public class MCImplSynthesis { Iterator it_cores = tooptimize.keySet().iterator(); while(it_cores.hasNext()) { int corenum = it_cores.next(); - Hashtable> candidatetasks = + Vector candidatetasks = tooptimize.get(corenum); - Iterator it_tds = candidatetasks.keySet().iterator(); - while(it_tds.hasNext()) { - TaskDescriptor td = it_tds.next(); - int numtosplit = candidatetasks.get(td).size(); + for(int i = 0; i < candidatetasks.size(); i++) { + TaskDescriptor td = candidatetasks.elementAt(i).getTd(); // TODO: currently do not consider multi-param tasks if(td.numParameters() == 1) { ClassDescriptor cd = td.getParamType(0).getClassDesc(); ScheduleNode snode = newscheduleGraph.elementAt(corenum); // corresponding ScheduleNode Iterator it_cnodes = snode.getClassNodesIterator(); - Vector tosplit = new Vector(); - while((numtosplit > 0) && (it_cnodes.hasNext())) { + ClassNode tosplit = null; + while(it_cnodes.hasNext()) { ClassNode cnode = it_cnodes.next(); if(cnode.getClassDescriptor().equals(cd)) { - tosplit.add(cnode); - numtosplit--; + tosplit= cnode; + break; } } it_cnodes = null; - // split these node - for(int i = 0; i < tosplit.size(); i++) { - ScheduleNode splitnode = snode.spliteClassNode(tosplit.elementAt(i)); - newscheduleGraph.add(splitnode); - tocombines.add(splitnode); - } + // split the node + ScheduleNode splitnode = snode.spliteClassNode(tosplit); + newscheduleGraph.add(splitnode); + tocombines.add(splitnode); tosplit = null; } } candidatetasks = null; - it_tds = null; } it_cores = null; diff --git a/Robust/src/Analysis/Scheduling/ScheduleSimulator.java b/Robust/src/Analysis/Scheduling/ScheduleSimulator.java index 754d2356..db817797 100644 --- a/Robust/src/Analysis/Scheduling/ScheduleSimulator.java +++ b/Robust/src/Analysis/Scheduling/ScheduleSimulator.java @@ -109,8 +109,10 @@ public class ScheduleSimulator { selectedSimExeGraphs.add(simexegraph); processTime = tmpTime; } else if(tmpTime == processTime) { - selectedScheduling.add(index); - selectedSimExeGraphs.add(simexegraph); + if(!selectedScheduling.contains(index)) { + selectedScheduling.add(index); + selectedSimExeGraphs.add(simexegraph); + } } scheduling = null; checkpoints.clear(); diff --git a/Robust/src/Analysis/Scheduling/SimExecutionEdge.java b/Robust/src/Analysis/Scheduling/SimExecutionEdge.java index 4f0a5014..49f9d93f 100644 --- a/Robust/src/Analysis/Scheduling/SimExecutionEdge.java +++ b/Robust/src/Analysis/Scheduling/SimExecutionEdge.java @@ -134,4 +134,24 @@ public class SimExecutionEdge extends Edge { + "(" + this.weight + " | " + this.bestStartPoint + ")"; return completeLabel; } + + public void destroy() { + this.td = null; + if(this.taskparams != null) { + this.taskparams.clear(); + this.taskparams = null; + } + this.lastpredicatenode = null; + this.lastpredicateedge = null; + if(this.predicates != null) { + this.predicates.clear(); + this.predicates = null; + } + this.source.getEdgeVector().clear(); + this.source.getInedgeVector().clear(); + this.source = null; + this.target.getEdgeVector().clear(); + this.target.getInedgeVector().clear(); + this.target = null; + } } diff --git a/Robust/src/Main/Main.java b/Robust/src/Main/Main.java index 6a6f6a52..06b9b747 100644 --- a/Robust/src/Main/Main.java +++ b/Robust/src/Main/Main.java @@ -262,13 +262,13 @@ public class Main { if (state.SCHEDULING) { // Use ownership analysis to get alias information CallGraph callGraph = new CallGraph(state); - OwnershipAnalysis oa = new OwnershipAnalysis(state, + OwnershipAnalysis oa = null;/*new OwnershipAnalysis(state, tu, callGraph, state.OWNERSHIPALLOCDEPTH, state.OWNERSHIPWRITEDOTS, state.OWNERSHIPWRITEALL, - state.OWNERSHIPALIASFILE); + state.OWNERSHIPALIASFILE);*/ // synthesis a layout according to target multicore processor MCImplSynthesis mcImplSynthesis = new MCImplSynthesis(state, @@ -277,7 +277,7 @@ public class Main { if(isDistributeInfo) { mcImplSynthesis.distribution(); } else { - mcImplSynthesis.setScheduleThreshold(50); + mcImplSynthesis.setScheduleThreshold(20); mcImplSynthesis.setProbThreshold(0); mcImplSynthesis.setGenerateThreshold(30); Vector scheduling = mcImplSynthesis.synthesis(); diff --git a/Robust/src/buildscript b/Robust/src/buildscript index 3eaa02dc..e740a42e 100755 --- a/Robust/src/buildscript +++ b/Robust/src/buildscript @@ -255,6 +255,9 @@ then JAVAOPTS="$JAVAOPTS -thread" EXTRAOPTIONS="$EXTRAOPTIONS -DTHREADS -lpthread" THREADFLAG=true +elif [[ $1 = '-distributioninfo' ]] +then +JAVAOPTS="$JAVAOPTS -distributioninfo" elif [[ $1 = '-curdir' ]] then CURDIR=$2