Skip to content

Commit

Permalink
- Moved around some realtime timer indices (keep them together so we …
Browse files Browse the repository at this point in the history
…don't use the same index at the same place by accident)

- Made the simulate() command faster, by using any qualified classname as it is, without looking in the symboltable
- Enabled a few more tests


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@14798 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Jan 16, 2013
1 parent 0dbb773 commit 4868c73
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 50 deletions.
7 changes: 0 additions & 7 deletions Compiler/BackEnd/BackendDAE.mo
Expand Up @@ -45,13 +45,6 @@ public import Values;
public import HashTable3;
public import HashTableCG;

public constant Integer RT_PROFILER0=6;
public constant Integer RT_PROFILER1=7;
public constant Integer RT_PROFILER2=8;
public constant Integer RT_CLOCK_EXECSTAT_BACKEND_MODULES=12;
public constant Integer RT_CLOCK_EXECSTAT_JACOBIANS=16;


public constant Integer SymbolicJacobianAIndex = 1;
public constant Integer SymbolicJacobianBIndex = 2;
public constant Integer SymbolicJacobianCIndex = 3;
Expand Down
7 changes: 4 additions & 3 deletions Compiler/BackEnd/BackendDAECreate.mo
Expand Up @@ -50,6 +50,7 @@ protected import BackendEquation;
protected import BackendVariable;
protected import BackendVarTransform;
protected import BaseHashTable;
protected import CevalScript;
protected import CheckModel;
protected import ComponentReference;
protected import ClassInf;
Expand Down Expand Up @@ -103,8 +104,8 @@ protected
list<BackendDAE.ZeroCrossing> zero_crossings;
DAE.FunctionTree functionTree;
algorithm
System.realtimeTick(BackendDAE.RT_CLOCK_EXECSTAT_BACKEND_MODULES);
Debug.execStat("Enter Backend", BackendDAE.RT_CLOCK_EXECSTAT_BACKEND_MODULES);
System.realtimeTick(CevalScript.RT_CLOCK_EXECSTAT_BACKEND_MODULES);
Debug.execStat("Enter Backend", CevalScript.RT_CLOCK_EXECSTAT_BACKEND_MODULES);
functionTree := Env.getFunctionTree(inCache);
(DAE.DAE(elems), functionTree) := processBuiltinExpressions(lst, functionTree);
vars := BackendVariable.emptyVars();
Expand Down Expand Up @@ -144,7 +145,7 @@ algorithm
symjacs));
BackendDAEUtil.checkBackendDAEWithErrorMsg(outBackendDAE);
Debug.fcall(Flags.DUMP_BACKENDDAE_INFO, print, "No. of Equations: " +& intString(BackendDAEUtil.equationSize(eqnarr)) +& "\nNo. of Variables: " +& intString(BackendVariable.varsSize(vars_1)) +& "\n");
Debug.execStat("generate Backend Data Structure", BackendDAE.RT_CLOCK_EXECSTAT_BACKEND_MODULES);
Debug.execStat("generate Backend Data Structure", CevalScript.RT_CLOCK_EXECSTAT_BACKEND_MODULES);
end lower;

protected function lower2
Expand Down
13 changes: 7 additions & 6 deletions Compiler/BackEnd/BackendDAEOptimize.mo
Expand Up @@ -60,6 +60,7 @@ protected import BaseHashTable;
protected import BaseHashSet;
protected import Builtin;
protected import Ceval;
protected import CevalScript;
protected import ClassInf;
protected import ComponentReference;
protected import DAEUtil;
Expand Down Expand Up @@ -5653,13 +5654,13 @@ protected
BackendDAE.SparsePattern sparsePattern;
BackendDAE.SparseColoring sparseColoring;
algorithm
System.realtimeTick(BackendDAE.RT_CLOCK_EXECSTAT_JACOBIANS);
System.realtimeTick(CevalScript.RT_CLOCK_EXECSTAT_JACOBIANS);
BackendDAE.DAE(eqs=eqs,shared=shared) := inBackendDAE;
(symJacA , sparsePattern, sparseColoring ):= createSymbolicJacobianforStates(inBackendDAE);
shared := BackendDAEUtil.addBackendDAESharedJacobian(symJacA, sparsePattern, sparseColoring, shared);
outBackendDAE := BackendDAE.DAE(eqs,shared);
_ := Flags.enableDebug(Flags.JACOBIAN);
_ := System.realtimeTock(BackendDAE.RT_CLOCK_EXECSTAT_JACOBIANS);
_ := System.realtimeTock(CevalScript.RT_CLOCK_EXECSTAT_JACOBIANS);
end generateSymbolicJacobianPast;

