Skip to content

Commit 4734579

Browse files
author
Volker Waurich
committed
- update equations in linear systems when duplicating tasks
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@21658 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent e0b690d commit 4734579

File tree

3 files changed

+78
-20
lines changed

3 files changed

+78
-20
lines changed

Compiler/BackEnd/HpcOmScheduler.mo

Lines changed: 60 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2561,7 +2561,7 @@ protected function createTDSduplicateTasks2"sets the information about the new t
25612561
protected
25622562
String crefAppend;
25632563
Integer threadIdx,compIdx,simVarIdx,simVarIdx2,simEqSysIdx,simEqSysIdx2,simEqSysIdx3,numVars,numEqs,numInitEqs,taskIdx,lsIdx,nlsIdx,mIdx;
2564-
list<Integer> comps,simVarSysIdcs,simVarSysIdcs2,simEqSysIdcs,simEqSysIdcs2,simEqSysIdcsInit,thread,clTasks,origPredTasks,clPredTasks,duplPredTasks,pos;
2564+
list<Integer> comps,simVarSysIdcs,simVarSysIdcs2,simEqSysIdcs,simEqSysIdcs2,systSimEqSysIdcs2,simEqSysIdcsInit,thread,clTasks,origPredTasks,clPredTasks,duplPredTasks,pos;
25652565
list<list<Integer>> simEqIdxLst,simVarIdxLst;
25662566
array<list<Integer>> inComps;
25672567
BackendVarTransform.VariableReplacements repl;
@@ -2576,7 +2576,7 @@ protected
25762576
list<list<DAE.ComponentRef>> crefLst;
25772577
list<DAE.Exp> crefsDuplExp;
25782578
list<SimCode.SimVar> simVarLst,simVarDupl,algVars;
2579-
list<SimCode.SimEqSystem> simEqSysts,simEqSystsDupl,initEqs;
2579+
list<SimCode.SimEqSystem> simEqSysts,simEqSystsDupl,systemSimEqSys,systemSimEqSysDupl,initEqs;
25802580
list<list<SimCode.SimEqSystem>> odes;
25812581
algorithm
25822582
HpcOmTaskGraph.TASKGRAPHMETA(inComps=inComps) := iTaskGraphMeta;
@@ -2587,26 +2587,23 @@ algorithm
25872587
//print("node to duplicate "+&intString(node)+&"\n");
25882588
comps := arrayGet(inComps,node);
25892589
comps := listReverse(comps);
2590-
//print("comps :"+&intListString(comps)+&"\n");
2591-
//print("task :"+&intString(taskIdx)+&"\n");
2590+
print("comps :"+&intListString(comps)+&"\n");
2591+
print("task :"+&intString(taskIdx)+&"\n");
25922592
simEqIdxLst := List.map1(comps,Util.arrayGetIndexFirst,sccSimEqMappingIn);
25932593
simEqSysIdcs := List.flatten(simEqIdxLst);
2594-
//print("simEqSysIdcs :"+&intListString(simEqSysIdcs)+&"\n");
2595-
2594+
print("simEqSysIdcs :"+&intListString(simEqSysIdcs)+&"\n");
2595+
25962596
crefLst := List.map1(simEqSysIdcs,SimCodeUtil.getAssignedCrefsOfSimEq,simCodeIn);
25972597
crefs := List.flatten(crefLst);
2598-
//print("crefs :\n"+&stringDelimitList(List.map(crefs,ComponentReference.debugPrintComponentRefTypeStr),"\n")+&"\n");
2599-
2598+
print("crefs :\n"+&stringDelimitList(List.map(crefs,ComponentReference.debugPrintComponentRefTypeStr),"\n")+&"\n");
26002599
simVarLst := List.map1(crefs,SimCodeUtil.get,ht);
2601-
simEqSysts := List.map1(simEqSysIdcs,SimCodeUtil.getSimEqSysForIndex,List.flatten(odes));
26022600

