Am 10.07.2011 16:42, schrieb Vitalie Ciubotaru:
Hi,
I am facing a scalability problem when working with matrix elements.
Below is a fragment of the script I am working with.
</script>
nulldata 1000
scalar nobs_full = $nobs
scalar nmc = 400
...
# generate a matrix of zeros, with rows = number of obs, cols = number
of Monte Carlo runs
matrix M = zeros(nobs_full, nmc)
# outer loop for operations on rows (actually, series of data)
loop for j=1..nmc --progressive --quiet
# series-wise operations go here
...
genr y_new = constant + 0.5 * x1 + 0.5 * x2 # an example
...
#inner loop for operations on elements of matrix
loop for i=2..nobs_full --progressive --quiet
# element-wise operations go here
...
M[i,j] += exp(y_new[i]) * M[i-1,j] # an example
...
endloop
endloop
</script>
The amount of calculation is proportionate to matrix size (generate
series and perform element-wise operations), no regressions, no matrix
manipulations. I did some quick tests and here are the results:
* Create a matrix 1000x20, run 1000 iterations (inner loop) time 20
iterations (outer loop). Time: 7 seconds.
* Matrix 1000x40, 1000 iterations by 40 iterations. Time:33 seconds.
* Matrix 1000x100, 1000 iterations by 100 iterations. Time: 4 minutes 21
seconds.
It looks like the problem is not in the loops, but in the way gretl
handles matrices, because:
* Matrix 1000x40, 1000 iterations by 20 iterations (affecting only the
first 20 columns of the matrix). Time: 15 seconds.
* Matrix 1000x60, 1000 iterations by 20 iterations (affecting only the
first 20 columns of the matrix). Time: 24 seconds.
* Matrix 1000x100, 1000 iterations by 20 iterations (affecting only the
first 20 columns of the matrix). Time: 41 second.
Actually, I was planning to test a matrix of size 1000x400, but it would
have taken too much time.
I'm not sure I understand your point (but I admit I haven't looked very
carefully). As a first reaction, I would not always expect an operation
to take (only) 10 times longer when the size is 10 times bigger. For
example, maybe the latency and speed differences of various CPU caches
and RAM could be a factor. Your numbers do not look totally weird in the
sense of necessarily indicating a bug. But maybe I'm missing the point
(as I said).
cheers,
sven