public function generateSymbolicLinearizationPast
Expand All @@ -5670,13 +5671,13 @@ protected
BackendDAE.Shared shared;
BackendDAE.SymbolicJacobians linearModelMatrixes;
algorithm
System.realtimeTick(BackendDAE.RT_CLOCK_EXECSTAT_JACOBIANS);
System.realtimeTick(CevalScript.RT_CLOCK_EXECSTAT_JACOBIANS);
BackendDAE.DAE(eqs=eqs,shared=shared) := inBackendDAE;
linearModelMatrixes := createLinearModelMatrixes(inBackendDAE);
shared := BackendDAEUtil.addBackendDAESharedJacobians(linearModelMatrixes, shared);
outBackendDAE := BackendDAE.DAE(eqs,shared);
_ := Flags.enableDebug(Flags.JACOBIAN);
_ := System.realtimeTock(BackendDAE.RT_CLOCK_EXECSTAT_JACOBIANS);
_ := System.realtimeTock(CevalScript.RT_CLOCK_EXECSTAT_JACOBIANS);
end generateSymbolicLinearizationPast;

protected function createSymbolicJacobianforStates
Expand Down Expand Up @@ -5871,7 +5872,7 @@ algorithm
s1 = intString(listLength(inVars));

Debug.execStat("analytical Jacobians -> starting to generate the jacobian. DiffVars:"
+& s +& " diffed equations: " +& s1 +& "\n", BackendDAE.RT_CLOCK_EXECSTAT_JACOBIANS);
+& s +& " diffed equations: " +& s1 +& "\n", CevalScript.RT_CLOCK_EXECSTAT_JACOBIANS);

// Differentiate the ODE system w.r.t states for jacobian
(backendDAE as BackendDAE.DAE(shared=shared)) = generateSymbolicJacobian(inBackendDAE, comref_vars, inDifferentiatedVars, BackendVariable.listVar1(seedlst), inStateVars, inInputVars, inParameterVars, inName);
Expand All @@ -5891,7 +5892,7 @@ algorithm
Debug.fcall(Flags.JAC_DUMP, print, "analytical Jacobians -> sorted know vars(" +& intString(listLength(knvarsTmp)) +& ") for Jacobian DAE time: " +& realString(clock()) +& "\n");
knvars = BackendVariable.listVar1(knvarsTmp);
backendDAE = BackendDAEUtil.addBackendDAEKnVars(knvars,backendDAE);
Debug.execStat("analytical Jacobians -> generated optimized jacobians", BackendDAE.RT_CLOCK_EXECSTAT_JACOBIANS);
Debug.execStat("analytical Jacobians -> generated optimized jacobians", CevalScript.RT_CLOCK_EXECSTAT_JACOBIANS);

// generate sparse pattern
(sparsepattern,colsColors) = generateSparsePattern(inBackendDAE, inDiffVars, diffedVars);
Expand Down
39 changes: 20 additions & 19 deletions Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -63,6 +63,7 @@ protected import BackendVariable;
protected import BackendVarTransform;
protected import BinaryTree;
protected import Ceval;
protected import CevalScript;
protected import CheckModel;
protected import ClassInf;
protected import ComponentReference;
Expand Down Expand Up @@ -7932,11 +7933,11 @@ algorithm
daeHandler := getIndexReductionMethod(strdaeHandler);

