Skip to content

Commit

Permalink
- use -O3 for omc_release and -pg for omc_profiler
Browse files Browse the repository at this point in the history
- have an (key,value) array of 70% of bucket size in hashtables instead of size/10!
- faster
   false = Expression.expHasCrefs(e) 
  to be used instead 
   {} = Expression.extractCrefsFromExp(e);
- smaller hastable sizes in SimCode.translateFunctions
- Hashtables do not take second size anymore, just bucket size.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@8796 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed May 3, 2011
1 parent 8659c1b commit 4392dec
Show file tree
Hide file tree
Showing 18 changed files with 122 additions and 65 deletions.
7 changes: 2 additions & 5 deletions Compiler/BackEnd/BackendVarTransform.mo
Expand Up @@ -94,14 +94,11 @@ algorithm
end emptyReplacements;

public function emptyReplacementsSized "function: emptyReplacements

Returns an empty set of replacement rules, giving a size of hashtables to allocate
"
Returns an empty set of replacement rules, giving a size of hashtables to allocate"
input Integer size;
output VariableReplacements outVariableReplacements;
algorithm
outVariableReplacements:=
match (size)
outVariableReplacements := match (size)
local HashTable2.HashTable ht,eht;
HashTable3.HashTable invHt;
case (size)
Expand Down
12 changes: 10 additions & 2 deletions Compiler/BackEnd/SimCode.mo
Expand Up @@ -1313,7 +1313,11 @@ algorithm
case (name, SOME(daeMainFunction), daeElements, metarecordTypes, includes)
equation
// Create FunctionCode
(daeElements,(_,(_,_,literals))) = DAEUtil.traverseDAEFunctions(daeMainFunction::daeElements,Expression.traverseSubexpressionsHelper,(replaceLiteralExp,(0,HashTableExpToIndex.emptyHashTableSized(24971),{})));
(daeElements,(_,(_,_,literals))) =
DAEUtil.traverseDAEFunctions(
daeMainFunction::daeElements,
Expression.traverseSubexpressionsHelper,
(replaceLiteralExp,(0,HashTableExpToIndex.emptyHashTableSized(BaseHashTable.bigBucketSize),{})));
literals = listReverse(literals);
(mainFunction::fns, extraRecordDecls, includes, libs) = elaborateFunctions(daeElements, metarecordTypes, literals, includes);
checkValidMainFunction(name, mainFunction);
Expand All @@ -1326,7 +1330,11 @@ algorithm
case (name, NONE(), daeElements, metarecordTypes, includes)
equation
// Create FunctionCode
(daeElements,(_,(_,_,literals))) = DAEUtil.traverseDAEFunctions(daeElements,Expression.traverseSubexpressionsHelper,(replaceLiteralExp,(0,HashTableExpToIndex.emptyHashTableSized(24971),{})));
(daeElements,(_,(_,_,literals))) =
DAEUtil.traverseDAEFunctions(
daeElements,
Expression.traverseSubexpressionsHelper,
(replaceLiteralExp,(0,HashTableExpToIndex.emptyHashTableSized(BaseHashTable.bigBucketSize),{})));
literals = listReverse(literals);
(fns, extraRecordDecls, includes, libs) = elaborateFunctions(daeElements, metarecordTypes, literals, includes);
makefileParams = createMakefileParams(libs);
Expand Down
4 changes: 2 additions & 2 deletions Compiler/BackEnd/TaskGraph.mo
Expand Up @@ -353,7 +353,7 @@ algorithm
name = ComponentReference.printComponentRefStr(cr) " Util.string_append_list({\"xd{\",indxs,\"}\"}) => id &" ;
//c_name = Util.modelicaStringToCStr(name,true);
c_name = name;
//id = stringAppendList({BackendDAE.derivativeNamePrefix,c_name});
//id = stringAppendList({DAE.derivativeNamePrefix,c_name});
id = c_name;
cr_1 = ComponentReference.makeCrefIdent(id,DAE.ET_REAL(),{});
varexp = Expression.crefExp(cr_1);
Expand Down Expand Up @@ -388,7 +388,7 @@ algorithm
name = ComponentReference.printComponentRefStr(cr) " Util.string_append_list({\"xd{\",indxs,\"}\"}) => id &" ;
//c_name = Util.modelicaStringToCStr(name,true);
c_name = name;
//id = stringAppendList({BackendDAE.derivativeNamePrefix,c_name});
//id = stringAppendList({DAE.derivativeNamePrefix,c_name});
id = c_name;
cr_1 = ComponentReference.makeCrefIdent(id,DAE.ET_REAL(),{});
varexp = Expression.crefExp(cr_1);
Expand Down
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/DAE.mo
Expand Up @@ -55,7 +55,7 @@ public type StartValue = Option<Exp>;