26032601
// build the new crefs, new simVars
26042602
numVars := listLength(simVarLst);
26052603
simVarSysIdcs2 := List.intRange2(simVarIdx,simVarIdx+numVars-1);
26062604
crefAppend := "_thr"+&intString(threadIdx);
2607-
//crefsDupl := List.map1(crefs,ComponentReference.joinArrayCrefs,DAE.CREF_IDENT(crefAppend,DAE.T_UNKNOWN_DEFAULT,{}));
26082605
crefsDupl := List.map1r(crefs,ComponentReference.appendStringLastIdent,crefAppend);
2609-
//print("crefs new :\n"+&stringDelimitList(List.map(crefsDupl,ComponentReference.debugPrintComponentRefTypeStr),"\n")+&"\n");
2606+
print("crefs new :\n"+&stringDelimitList(List.map(crefsDupl,ComponentReference.debugPrintComponentRefTypeStr),"\n")+&"\n");
26102607
crefsDuplExp := List.map(crefsDupl,Expression.crefExp);
26112608
simVarDupl := List.threadMap(crefsDupl,simVarLst,SimCodeUtil.replaceSimVarName);
26122609
simVarDupl := List.threadMap(simVarSysIdcs2,simVarDupl,SimCodeUtil.replaceSimVarIndex);
@@ -2617,14 +2614,20 @@ algorithm
26172614
ht := List.fold(simVarDupl,SimCodeUtil.addSimVarToHashTable,ht);
26182615
repl := BackendVarTransform.addReplacements(replIn,crefs,crefsDuplExp,NONE());
26192616
//BackendVarTransform.dumpReplacements(repl);
2617+
simEqSysts := List.map1(simEqSysIdcs,SimCodeUtil.getSimEqSysForIndex,List.flatten(odes));
26202618
numEqs := listLength(simEqSysts);
26212619
simEqSysIdcs2 := List.intRange2(simEqSysIdx,simEqSysIdx+numEqs-1);
2622-
//print("simEqSysIdcs2 :"+&intListString(simEqSysIdcs2)+&"\n");
2620+
print("simEqSysIdcs2 :"+&intListString(simEqSysIdcs2)+&"\n");
26232621
(simEqSystsDupl,_) := List.map1_2(simEqSysts,replaceExpsInSimEqSystem,repl);// replace the exps and crefs
26242622
(simEqSystsDupl,(lsIdx,nlsIdx,mIdx)) := List.mapFold(simEqSystsDupl,replaceSystemIndex,(lsIdx,nlsIdx,mIdx));// udpate the indeces of th systems
26252623
simEqSystsDupl := List.threadMap(simEqSystsDupl,simEqSysIdcs2,SimCodeUtil.replaceSimEqSysIndex);
2626-
//print("the simEqSystsDupl "+&SimCodeUtil.dumpSimEqSystemLst(simEqSystsDupl)+&"\n");
2624+
print("the simEqSystsDupl "+&SimCodeUtil.dumpSimEqSystemLst(simEqSystsDupl)+&"\n");
26272625
simEqSysIdx2 := simEqSysIdx + numEqs;
2626+
2627+
//duplicate the equations inside a system of equations
2628+
(simEqSystsDupl,simEqSysIdx2) := TDS_duplicateSystemOfEquations(simEqSystsDupl,simEqSysIdx2,repl,{});
2629+
print("the simEqSystsDupl after EqSys "+&SimCodeUtil.dumpSimEqSystemLst(simEqSystsDupl)+&"\n");
2630+
26282631
// update sccSimEqmapping for the duplicated
26292632
duplSccSimEqMapOut := listAppend(List.map(simEqSysIdcs2,List.create),duplSccSimEqMapIn);
26302633
simCode := List.fold1(simEqSystsDupl,SimCodeUtil.addSimEqSysToODEquations,1,simCode);
@@ -2677,6 +2680,50 @@ algorithm
26772680
replOut := repl;
26782681
end createTDSduplicateTasks2;
26792682

