[clean-list] Sub-arrays
Matthew Bromberg
mattcbro at earthlink.net
Wed May 31 20:22:54 MEST 2006
I am attempting to use clean to develop a fairly complex simulation of a
wireless network.
A fully parameterized simulation of my Matlab code can take days to run,
and I need to run even more
challenging cases. Thus speed is a critical issue. The simulation has a
lot of state variables (hundreds perhaps) set by the user at the start
of a run,
so I'll probably use strict assignment of these variables prior to the
run, after they read from a file.
The real challenge is to handle hundreds of complex valued matrices,
including tasks such as matrix inversion and
matrix multiplies of reasonably large matrices. (The matrix dimension
is anywhere from dimension 32 complex to 100 real).
Now I've been attempting to link to some optimized blas libraries (which
took some time to get working as some of you may have noticed :)).
My matrix type uses a flat array of unboxed reals to hold the matrix
elements. The array must be a unique type, so that
I can call the BLAS library with side effects. However, I need to
support the concept of a sub-array for efficiency reasons.
In particular I need to create another reference to an arbitrary point
in the middle of the array without doing any array copies.
Doing so would support the idea of a 'view' of a matrix, which
essentially is a submatrix consisting of a range of rows and columns (in
consecutive order)
from the original matrix. This concept is very important to support
block recursive matrix algorithms, which give us the best performance.
It is also
convenient any time I want to update or work with a component of the
original matrix (which I plan to do extensively in my simulation.)
The documentation does not provide such a concept as a pointer to the
middle of an array as far as I can tell, but I'll bet it would be
'trivial' to
write some abc code to do it. That is unless array sizing information
is held at a negative offset with respect to the start of the array. If
it's completely
impossible, then I will probably retain an integer offset that will have
to be added to the array pointer inside a C stub. This would be quite
unpleasant and add unnecessarily to the size of the matrix type, add an
additional integer addition for every matrix call as well as an
additional C stub just to massage the array pointer.
Now a matrix 'view' would normally constitute a second reference to the
unique matrix type. However, for block algorithms, these views often
point to non-intersecting components of the matrix, so that, while they
are second references to the original matrix, they are not separate
references with respect to each other. I have no idea if uniquness
typing can even express this relationship. There is a beautiful matrix
representation theory of blocked matrices, such as the quadmatrix
concept (quad-trees) http://www.cs.ucla.edu/~stott/ge/CSD-950039.ps
that yields some of the most efficient algorithms. By the way these
algorithms are perfectly represented using recursive functional
programming, but that's another story.
So my questions are
1) How can I support a reference to the middle of an unboxed array (a
subarray) and
2) How can I make such unique references not be unique with respect to
one another, if the blocks are non overlapping.
Thanks for your help so far. I hope I'm not spamming you with all my
questions.
Regards,
More information about the clean-list
mailing list