Skip to content

Commit 4111c1f

Browse files
author
Jens Frenkel
committed
- implement runtime options +preOptModules and +pastOptModuels, now it is posible to select the optimisation modules for the backend via flag, use for example +preOptModules=removeSimpleEquations,removeParameterEqns,expandDerOperator or +pastOptModules=lateInline,inlineArrayEqn,removeSimpleEquations,removeAliasEquations
ToDo: implement a script function to set and get the optimisation modules - dumpComponentsGraphStr is now availible via the pastOptimisation flag use +pastOptModuels=dumpComponentsGraphStr git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@8375 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 0f97b03 commit 4111c1f

File tree

8 files changed

+354
-88
lines changed

8 files changed

+354
-88
lines changed

Compiler/BackEnd/BackendDAEUtil.mo

Lines changed: 11 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,6 @@ protected import Util;
7777
protected import Values;
7878
protected import VarTransform;
7979

80-
81-
// global root index for preoptimisation
82-
public
83-
constant Integer preOptimisationIndex = 10;
84-
// global root index for postoptimisation
85-
public
86-
constant Integer postOptimisationIndex = 11;
87-
// global root index for indexreduction method
88-
public
89-
constant Integer indexReductionMethodIndex = 12;
90-
9180
/*************************************************
9281
* checkBackendDAE and stuff
9382
************************************************/
@@ -5413,9 +5402,9 @@ public function getSolvedSystem
54135402
input Env.Env inEnv;
54145403
input BackendDAE.BackendDAE inDAE;
54155404
input DAE.FunctionTree functionTree;
5416-
input list<String> strPreOptModules;
5405+
input Option<list<String>> strPreOptModules;
54175406
input daeHandlerFunc daeHandler;
5418-
input list<String> strPastOptModules;
5407+
input Option<list<String>> strPastOptModules;
54195408
output BackendDAE.BackendDAE outSODE;
54205409
output BackendDAE.IncidenceMatrix outM;
54215410
output BackendDAE.IncidenceMatrix outMT;
@@ -5493,7 +5482,7 @@ public function preOptimiseBackendDAE
54935482
Run the optimisation modules"
54945483
input BackendDAE.BackendDAE inDAE;
54955484
input DAE.FunctionTree functionTree;
5496-
input list<String> strPreOptModules;
5485+
input Option<list<String>> strPreOptModules;
54975486
input Option<BackendDAE.IncidenceMatrix> inM;
54985487
input Option<BackendDAE.IncidenceMatrix> inMT;
54995488
output BackendDAE.BackendDAE outDAE;
@@ -5686,49 +5675,9 @@ end checktransformDAE;
56865675
* Optimisation Selection
56875676
************************************************/
56885677

5689-
public function setBackendGlobalRoots
5690-
protected
5691-
list<String> preOptModules,pastOptModules;
5692-
algorithm
5693-
// collect all modules
5694-
preOptModules := {"removeSimpleEquations","removeParameterEqns","expandDerOperator"};
5695-
5696-
pastOptModules := Util.listConsOnTrue(RTOpts.debugFlag("dumpcompgraph"),"dumpComponentsGraphStr",{});
5697-
pastOptModules := Util.listConsOnTrue(RTOpts.debugFlag("removeAliasEquations"),"removeAliasEquations",pastOptModules);
5698-
pastOptModules := "lateInline"::("removeSimpleEquations"::pastOptModules);
5699-
// set modules
5700-
setPreOptimisation(preOptModules);
5701-
setPostOptimisation(pastOptModules);
5702-
end setBackendGlobalRoots;
5703-
5704-
public function setPreOptimisation
5705-
input list<String> modules;
5706-
algorithm
5707-
setGlobalRoot(preOptimisationIndex,modules);
5708-
end setPreOptimisation;
5709-
5710-
public function setPostOptimisation
5711-
input list<String> modules;
5712-
algorithm
5713-
setGlobalRoot(postOptimisationIndex,modules);
5714-
end setPostOptimisation;
5715-
5716-
public function getPreOptimisation
5717-
output list<String> modules;
5718-
algorithm
5719-
modules := getGlobalRoot(preOptimisationIndex);
5720-
end getPreOptimisation;
5721-
5722-
public function getPostOptimisation
5723-
output list<String> modules;
5724-
algorithm
5725-
modules := getGlobalRoot(postOptimisationIndex);
5726-
end getPostOptimisation;
5727-
5728-
57295678
protected function getPreOptModules
57305679
" function: getPreOptModules"
5731-
input list<String> strPreOptModules;
5680+
input Option<list<String>> ostrPreOptModules;
57325681
output list<tuple<preoptimiseDAEModule,String>> preOptModules;
57335682
partial function preoptimiseDAEModule
57345683
input BackendDAE.BackendDAE inDAE;
@@ -5741,19 +5690,22 @@ protected function getPreOptModules
57415690
end preoptimiseDAEModule;
57425691
protected
57435692
list<tuple<preoptimiseDAEModule,String>> allPreOptModules;
5693+
list<String> strPreOptModules;
57445694
algorithm
57455695
allPreOptModules := {(BackendDAEOptimize.removeSimpleEquations,"removeSimpleEquations"),
57465696
(BackendDAEOptimize.removeParameterEqns,"removeParameterEqns"),
57475697
(BackendDAEOptimize.removeAliasEquations,"removeAliasEquations"),
57485698
(BackendDAEOptimize.inlineArrayEqn,"inlineArrayEqn"),
57495699
(BackendDAECreate.expandDerOperator,"expandDerOperator")};
5700+
strPreOptModules := RTOpts.getPreOptModules({"removeSimpleEquations","removeParameterEqns","expandDerOperator"});
5701+
strPreOptModules := Util.getOptionOrDefault(ostrPreOptModules,strPreOptModules);
57505702
preOptModules := selectOptModules(strPreOptModules,allPreOptModules,{});
57515703
preOptModules := listReverse(preOptModules);
57525704
end getPreOptModules;
57535705