2683+
protected function TDS_duplicateSystemOfEquations
2684+
input list<SimCode.SimEqSystem> simEqsIn;
2685+
input Integer simEqSysIdxIn;
2686+
input BackendVarTransform.VariableReplacements repl;
2687+
input list<SimCode.SimEqSystem> simEqsFold;
2688+
output list<SimCode.SimEqSystem> simEqsOut;
2689+
output Integer simEqSysIdxOut;
2690+
algorithm
2691+
(simEqsOut,simEqSysIdxOut) := matchcontinue(simEqsIn,simEqSysIdxIn,repl,simEqsFold)
2692+
local
2693+
Integer simEqSysIdx, index, numEqs;
2694+
Boolean partOfMixed;
2695+
list<Integer> systSimEqSysIdcs2;
2696+
SimCode.SimEqSystem simEqSys;
2697+
list<SimCode.SimEqSystem> rest,duplicated,residual;
2698+
list<SimCode.SimVar> vars;
2699+
list<DAE.Exp> beqs;
2700+
list<tuple<Integer, Integer, SimCode.SimEqSystem>> simJac;
2701+
Option<SimCode.JacobianMatrix> jacobianMatrix;
2702+
list<DAE.ElementSource> sources;
2703+
Integer indexLinearSystem;
2704+
case({},_,_,_)
2705+
then (listReverse(simEqsFold),simEqSysIdxIn);
2706+
case((simEqSys as SimCode.SES_LINEAR(index=index,partOfMixed=partOfMixed,vars=vars,beqs=beqs,simJac=simJac,jacobianMatrix=jacobianMatrix, residual=residual,sources=sources,indexLinearSystem=indexLinearSystem))::rest,_,_,_)
2707+
equation
2708+
//print("the systemSimEqSys "+&SimCodeUtil.dumpSimEqSystemLst(residual)+&"\n");
2709+
numEqs = listLength(residual);
2710+
systSimEqSysIdcs2 = Util.if_(intEq(numEqs,0),{},List.intRange2(simEqSysIdxIn,simEqSysIdxIn+numEqs-1));
2711+
//print("systSimEqSysIdcs2 :"+&intListString(systSimEqSysIdcs2)+&"\n");
2712+
(duplicated,_) = List.map1_2(residual,replaceExpsInSimEqSystem,repl);// replace the exps and crefs
2713+
duplicated = List.threadMap(duplicated,systSimEqSysIdcs2,SimCodeUtil.replaceSimEqSysIndex);
2714+
//print("the systemSimEqSysDupl "+&SimCodeUtil.dumpSimEqSystemLst(duplicated)+&"\n");
2715+
simEqSys = SimCode.SES_LINEAR(index,partOfMixed,vars,beqs,simJac,duplicated,jacobianMatrix,sources,indexLinearSystem);
2716+
simEqSysIdx = simEqSysIdxIn + numEqs;
2717+
(duplicated,simEqSysIdx) = TDS_duplicateSystemOfEquations(rest,simEqSysIdx,repl,simEqSys::simEqsFold);
2718+
then (duplicated,simEqSysIdx);
2719+
else
2720+
equation
2721+
simEqSys::rest = simEqsIn;
2722+
(duplicated,simEqSysIdx) = TDS_duplicateSystemOfEquations(rest,simEqSysIdxIn,repl,simEqSys::simEqsFold);
2723+
then (duplicated,simEqSysIdx);
2724+
end matchcontinue;
2725+
end TDS_duplicateSystemOfEquations;
2726+
26802727
protected function makeSEScrefAssignment
26812728
input DAE.ComponentRef lhs;
26822729
input DAE.ComponentRef rhs;