Debug.fcall2(Flags.DUMP_DAE_LOW, BackendDump.dumpBackendDAE, inDAE, "dumpdaelow");
System.realtimeTick(BackendDAE.RT_CLOCK_EXECSTAT_BACKEND_MODULES);
System.realtimeTick(CevalScript.RT_CLOCK_EXECSTAT_BACKEND_MODULES);
// pre optimisation phase
// Frenkel TUD: why is this neccesarray? it only consumes time!
_ := traverseBackendDAEExpsNoCopyWithUpdate(inDAE,ExpressionSimplify.simplifyTraverseHelper,0) "simplify all expressions";
Debug.execStat("preOpt SimplifyAllExp",BackendDAE.RT_CLOCK_EXECSTAT_BACKEND_MODULES);
Debug.execStat("preOpt SimplifyAllExp",CevalScript.RT_CLOCK_EXECSTAT_BACKEND_MODULES);
(optdae,Util.SUCCESS()) := preoptimiseDAE(inDAE,preOptModules);

// transformation phase (matching and sorting using a index reduction method
Expand All @@ -7946,13 +7947,13 @@ algorithm
// past optimisation phase
(optsode,Util.SUCCESS()) := pastoptimiseDAE(sode,pastOptModules,matchingAlgorithm,daeHandler);
sode1 := BackendDAECreate.findZeroCrossings(optsode);
Debug.execStat("findZeroCrossings",BackendDAE.RT_CLOCK_EXECSTAT_BACKEND_MODULES);
Debug.execStat("findZeroCrossings",CevalScript.RT_CLOCK_EXECSTAT_BACKEND_MODULES);
_ := traverseBackendDAEExpsNoCopyWithUpdate(sode1,ExpressionSimplify.simplifyTraverseHelper,0) "simplify all expressions";
outSODE := calculateValues(sode1);
// moved to SimCodeUtil because of initial system
//Debug.execStat("calculateValue",BackendDAE.RT_CLOCK_EXECSTAT_BACKEND_MODULES);
//Debug.execStat("calculateValue",CevalScript.RT_CLOCK_EXECSTAT_BACKEND_MODULES);
//outSODE := expandAlgorithmsbyInitStmts(sode2);
Debug.execStat("expandAlgorithmsbyInitStmts",BackendDAE.RT_CLOCK_EXECSTAT_BACKEND_MODULES);
Debug.execStat("expandAlgorithmsbyInitStmts",CevalScript.RT_CLOCK_EXECSTAT_BACKEND_MODULES);
Debug.fcall2(Flags.DUMP_INDX_DAE, BackendDump.dumpBackendDAE, outSODE, "dumpindxdae");
Debug.fcall(Flags.DUMP_BACKENDDAE_INFO, BackendDump.dumpCompShort, outSODE);
Debug.fcall(Flags.DUMP_EQNINORDER, BackendDump.dumpEqnsSolved, outSODE);
Expand Down Expand Up @@ -7995,14 +7996,14 @@ algorithm
case (_,(optModule,moduleStr,_)::rest)
equation
dae = optModule(inDAE);
Debug.execStat("preOpt " +& moduleStr,BackendDAE.RT_CLOCK_EXECSTAT_BACKEND_MODULES);
Debug.execStat("preOpt " +& moduleStr,CevalScript.RT_CLOCK_EXECSTAT_BACKEND_MODULES);
Debug.fcall(Flags.OPT_DAE_DUMP, print, stringAppendList({"\nOptimisation Module ",moduleStr,":\n\n"}));
Debug.fcall(Flags.OPT_DAE_DUMP, BackendDump.printBackendDAE, dae);
(dae1,status) = preoptimiseDAE(dae,rest);
then (dae1,status);
case (_,(optModule,moduleStr,b)::rest)
equation
Debug.execStat("<failed> preOpt " +& moduleStr,BackendDAE.RT_CLOCK_EXECSTAT_BACKEND_MODULES);
Debug.execStat("<failed> preOpt " +& moduleStr,CevalScript.RT_CLOCK_EXECSTAT_BACKEND_MODULES);
str = stringAppendList({"Optimisation Module ",moduleStr," failed."});
Debug.bcall2(not b,Error.addMessage, Error.INTERNAL_ERROR, {str});
(dae,status) = preoptimiseDAE(inDAE,rest);
Expand Down Expand Up @@ -8053,7 +8054,7 @@ algorithm
// do state selection
(_,_,sDfunc,methodstr) := stateDeselection;
BackendDAE.DAE(systs,shared) := sDfunc(BackendDAE.DAE(systs,shared),args);
Debug.execStat("transformDAE -> state selection " +& methodstr,BackendDAE.RT_CLOCK_EXECSTAT_BACKEND_MODULES);
Debug.execStat("transformDAE -> state selection " +& methodstr,CevalScript.RT_CLOCK_EXECSTAT_BACKEND_MODULES);
// sort assigned equations to blt form
(systs,shared) := mapSortEqnsDAE(systs,shared,{});
outDAE := BackendDAE.DAE(systs,shared);
Expand Down Expand Up @@ -8130,7 +8131,7 @@ algorithm
arg = IndexReduction.getStructurallySingularSystemHandlerArg(syst,ishared,mapEqnIncRow,mapIncRowEqn);
// match the system and reduce index if neccessary
(syst,shared,arg) = matchingAlgorithmfunc(syst,ishared, match_opts, sssHandler, arg);
Debug.execStat("transformDAE -> matchingAlgorithm " +& mAmethodstr +& " index Reduction Method " +& str1,BackendDAE.RT_CLOCK_EXECSTAT_BACKEND_MODULES);
Debug.execStat("transformDAE -> matchingAlgorithm " +& mAmethodstr +& " index Reduction Method " +& str1,CevalScript.RT_CLOCK_EXECSTAT_BACKEND_MODULES);
then (syst,shared,SOME(arg));
case (_,_,_,(_,mAmethodstr),(_,str1,_,_))
equation
Expand Down Expand Up @@ -8189,7 +8190,7 @@ algorithm
funcs = getFunctions(ishared);
(syst,_,_,mapEqnIncRow,mapIncRowEqn) = getIncidenceMatrixScalar(isyst,BackendDAE.NORMAL(), SOME(funcs));
(syst,_) = BackendDAETransform.strongComponentsScalar(syst, ishared,mapEqnIncRow,mapIncRowEqn);
Debug.execStat("transformDAE -> sort components",BackendDAE.RT_CLOCK_EXECSTAT_BACKEND_MODULES);
Debug.execStat("transformDAE -> sort components",CevalScript.RT_CLOCK_EXECSTAT_BACKEND_MODULES);
then (syst,ishared);
else
equation
Expand Down Expand Up @@ -8225,7 +8226,7 @@ algorithm
case (_,(optModule,moduleStr,_)::rest,_,_)
equation
dae = optModule(inDAE);
Debug.execStat("pastOpt " +& moduleStr,BackendDAE.RT_CLOCK_EXECSTAT_BACKEND_MODULES);
Debug.execStat("pastOpt " +& moduleStr,CevalScript.RT_CLOCK_EXECSTAT_BACKEND_MODULES);
Debug.fcall(Flags.OPT_DAE_DUMP, print, stringAppendList({"\nOptimisation Module ",moduleStr,":\n\n"}));
Debug.fcall(Flags.OPT_DAE_DUMP, BackendDump.printBackendDAE, dae);
dae1 = causalizeDAE(dae,NONE(),matchingAlgorithm,daeHandler,false);
Expand All @@ -8234,7 +8235,7 @@ algorithm
(dae2,status);
case (_,(optModule,moduleStr,b)::rest,_,_)
equation
Debug.execStat("pastOpt <failed> " +& moduleStr,BackendDAE.RT_CLOCK_EXECSTAT_BACKEND_MODULES);
Debug.execStat("pastOpt <failed> " +& moduleStr,CevalScript.RT_CLOCK_EXECSTAT_BACKEND_MODULES);
str = stringAppendList({"Optimisation Module ",moduleStr," failed."});
Debug.bcall2(not b,Error.addMessage, Error.INTERNAL_ERROR, {str});
(dae,status) = pastoptimiseDAE(inDAE,rest,matchingAlgorithm,daeHandler);
Expand Down Expand Up @@ -8657,14 +8658,14 @@ public function profilerinit
algorithm
setGlobalRoot(Global.profilerTime1Index, 0.0);
setGlobalRoot(Global.profilerTime2Index, 0.0);
System.realtimeTick(BackendDAE.RT_PROFILER0);
System.realtimeTick(CevalScript.RT_PROFILER0);
end profilerinit;