57545706
protected function getPastOptModules
57555707
" function: getPastOptModules"
5756-
input list<String> strPastOptModules;
5708+
input Option<list<String>> ostrPastOptModules;
57575709
output list<tuple<pastoptimiseDAEModule,String>> pastOptModules;
57585710
partial function pastoptimiseDAEModule
57595711
input BackendDAE.BackendDAE inDAE;
@@ -5773,12 +5725,15 @@ protected function getPastOptModules
57735725
end pastoptimiseDAEModule;
57745726
protected
57755727
list<tuple<pastoptimiseDAEModule,String>> allPastOptModules;
5728+
list<String> strPastOptModules;
57765729
algorithm
57775730
allPastOptModules := {(BackendDAEOptimize.lateInline,"lateInline"),
57785731
(BackendDAEOptimize.removeSimpleEquationsPast,"removeSimpleEquations"),
57795732
(BackendDAEOptimize.removeAliasEquationsPast,"removeAliasEquations"),
57805733
(BackendDAEOptimize.inlineArrayEqnPast,"inlineArrayEqn"),
57815734
(BackendDump.dumpComponentsGraphStr,"dumpComponentsGraphStr")};
5735+
strPastOptModules := RTOpts.getPastOptModules({"lateInline","removeSimpleEquations"});
5736+
strPastOptModules := Util.getOptionOrDefault(ostrPastOptModules,strPastOptModules);
57825737
pastOptModules := selectOptModules(strPastOptModules,allPastOptModules,{});
57835738
pastOptModules := listReverse(pastOptModules);
57845739
end getPastOptModules;

Compiler/BackEnd/SimCode.mo

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,6 @@ algorithm
932932
Env.Cache cache;
933933
DAE.FunctionTree funcs;
934934
Real timeSimCode, timeTemplates, timeBackend, timeFrontend;
935-
list<String> preOptModules,pastOptModules;
936935
case (cache,env,className,(st as Interactive.SYMBOLTABLE(ast = p)),filenameprefix,addDummy, inSimSettingsOpt)
937936
equation
938937
/* calculate stuff that we need to create SimCode data structure */
@@ -947,12 +946,8 @@ algorithm
947946
dae = DAEUtil.transformationsBeforeBackend(dae);
948947
funcs = Env.getFunctionTree(cache);
949948
dlow = BackendDAECreate.lower(dae,funcs,true);
950-
preOptModules = {"removeSimpleEquations","removeParameterEqns","expandDerOperator"};
951-
pastOptModules = Util.listConsOnTrue(RTOpts.debugFlag("inlineArrayEqn"),"inlineArrayEqn",{});
952-
pastOptModules = Util.listConsOnTrue(RTOpts.debugFlag("removeAliasEquations"),"removeAliasEquations",pastOptModules);
953-
pastOptModules = "lateInline"::("removeSimpleEquations"::pastOptModules);
954949
(dlow_1,m,mT,ass1,ass2,comps) = BackendDAEUtil.getSolvedSystem(cache, env, dlow, funcs,
955-
preOptModules, BackendDAETransform.dummyDerivative, pastOptModules);
950+
NONE(), BackendDAETransform.dummyDerivative, NONE());
956951
Debug.fprintln("dynload", "translateModel: Generating simulation code and functions.");
957952
(indexed_dlow_1,libs,file_dir,timeBackend,timeSimCode,timeTemplates) =
958953
generateModelCodeFMU(dlow_1,funcs,p, dae, className, filenameprefix, inSimSettingsOpt,m,mT,ass1,ass2,comps);
@@ -1064,7 +1059,6 @@ algorithm
10641059
Env.Cache cache;
10651060
DAE.FunctionTree funcs;
10661061
Real timeSimCode, timeTemplates, timeBackend, timeFrontend;
1067-
list<String> preOptModules,pastOptModules;
10681062

