Skip to content

Commit

Permalink
- deactivate schedule repetition, provide backendDAE and SimCode for …
Browse files Browse the repository at this point in the history
…schedule method

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@20827 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Volker Waurich committed May 26, 2014
1 parent e0ecf1b commit 675c65d
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 108 deletions.
24 changes: 16 additions & 8 deletions Compiler/BackEnd/HpcOmScheduler.mo
Expand Up @@ -36,8 +36,10 @@ encapsulated package HpcOmScheduler
RCS: $Id: HpcOmScheduler.mo 15486 2013-08-07 12:46:00Z marcusw $
"

public import BackendDAE;
public import HpcOmTaskGraph;
public import HpcOmSimCode;
public import SimCode;

protected import BackendDAEUtil;
protected import Debug;
Expand Down Expand Up @@ -1574,6 +1576,8 @@ author: Waurich TUD 2015-05"
input HpcOmTaskGraph.TaskGraphMeta iTaskGraphMeta;
input Integer numProc;
input array<list<Integer>> iSccSimEqMapping;
input BackendDAE.BackendDAE iDAE;
input SimCode.SimCode iSimCode;
output HpcOmSimCode.Schedule oSchedule;
protected
Integer size;
Expand All @@ -1600,7 +1604,7 @@ algorithm
//print("levels:\n"+&stringDelimitList(List.map(levels,realString)," , ")+&"\n");
initClusters := createTDSInitialCluster(iTaskGraph,taskGraphT,iTaskGraphMeta,lastArray,lactArray,fpredArray,queue);
print("initClusters:\n"+&stringDelimitList(List.map(initClusters,intListString),"\n")+&"\n");
oSchedule := createTDSschedule1(initClusters,iTaskGraph,taskGraphT,iTaskGraphMeta,tdsLevelArray,numProc,iSccSimEqMapping);
oSchedule := createTDSschedule1(initClusters,iTaskGraph,taskGraphT,iTaskGraphMeta,tdsLevelArray,numProc,iSccSimEqMapping,iDAE,iSimCode);
end createTDSschedule;

protected function createTDSschedule1"takes the initial Cluster and compactes or duplicates them to the given number of threads.
Expand All @@ -1612,9 +1616,11 @@ author:Waurich TUD 2014-05"
input array<Real> TDSLevel;
input Integer numProc;
input array<list<Integer>> iSccSimEqMapping;
input BackendDAE.BackendDAE inDAE;
input SimCode.SimCode iSimCode;
output HpcOmSimCode.Schedule oSchedule;
algorithm
oSchedule := matchcontinue(clustersIn,iTaskGraph,iTaskGraphT,iTaskGraphMeta,TDSLevel,numProc,iSccSimEqMapping)
oSchedule := matchcontinue(clustersIn,iTaskGraph,iTaskGraphT,iTaskGraphMeta,TDSLevel,numProc,iSccSimEqMapping,inDAE,iSimCode)
local
Integer size, numSfLocks;
array<Integer> taskAss;
Expand All @@ -1624,30 +1630,32 @@ algorithm
HpcOmSimCode.Schedule schedule;
array<list<HpcOmSimCode.Task>> threadTask;
list<HpcOmSimCode.Task> removeLocks;
case(_,_,_,_,_,_,_)
case(_,_,_,_,_,_,_,_,_)
equation
// we need cluster duplication, repeat until numProc=num(clusters)
true = listLength(clustersIn) < numProc;
print("There are less initial clusters than processors. we need duplication, but since this is a rare case, it is not done. Less processors are used.\n");
clusters = List.map(clustersIn,listReverse);
Flags.setConfigInt(Flags.NUM_PROC,listLength(clustersIn));
schedule = createTDSschedule1(clusters,iTaskGraph,iTaskGraphT,iTaskGraphMeta,TDSLevel,listLength(clustersIn),iSccSimEqMapping);
schedule = createTDSschedule1(clusters,iTaskGraph,iTaskGraphT,iTaskGraphMeta,TDSLevel,listLength(clustersIn),iSccSimEqMapping,inDAE,iSimCode);
then
schedule;
case(_,_,_,_,_,_,_)
case(_,_,_,_,_,_,_,_,_)
equation
// we need cluster compaction, repeat until numProc=num(clusters)
true = listLength(clustersIn) > numProc;
clusters = createTDSCompactClusters(clustersIn,iTaskGraph,iTaskGraphMeta,TDSLevel,numProc);
schedule = createTDSschedule1(clusters,iTaskGraph,iTaskGraphT,iTaskGraphMeta,TDSLevel,numProc,iSccSimEqMapping);
schedule = createTDSschedule1(clusters,iTaskGraph,iTaskGraphT,iTaskGraphMeta,TDSLevel,numProc,iSccSimEqMapping,inDAE,iSimCode);
then
schedule;
case(_,_,_,_,_,_,_)
case(_,_,_,_,_,_,_,_,_)
equation
// the clusters can be scheduled, build assignments
// the clusters can be scheduled,
true = listLength(clustersIn) == numProc;
clusters = List.map1(clustersIn,createTDSSortCompactClusters,TDSLevel);
print("clusters:\n"+&stringDelimitList(List.map(clusters,intListString),"\n")+&"\n");


