Skip to content

Commit

Permalink
singleThreadSchedule
Browse files Browse the repository at this point in the history
  • Loading branch information
vwaurich authored and OpenModelica-Hudson committed Jul 13, 2015
1 parent 37686b4 commit 69cde81
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 10 deletions.
53 changes: 50 additions & 3 deletions Compiler/BackEnd/HpcOmScheduler.mo
Expand Up @@ -4595,7 +4595,7 @@ algorithm
then oSchedule;
case(_,_,_,_,_)
algorithm
true := intEq(arrayLength(iTaskGraph),0);a
true := intEq(arrayLength(iTaskGraph),0);
then HpcOmSimCode.EMPTYSCHEDULE(HpcOmSimCode.PARALLELTASKLIST({}));
else
algorithm
Expand Down Expand Up @@ -4704,12 +4704,14 @@ end reassignPartitions;
public function createSingleThreadSchedule"creates a schedule in which all tasks are computed in thread 1"
input HpcOmTaskGraph.TaskGraph iTaskGraph;
input HpcOmTaskGraph.TaskGraphMeta iTaskGraphMeta;
input array<list<Integer>> iSccSimEqMapping;
input Integer numProc;
output HpcOmSimCode.Schedule oSchedule;
protected
Integer nTasks, size;
list<Integer> order;
HpcOmTaskGraph.TaskGraph taskGraphT;
list<HpcOmSimCode.Task> allTasksLst;
list<HpcOmSimCode.Task> allTasksLst={};
array<list<HpcOmSimCode.Task>> thread2TaskAss;
array<tuple<HpcOmSimCode.Task,Integer>> allCalcTasks;
algorithm
Expand All @@ -4718,8 +4720,16 @@ algorithm
taskGraphT := BackendDAEUtil.transposeMatrix(iTaskGraph,size);
// create the schedule
allCalcTasks := convertTaskGraphToTasks(taskGraphT,iTaskGraphMeta,convertNodeToTask);

order := List.flatten(HpcOmTaskGraph.getLevelNodes(iTaskGraph));
for i in order loop
// get the correct ordered tasks, replace the scc indexes with simEq indexes
allTasksLst := setSimEqIdcsInTask(Util.tuple21(arrayGet(allCalcTasks,i)),iSccSimEqMapping)::allTasksLst;
end for;
allTasksLst := listReverse(allTasksLst);
// set the thread Index
allTasksLst := List.map1(allTasksLst,setThreadIdxInTask,1);
thread2TaskAss := arrayCreate(numProc,{});
allTasksLst := List.map(arrayList(allCalcTasks),Util.tuple21);
thread2TaskAss := arrayUpdate(thread2TaskAss,1,allTasksLst);
oSchedule := HpcOmSimCode.THREADSCHEDULE(thread2TaskAss,{},{},allCalcTasks);
end createSingleThreadSchedule;
Expand Down Expand Up @@ -4966,6 +4976,7 @@ algorithm
taskLstAss = List.map6(otherParents,createDepTaskByTaskIdc,node,allCalcTasks,false,inCommCosts,inComps,iSimVarMapping);
//relLockDepTasks = List.map1(otherChildren,getReleaseLockString,node);
taskLstRel = List.map6(otherChildren,createDepTaskByTaskIdcR,node,allCalcTasks,true,inCommCosts,inComps,iSimVarMapping);

//build the calcTask
components = arrayGet(inComps,node);
mark = arrayGet(nodeMark,node);
Expand All @@ -4991,6 +5002,42 @@ algorithm
end match;
end createScheduleFromAssignments;

protected function setSimEqIdcsInTask"updates the eqIdcs from scc-Indexes to simEq-Indexes in calctasks "
input HpcOmSimCode.Task taskIn;
input array<list<Integer>> SccSimEqMappingIn;
output HpcOmSimCode.Task taskOut;
algorithm
taskOut := matchcontinue(taskIn)
local
Integer weighting, index, threadIdx;
Real calcTime, timeFinished;
list<Integer> eqIdc;
case(HpcOmSimCode.CALCTASK(weighting=weighting,index=index,calcTime=calcTime,timeFinished=timeFinished,threadIdx=threadIdx,eqIdc=eqIdc))
equation
eqIdc = List.flatten(List.map1(eqIdc,getSimEqSysIdxForComp,SccSimEqMappingIn));
then HpcOmSimCode.CALCTASK(weighting,index,calcTime,timeFinished,threadIdx,eqIdc);
else
then taskIn;
end matchcontinue;
end setSimEqIdcsInTask;