public constant String UNIQUEIO = "$unique$outer$";

public constant String derivativeNamePrefix="$DER";
public constant String derivativeNamePrefix = "$DER";


public uniontype VarKind
Expand Down
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/DAEUtil.mo
Expand Up @@ -2547,7 +2547,7 @@ algorithm
then e;
case (e,_)
equation
{} = Expression.extractCrefsFromExp(e);
false = Expression.expHasCrefs(e); // {} = Expression.extractCrefsFromExp(e);
then e;
case (e,pv)
equation
Expand Down
43 changes: 41 additions & 2 deletions Compiler/FrontEnd/Expression.mo
Expand Up @@ -4067,12 +4067,50 @@ algorithm
end match;
end extractCrefsFromExp;

public function expHasCrefs "
@author: adrpo 2011-04-29
returns true if the expression contains crefs"
input DAE.Exp inExp;
output Boolean hasCrefs;
algorithm
hasCrefs := match(inExp)
local
Boolean b;

case(inExp)
equation
((_,b)) = traverseExp(inExp, traversingComponentRefPresent, false);
then
b;
end match;
end expHasCrefs;

public function traversingComponentRefPresent "
@author: adrpo 2011-04
Returns a true if the exp is a componentRef"
input tuple<DAE.Exp, Boolean> inExp;
output tuple<DAE.Exp, Boolean> outExp;
algorithm
outExp := matchcontinue(inExp)
local
Boolean b;
DAE.Exp e;

case((e as DAE.CREF(componentRef = _), b))
then
((e, true));

case(inExp) then inExp;

end matchcontinue;
end traversingComponentRefPresent;

public function traversingComponentRefFinder "
Author: BZ 2008-06
Exp traverser that Union the current ComponentRef with list if it is already there.
Returns a list containing, unique, all componentRef in an Expression."
input tuple<DAE.Exp, list<ComponentRef> > inExp;
output tuple<DAE.Exp, list<ComponentRef> > outExp;
input tuple<DAE.Exp, list<ComponentRef>> inExp;
output tuple<DAE.Exp, list<ComponentRef>> outExp;
algorithm
outExp := matchcontinue(inExp)
local
Expand All @@ -4084,6 +4122,7 @@ algorithm
case((e as DAE.CREF(cr,ty), crefs))
equation
crefs = Util.listUnionEltOnTrue(cr,crefs,ComponentReference.crefEqual);
// e = makeCrefExp(cr,ty);
then
((e, crefs ));

Expand Down
10 changes: 4 additions & 6 deletions Compiler/FrontEnd/Inst.mo
Expand Up @@ -15074,22 +15074,20 @@ end opaqVal;
public function emptyInstHashTable
"
Returns an empty HashTable.
Using the bucketsize 1000 and array size 100.
Using the default bucketsize..
"
output InstHashTable hashTable;
algorithm
hashTable := emptyInstHashTableSized(BaseHashTable.defaultBucketSize);
end emptyInstHashTable;

public function emptyInstHashTableSized
"
Returns an empty HashTable.
Using the bucketsize size and arraysize size/10.
"
"Returns an empty HashTable.
Using the bucketsize size"
input Integer size;
output InstHashTable hashTable;
algorithm
hashTable := BaseHashTable.emptyHashTableWork(size,intDiv(size,10),(Absyn.pathHashMod,Absyn.pathEqual,Absyn.pathString,opaqVal));
hashTable := BaseHashTable.emptyHashTableWork(size,(Absyn.pathHashMod,Absyn.pathEqual,Absyn.pathString,opaqVal));
end emptyInstHashTableSized;

/* end HashTable */
Expand Down
31 changes: 27 additions & 4 deletions Compiler/Util/BaseHashTable.mo
Expand Up @@ -57,12 +57,33 @@ protected import Util;
// Generic hashtable code below