Compiler/BackEnd/HpcOmSimCodeMain.mo

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,11 @@ algorithm
318318
numProc = Flags.getConfigInt(Flags.NUM_PROC);
319319
(numProc,_) = setNumProc(numProc,cpCostsWoC,taskGraphDataOde);//in case n-flag is not set
320320
(schedule,simCode,taskGraphScheduled,taskGraphDataScheduled,sccSimEqMapping) = createSchedule(taskGraphSimplified,taskGraphDataSimplified,sccSimEqMapping,filenamePrefix,numProc,simCode,scheduledTasks);
321+
322+
SimCode.SIMCODE(modelInfo, simCodeLiterals, simCodeRecordDecls, simCodeExternalFunctionIncludes, allEquations, odeEquations, algebraicEquations, residualEquations, useSymbolicInitialization, useHomotopy, initialEquations, removedInitialEquations, startValueEquations, nominalValueEquations, minValueEquations, maxValueEquations,
323+
parameterEquations, removedEquations, algorithmAndEquationAsserts, zeroCrossingsEquations, jacobianEquations, stateSets, constraints, classAttributes, zeroCrossings, relations, timeEvents, whenClauses,
324+
discreteModelVars, extObjInfo, makefileParams, delayedExps, jacobianMatrixes, simulationSettingsOpt, fileNamePrefix, _, _, _, crefToSimVarHT, backendMapping) = simCode;
325+
321326
//(schedule,numProc) = repeatScheduleWithOtherNumProc(taskGraphSimplified,taskGraphDataSimplified,sccSimEqMapping,filenamePrefix,cpCostsWoC,schedule,numProc,numFixed);
322327
numProc = Flags.getConfigInt(Flags.NUM_PROC);
323328
criticalPathInfo = HpcOmScheduler.analyseScheduledTaskGraph(schedule,numProc,taskGraphScheduled,taskGraphDataScheduled);

Compiler/BackEnd/SimCodeUtil.mo

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7522,7 +7522,7 @@ algorithm
75227522
SimCode.SimEqSystem cont;
75237523
list<DAE.ComponentRef> crefs,conds;
75247524
list<DAE.Statement> stmts;
7525-
list<SimCode.SimEqSystem> elsebranch,discEqs,eqs;
7525+
list<SimCode.SimEqSystem> elsebranch,discEqs,eqs,residual;
75267526
list<SimCode.SimVar> vars,discVars;
75277527
list<DAE.Exp> beqs;
75287528
list<tuple<DAE.Exp,list<SimCode.SimEqSystem>>> ifbranches;
@@ -7558,9 +7558,10 @@ algorithm
75587558
s = intString(idx) +&": "+& List.fold(sLst,stringAppend,"");
75597559
then (s);
75607560

7561-
case(SimCode.SES_LINEAR(index=idx,partOfMixed=_,indexLinearSystem=idxLS,beqs = beqs))
7561+
case(SimCode.SES_LINEAR(index=idx,partOfMixed=_,indexLinearSystem=idxLS,beqs = beqs, residual=residual))
75627562
equation
7563-
s = intString(idx) +&": "+& " (LINEAR) index:"+&intString(idxLS)+&" size :"+&intString(listLength(beqs))+&"\n";
7563+
s = intString(idx) +&": "+& " (LINEAR) index:"+&intString(idxLS)+&"\n";
7564+
s = s+&"\t"+&stringDelimitList(List.map(residual,dumpSimEqSystem),"\n\t");
75647565
then (s);
75657566