procAss = listArray(clusters);
size = arrayLength(iTaskGraph);
taskAss = arrayCreate(size,-1);
Expand Down
202 changes: 102 additions & 100 deletions Compiler/BackEnd/HpcOmSimCodeMain.mo
Expand Up @@ -247,10 +247,9 @@ algorithm
//Create schedule
//---------------
numProc = Flags.getConfigInt(Flags.NUM_PROC);
(numProc,numFixed) = setNumProc(numProc,cpCostsWoC,taskGraphDataOde);
schedule = createSchedule(taskGraph1,taskGraphData1,sccSimEqMapping,filenamePrefix,numProc);
numProc = Flags.getConfigInt(Flags.NUM_PROC);
(schedule,numProc) = repeatScheduleWithOtherNumProc(taskGraph1,taskGraphData1,sccSimEqMapping,filenamePrefix,cpCostsWoC,schedule,numProc,numFixed);
(numProc,_) = setNumProc(numProc,cpCostsWoC,taskGraphDataOde);//in case n-flag is not set
schedule = createSchedule(taskGraph1,taskGraphData1,sccSimEqMapping,filenamePrefix,numProc,inBackendDAE,simCode);
//(schedule,numProc) = repeatScheduleWithOtherNumProc(taskGraph1,taskGraphData1,sccSimEqMapping,filenamePrefix,cpCostsWoC,schedule,numProc,numFixed);
criticalPathInfo = HpcOmScheduler.analyseScheduledTaskGraph(schedule,numProc,taskGraph1,taskGraphData1);
schedulerInfo = HpcOmScheduler.convertScheduleStrucToInfo(schedule,arrayLength(taskGraph));
Debug.execStat("hpcom create schedule", GlobalScript.RT_CLOCK_EXECSTAT_HPCOM_MODULES);
Expand Down Expand Up @@ -283,89 +282,6 @@ algorithm
end matchcontinue;
end createSimCode;


protected function repeatScheduleWithOtherNumProc"checks if the scheduling with the given numProc is fine.
if n=auto, more cores are available and more speedup could be achieved repeat schedule with increased num of procs.
author:Waurich TUD 2013-011"
input HpcOmTaskGraph.TaskGraph taskGraphIn;
input HpcOmTaskGraph.TaskGraphMeta taskGraphMetaIn;
input array<list<Integer>> sccSimEqMappingIn;
input String fileNamePrefix;
input Real cpCostsWoC;
input HpcOmSimCode.Schedule scheduleIn;
input Integer numProcIn;
input Boolean numFixed;
output HpcOmSimCode.Schedule scheduleOut;
output Integer numProcOut;
protected
Integer maxNumProc, maxIter;
Real maxDiff;
algorithm
maxNumProc := System.numProcessors();
maxIter := 3;
maxDiff := 0.5;
(scheduleOut,numProcOut,_) := repeatScheduleWithOtherNumProc1(taskGraphIn,taskGraphMetaIn,sccSimEqMappingIn,fileNamePrefix,cpCostsWoC,scheduleIn,numProcIn,numFixed,maxNumProc,maxDiff,maxIter);
end repeatScheduleWithOtherNumProc;


