Re: [pydstool-users] Improving code generation for constant mass matrix
Status: Beta
Brought to you by:
robclewley
|
From: Juan P. C. <jua...@ug...> - 2013-03-13 22:53:19
|
Hi,
I manage to get my hack in by printing to the C code only the non-zero elements.
The new code for FuncSpec is (between lines 1690 and 1699)
# C integrators expect column-major matrices
for col in range(n):
for row in range(m):
try:
if specdict[specvars[row]][col] != "0" and
specdict[specvars[row]][col] != "0.0": ##Print only nonzero elements
body_processed += "f_[" + str(col) +
"][" + str(row) \
+ "] = " + specdict[specvars[row]][col] + ";\n"
except KeyError:
raise ValueError("Mass matrix should be
%sx%s"%(m,n))
The new compilation times are
rows of matrix, compilation time, ODEsystem constructor time, number
of equations
3 2.3 0.3 37
6 2.9 5.0 181
12 6.4 98.8 793
So now the bottle neck is in the constructor of the generator. I see a
lot of dictionary time which I guess corresponds to the entries of the
zero rows of the mass matrix. A solution would be to not make entry
for zero rows, but I guess this will brake all the code.
Is anybody interested in helping with the implementation of fast
assembly and C code compilation for the case of sparse and constant
mass matrix?
Thank you
The only problem with this is that all the other elements of f_ are
not set to zero. Where is the declaration and initialization of the
**double pointer that is passed to the massMatrix function?
On Wed, Mar 13, 2013 at 10:41 PM, Juan Pablo Carbajal
<jua...@ug...> wrote:
> Hello,
>
> When a DAE is defined with a constant mass matrix the C code generated
> has one line per element in the matrix. This causes very long
> compilation times for big matrices
> number of rows in massmatrix, size of c-code (KB), size of .so (KB),
> time to compile (seconds)
> 3 33 963 2
> 4 102 1100 4
> 5 265 1400 12
> 6 591 1800 58
> 7 1200 2400 238
> 8 2100 3200 831
> When replaced with a nested for loop the compilation time for rows==7
> goes down to 4 seconds.
>
> I tried to improve FuncSpec to print a for loop fr the case of
> constant matrix, but I can't cause the for loop is parsed as a macro
> by QuantSpec.
>
> Is there a way to prevent enumeration of the mass matrix and just get
> code of the kind
>
> # C integrators expect column-major matrices
> body_processed += "unsigned int i,j;\n" + \
> "for (i=0;i<" + str(n) + ";i++)\n" + \
> "\tfor (j=0;j<" + str(m) + ";j++)\n" + \
> "\t\t f_[i][j] = 0;\n\n"
> for col in range(n):
> for row in range(m):
> try:
> if specdict[specvars[row]][col]:
> body_processed += "f_[" + str(col) + "][" + str(row) \
> + "] = " +
> specdict[specvars[row]][col] + ";\n"
>
> (this was my attemp in FuncSpec.py line 1688)
>
> Thanks
>
> --
> ---------------
> Dr. sc. nat. Juan Pablo Carbajal
> Reservoir Computing Lab
> Department of Electronics and Information Systems (ELIS)
> Ghent University
> Sint Pietersnieuwstraat 41
> 9000 Ghent
> Belgium
> web: http://users.elis.ugent.be/~jcarbaja/
--
---------------
Dr. sc. nat. Juan Pablo Carbajal
Reservoir Computing Lab
Department of Electronics and Information Systems (ELIS)
Ghent University
Sint Pietersnieuwstraat 41
9000 Ghent
Belgium
web: http://users.elis.ugent.be/~jcarbaja/
|