10691063
case (cache,env,className,(st as Interactive.SYMBOLTABLE(ast = p)),filenameprefix,addDummy, inSimSettingsOpt)
10701064
equation
@@ -1079,12 +1073,8 @@ algorithm
10791073
dae = DAEUtil.transformationsBeforeBackend(dae);
10801074
funcs = Env.getFunctionTree(cache);
10811075
dlow = BackendDAECreate.lower(dae,funcs,true);
1082-
preOptModules = {"removeSimpleEquations","removeParameterEqns","expandDerOperator"};
1083-
pastOptModules = Util.listConsOnTrue(RTOpts.debugFlag("inlineArrayEqn"),"inlineArrayEqn",{});
1084-
pastOptModules = Util.listConsOnTrue(RTOpts.debugFlag("removeAliasEquations"),"removeAliasEquations",pastOptModules);
1085-
pastOptModules = "lateInline"::("removeSimpleEquations"::pastOptModules);
10861076
(dlow_1,m,mT,ass1,ass2,comps) = BackendDAEUtil.getSolvedSystem(cache, env, dlow, funcs,
1087-
preOptModules, BackendDAETransform.dummyDerivative, pastOptModules);
1077+
NONE(), BackendDAETransform.dummyDerivative, NONE());
10881078
(indexed_dlow_1,libs,file_dir,timeBackend,timeSimCode,timeTemplates) =
10891079
generateModelCode(dlow_1,funcs,p, dae, className, filenameprefix, inSimSettingsOpt,m,mT,ass1,ass2,comps);
10901080
resultValues =

Compiler/Main/Main.mo

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -769,19 +769,14 @@ algorithm
769769
Env.Env env;
770770
DAE.FunctionTree funcs;
771771
String str;
772-
list<String> preOptModules,pastOptModules;
773772

774773
case (cache,env,p,ap,dae,daeimpl,classname)
775774
equation
776775
true = runBackendQ();
777776
Debug.fcall("execstat",print, "*** Main -> To lower dae at time: " +& realString(clock()) +& "\n" );
778777
funcs = Env.getFunctionTree(cache);
779778
dlow = BackendDAECreate.lower(dae,funcs,true);
780-
preOptModules = {"removeSimpleEquations","removeParameterEqns","expandDerOperator"};
781-
pastOptModules = Util.listConsOnTrue(RTOpts.debugFlag("dumpcompgraph"),"dumpComponentsGraphStr",{});
782-
pastOptModules = Util.listConsOnTrue(RTOpts.debugFlag("removeAliasEquations"),"removeAliasEquations",pastOptModules);
783-
pastOptModules = "lateInline"::("removeSimpleEquations"::pastOptModules);
784-
(dlow_1,m,mT,v1,v2,comps) = BackendDAEUtil.getSolvedSystem(cache,env,dlow,funcs,preOptModules,BackendDAETransform.dummyDerivative,pastOptModules);
779+
(dlow_1,m,mT,v1,v2,comps) = BackendDAEUtil.getSolvedSystem(cache,env,dlow,funcs,NONE(),BackendDAETransform.dummyDerivative,NONE());
785780
modpar(dlow_1,v1,v2,comps);
786781
simcodegen(dlow_1,funcs,classname,p,ap,daeimpl,m,mT,v1,v2,comps);
787782
then
@@ -1117,6 +1112,8 @@ algorithm
11171112
print("\t+annotationVersion=1.x what annotation version should we use\n");
11181113
print("\t accept 1.x or 2.x (default) or 3.x\n");
11191114
print("\t+noSimplify do not simplify expressions (default is to simplify)\n");
1115+
print("\t+preOptModules=module1,.. pre optimisation modules (default is removeSimpleEquations,removeParameterEqns,expandDerOperator)\n");
1116+
print("\t+pastOptModules=module1,.. past optimisation modules (default is lateInline,removeSimpleEquations)\n");
11201117
print("\t+q run in quiet mode, output nothing\n");
11211118
print("\t+g=MetaModelica accept MetaModelica grammar and semantics\n");
11221119
print("\t+showErrorMessages show error messages while they happen; default to no. \n");
@@ -1189,8 +1186,7 @@ algorithm
11891186
// cummulative time of some functions
11901187
// search for System.startTimer/System.stopTimer/System.getTimerIntervalTimer
11911188
// System.resetTimer();
1192-
1193-
1189+
11941190
//setGlobalRoot(ComponentReference.crefMemoryIndex, ComponentReference.createEmptyCrefMemory());
11951191
//Env.globalCache = fill(Env.emptyCache,1);
11961192
symbolTable = readSettings(args);