protected function repeatScheduleWithOtherNumProc1"checks if the scheduling with the given numProc is fine.
if n=auto, more cores are available and more speedup could be achieved repeat schedule with increased num of procs.
author:Waurich TUD 2013-011"
input HpcOmTaskGraph.TaskGraph taskGraphIn;
input HpcOmTaskGraph.TaskGraphMeta taskGraphMetaIn;
input array<list<Integer>> sccSimEqMappingIn;
input String fileNamePrefix;
input Real cpCostsWoC;
input HpcOmSimCode.Schedule scheduleIn;
input Integer numProcIn;
input Boolean numFixed;
input Integer maxNumProc;
input Real maxDiff;
input Integer numIterIn;
output HpcOmSimCode.Schedule scheduleOut;
output Integer numProcOut;
output Integer numIterOut;
algorithm
(scheduleOut,numProcOut,numIterOut) := matchcontinue(taskGraphIn,taskGraphMetaIn,sccSimEqMappingIn,fileNamePrefix,cpCostsWoC,scheduleIn,numProcIn,numFixed,maxNumProc,maxDiff,numIterIn)
local
Boolean scheduleAgain;
Integer numProc, numIt;
Real serTime,parTime,speedup,speedUp,speedUpMax,diff;
HpcOmSimCode.Schedule schedule;
case(_,_,_,_,_,_,_,true,_,_,_)
equation // do not schedule again because the number of procs was given
then
(scheduleIn,numProcIn,0);
case(_,_,_,_,_,_,_,false,_,_,_)
equation
true = numIterIn == 0; // the max number of schedules with increased num of procs
then
(scheduleIn,numProcIn,0);
case(_,_,_,_,_,_,_,false,_,_,_)
equation
(_,_,speedUp,speedUpMax) = HpcOmScheduler.predictExecutionTime(scheduleIn,SOME(cpCostsWoC),numProcIn,taskGraphIn,taskGraphMetaIn);
diff = speedUpMax -. speedUp;
//print("the new speedUp with "+&intString(numProcIn)+&" processors: "+&realString(speedUp)+&"\n");
true = diff <. maxDiff;
//print("the schedule is fine\n");
then
(scheduleIn,numProcIn,numIterIn);
else
equation
numProc = numProcIn+1; // increase the number of procs
numIt = numIterIn-1; // lower the counter of scheduling runs
scheduleAgain = intLe(numProc,maxNumProc);
//print("schedule again\n");
numProc = Util.if_(scheduleAgain,numProc,numProcIn);
numIt = Util.if_(scheduleAgain,numIt,0);
schedule= Debug.bcallret5(scheduleAgain,createSchedule,taskGraphIn,taskGraphMetaIn,sccSimEqMappingIn,fileNamePrefix,numProc,scheduleIn);
(schedule,numProc,numIt) = repeatScheduleWithOtherNumProc1(taskGraphIn,taskGraphMetaIn,sccSimEqMappingIn,fileNamePrefix,cpCostsWoC,schedule,numProc,numFixed,maxNumProc,maxDiff,numIt);
then
(schedule,numProc,numIt);
end matchcontinue;
end repeatScheduleWithOtherNumProc1;


