Skip to content

Commit

Permalink
Fix scalability issue in NFUnitCheck
Browse files Browse the repository at this point in the history
Set the cref hashtable to an appropriate size at the start.

Also re-added the `-d=-frontEndUnitCheck` flag which was previously
not used in the new frontend always enabling the unit checking. This
has the default set to true with the ability to disable the phase.

Belonging to [master]:
  - OpenModelica/OMCompiler#1978
  - OpenModelica/OpenModelica-testsuite#764
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Nov 6, 2017
1 parent 9e0eb5f commit 037d5bb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/Inst.mo
Expand Up @@ -329,7 +329,7 @@ algorithm
case (cache,ih,cdecls as _::_,path)
equation
(outCache,outEnv,outIH,outDAElist) = instantiateClass_dispatch(cache,ih,cdecls,path,doSCodeDep);
if Flags.isSet(Flags.NF_UNITCHECK) then
if Flags.isSet(Flags.OLD_FE_UNITCHECK) then
NFUnitCheck.checkUnits(outDAElist,FCore.getFunctionTree(outCache));
end if;
then
Expand Down
26 changes: 14 additions & 12 deletions Compiler/NFFrontEnd/NFUnitCheck.mo
Expand Up @@ -52,13 +52,16 @@ protected
NFHashTableStringToUnit.HashTable HtS2U;
NFHashTableUnitToString.HashTable HtU2S;
algorithm
if not Flags.isSet(Flags.NF_UNITCHECK) then
return;
end if;
try
(elts1, elts2) := DAEUtil.splitDAEIntoVarsAndEquations(inDAE);
varlist := GetVarList(elts1);
eqlist := GetElementList(elts2);
functionlist := DAEUtil.getFunctionList(func);

HtCr2U1 := NFHashTableCrToUnit.emptyHashTableSized(2053);
HtCr2U1 := NFHashTableCrToUnit.emptyHashTableSized(Util.nextPrime(integer(10+1.4*listLength(varlist))));
HtS2U := NFUnit.getKnownUnits();
HtU2S := NFUnit.getKnownUnitsInverse();

Expand All @@ -68,7 +71,6 @@ algorithm

// new instantiation
//((HtCr2U1, HtS2U, HtU2S)) := List.fold(varlist, convertUnitString2unit, (HtCr2U1, HtS2U, HtU2S));

// old instantiation
((HtCr2U1, HtS2U, HtU2S)) := List.fold(varlist, convertUnitString2unit_old, (HtCr2U1, HtS2U, HtU2S));
HtCr2U2 := BaseHashTable.copy(HtCr2U1);
Expand Down Expand Up @@ -1368,18 +1370,18 @@ protected function parse "author: lochel"
output NFHashTableStringToUnit.HashTable outHtS2U = inHtS2U;
output NFHashTableUnitToString.HashTable outHtU2S = inHtU2S;
algorithm
if inUnitString == "" then
outUnit := NFUnit.MASTER({inCref});
return;
end if;
try
outUnit := BaseHashTable.get(inUnitString, inHtS2U);
outUnit := BaseHashTable.get(inUnitString, inHtS2U);
else
outUnit := matchcontinue(inUnitString)
case ""
then NFUnit.MASTER({inCref});

case _
then NFUnit.parseUnitString(inUnitString, inHtS2U);

else NFUnit.UNKNOWN(inUnitString);
end matchcontinue;
try
outUnit := NFUnit.parseUnitString(inUnitString, inHtS2U);
else
outUnit := NFUnit.UNKNOWN(inUnitString);
end try;
outHtS2U := addUnit2HtS2U((inUnitString, outUnit), outHtS2U);
outHtU2S := addUnit2HtU2S((inUnitString, outUnit), outHtU2S);
end try;
Expand Down
7 changes: 5 additions & 2 deletions Compiler/Util/Flags.mo
Expand Up @@ -508,7 +508,7 @@ constant DebugFlag PARTITION_INITIALIZATION = DEBUG_FLAG(166, "partitionInitiali
Util.gettext("This flag controls if partitioning is applied to the initialization system."));
constant DebugFlag EVAL_PARAM_DUMP = DEBUG_FLAG(167, "evalParameterDump", false,
Util.gettext("Dumps information for evaluating parameters."));
constant DebugFlag NF_UNITCHECK = DEBUG_FLAG(168, "frontEndUnitCheck", false,
constant DebugFlag NF_UNITCHECK = DEBUG_FLAG(168, "frontEndUnitCheck", true,
Util.gettext("Checks the consistency of units in equation."));
constant DebugFlag DISABLE_COLORING = DEBUG_FLAG(169, "disableColoring", false,
Util.gettext("Disables coloring algorithm while spasity detection."));
Expand All @@ -522,6 +522,8 @@ constant DebugFlag ALIAS_CONFLICTS = DEBUG_FLAG(173, "aliasConflicts", false,
Util.gettext("Dumps alias sets with different start or nominal values."));
constant DebugFlag SUSAN_MATCHCONTINUE_DEBUG = DEBUG_FLAG(174, "susanDebug", false,
Util.gettext("Makes Susan generate code using try/else to better debug which function broke the expected match semantics."));
constant DebugFlag OLD_FE_UNITCHECK = DEBUG_FLAG(175, "oldFrontEndUnitCheck", false,
Util.gettext("Checks the consistency of units in equation (for the old front-end)."));

// This is a list of all debug flags, to keep track of which flags are used. A
// flag can not be used unless it's in this list, and the list is checked at
Expand Down Expand Up @@ -702,7 +704,8 @@ constant list<DebugFlag> allDebugFlags = {
WARN_NO_NOMINAL,
IGNORE_CYCLES,
ALIAS_CONFLICTS,
SUSAN_MATCHCONTINUE_DEBUG
SUSAN_MATCHCONTINUE_DEBUG,
OLD_FE_UNITCHECK
};

public
Expand Down

0 comments on commit 037d5bb

Please sign in to comment.