Skip to content

Commit

Permalink
- if num_proc flag is not set, a reasonable number will be offered. r…
Browse files Browse the repository at this point in the history
…epeat scheduling iteratively

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@18362 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Volker Waurich committed Dec 2, 2013
1 parent 8715a62 commit 846d2fc
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 16 deletions.
42 changes: 34 additions & 8 deletions Compiler/BackEnd/HpcOmScheduler.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2028,17 +2028,14 @@ author:Waurich TUD 2013-11"
algorithm
(serialTimeOut,parallelTimeOut,speedUpOut,speedUpMaxOut) := matchcontinue(scheduleIn,cpCostsOption,numProc,taskGraphIn,taskGraphMetaIn)
local
Boolean isODE;
Real parTime, serTime, speedUp, speedUpMax, cpCosts;
String isOkString, isNotOkString;
Schedule schedule;
case(_,NONE(),_,_,_)
equation
true = intNe(arrayLength(taskGraphIn),0); //is an ODE system
(_,parTime) = getFinishingTimesForSchedule(scheduleIn,numProc,taskGraphIn,taskGraphMetaIn);
serTime = getSerialExecutionTime(taskGraphMetaIn);
speedUp = serTime /. parTime;
print("The predicted SpeedUp with "+&intString(numProc)+&" processors is "+&realString(speedUp)+&".\n");
then
(serTime,parTime,speedUp,-1.0);
case(_,SOME(cpCosts),_,_,_)
Expand All @@ -2048,23 +2045,52 @@ algorithm
serTime = getSerialExecutionTime(taskGraphMetaIn);
speedUp = serTime /. parTime;
speedUpMax = serTime /. cpCosts;
isOkString = "The predicted SpeedUp with "+&intString(numProc)+&" processors is: "+&realString(speedUp)+&" With a theoretical maxmimum speedUp of: "+&realString(speedUpMax)+&"\n";
isNotOkString = "Something is weird. The predicted SpeedUp is "+&realString(speedUp)+&" and the theoretical maximum speedUp is "+&realString(speedUpMax)+&"\n";
Debug.bcall(realGt(speedUp,speedUpMax),print,isNotOkString);
Debug.bcall(realLe(speedUp,speedUpMax),print,isOkString);
//print("the serialCosts: "+&realString(serTime)+&"\n");
//print("the parallelCosts: "+&realString(parTime)+&"\n");
//print("the cpCosts: "+&realString(cpCosts)+&"\n");
then
(serTime,parTime,speedUp,speedUpMax);
case(_,_,_,_,_)
else
equation
then
(0.0,0.0,0.0,0.0);
end matchcontinue;
end predictExecutionTime;


public function printPredictedExeTimeInfo "function to print the information about the predicted execution times.
author:Waurich TUD 2013-11"
input Real serTime;
input Real parTime;
input Real speedUp;
input Real speedUpMax;
input Integer numProc;
algorithm
_ := matchcontinue(serTime,parTime,speedUp,speedUpMax,numProc)
local
String isOkString, isNotOkString;
case(_,_,_,0.0,_)// possibly there is no ode-system that can be parallelized
equation
then
();
case(_,_,_,_,_)
equation
true = speedUpMax ==. -1.0;
print("The predicted SpeedUp with "+&intString(numProc)+&" processors is "+&realString(speedUp)+&".\n");
then
();
else
equation
isOkString = "The predicted SpeedUp with "+&intString(numProc)+&" processors is: "+&realString(speedUp)+&" With a theoretical maxmimum speedUp of: "+&realString(speedUpMax)+&"\n";
isNotOkString = "Something is weird. The predicted SpeedUp is "+&realString(speedUp)+&" and the theoretical maximum speedUp is "+&realString(speedUpMax)+&"\n";
Debug.bcall(realGt(speedUp,speedUpMax),print,isNotOkString);
Debug.bcall(realLe(speedUp,speedUpMax),print,isOkString);
then
();
end matchcontinue;
end printPredictedExeTimeInfo;


public function getSerialExecutionTime "computes thes serial execution time by summing up all exeCosts of all tasks.
author:Waurich TUD 2013-11"
input HpcOmTaskGraph.TaskGraphMeta taskGraphMetaIn;
Expand Down
103 changes: 95 additions & 8 deletions Compiler/BackEnd/HpcOmSimCode.mo
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ algorithm
list<SimCode.RecordDeclaration> simCodeRecordDecls;
list<String> simCodeExternalFunctionIncludes;