protected function setNumProc "sets the number of processors. its upper limit is the number of processsors provided by the system.
if no n-flag is set, a ideal number is suggested but the simulation fails.
author: Waurich TUD 2013-11"
Expand Down Expand Up @@ -456,74 +372,76 @@ protected function createSchedule
input array<list<Integer>> iSccSimEqMapping;
input String iFilenamePrefix;
input Integer numProc;
input BackendDAE.BackendDAE iDAE;
input SimCode.SimCode iSimCode;
output HpcOmSimCode.Schedule oSchedule;
protected
String flagValue;
list<Integer> lst;
HpcOmTaskGraph.TaskGraph taskGraph1;
HpcOmTaskGraph.TaskGraphMeta taskGraphMeta1;
algorithm
oSchedule := matchcontinue(iTaskGraph,iTaskGraphMeta,iSccSimEqMapping,iFilenamePrefix,numProc)
case(_,_,_,_,_)
oSchedule := matchcontinue(iTaskGraph,iTaskGraphMeta,iSccSimEqMapping,iFilenamePrefix,numProc,iDAE,iSimCode)
case(_,_,_,_,_,_,_)
equation
true = arrayLength(iTaskGraph) == 0;
print("There is no ODE system that can be parallelized!\n");
// just did this because this works fine. TODO: make something reasonable here and do not use a scheduler.
then
HpcOmScheduler.createLevelSchedule(iTaskGraphMeta,iSccSimEqMapping);
case(_,_,_,_,_)
case(_,_,_,_,_,_,_)
equation
flagValue = Flags.getConfigString(Flags.HPCOM_SCHEDULER);
true = stringEq(flagValue, "level");
print("Using level Scheduler\n");
then HpcOmScheduler.createLevelSchedule(iTaskGraphMeta,iSccSimEqMapping);
case(_,_,_,_,_)
case(_,_,_,_,_,_,_)
equation
flagValue = Flags.getConfigString(Flags.HPCOM_SCHEDULER);
true = stringEq(flagValue, "ext");
print("Using external Scheduler\n");
then HpcOmScheduler.createExtSchedule(iTaskGraph, iTaskGraphMeta, numProc, iSccSimEqMapping, "taskGraph" +& iFilenamePrefix +& "_ext.graphml");
case(_,_,_,_,_)
case(_,_,_,_,_,_,_)
equation
flagValue = Flags.getConfigString(Flags.HPCOM_SCHEDULER);
true = stringEq(flagValue, "metis");
print("Using METIS Scheduler\n");
then HpcOmScheduler.createExtCSchedule(iTaskGraph, iTaskGraphMeta, numProc, iSccSimEqMapping);
case(_,_,_,_,_)
case(_,_,_,_,_,_,_)
equation
flagValue = Flags.getConfigString(Flags.HPCOM_SCHEDULER);
true = stringEq(flagValue, "hmet");
print("Using hMETIS Scheduler\n");
then HpcOmScheduler.createhmetSchedule(iTaskGraph, iTaskGraphMeta, numProc, iSccSimEqMapping);
case(_,_,_,_,_)
case(_,_,_,_,_,_,_)
equation
flagValue = Flags.getConfigString(Flags.HPCOM_SCHEDULER);
true = stringEq(flagValue, "listr");
then HpcOmScheduler.createListScheduleReverse(iTaskGraph,iTaskGraphMeta,numProc,iSccSimEqMapping);
case(_,_,_,_,_)
case(_,_,_,_,_,_,_)
equation
flagValue = Flags.getConfigString(Flags.HPCOM_SCHEDULER);
true = stringEq(flagValue, "list");
then HpcOmScheduler.createListSchedule(iTaskGraph,iTaskGraphMeta,numProc,iSccSimEqMapping);
case(_,_,_,_,_)
case(_,_,_,_,_,_,_)
equation
flagValue = Flags.getConfigString(Flags.HPCOM_SCHEDULER);
true = stringEq(flagValue, "mcp");
print("Using Modified Critical Path Scheduler\n");
then HpcOmScheduler.createMCPschedule(iTaskGraph,iTaskGraphMeta,numProc,iSccSimEqMapping);
case(_,_,_,_,_)
case(_,_,_,_,_,_,_)
equation
flagValue = Flags.getConfigString(Flags.HPCOM_SCHEDULER);
true = stringEq(flagValue, "taskdep");
print("Using OpenMP task dependencies\n");
then HpcOmScheduler.createTaskDepSchedule(iTaskGraph,iTaskGraphMeta,iSccSimEqMapping);
case(_,_,_,_,_)
case(_,_,_,_,_,_,_)
equation
flagValue = Flags.getConfigString(Flags.HPCOM_SCHEDULER);
true = stringEq(flagValue, "tds");
print("Using Task Duplication-based Scheduling\n");
then HpcOmScheduler.createTDSschedule(iTaskGraph,iTaskGraphMeta,numProc,iSccSimEqMapping);
case(_,_,_,_,_)
then HpcOmScheduler.createTDSschedule(iTaskGraph,iTaskGraphMeta,numProc,iSccSimEqMapping,iDAE,iSimCode);
case(_,_,_,_,_,_,_)
equation
flagValue = Flags.getConfigString(Flags.HPCOM_SCHEDULER);
print("HpcOmScheduler.createSchedule warning: The scheduler '" +& flagValue +& "' is unknown. The list-scheduling algorithm is used instead.\n");
Expand Down Expand Up @@ -828,4 +746,88 @@ algorithm
end matchcontinue;
end checkOdeSystemSize;