75667567
case(SimCode.SES_NONLINEAR(index=idx,indexNonLinearSystem=idxNLS,jacobianMatrix=_,linearTearing=_,eqs=eqs, crefs=crefs))
@@ -7586,12 +7587,12 @@ public function dumpSimCode
75867587
input SimCode.SimCode simCode;
75877588
protected
75887589
Integer nls,nnls,nms,ninite,ninita,ninitr,ne;
7589-
list<SimCode.SimEqSystem> allEquations,jacobianEquations,equationsForZeroCrossings,algorithmAndEquationAsserts,initialEquations;
7590+
list<SimCode.SimEqSystem> allEquations,jacobianEquations,equationsForZeroCrossings,algorithmAndEquationAsserts,initialEquations,residualEquations;
75907591
SimCode.ModelInfo modelInfo;
75917592
SimCode.VarInfo varInfo;
75927593
list<list<SimCode.SimEqSystem>> odeEquations, algebraicEquations;
75937594
algorithm
7594-
SimCode.SIMCODE(modelInfo = modelInfo,allEquations = allEquations, odeEquations=odeEquations, algebraicEquations=algebraicEquations, algorithmAndEquationAsserts=algorithmAndEquationAsserts,
7595+
SimCode.SIMCODE(modelInfo = modelInfo,allEquations = allEquations, odeEquations=odeEquations, algebraicEquations=algebraicEquations,residualEquations=residualEquations, algorithmAndEquationAsserts=algorithmAndEquationAsserts,
75957596
equationsForZeroCrossings=equationsForZeroCrossings, jacobianEquations=jacobianEquations,initialEquations=initialEquations) := simCode;
75967597
SimCode.MODELINFO(varInfo=varInfo) := modelInfo;
75977598
SimCode.VARINFO(numInitialEquations=ninite,numInitialAlgorithms=ninita,numInitialResiduals=ninitr,numEquations=ne,numLinearSystems=nls,numNonLinearSystems=nnls,numMixedSystems=nms) := varInfo;
@@ -7601,6 +7602,8 @@ algorithm
76017602
print(stringDelimitList(List.map(odeEquations,dumpSimEqSystemLst),"\n--------------\n")+&"\n");
76027603
print("algebraicEquations: \n-----------------------\n");
76037604
print(stringDelimitList(List.map(algebraicEquations,dumpSimEqSystemLst),"\n")+&"\n");
7605+
print("residualEquations: \n-----------------------\n");
7606+
print(dumpSimEqSystemLst(residualEquations)+&"\n");
76047607
print("initialEquations: ("+&intString(ninite)+&"+"+&intString(ninita)+&"="+&intString(ninitr)+&")\n-----------------------\n");
76057608
print(dumpSimEqSystemLst(initialEquations)+&"\n");
76067609
print("algorithmAndEquationAsserts: \n-----------------------\n");
@@ -12972,8 +12975,9 @@ algorithm
1297212975
crefsOut := match(simEqSys)
1297312976
local
1297412977
DAE.ComponentRef cref;
12975-
list<DAE.ComponentRef> crefs;
12978+
list<DAE.ComponentRef> crefs,crefs2;
1297612979
list<SimCode.SimVar> simVars;
12980+
list<SimCode.SimEqSystem> residual;
1297712981
case(SimCode.SES_RESIDUAL(index=_,exp=_,source=_))
1297812982
equation
1297912983
print("implement SES_RESIDUAL in SimCodeUtil.getSimEqSystemCrefsLHS!\n");
@@ -12992,9 +12996,11 @@ algorithm
1299212996
equation
1299312997
print("implement SES_ALGORITHM in SimCodeUtil.getSimEqSystemCrefsLHS!\n");
1299412998
then {};
12995-
case(SimCode.SES_LINEAR(index=_,partOfMixed=_,vars=simVars,beqs=_,sources=_,simJac=_,indexLinearSystem=_))
12999+
case(SimCode.SES_LINEAR(index=_,partOfMixed=_,vars=simVars,beqs=_,sources=_,simJac=_,indexLinearSystem=_,residual=residual))
1299613000
equation
13001+
crefs2 = List.flatten(List.map(residual,getSimEqSystemCrefsLHS));
1299713002
crefs = List.map(simVars,varName);
13003+
crefs = listAppend(crefs,crefs2);
1299813004
then crefs;
1299913005
case(SimCode.SES_NONLINEAR(index=_,eqs=_,crefs=crefs,indexNonLinearSystem=_,jacobianMatrix=_,linearTearing=_))
1300013006
equation

0 commit comments

Comments
 (0)