Skip to content

Commit

Permalink
- way faster matrix creation (speedup of about 50% for some AVM models)
Browse files Browse the repository at this point in the history
- when using Boehm GC do not explicitely call GC_collect_a_little during simulation


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@19943 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Apr 3, 2014
1 parent ad5d5df commit 72388bc
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 14 deletions.
48 changes: 35 additions & 13 deletions Compiler/Template/CodegenC.tpl
Expand Up @@ -9128,22 +9128,44 @@ template daeExpMatrix(Exp exp, Context context, Text &preExp /*BUFP*/,
let &preExp += 'alloc_<%arrayTypeStr%>(&<%tmp%>, 2, 0, 1);<%\n%>'
tmp
case m as MATRIX(__) then
let typeStr = expTypeShort(m.ty)
let arrayTypeStr = expTypeArray(m.ty)
let &vars2 = buffer "" /*BUFD*/
let &promote = buffer "" /*BUFD*/
let catAlloc = (m.matrix |> row =>
match typeStr
// faster creation of the matrix for basic types
case "real"
case "integer"
case "boolean" then
let tmp = tempDecl(arrayTypeStr, &varDecls /*BUFD*/)
let vars = daeExpMatrixRow(row, arrayTypeStr, context,
let rows = '<%listLength(m.matrix)%>'
let cols = '<%listLength(listGet(m.matrix, 1))%>'
let matrix = (m.matrix |> row hasindex i0 =>
let els = (row |> e hasindex j0 =>
let expVar = daeExp(e, context, &preExp /*BUFC*/, &varDecls /*BUFD*/)
'put_<%typeStr%>_matrix_element(<%expVar%>, <%i0%>, <%j0%>, &<%tmp%>);' ;separator="\n")
'<%els%>'
;separator="\n")
let &preExp += '/* -- start: matrix[<%rows%>,<%cols%>] -- */<%\n%>'
let &preExp += 'alloc_<%typeStr%>_array(&<%tmp%>, 2, <%rows%>, <%cols%>);<%\n%>'
let &preExp += '<%matrix%><%\n%>'
let &preExp += '/* -- end: matrix[<%rows%>,<%cols%>] -- */<%\n%>'
tmp
// everything else
case _ then
let &vars2 = buffer "" /*BUFD*/
let &promote = buffer "" /*BUFD*/
let catAlloc = (m.matrix |> row =>
let tmp = tempDecl(arrayTypeStr, &varDecls /*BUFD*/)
let vars = daeExpMatrixRow(row, arrayTypeStr, context,
&promote /*BUFC*/, &varDecls /*BUFD*/)
let &vars2 += ', &<%tmp%>'
'cat_alloc_<%arrayTypeStr%>(2, &<%tmp%>, <%listLength(row)%><%vars%>);'
;separator="\n")
let &preExp += promote
let &preExp += catAlloc
let &preExp += "\n"
let tmp = tempDecl(arrayTypeStr, &varDecls /*BUFD*/)
let &preExp += 'cat_alloc_<%arrayTypeStr%>(1, &<%tmp%>, <%listLength(m.matrix)%><%vars2%>);<%\n%>'
tmp
let &vars2 += ', &<%tmp%>'
'cat_alloc_<%arrayTypeStr%>(2, &<%tmp%>, <%listLength(row)%><%vars%>);'
;separator="\n")
let &preExp += promote
let &preExp += catAlloc
let &preExp += "\n"
let tmp = tempDecl(arrayTypeStr, &varDecls /*BUFD*/)
let &preExp += 'cat_alloc_<%arrayTypeStr%>(1, &<%tmp%>, <%listLength(m.matrix)%><%vars2%>);<%\n%>'
tmp
end daeExpMatrix;


Expand Down
7 changes: 6 additions & 1 deletion SimulationRuntime/c/util/memory_pool.c
Expand Up @@ -39,13 +39,18 @@
extern "C" {
#endif

static int GC_collect_a_little_or_not(void)
{
return 0;
}

omc_alloc_interface_t omc_alloc_interface = {
GC_init,
GC_malloc,
GC_malloc_atomic,
(char*(*)(size_t)) GC_malloc_atomic,
GC_strdup,
GC_collect_a_little
GC_collect_a_little_or_not
};

typedef struct list_s {
Expand Down

0 comments on commit 72388bc

Please sign in to comment.