// adrpo: use a prime here (pick your poison):
// 1013 2053 3023 4013 4999 5051 5087 24971
public constant Integer defaultBucketSize = 2053;
// 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67
// 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157
// 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257
// 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367
// 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467
// 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599
// 601 607 613 617 619 631 641 643 647 653 659 661 673 677 683 691 701 709
// 719 727 733 739 743 751 757 761 769 773 787 797 809 811 821 823 827 829
// 839 853 857 859 863 877 881 883 887 907 911 919 929 937 941 947 953 967
// 971 977 983 991 997 1013 2053 3023 4013 4999 5051 5087 24971

public constant Integer lowBucketSize = 257;
public constant Integer avgBucketSize = 2053;
public constant Integer bigBucketSize = 4013;
public constant Integer defaultBucketSize = avgBucketSize;

protected function bucketToValuesSize
"calculate the values array size based on the bucket size"
input Integer szBucket;
output Integer szArr;
algorithm
szArr := realInt(realMul(intReal(szBucket), 0.7)); // intDiv(szBucket, 10);
end bucketToValuesSize;


public function emptyHashTableWork
input Integer szBucket;
input Integer szArr;
input FuncsTuple fntpl;
output HashTable hashTable;
protected
Expand All @@ -80,8 +101,10 @@ protected
partial function FuncEq input Key key1; input Key key2; output Boolean b; end FuncEq;
partial function FuncKeyString input Key key; output String str; end FuncKeyString;
partial function FuncValString input Value val; output String str; end FuncValString;
Integer szArr;
algorithm
arr := arrayCreate(szBucket, {});
szArr := bucketToValuesSize(szBucket);
emptyarr := arrayCreate(szArr, NONE());
hashTable := (arr,(0,szArr,emptyarr),szBucket,0,fntpl);
end emptyHashTableWork;
Expand Down Expand Up @@ -564,7 +587,7 @@ algorithm
expandsize = realInt(rexpandsize);
expandsize_1 = intMax(expandsize, 1);
newsize = expandsize_1 + size;
arr_1 = Util.arrayExpand(expandsize_1, arr,NONE());
arr_1 = Util.arrayExpand(expandsize_1, arr, NONE());
n_1 = n + 1;
arr_2 = arrayUpdate(arr_1, n + 1, SOME(entry));
then
Expand Down
10 changes: 4 additions & 6 deletions Compiler/Util/HashTable.mo
Expand Up @@ -65,22 +65,20 @@ end FuncExpStr;
public function emptyHashTable
"
Returns an empty HashTable.
Using the bucketsize 1000 and array size 100.
Using the default bucketsize..
"
output HashTable hashTable;
algorithm
hashTable := emptyHashTableSized(BaseHashTable.defaultBucketSize);
end emptyHashTable;

public function emptyHashTableSized
"
Returns an empty HashTable.
Using the bucketsize size and arraysize size/10.
"
"Returns an empty HashTable.
Using the bucketsize size"
input Integer size;
output HashTable hashTable;
algorithm
hashTable := BaseHashTable.emptyHashTableWork(size,intDiv(size,10),(HashTable2.hashFunc,ComponentReference.crefEqual,ComponentReference.printComponentRefStr,intString));
hashTable := BaseHashTable.emptyHashTableWork(size,(HashTable2.hashFunc,ComponentReference.crefEqual,ComponentReference.printComponentRefStr,intString));
end emptyHashTableSized;

end HashTable;
10 changes: 4 additions & 6 deletions Compiler/Util/HashTable2.mo
Expand Up @@ -78,22 +78,20 @@ end hashFunc;
public function emptyHashTable
"
Returns an empty HashTable.
Using the bucketsize 1000 and array size 100.
Using the default bucketsize..
"
output HashTable hashTable;
algorithm
hashTable := emptyHashTableSized(BaseHashTable.defaultBucketSize);
end emptyHashTable;

public function emptyHashTableSized
"
Returns an empty HashTable.
Using the bucketsize size and arraysize size/10.
"
"Returns an empty HashTable.
Using the bucketsize size."
input Integer size;
output HashTable hashTable;
algorithm
hashTable := BaseHashTable.emptyHashTableWork(size,intDiv(size,10),(hashFunc,ComponentReference.crefEqual,ComponentReference.printComponentRefStr,ExpressionDump.printExpStr));
hashTable := BaseHashTable.emptyHashTableWork(size,(hashFunc,ComponentReference.crefEqual,ComponentReference.printComponentRefStr,ExpressionDump.printExpStr));
end emptyHashTableSized;