Compiler/Script/CevalScript.mo

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -771,8 +771,7 @@ algorithm
771771
ic_1 = Interactive.addInstantiatedClass(ic, Interactive.INSTCLASS(path,dae,env));
772772
funcs = Env.getFunctionTree(cache);
773773
daelow = BackendDAECreate.lower(dae, funcs, false) "no dummy state" ;
774-
(optdae,om,omt) = BackendDAEUtil.preOptimiseBackendDAE(daelow,funcs,
775-
{"removeSimpleEquations","removeParameterEqns","expandDerOperator"},NONE(),NONE());
774+
(optdae,om,omt) = BackendDAEUtil.preOptimiseBackendDAE(daelow,funcs,NONE(),NONE(),NONE());
776775
(m,mt) = BackendDAEUtil.getIncidenceMatrixfromOption(optdae,om,omt);
777776
vars = BackendVariable.daeVars(optdae);
778777
eqnarr = BackendEquation.daeEqns(optdae);
@@ -2816,7 +2815,7 @@ algorithm
28162815
funcs = Env.getFunctionTree(cache);
28172816
dlow = BackendDAECreate.lower(dae, funcs, false) "no dummy state" ;
28182817
(dlow1,_,_) = BackendDAEUtil.preOptimiseBackendDAE(dlow,funcs,
2819-
{"removeSimpleEquations","expandDerOperator"},NONE(),NONE());
2818+
SOME({"removeSimpleEquations","expandDerOperator"}),NONE(),NONE());
28202819
Debug.fcall("dumpdaelow", BackendDump.dump, dlow1);
28212820
RTOpts.setEliminationLevel(elimLevel); // reset elimination level.
28222821
eqns = BackendEquation.daeEqns(dlow1);
@@ -2861,7 +2860,7 @@ algorithm
28612860
funcs = Env.getFunctionTree(cache);
28622861
dlow = BackendDAECreate.lower(dae, funcs, false) "no dummy state" ;
28632862
(dlow1,_,_) = BackendDAEUtil.preOptimiseBackendDAE(dlow,funcs,
2864-
{"removeSimpleEquations","expandDerOperator"},NONE(),NONE());
2863+
SOME({"removeSimpleEquations","expandDerOperator"}),NONE(),NONE());
28652864
Debug.fcall("dumpdaelow", BackendDump.dump, dlow1);
28662865
RTOpts.setEliminationLevel(elimLevel); // reset elimination level.
28672866
eqns = BackendEquation.daeEqns(dlow1);
@@ -3065,7 +3064,6 @@ algorithm
30653064
list<SCode.Class> p_1,sp;
30663065
list<list<Integer>> comps;
30673066
DAE.FunctionTree funcs;
3068-
list<String> preOptModules,pastOptModules;
30693067