/*
protected function repeatScheduleWithOtherNumProc"checks if the scheduling with the given numProc is fine.
if n=auto, more cores are available and more speedup could be achieved repeat schedule with increased num of procs.
author:Waurich TUD 2013-011"
input HpcOmTaskGraph.TaskGraph taskGraphIn;
input HpcOmTaskGraph.TaskGraphMeta taskGraphMetaIn;
input array<list<Integer>> sccSimEqMappingIn;
input String fileNamePrefix;
input Real cpCostsWoC;
input HpcOmSimCode.Schedule scheduleIn;
input Integer numProcIn;
input Boolean numFixed;
output HpcOmSimCode.Schedule scheduleOut;
output Integer numProcOut;
protected
Integer maxNumProc, maxIter;
Real maxDiff;
algorithm
maxNumProc := System.numProcessors();
maxIter := 3;
maxDiff := 0.5;
(scheduleOut,numProcOut,_) := repeatScheduleWithOtherNumProc1(taskGraphIn,taskGraphMetaIn,sccSimEqMappingIn,fileNamePrefix,cpCostsWoC,scheduleIn,numProcIn,numFixed,maxNumProc,maxDiff,maxIter);
end repeatScheduleWithOtherNumProc;
protected function repeatScheduleWithOtherNumProc1"checks if the scheduling with the given numProc is fine.
if n=auto, more cores are available and more speedup could be achieved repeat schedule with increased num of procs.
author:Waurich TUD 2013-011"
input HpcOmTaskGraph.TaskGraph taskGraphIn;
input HpcOmTaskGraph.TaskGraphMeta taskGraphMetaIn;
input BackendDAE.BackendDAE inDAE;
input array<list<Integer>> sccSimEqMappingIn;
input String fileNamePrefix;
input Real cpCostsWoC;
input HpcOmSimCode.Schedule scheduleIn;
input Integer numProcIn;
input Boolean numFixed;
input Integer maxNumProc;
input Real maxDiff;
input Integer numIterIn;
output HpcOmSimCode.Schedule scheduleOut;
output Integer numProcOut;
output Integer numIterOut;
algorithm
(scheduleOut,numProcOut,numIterOut) := matchcontinue(taskGraphIn,taskGraphMetaIn,inDAE,sccSimEqMappingIn,fileNamePrefix,cpCostsWoC,scheduleIn,numProcIn,numFixed,maxNumProc,maxDiff,numIterIn)
local
Boolean scheduleAgain;
Integer numProc, numIt;
Real serTime,parTime,speedup,speedUp,speedUpMax,diff;
HpcOmSimCode.Schedule schedule;
case(_,_,_,_,_,_,_,_,true,_,_,_)
equation // do not schedule again because the number of procs was given
then
(scheduleIn,numProcIn,0);
case(_,_,_,_,_,_,_,_,false,_,_,_)
equation
true = numIterIn == 0; // the max number of schedules with increased num of procs
then
(scheduleIn,numProcIn,0);
case(_,_,_,_,_,_,_,_,false,_,_,_)
equation
(_,_,speedUp,speedUpMax) = HpcOmScheduler.predictExecutionTime(scheduleIn,SOME(cpCostsWoC),numProcIn,taskGraphIn,taskGraphMetaIn);
diff = speedUpMax -. speedUp;
//print("the new speedUp with "+&intString(numProcIn)+&" processors: "+&realString(speedUp)+&"\n");
true = diff <. maxDiff;
//print("the schedule is fine\n");
then
(scheduleIn,numProcIn,numIterIn);
else
equation
numProc = numProcIn+1; // increase the number of procs
numIt = numIterIn-1; // lower the counter of scheduling runs
scheduleAgain = intLe(numProc,maxNumProc);
//print("schedule again\n");
numProc = Util.if_(scheduleAgain,numProc,numProcIn);
numIt = Util.if_(scheduleAgain,numIt,0);
schedule= Debug.bcallret6(scheduleAgain,createSchedule,taskGraphIn,taskGraphMetaIn,sccSimEqMappingIn,fileNamePrefix,numProc,scheduleIn);
(schedule,numProc,numIt) = repeatScheduleWithOtherNumProc1(taskGraphIn,taskGraphMetaIn,sccSimEqMappingIn,fileNamePrefix,cpCostsWoC,schedule,numProc,numFixed,maxNumProc,maxDiff,numIt);
then
(schedule,numProc,numIt);
end matchcontinue;
end repeatScheduleWithOtherNumProc1;
*/

end HpcOmSimCodeMain;

0 comments on commit 675c65d

Please sign in to comment.