end HashTable2;
10 changes: 4 additions & 6 deletions Compiler/Util/HashTable3.mo
Expand Up @@ -65,22 +65,20 @@ end FuncExpStr;
public function emptyHashTable
"
Returns an empty HashTable.
Using the bucketsize 1000 and array size 100.
Using the default bucketsize..
"
output HashTable hashTable;
algorithm
hashTable := emptyHashTableSized(BaseHashTable.defaultBucketSize);
end emptyHashTable;

public function emptyHashTableSized
"
Returns an empty HashTable.
Using the bucketsize size and arraysize size/10.
"
"Returns an empty HashTable.
Using the bucketsize size."
input Integer size;
output HashTable hashTable;
algorithm
hashTable := BaseHashTable.emptyHashTableWork(size,intDiv(size,10),(HashTable2.hashFunc,ComponentReference.crefEqual,ComponentReference.printComponentRefStr,ComponentReference.printComponentRefListStr));
hashTable := BaseHashTable.emptyHashTableWork(size,(HashTable2.hashFunc,ComponentReference.crefEqual,ComponentReference.printComponentRefStr,ComponentReference.printComponentRefListStr));
end emptyHashTableSized;

end HashTable3;
10 changes: 4 additions & 6 deletions Compiler/Util/HashTable4.mo
Expand Up @@ -79,22 +79,20 @@ end hashFunc;
public function emptyHashTable
"
Returns an empty HashTable.
Using the bucketsize 1000 and array size 100.
Using the default bucketsize..
"
output HashTable hashTable;
algorithm
hashTable := emptyHashTableSized(BaseHashTable.defaultBucketSize);
end emptyHashTable;

public function emptyHashTableSized
"
Returns an empty HashTable.
Using the bucketsize size and arraysize size/10.
"
"Returns an empty HashTable.
Using the bucketsize size."
input Integer size;
output HashTable hashTable;
algorithm
hashTable := BaseHashTable.emptyHashTableWork(size,intDiv(size,10),(hashFunc,Expression.expEqual,ExpressionDump.printExpStr,ComponentReference.printComponentRefStr));
hashTable := BaseHashTable.emptyHashTableWork(size,(hashFunc,Expression.expEqual,ExpressionDump.printExpStr,ComponentReference.printComponentRefStr));
end emptyHashTableSized;

end HashTable4;
6 changes: 3 additions & 3 deletions Compiler/Util/HashTable5.mo
Expand Up @@ -77,7 +77,7 @@ end hashFunc;
public function emptyHashTable
"
Returns an empty HashTable.
Using the bucketsize 1000 and array size 100.
Using the default bucketsize..
"
output HashTable hashTable;
algorithm
Expand All @@ -87,12 +87,12 @@ end emptyHashTable;
public function emptyHashTableSized
"
Returns an empty HashTable.
Using the bucketsize size and arraysize size/10.
Using the bucketsize size.
"
input Integer size;
output HashTable hashTable;
algorithm
hashTable := BaseHashTable.emptyHashTableWork(size,intDiv(size,10),(hashFunc,Absyn.crefEqual,Dump.printComponentRefStr,intString));
hashTable := BaseHashTable.emptyHashTableWork(size,(hashFunc,Absyn.crefEqual,Dump.printComponentRefStr,intString));
end emptyHashTableSized;

end HashTable5;
6 changes: 3 additions & 3 deletions Compiler/Util/HashTable6.mo
Expand Up @@ -99,7 +99,7 @@ end printKey;
public function emptyHashTable
"
Returns an empty HashTable.
Using the bucketsize 1000 and array size 100.
Using the default bucketsize..
"
output HashTable hashTable;
algorithm
Expand All @@ -109,12 +109,12 @@ end emptyHashTable;
public function emptyHashTableSized
"
Returns an empty HashTable.
Using the bucketsize size and arraysize size/10.
Using the bucketsize size.
"
input Integer size;
output HashTable hashTable;
algorithm
hashTable := BaseHashTable.emptyHashTableWork(size,intDiv(size,10),(hashFunc,keyEqual,printKey,ExpressionDump.printExpStr));
hashTable := BaseHashTable.emptyHashTableWork(size,(hashFunc,keyEqual,printKey,ExpressionDump.printExpStr));
end emptyHashTableSized;

end HashTable6;

0 comments on commit 4392dec

Please sign in to comment.