public function profilerresults
protected
Real tg,t1,t2;
algorithm
tg := System.realtimeTock(BackendDAE.RT_PROFILER0);
tg := System.realtimeTock(CevalScript.RT_PROFILER0);
t1 := getGlobalRoot(Global.profilerTime1Index);
t2 := getGlobalRoot(Global.profilerTime2Index);
print("Time all: "); print(realString(tg)); print("\n");
Expand All @@ -8687,19 +8688,19 @@ end profilertime2;

public function profilerstart1
algorithm
System.realtimeTick(BackendDAE.RT_PROFILER1);
System.realtimeTick(CevalScript.RT_PROFILER1);
end profilerstart1;

public function profilerstart2
algorithm
System.realtimeTick(BackendDAE.RT_PROFILER2);
System.realtimeTick(CevalScript.RT_PROFILER2);
end profilerstart2;

public function profilerstop1
protected
Real t;
algorithm
t := System.realtimeTock(BackendDAE.RT_PROFILER1);
t := System.realtimeTock(CevalScript.RT_PROFILER1);
setGlobalRoot(Global.profilerTime1Index,
realAdd(getGlobalRoot(Global.profilerTime1Index),t));
end profilerstop1;
Expand All @@ -8708,7 +8709,7 @@ public function profilerstop2
protected
Real t;
algorithm
t := System.realtimeTock(BackendDAE.RT_PROFILER2);
t := System.realtimeTock(CevalScript.RT_PROFILER2);
setGlobalRoot(Global.profilerTime2Index,
realAdd(getGlobalRoot(Global.profilerTime2Index),t));
end profilerstop2;
Expand All @@ -8726,7 +8727,7 @@ end profilerreset2;
public function profilertock1
output Real t;
algorithm
t := System.realtimeTock(BackendDAE.RT_PROFILER1);
t := System.realtimeTock(CevalScript.RT_PROFILER1);
end profilertock1;


