Re: [eigen] tracking memory usage?

[ Thread Index | Date Index | More Archives ]

2010/9/13 David Roundy <roundyd@xxxxxxxxxxxxxxxxxxxxxxx>:
> Hi all,
> I've written a program using eigen2, without paying too much attention
> either to time or space efficiency.  I'm now confident that the
> program is correct (so far... but it's not complete), and am looking
> to refactor it to reduce memory consumption.
> Ordinarily in C++ I would figure out where the memory is going by
> instrumenting the constructors and destructors of large data types to
> track net memory use and log it (and log who allocated it).  I can do
> the same thing with some of my code in this case (since I derive a
> subclass of VectorXd), but that won't count any actual VectorXds that
> get allocated directly.

You can do several things:
 - first of all, all heap allocations done by eigen go through the few
functions defined in Eigen/src/Core/util/Memory.h. So you would only
have to instrument them, if all you want to do is instrument the heap.
Alternatively, if you run linux, you can use valgrind's various tools.
 - if you want to count Vector/Matrix/Array objects, you only have a
few classes to instrument, since they are all specializations of the
same few classes. Vectors and matrices all are the Matrix<...> class
template, for instance.

> My primary approach I expect to be switching functions that currently
> accept (const VectorXd &) to accept instead somthing like (const
> Eigen::MatrixBase <OtherDerived>&) to enable lazy evaluation of
> expressions.  My understanding is that creating functions that
> *return* a lazily evaluated vector is tricky...

In order to achieve that you have to let it return an expression
object. You need to figure the right return type, probably by reading
Eigen source code: DenseBase.h MatrixBase.h and the files under
src/plugins/ defining the common operators.


> Any suggestions or hints, of approaches that work effectively in
> improving memory use in eigen2 programs? (Or if it'd be worth
> switching to eigen3?)
> Thanks for the great package!
> --
> David Roundy

Mail converted by MHonArc 2.6.19+