Skip to content

Commit

Permalink
Fix initialization of reductions in Cpp runtime (#7650)
Browse files Browse the repository at this point in the history
* Fix initialization of reductions in Cpp and C runtime

`foldExpPre` had been declared but not used. This resulted in Cpp errors.

See e.g. ModelicaTest.Fluid.TestComponents.Machines.TestWaterPumpCharacteristics
or PowerSystems.Examples.AC3ph.Precalculation.Z_matrixTrDat3
ERROR  : init  : SimManager: Right and left array must have the same size for element wise addition

* Revert fix of initialization of reductions for C runtime
  • Loading branch information
rfranke committed Jul 4, 2021
1 parent 8f503c4 commit d210b0e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
3 changes: 1 addition & 2 deletions OMCompiler/Compiler/Template/CodegenCFunctions.tpl
Expand Up @@ -7052,7 +7052,6 @@ template daeExpReduction(Exp exp, Context context, Text &preExp,
case r as REDUCTION(reductionInfo=ri as REDUCTIONINFO(iterType=COMBINE()),iterators=iterators as {_}) then
(
let &tmpVarDecls = buffer ""
let &tmpExpPre = buffer ""
let &bodyExpPre = buffer ""
let &rangeExpPre = buffer ""
let arrayTypeResult = expTypeFromExpArray(r)
Expand Down Expand Up @@ -7101,7 +7100,7 @@ template daeExpReduction(Exp exp, Context context, Text &preExp,
let fExpStr = daeExp(fExp, context, &bodyExpPre, &tmpVarDecls, &auxFunction)
if foundFirst then
<<
if(<%foundFirst%>)
if (<%foundFirst%>)
{
<%res%> = <%fExpStr%>;
}
Expand Down
10 changes: 4 additions & 6 deletions OMCompiler/Compiler/Template/CodegenCppCommon.tpl
Expand Up @@ -1022,7 +1022,6 @@ template daeExpReduction(Exp exp, Context context, Text &preExp,
case r as REDUCTION(reductionInfo=ri as REDUCTIONINFO(iterType=COMBINE()),iterators=iterators as {_}) then
(
let &tmpVarDecls = buffer ""
let &tmpExpPre = buffer ""
let &bodyExpPre = buffer ""
let &rangeExpPre = buffer ""
let arrayTypeResult = expTypeFromExpArray(r)
Expand Down Expand Up @@ -1087,11 +1086,12 @@ template daeExpReduction(Exp exp, Context context, Text &preExp,
'<%res%>(<%arrIndex%>++) = <%reductionBodyExpr%>;'
else match ri.foldExp case SOME(fExp) then
let &foldExpPre = buffer ""
let fExpStr = daeExp(fExp, context, &bodyExpPre, &tmpVarDecls, simCode, &extraFuncs, &extraFuncsDecl, extraFuncsNamespace, stateDerVectorName, useFlatArrayNotation)
let fExpStr = daeExp(fExp, context, &foldExpPre, &tmpVarDecls, simCode, &extraFuncs, &extraFuncsDecl, extraFuncsNamespace, stateDerVectorName, useFlatArrayNotation)
if foundFirst then
<<
if(<%foundFirst%>)
if (<%foundFirst%>)
{
<%foldExpPre%>
<%res%> = <%fExpStr%>;
}
else
Expand Down Expand Up @@ -1167,10 +1167,8 @@ template daeExpReduction(Exp exp, Context context, Text &preExp,
<%dimSizes%>;
<%res%>.setDims(<%dim_vec%>);
>>

else
'<%res%>.setDims(<%length%>);'%>

>>
else
(if foundFirst then
Expand All @@ -1182,7 +1180,7 @@ template daeExpReduction(Exp exp, Context context, Text &preExp,
<%&preDefault%>
<%res%> = <%defaultValue%>; /* defaultValue */
>>)
)
)
let loop =
<<
while(1) {
Expand Down

0 comments on commit d210b0e

Please sign in to comment.