#2505 closed defect (fixed)
Code generation fails for a simple model
Reported by: | Lennart Ochel | Owned by: | Adrian Pop |
---|---|---|---|
Priority: | blocker | Milestone: | 1.9.1 |
Component: | Frontend | Version: | trunk |
Keywords: | Cc: |
Description
Code generation fails for the following simple model:
model Unnamed block activationCon parameter input Integer nIn; parameter input Integer nOut; input Real tIn[:]; input Real tOut[:]; input Integer tIntIn[:]; input Integer tIntOut[:]; input Integer arcType[:]; input Real arcWeightIn[:]; input Real arcWeightOut[:]; input Integer arcWeightIntIn[:]; input Integer arcWeightIntOut[:]; input Real minTokens[:]; input Real maxTokens[:]; input Integer minTokensInt[:]; input Integer maxTokensInt[:]; input Boolean firingCon; input Boolean fed[:]; input Boolean emptied[:]; input Boolean disPlaceIn[:]; input Boolean disPlaceOut[:]; input Real testValue[:]; input Integer testValueInt[:]; input Integer normalArc[:]; input Boolean testChange[:]; output Boolean active; output Boolean weaklyInputActiveVec[nIn]; output Boolean weaklyOutputActiveVec[nOut]; algorithm active:=true; weaklyInputActiveVec:=fill(false, nIn); weaklyOutputActiveVec:=fill(false, nOut); for i in 1:nIn loop if disPlaceIn[i] then if arcType[i]==1 and not (tIntIn[i]-arcWeightIntIn[i] >= minTokensInt[i]) then active:=false; elseif arcType[i]==2 and not (tIntIn[i] > testValueInt[i]) then active:=false; elseif arcType[i]==3 and not (tIntIn[i] < testValueInt[i]) then active:=false; end if; else if arcType[i]==1 or normalArc[i]==2 then if not (tIn[i]>minTokens[i] or (tIn[i]<=minTokens[i] and fed[i])) then active:=false; elseif tIn[i]<=minTokens[i] and fed[i] then weaklyInputActiveVec[i]:=true; end if; end if; if arcType[i]==2 then if not (tIn[i] > testValue[i]) then active:=false; end if; if testChange[i] and fed[i] and normalArc[i]==2 then weaklyInputActiveVec[i]:=true; end if; elseif arcType[i]==3 and not (tIn[i] < testValue[i]) then active:=false; end if; end if; end for; for i in 1:nOut loop if disPlaceOut[i] then if not (tIntOut[i]+arcWeightIntOut[i]<=maxTokensInt[i]) then active:=false; end if; else if not (tOut[i]<maxTokens[i] or (tOut[i]>=maxTokens[i] and emptied[i])) then active:=false; elseif tOut[i]>=maxTokens[i] and emptied[i] then weaklyOutputActiveVec[i]:=true; end if; end if; end for; active:=active and firingCon; weaklyOutputActiveVec:=weaklyOutputActiveVec and fill(firingCon,nOut); weaklyInputActiveVec:=weaklyInputActiveVec and fill(firingCon,nIn); end activationCon; activationCon activation(nIn=0, nOut=0, tIn=fill(0, 0), tOut=fill(0, 0), tIntIn=fill(0, 0), tIntOut=fill(0, 0), arcType=fill(0, 0), arcWeightIn=fill(0, 0), arcWeightOut=fill(0, 0), arcWeightIntIn=fill(0, 0), arcWeightIntOut=fill(0, 0), minTokens=fill(0, 0), maxTokens=fill(0, 0), minTokensInt=fill(0, 0), maxTokensInt=fill(0, 0), firingCon=false, fed=fill(false, 0), emptied=fill(false, 0), disPlaceIn=fill(false, 0), disPlaceOut=fill(false, 0), testValue=fill(0, 0), testValueInt=fill(0, 0), normalArc=fill(0, 0), testChange=fill(false, 0)); end Unnamed;
Error message:
Unnamed.c: In function 'eqFunction_4': Unnamed.c:354: error: '$Pactivation$PweaklyInputActiveVec' undeclared (first use in this function) Unnamed.c:354: error: (Each undeclared identifier is reported only once Unnamed.c:354: error: for each function it appears in.) Unnamed.c:532: error: '$Pactivation$PweaklyOutputActiveVec' undeclared (first use in this function) mingw32-make: *** [Unnamed.o] Error 1 mingw32-make: *** Waiting for unfinished jobs.... Unnamed_06inz.c: In function 'eqFunction_2': Unnamed_06inz.c:340: error: '$Pactivation$PweaklyInputActiveVec' undeclared (first use in this function) Unnamed_06inz.c:340: error: (Each undeclared identifier is reported only once Unnamed_06inz.c:340: error: for each function it appears in.) Unnamed_06inz.c:518: error: '$Pactivation$PweaklyOutputActiveVec' undeclared (first use in this function) mingw32-make: *** [Unnamed_06inz.o] Error 1 Compilation process exited with code 2
Change History (7)
comment:1 by , 11 years ago
comment:2 by , 11 years ago
Component: | Code Generation → Backend |
---|---|
Owner: | changed from | to
Status: | new → assigned |
Yes, Adrian is right, the corresponding variable is removed from the DAE.
Somewhere we need to analyse the algorithm section, and detect that the for loop doesn't do anything, so it should removed. The question is where we want to do that, I guess not in code generation phase.
comment:3 by , 11 years ago
The flattened code of the model looks like:
class Unnamed parameter input Integer activation.nIn = 0; parameter input Integer activation.nOut = 0; input Boolean activation.firingCon = false; output Boolean activation.active; equation activation.tIn = {}; activation.tOut = {}; activation.tIntIn = {}; activation.tIntOut = {}; activation.arcType = {}; activation.arcWeightIn = {}; activation.arcWeightOut = {}; activation.arcWeightIntIn = {}; activation.arcWeightIntOut = {}; activation.minTokens = {}; activation.maxTokens = {}; activation.minTokensInt = {}; activation.maxTokensInt = {}; activation.fed = {}; activation.emptied = {}; activation.disPlaceIn = {}; activation.disPlaceOut = {}; activation.testValue = {}; activation.testValueInt = {}; activation.normalArc = {}; activation.testChange = {}; algorithm activation.active := true; for i in 1:activation.nIn loop if {}[i] then if {}[i] == 1 and not 0 >= {}[i] then activation.active := false; elseif {}[i] == 2 and not {}[i] > {}[i] then activation.active := false; elseif {}[i] == 3 and not {}[i] < {}[i] then activation.active := false; end if; else if {}[i] == 1 or {}[i] == 2 then if not ({}[i] > {}[i] or {}[i] <= {}[i] and {}[i]) then activation.active := false; elseif {}[i] <= {}[i] and {}[i] then activation.weaklyInputActiveVec[i] := true; end if; end if; if {}[i] == 2 then if not {}[i] > {}[i] then activation.active := false; end if; if {}[i] and {}[i] == 2 then activation.weaklyInputActiveVec[i] := true; end if; elseif {}[i] == 3 and not {}[i] < {}[i] then activation.active := false; end if; end if; end for; for i in 1:activation.nOut loop if {}[i] then if not 2 * {}[i] <= {}[i] then activation.active := false; end if; else if not ({}[i] < {}[i] or {}[i] >= {}[i] and {}[i]) then activation.active := false; elseif {}[i] >= {}[i] and {}[i] then activation.weaklyOutputActiveVec[i] := true; end if; end if; end for; activation.active := activation.active and activation.firingCon; end Unnamed;
comment:4 by , 11 years ago
The question is if we should remove the for loops which are from 1 to 0 during front-end.
The problem is that they are based on parameters, but also the arrays we're removing are based on parameters.
I think that if we remove arrays of 0 size we should also remove for-loops of 0 size.
comment:5 by , 11 years ago
Component: | Backend → Frontend |
---|---|
Owner: | changed from | to
I'll have a look at this, as it seems to be a front-end issue.
We either should not remove zero size arrays from the DAE or remove everything that is zero sized, including for and while loops.
comment:7 by , 11 years ago
Thanks for that fix! Thus, much more PNlib tests are working (see r18613).
Note that when array sizes are zero some things start to disappear from the DAE.
So this might not actually be a codegen issue. Have a look at the flattened code.