Boolean taskGraphMetaValid;
Boolean taskGraphMetaValid, numFixed;
String taskGraphMetaMessage, criticalPathInfo;
array<tuple<Integer,Integer>> schedulerInfo;
HpcOmScheduler.Schedule schedule;
Expand Down Expand Up @@ -239,10 +239,12 @@ algorithm
//Create schedule
//---------------
numProc = Flags.getConfigInt(Flags.NUM_PROC);
numProc = setNumProc(numProc,cpCostsWoC,taskGraphDataOde);
(numProc,numFixed) = setNumProc(numProc,cpCostsWoC,taskGraphDataOde);
schedule = createSchedule(taskGraph1,taskGraphData1,sccSimEqMapping,filenamePrefix,numProc);
(schedule,numProc) = repeatScheduleWithOtherNumProc(taskGraph1,taskGraphData1,sccSimEqMapping,filenamePrefix,cpCostsWoC,schedule,numProc,numFixed);

(serTime,parTime,speedUp,speedUpMax) = HpcOmScheduler.predictExecutionTime(schedule,SOME(cpCostsWoC),numProc,taskGraph1,taskGraphData1);
HpcOmScheduler.printPredictedExeTimeInfo(serTime,parTime,speedUp,speedUpMax,numProc);
((criticalPaths,cpCosts),(criticalPathsWoC,cpCostsWoC),parallelSets) = HpcOmTaskGraph.longestPathMethod(taskGraph1,taskGraphData1);
criticalPathInfo = HpcOmTaskGraph.dumpCriticalPathInfo((criticalPaths,cpCosts),(criticalPathsWoC,cpCostsWoC));

Expand Down Expand Up @@ -274,16 +276,100 @@ algorithm
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 HpcOmScheduler.Schedule scheduleIn;
input Integer numProcIn;
input Boolean numFixed;
output HpcOmScheduler.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 HpcOmScheduler.Schedule scheduleIn;
input Integer numProcIn;
input Boolean numFixed;
input Integer maxNumProc;
input Real maxDiff;
input Integer numIterIn;
output HpcOmScheduler.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;
HpcOmScheduler.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
(serTime,parTime,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 chosen
author: Waurich TUD 2013-11"
input Integer numProcFlag;
input Real cpCosts;
input HpcOmTaskGraph.TaskGraphMeta taskGraphMetaIn;
output Integer numProcOut;
output Boolean numFixed;
algorithm
numProcOut := match(numProcFlag,cpCosts,taskGraphMetaIn)
(numProcOut,numFixed) := match(numProcFlag,cpCosts,taskGraphMetaIn)
local
Boolean isFixed;
Integer numProcSys, numProc, numProcSched;
Real serCosts, maxSpeedUp;
String string1, string2;
Expand All @@ -294,19 +380,20 @@ algorithm
numProcSched = realInt(realAdd(maxSpeedUp,1.0));
numProcSys = System.numProcessors();
numProc = intMin(numProcSched,numProcSys);
string1 = "Your system provides only"+&intString(numProcSys)+&" processors. You could achieve more speedup with "+&intString(numProcSched)+&"!\n";
string2 = "The model is simulated using"+&intString(numProcSched)+&"because thats the ideal number of threads\n";
string1 = Util.if_(intGt(numProcSched,numProcSys),string1,string2);
string1 = "Your system provides only "+&intString(numProcSys)+&" processors!\n";
string2 = "The model is simulated using "+&intString(numProcSched)+&" processors, because that might be a reasonable number of threads.\n";
string1 = Util.if_(intGt(numProcSched,numProcSys),string1,string2);
isFixed = Util.if_(intGt(numProcSched,numProcSys),true,false);
print(string1);
then
numProc;
(numProc,isFixed);
else
equation
numProcSys = System.numProcessors();
numProc = Util.if_(intGt(numProcFlag,numProcSys),numProcSys,numProcFlag); // the system does not provide so many cores
Debug.bcall(intGt(numProcFlag,numProcSys),print,"Warning: Your system provides only "+&intString(numProcSys)+&" processors!\n");
then
numProc;
(numProc,true);
end match;
end setNumProc;

Expand Down

0 comments on commit 846d2fc

Please sign in to comment.