protected function setThreadIdxInTask"updates threadIdxs in calctasks "
input HpcOmSimCode.Task taskIn;
input Integer threadIdx;
output HpcOmSimCode.Task taskOut;
algorithm
taskOut := matchcontinue(taskIn)
local
Integer weighting, index;
Real calcTime, timeFinished;
list<Integer> eqIdc;
case(HpcOmSimCode.CALCTASK(weighting=weighting,index=index,calcTime=calcTime,timeFinished=timeFinished,eqIdc=eqIdc))
then HpcOmSimCode.CALCTASK(weighting,index,calcTime,timeFinished,threadIdx,eqIdc);
else
then taskIn;
end matchcontinue;
end setThreadIdxInTask;

protected function tasksEqual "author: marcusw
Checks if the given tasks are equal. The following conditions are checked:
- if both tasks are of type CALCTASK: true if index equal
Expand Down
14 changes: 7 additions & 7 deletions Compiler/SimCode/HpcOmSimCodeMain.mo
Expand Up @@ -350,18 +350,18 @@ algorithm

(scheduleDae,simCode,taskGraphDaeScheduled,taskGraphDataDaeScheduled,sccSimEqMapping) = createSchedule(taskGraphDaeSimplified,taskGraphDataDaeSimplified,daeSccSimEqMapping,simVarMapping,filenamePrefix,numProc,simCode,scheduledTasksDae,"DAE system",Flags.getConfigString(Flags.HPCOM_SCHEDULER));
//HpcOmScheduler.printSchedule(scheduleDae);
schedulerInfo = HpcOmScheduler.convertScheduleStrucToInfo(scheduleDae,arrayLength(taskGraphDaeScheduled));
HpcOmTaskGraph.dumpAsGraphMLSccLevel(taskGraphDaeScheduled, taskGraphDataDaeScheduled, "taskGraph"+filenamePrefix+"DAE_scheduled.graphml", "", HpcOmTaskGraph.convertNodeListToEdgeTuples(listHead(criticalPaths)), HpcOmTaskGraph.convertNodeListToEdgeTuples(listHead(criticalPathsWoC)), sccSimEqMapping, schedulerInfo, HpcOmTaskGraph.GRAPHDUMPOPTIONS(false,false,false,false));
//schedulerInfo = HpcOmScheduler.convertScheduleStrucToInfo(scheduleDae,arrayLength(taskGraphDaeScheduled));
//HpcOmTaskGraph.dumpAsGraphMLSccLevel(taskGraphDaeScheduled, taskGraphDataDaeScheduled, "taskGraph"+filenamePrefix+"DAE_scheduled.graphml", "", HpcOmTaskGraph.convertNodeListToEdgeTuples(listHead(criticalPaths)), HpcOmTaskGraph.convertNodeListToEdgeTuples(listHead(criticalPathsWoC)), sccSimEqMapping, schedulerInfo, HpcOmTaskGraph.GRAPHDUMPOPTIONS(false,false,false,false));