Expand Down
3 changes: 2 additions & 1 deletion Compiler/BackEnd/BackendVariable.mo
Expand Up @@ -47,6 +47,7 @@ protected import Absyn;
protected import BackendDAEUtil;
protected import BaseHashSet;
protected import BaseHashTable;
protected import CevalScript;
protected import ComponentReference;
protected import DAEUtil;
protected import Debug;
Expand Down Expand Up @@ -2273,7 +2274,7 @@ algorithm
case (BackendDAE.VARIABLE_ARRAY(numberOfElements = n,arrSize = size,varOptArr = arr),_)
equation
print("- vararrayAdd failed\nn: " +& intString(n) +& ", size: " +& intString(size) +& " arraysize: " +& intString(arrayLength(arr)) +& "\n");
Debug.execStat("vararrayAdd",BackendDAE.RT_CLOCK_EXECSTAT_BACKEND_MODULES);
Debug.execStat("vararrayAdd",CevalScript.RT_CLOCK_EXECSTAT_BACKEND_MODULES);
then
fail();
case (_,_)
Expand Down
17 changes: 9 additions & 8 deletions Compiler/BackEnd/Matching.mo
Expand Up @@ -46,6 +46,7 @@ protected import BackendDAEUtil;
protected import BackendDump;
protected import BackendEquation;
protected import BackendVariable;
protected import CevalScript;
protected import Config;
protected import DAEUtil;
protected import Debug;
Expand Down Expand Up @@ -6001,11 +6002,11 @@ algorithm
syst := randSortSystem(isyst,ishared);
testMatchingAlgorithms1(matchingAlgorithms,syst,ishared,inMatchingOptions);

