Vector<Vector<ScheduleNode>> rootNodes;
int rootNum;
- public RootsGenerator(Vector<Vector<ScheduleNode>> snodevecs, int rootNum) {
+ public RootsGenerator(Vector<Vector<ScheduleNode>> snodevecs,
+ int rootNum) {
this.sNodeVecs = snodevecs;
this.rootNum = rootNum;
this.node2Combine = null;
trial = trial(num2choose, next);
}
if(trial) {
- // left nodes are all to be combined
+ // remaining nodes are all to be combined
this.node2Combine = new Vector<Vector<ScheduleNode>>();
int next = 1;
int index = 0;
return trial;
}
- private boolean trial(int num2choose, int next) {
+ private boolean trial(int num2choose,
+ int next) {
int index = 0;
boolean first = true;
while(num2choose > 0) {
int[] lastchoices;
boolean first4choice;
- public CombineGenerator(Vector<Vector<ScheduleNode>> rootnodes, Vector<Vector<ScheduleNode>> node2combine) {
+ public CombineGenerator(Vector<Vector<ScheduleNode>> rootnodes,
+ Vector<Vector<ScheduleNode>> node2combine) {
this.rootNodes = rootnodes;
this.node2Combine = node2combine;
this.rootNStates = new Vector<Vector<int[]>>();
return suc;
}
- private boolean firstexpand(int next, boolean first) {
+ private boolean firstexpand(int next,
+ boolean first) {
for(int i = next; i < this.node2Combine.size(); i++) {
if(this.node2Combine.elementAt(i) != null) {
int choice = this.lastchoices[i];
return true;
}
- private boolean innertrial(int next, int layer) {
+ private boolean innertrial(int next,
+ int layer) {
if((this.combine.elementAt(next) == null) ||
(this.combine.elementAt(next).size() < 2)) {
// skip over empty buckets and bucket with only one obj ( make sure
}
}
- private boolean propagateOne(int next, int rooti, int indexi, int ti, Combine tmp) {
+ private boolean propagateOne(int next,
+ int rooti,
+ int indexi,
+ int ti,
+ Combine tmp) {
int root = rooti;
int index = indexi;
int t = ti;
import java.io.PrintStream;
import java.util.Hashtable;
import java.util.Iterator;
+import java.util.Random;
import java.util.Vector;
import Analysis.OwnershipAnalysis.OwnershipAnalysis;
int coreNum;
int scheduleThreshold;
+ int probThreshold;
public MCImplSynthesis(State state,
TaskAnalysis ta,
state,
ta);
this.scheduleThreshold = 1000;
+ this.probThreshold = 0;
}
public int getCoreNum() {
this.scheduleThreshold = scheduleThreshold;
}
+ public int getProbThreshold() {
+ return probThreshold;
+ }
+
+ public void setProbThreshold(int probThreshold) {
+ this.probThreshold = probThreshold;
+ }
+
public Vector<Schedule> synthesis() {
// Print stuff to the original output and error streams.
// The stuff printed through the 'origOut' and 'origErr' references
int tryindex = 1;
int bestexetime = Integer.MAX_VALUE;
+ Random rand = new Random();
// simulate the generated schedulings and try to optimize it
do {
System.out.print("+++++++++++++++++++++++++++++++++++++++++++++++++++\n");
System.out.print("end of: #" + tryindex + " (bestexetime: " + bestexetime + ")\n");
System.out.print("+++++++++++++++++++++++++++++++++++++++++++++++++++\n");
tryindex++;
+ } 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;
}
selectedSimExeGraphs = null;
multiparamtds = null;
- String path = "scheduling_selected.dot";
+ String path = this.state.outputdir + "scheduling_selected.dot";
SchedulingUtil.printScheduleGraph(path, schedulinggraph);
// Close the streams.
Vector<Vector<ScheduleNode>> optimizeschedulegraphs = null;
int lgid = gid;
int left = count;
- int num2try = (gid - 1) / this.scheduleThreshold;
for(int i = 0; i < selectedScheduleGraphs.size(); i++) {
Vector<ScheduleNode> schedulegraph = scheduleGraphs.elementAt(
selectedScheduleGraphs.elementAt(i));
Vector<SimExecutionEdge> simexegraph = selectedSimExeGraphs.elementAt(i);
Vector<SimExecutionEdge> criticalPath = analyzeCriticalPath(simexegraph);
- // for test, print out the criticalPath
- if(this.state.PRINTCRITICALPATH) {
- SchedulingUtil.printCriticalPath("criticalpath_" + num2try + ".dot", criticalPath);
- }
- num2try++;
Vector<Vector<ScheduleNode>> tmposchedulegraphs = optimizeCriticalPath(schedulegraph,
criticalPath,
lgid,
int lgid = gid;
int left = count;
+ // for test, print out the criticalPath
+ if(this.state.PRINTCRITICALPATH) {
+ SchedulingUtil.printCriticalPath(this.state.outputdir + "criticalpath_" + lgid + ".dot",
+ criticalPath);
+ }
+
// first check all seedges whose real start point is late than predicted
// earliest start time and group them
int opcheckpoint = Integer.MAX_VALUE;
seedge.setFixedTime(false);
// consider to optimize it only when its predicates can NOT
// be optimized, otherwise first considering optimize its predicates
- if(seedge.getLastpredicateEdge().isFixedTime()) {
+ 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;
- sparecores = seedge.getLastpredicateNode().getSpareCores();
+ 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)) {
tooptimize2.put(corenum, candidatetasks);
Vector<Vector<ScheduleNode>> ops = innerOptimizeCriticalPath(scheduleGraph,
tooptimize2,
+ null,
lgid,
left);
if(ops != null) {
// cores
Vector<Vector<ScheduleNode>> ops = innerOptimizeCriticalPath(scheduleGraph,
tooptimize,
+ sparecores,
lgid,
left);
if(ops != null) {
private Vector<Vector<ScheduleNode>> innerOptimizeCriticalPath(Vector<ScheduleNode> scheduleGraph,
Hashtable<Integer, Hashtable<TaskDescriptor, Vector<SimExecutionEdge>>> tooptimize,
+ Vector<Integer> sparecores,
int gid,
int count) {
int lgid = gid;
// these nodes are root nodes
Vector<ScheduleNode> roots = new Vector<ScheduleNode>();
for(int i = 0; i < newscheduleGraph.size(); i++) {
- roots.add(newscheduleGraph.elementAt(i));
+ if((sparecores == null) || (sparecores.contains(i))) {
+ roots.add(newscheduleGraph.elementAt(i));
+ }
}
// map the tasks associated to SimExecutionedges to original
toVisit = null;
if(this.state.PRINTSCHEDULING) {
- SchedulingUtil.printScheduleGraph("scheduling_ori.dot",
+ SchedulingUtil.printScheduleGraph(this.state.outputdir + "scheduling_ori.dot",
this.scheduleNodes);
}
}
sn2fes = null;
if(this.state.PRINTSCHEDULING) {
- SchedulingUtil.printScheduleGraph("scheduling_extend.dot", this.scheduleNodes);
+ SchedulingUtil.printScheduleGraph(this.state.outputdir + "scheduling_extend.dot",
+ this.scheduleNodes);
}
}
this.scheduleGraphs.addElement(this.scheduleNodes);
int gid = 1;
if(this.state.PRINTSCHEDULING) {
- String path = "scheduling_" + gid + ".dot";
+ String path = this.state.outputdir + "scheduling_" + gid + ".dot";
SchedulingUtil.printScheduleGraph(path, this.scheduleNodes);
}
} else {
+ SchedulingUtil.assignCids(this.scheduleNodes);
+
// Go through all the Schedule Nodes, organize them in order of their cid
Vector<Vector<ScheduleNode>> sNodeVecs =
SchedulingUtil.rangeScheduleNodes(this.scheduleNodes);
this.setScheduling(scheduling);
Vector<SimExecutionEdge> simexegraph = new Vector<SimExecutionEdge>();
Vector<CheckPoint> checkpoints = new Vector<CheckPoint>();
- int tmpTime = this.process(checkpoints, simexegraph);
+ int tmpTime = process(checkpoints, simexegraph);
if(tmpTime < processTime) {
selectedScheduling.clear();
selectedScheduling.add(index);
int gid = this.scheduling.elementAt(0).getGid();
if(this.state.PRINTSCHEDULESIM) {
- SchedulingUtil.printSimulationResult("SimulatorResult_" + gid + ".dot",
+ SchedulingUtil.printSimulationResult(this.state.outputdir + "SimulatorResult_" + gid + ".dot",
this.processTime,
this.coreNum,
checkpoints);
}
} else if(tttasks.size() > 0) {
SimExecutionNode seNode = new SimExecutionNode(corenum, this.processTime);
- seNode.setSpareCores(cp.getSpareCores());
+ //seNode.setSpareCores(cp.getSpareCores());
// no action associated here
SimExecutionNode lastsenode = lastseNodes[corenum];
// create edges between previous senode on this core to this node
sn2sn = null;
if(state.PRINTSCHEDULING) {
- String path = "scheduling_" + gid + ".dot";
+ String path = state.outputdir + "scheduling_" + gid + ".dot";
SchedulingUtil.printScheduleGraph(path, result);
}
for(int i = 0; i < scheduleNodes.size(); i++) {
ScheduleNode tmpn = scheduleNodes.elementAt(i);
- int index = tmpn.getCid();
+ int tmpcid = tmpn.getCid();
+ int index = 0;
+ for(index = 0; index < sNodeVecs.size(); index++) {
+ if(sNodeVecs.elementAt(index).elementAt(0).getCid() > tmpcid) {
+ // find the place to insert
+ sNodeVecs.add(sNodeVecs.lastElement());
+ for(int j = sNodeVecs.size() - 2; j > index; j--) {
+ sNodeVecs.setElementAt(sNodeVecs.elementAt(j - 1), j);
+ }
+ sNodeVecs.setElementAt(new Vector<ScheduleNode>(), index);
+ } else if(sNodeVecs.elementAt(index).elementAt(0).getCid() == tmpcid) {
+ break;
+ }
+ }
+ if(index == sNodeVecs.size()) {
+ sNodeVecs.add(new Vector<ScheduleNode>());
+ }
+
+ /*int index = tmpcid;
while(sNodeVecs.size() <= index) {
sNodeVecs.add(null);
}
if(sNodeVecs.elementAt(index) == null) {
sNodeVecs.setElementAt(new Vector<ScheduleNode>(), index);
- }
+ }*/
sNodeVecs.elementAt(index).add(tmpn);
}
public int CORENUM = 1;
public String structfile;
public String main;
- public String outputdir = null;
+ public String outputdir = "/scratch/";
public HashSet selfloops;
public HashSet excprefetch;
ta,
oa);
mcImplSynthesis.setScheduleThreshold(50);
+ mcImplSynthesis.setProbThreshold(0);
Vector<Schedule> scheduling = mcImplSynthesis.synthesis();
// generate multicore codes