(scheduleOde,simCode,taskGraphOdeScheduled,taskGraphDataOdeScheduled,sccSimEqMapping) = createSchedule(taskGraphOdeSimplified,taskGraphDataOdeSimplified,sccSimEqMapping,simVarMapping,filenamePrefix,numProc,simCode,scheduledTasksOde,"ODE system",Flags.getConfigString(Flags.HPCOM_SCHEDULER));
//HpcOmScheduler.printSchedule(scheduleOde);
schedulerInfo = HpcOmScheduler.convertScheduleStrucToInfo(scheduleOde,arrayLength(taskGraphOdeScheduled));
HpcOmTaskGraph.dumpAsGraphMLSccLevel(taskGraphOdeScheduled, taskGraphDataOdeScheduled, "taskGraph"+filenamePrefix+"ODE_scheduled.graphml", "", HpcOmTaskGraph.convertNodeListToEdgeTuples(listHead(criticalPaths)), HpcOmTaskGraph.convertNodeListToEdgeTuples(listHead(criticalPathsWoC)), sccSimEqMapping, schedulerInfo, HpcOmTaskGraph.GRAPHDUMPOPTIONS(false,false,false,false));
//schedulerInfo = HpcOmScheduler.convertScheduleStrucToInfo(scheduleOde,arrayLength(taskGraphOdeScheduled));
//HpcOmTaskGraph.dumpAsGraphMLSccLevel(taskGraphOdeScheduled, taskGraphDataOdeScheduled, "taskGraph"+filenamePrefix+"ODE_scheduled.graphml", "", HpcOmTaskGraph.convertNodeListToEdgeTuples(listHead(criticalPaths)), HpcOmTaskGraph.convertNodeListToEdgeTuples(listHead(criticalPathsWoC)), sccSimEqMapping, schedulerInfo, HpcOmTaskGraph.GRAPHDUMPOPTIONS(false,false,false,false));

(scheduleZeroFunc,simCode,taskGraphZeroFuncScheduled,taskGraphDataZeroFuncScheduled,sccSimEqMapping) = createSchedule(taskGraphZeroFuncSimplified,taskGraphDataZeroFuncSimplified,daeSccSimEqMapping,simVarMapping,filenamePrefix,numProc,simCode,scheduledTasksZeroFunc,"ZeroFunc system",Flags.getConfigString(Flags.HPCOM_SCHEDULER));
//HpcOmScheduler.printSchedule(scheduleZeroFunc);
schedulerInfo = HpcOmScheduler.convertScheduleStrucToInfo(scheduleZeroFunc,arrayLength(taskGraphZeroFuncScheduled));
HpcOmTaskGraph.dumpAsGraphMLSccLevel(taskGraphZeroFuncScheduled, taskGraphDataZeroFuncScheduled, "taskGraph"+filenamePrefix+"ZF_scheduled.graphml", "", HpcOmTaskGraph.convertNodeListToEdgeTuples(listHead(criticalPaths)), HpcOmTaskGraph.convertNodeListToEdgeTuples(listHead(criticalPathsWoC)), sccSimEqMapping, schedulerInfo, HpcOmTaskGraph.GRAPHDUMPOPTIONS(false,false,false,false));
//schedulerInfo = HpcOmScheduler.convertScheduleStrucToInfo(scheduleZeroFunc,arrayLength(taskGraphZeroFuncScheduled));
//HpcOmTaskGraph.dumpAsGraphMLSccLevel(taskGraphZeroFuncScheduled, taskGraphDataZeroFuncScheduled, "taskGraph"+filenamePrefix+"ZF_scheduled.graphml", "", HpcOmTaskGraph.convertNodeListToEdgeTuples(listHead(criticalPaths)), HpcOmTaskGraph.convertNodeListToEdgeTuples(listHead(criticalPathsWoC)), sccSimEqMapping, schedulerInfo, HpcOmTaskGraph.GRAPHDUMPOPTIONS(false,false,false,false));

SimCode.SIMCODE( modelInfo, simCodeLiterals, simCodeRecordDecls, simCodeExternalFunctionIncludes, allEquations, odeEquations, algebraicEquations,
partitionsKind, baseClocks, useHomotopy, initialEquations, removedInitialEquations, startValueEquations,
Expand Down Expand Up @@ -894,7 +894,7 @@ algorithm
case(_,_,_,_,_,_,_,_,_,"sts")
equation
print("Using Single Thread Scheduling for the " + iSystemName + "\n");
schedule = HpcOmScheduler.createSingleThreadSchedule(iTaskGraph,iTaskGraphMeta,iNumProc);
schedule = HpcOmScheduler.createSingleThreadSchedule(iTaskGraph,iTaskGraphMeta,iSccSimEqMapping,iNumProc);
then (schedule,iSimCode,iTaskGraph,iTaskGraphMeta,iSccSimEqMapping);
else
equation
Expand Down

0 comments on commit 69cde81

Please sign in to comment.