System.realtimeTick(BackendDAE.RT_PROFILER0);
System.realtimeTick(CevalScript.RT_PROFILER0);
(_,m,_) := BackendDAEUtil.getIncidenceMatrixfromOption(syst,BackendDAE.NORMAL(),NONE());
matchingExternalsetIncidenceMatrix(nv,ne,m);
cheapID := 3;
t := System.realtimeTock(BackendDAE.RT_PROFILER0);
t := System.realtimeTock(CevalScript.RT_PROFILER0);
print("SetMEXT: " +& realString(t) +& "\n");
extmatchingAlgorithms := {("DFSEXT: ",1),
("BFSEXT: ",2),
Expand All @@ -6017,12 +6018,12 @@ algorithm
("ABMPEXT ",8),
("PREXT: ",10)};
testExternMatchingAlgorithms1(extmatchingAlgorithms,cheapID,nv,ne);
System.realtimeTick(BackendDAE.RT_PROFILER0);
System.realtimeTick(CevalScript.RT_PROFILER0);
vec1 := arrayCreate(ne,-1);
vec2 := arrayCreate(nv,-1);
BackendDAEEXT.getAssignment(vec1,vec2);
print("GetAssEXT: " +& realString(t) +& "\n");
System.realtimeTick(BackendDAE.RT_PROFILER0);
System.realtimeTick(CevalScript.RT_PROFILER0);
//unassigned := checkAssignment(1,ne,vec1,vec2,{});
//print("Unnasigned: " +& intString(listLength(unassigned)) +& "\n");
//print("Unassigned:\n");
Expand Down Expand Up @@ -6075,9 +6076,9 @@ algorithm
then ();
case ((str,matchingAlgorithm)::rest,_,_,_)
equation
System.realtimeTick(BackendDAE.RT_PROFILER0);
System.realtimeTick(CevalScript.RT_PROFILER0);
testMatchingAlgorithm(10,matchingAlgorithm,isyst,ishared,inMatchingOptions);
t = System.realtimeTock(BackendDAE.RT_PROFILER0);
t = System.realtimeTock(CevalScript.RT_PROFILER0);
print(str +& realString(realDiv(t,10.0)) +& "\n");
testMatchingAlgorithms1(rest,isyst,ishared,inMatchingOptions);
then
Expand Down Expand Up @@ -6161,9 +6162,9 @@ algorithm
then ();
case ((str,matchingAlgorithm)::rest,_,_,_)
equation
System.realtimeTick(BackendDAE.RT_PROFILER0);
System.realtimeTick(CevalScript.RT_PROFILER0);
testExternMatchingAlgorithm(10,matchingAlgorithm,cheapId,nv,ne);
t = System.realtimeTock(BackendDAE.RT_PROFILER0);
t = System.realtimeTock(CevalScript.RT_PROFILER0);
print(str +& realString(realDiv(t,10.0)) +& "\n");
testExternMatchingAlgorithms1(rest,cheapId,nv,ne);
then
Expand Down
6 changes: 3 additions & 3 deletions Compiler/BackEnd/SimCodeUtil.mo
Expand Up @@ -5089,16 +5089,16 @@ algorithm
case (_,_,_)
equation
//true = Flags.isSet(Flags.JACOBIAN);
System.realtimeTick(BackendDAE.RT_CLOCK_EXECSTAT_JACOBIANS);
System.realtimeTick(CevalScript.RT_CLOCK_EXECSTAT_JACOBIANS);
//b = Flags.disableDebug(Flags.EXEC_STAT);
// The jacobian code requires single systems;
// I did not rewrite it to take advantage of any parallelism in the code
(res,_) = createSymbolicJacobianssSimCode(inSymjacs,inModelInfo,uniqueEqIndex,{"A","B","C","D"});
// if optModule is not activated add dummy matrices
res = addLinearizationMatrixes(res);
//_ = Flags.set(Flags.EXEC_STAT, b);
Debug.execStat("generated analytical Jacobians SimCode. : ",BackendDAE.RT_CLOCK_EXECSTAT_JACOBIANS);
_ = System.realtimeTock(BackendDAE.RT_CLOCK_EXECSTAT_JACOBIANS);
Debug.execStat("generated analytical Jacobians SimCode. : ",CevalScript.RT_CLOCK_EXECSTAT_JACOBIANS);
_ = System.realtimeTock(CevalScript.RT_CLOCK_EXECSTAT_JACOBIANS);
then res;
else
equation
Expand Down
1 change: 1 addition & 0 deletions Compiler/Main/Main.mo
Expand Up @@ -999,6 +999,7 @@ algorithm
_ := matchcontinue args
case _
equation
System.realtimeTick(CevalScript.RT_CLOCK_SIMULATE_TOTAL);
args_1 = Flags.new(args);
System.gettextInit(Util.if_(Config.getRunningTestsuite(),"C",Flags.getConfigString(Flags.LOCALE_FLAG)));
main2(args_1);
Expand Down

0 comments on commit 4868c73

Please sign in to comment.