Skip to content

Commit

Permalink
Add new instCacheSize flag.
Browse files Browse the repository at this point in the history
- Added new instCacheSize flag that can be used to change the size
  of the instantiation cache.
- Increased the default size of the instantiation cache to better
  handle large models.
  • Loading branch information
perost committed Mar 29, 2016
1 parent 3dc2a24 commit 16226eb
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
25 changes: 13 additions & 12 deletions Compiler/FrontEnd/Inst.mo
Expand Up @@ -215,7 +215,7 @@ algorithm
//Debug.fcall2(Flags.CHECK_MODEL_BALANCE, checkModelBalancing, SOME(path), dae2);

// let the GC collect these as they are used only by Inst!
setGlobalRoot(Global.instHashIndex, emptyInstHashTable());
releaseInstHashTable();
then
(cache,env_2,ih,dae2);

Expand Down Expand Up @@ -282,7 +282,7 @@ algorithm
//print("\nSetSource+DAE: " + realString(System.getTimerIntervalTime()));

// let the GC collect these as they are used only by Inst!
setGlobalRoot(Global.instHashIndex, emptyInstHashTable());
releaseInstHashTable();
then
(cache, env_2, ih, dae);

Expand Down Expand Up @@ -340,7 +340,7 @@ algorithm
Error.addMessage(Error.ERROR_FLATTENING, {cname_str});

// let the GC collect these as they are used only by Inst!
setGlobalRoot(Global.instHashIndex, emptyInstHashTable());
releaseInstHashTable();
then
fail();
end matchcontinue;
Expand Down Expand Up @@ -2654,8 +2654,8 @@ protected function joinExtAlgorithms
input InstTypes.CallingScope inCallingScope;
output list<SCode.AlgorithmSection> outAlg;
algorithm
outAlg := match(inAlg, inExtAlg, inCallingScope)
case (_, _, InstTypes.TYPE_CALL()) then {};
outAlg := match inCallingScope
case InstTypes.TYPE_CALL() then {};
else listAppend(inAlg, inExtAlg);
end match;
end joinExtAlgorithms;
Expand Down Expand Up @@ -5427,19 +5427,20 @@ algorithm
setGlobalRoot(Global.instHashIndex, emptyInstHashTable());
end initInstHashTable;

public function releaseInstHashTable
algorithm
setGlobalRoot(Global.instHashIndex, emptyInstHashTableSized(1));
end releaseInstHashTable;

protected function emptyInstHashTable
"
Returns an empty HashTable.
Using the default bucketsize..
"
"Returns an empty HashTable."
output InstHashTable hashTable;
algorithm
hashTable := emptyInstHashTableSized(BaseHashTable.defaultBucketSize);
hashTable := emptyInstHashTableSized(Flags.getConfigInt(Flags.INST_CACHE_SIZE));
end emptyInstHashTable;

protected function emptyInstHashTableSized
"Returns an empty HashTable.
Using the bucketsize size"
"Returns an empty HashTable, using the given bucket size."
input Integer size;
output InstHashTable hashTable;
algorithm
Expand Down
13 changes: 11 additions & 2 deletions Compiler/Util/BaseHashTable.mo
Expand Up @@ -397,11 +397,20 @@ public function dumpHashTable
protected
FuncKeyString printKey;
FuncValString printValue;
Key k;
Value v;
algorithm
(_, _, _, _, (_, _, printKey, printValue)) := t;
print("HashTable:\n");
print(stringDelimitList(List.map2(hashTableList(t), dumpTuple, printKey, printValue), "\n"));
print("\n");

for entry in hashTableList(t) loop
(k, v) := entry;
print("{");
print(printKey(k));
print(",{");
print(printValue(v));
print("}}\n");
end for;
end dumpHashTable;

protected function dumpTuple
Expand Down
9 changes: 7 additions & 2 deletions Compiler/Util/Flags.mo
Expand Up @@ -1227,10 +1227,14 @@ constant ConfigFlag HETS = CONFIG_FLAG(88, "hets",
("none", Util.gettext("do nothing")),
("derCalls", Util.gettext("sort terms based on der-calls"))
})),
Util.gettext("heuristic euqtion terms sort"));
Util.gettext("Heuristic equation terms sort"));
constant ConfigFlag DEFAULT_CLOCK_PERIOD = CONFIG_FLAG(89, "defaultClockPeriod",
NONE(), INTERNAL(), REAL_FLAG(1.0), NONE(),
Util.gettext("Sets the default clock period (in seconds) for state machines (default: 1.0)."));
constant ConfigFlag INST_CACHE_SIZE = CONFIG_FLAG(90, "instCacheSize",
NONE(), EXTERNAL(), INT_FLAG(250007), NONE(),
Util.gettext("Sets the size of the internal hash table used for instantiation caching."));


protected
// This is a list of all configuration flags. A flag can not be used unless it's
Expand Down Expand Up @@ -1325,7 +1329,8 @@ constant list<ConfigFlag> allConfigFlags = {
INIT_OPT_MODULES_SUB,
PERMISSIVE,
HETS,
DEFAULT_CLOCK_PERIOD
DEFAULT_CLOCK_PERIOD,
INST_CACHE_SIZE
};

public function new
Expand Down

0 comments on commit 16226eb

Please sign in to comment.