30703068
case (cache,env,{Values.CODE(Absyn.C_TYPENAME(classname)),Values.STRING(string="flat"),Values.BOOL(addOriginalIncidenceMatrix),Values.BOOL(addSolvingInfo),Values.BOOL(addMathMLCode),Values.BOOL(dumpResiduals),Values.STRING(filenameprefix),Values.BOOL(cdToTemp)},(st as Interactive.SYMBOLTABLE(ast = p)),msg)
30713069
equation
@@ -3080,8 +3078,7 @@ algorithm
30803078
dae = DAEUtil.transformationsBeforeBackend(dae_1);
30813079
funcs = Env.getFunctionTree(cache);
30823080
dlow = BackendDAECreate.lower(dae, funcs, true); //Verificare cosa fa
3083-
(dlow_1,_,_) = BackendDAEUtil.preOptimiseBackendDAE(dlow,funcs,
3084-
{"removeSimpleEquations","removeParameterEqns","expandDerOperator"},NONE(),NONE());
3081+
(dlow_1,_,_) = BackendDAEUtil.preOptimiseBackendDAE(dlow,funcs,NONE(),NONE(),NONE());
30853082
dlow_1 = BackendDAECreate.findZeroCrossings(dlow_1);
30863083
xml_filename = stringAppendList({filenameprefix,".xml"});
30873084
funcelems = DAEUtil.getFunctionList(funcs);
@@ -3106,8 +3103,7 @@ algorithm
31063103
dae = DAEUtil.transformationsBeforeBackend(dae_1);
31073104
funcs = Env.getFunctionTree(cache);
31083105
dlow = BackendDAECreate.lower(dae, funcs, true); //Verificare cosa fa
3109-
(dlow_1,om,omT) = BackendDAEUtil.preOptimiseBackendDAE(dlow,funcs,
3110-
{"removeSimpleEquations","removeParameterEqns","expandDerOperator"},NONE(),NONE());
3106+
(dlow_1,om,omT) = BackendDAEUtil.preOptimiseBackendDAE(dlow,funcs,NONE(),NONE(),NONE());
31113107
(dlow_1,_,_,_,_,_) = BackendDAEUtil.transformDAE(dlow_1,funcs,BackendDAETransform.dummyDerivative,om,omT);
31123108
dlow_1 = BackendDAECreate.findZeroCrossings(dlow_1);
31133109
xml_filename = stringAppendList({filenameprefix,".xml"});
@@ -3133,10 +3129,8 @@ algorithm
31333129
dae = DAEUtil.transformationsBeforeBackend(dae_1);
31343130
funcs = Env.getFunctionTree(cache);
31353131
dlow = BackendDAECreate.lower(dae, funcs, true);
3136-
preOptModules = {"removeSimpleEquations","removeParameterEqns","expandDerOperator"};
3137-
pastOptModules = {"lateInline","removeSimpleEquations"};
31383132
(indexed_dlow,_,_,_,_,_) = BackendDAEUtil.getSolvedSystem(cache, env, dlow, funcs,
3139-
preOptModules, BackendDAETransform.dummyDerivative, pastOptModules);
3133+
NONE(), BackendDAETransform.dummyDerivative, NONE());
31403134
xml_filename = stringAppendList({filenameprefix,".xml"});
31413135
funcelems = DAEUtil.getFunctionList(funcs);
31423136
Print.clearBuf();

Compiler/Util/RTOpts.mo

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,5 +246,31 @@ public function setOrderConnections
246246
external "C" RTOpts_setOrderConnections(show) annotation(Library = "omcruntime");
247247
end setOrderConnections;
248248

249+
public function getPreOptModules
250+
input list<String> inStringLst;
251+
output list<String> outStringLst;
252+
253+
external "C" outStringLst=RTOpts_getPreOptModules(inStringLst) annotation(Library = "omcruntime");
254+
end getPreOptModules;
255+
256+
public function getPastOptModules
257+
input list<String> inStringLst;
258+
output list<String> outStringLst;
259+
260+
external "C" outStringLst=RTOpts_getPastOptModules(inStringLst) annotation(Library = "omcruntime");
261+
end getPastOptModules;
262+
263+
public function setPreOptModules
264+
input list<String> inStringLst;
265+
266+
external "C" RTOpts_setPreOptModules(inStringLst) annotation(Library = "omcruntime");
267+
end setPreOptModules;
268+
269+
public function setPastOptModules
270+
input list<String> inStringLst;
271+
272+
external "C" RTOpts_setPastOptModules(inStringLst) annotation(Library = "omcruntime");
273+
end setPastOptModules;
274+
249275
end RTOpts;
250276

0 commit comments

Comments
 (0)