From: Georg Baum (Georg.Baum_at_[hidden])
Date: 2007-09-25 04:42:26
Am Dienstag 25 September 2007 10:03 schrieb Peter Schmitteckert:
> Dear Georg,
> Georg Baum wrote:
> > Am Dienstag 25 September 2007 09:00 schrieb Peter Schmitteckert:
> >> Well, there is no guarantee that a matrix gets initialized to zero.
> > You are right.
> >> (Or is a guarantee introduced recently?)
> > Fortunately not. Unfortunately despite the missing guarantee its is in
> > practice quite often zero, so that it is easy to forget a clear() :-(
> > In this case I simply confused ublas clear() with std::vector::clear()
> > (which resizes to zero).
> Well, both set the matrices to zero matrices.
I guess this is a misunderstanding. std::vector::clear() resizes the vector
to have size 0 and no elements, ublas::matrix::clear() sets all elements to
zero but does not change the size. My confusion was that I assumed
ublas::matrix::clear() to resize to zero, too.
> Fortunately it is not guaranteed, even if it is often zero. There is a
> big difference on NUMA machines (non-uniform memory architecture) in a
> parallel environment. Suppose you want to define some matrices in the
> main code and you want to fill them in threads, then you end up with
> non-thread local memory, if you already access the memory in the main
> part. Of course, you could then avoid it by resizing the matrix, but that
> is additional programming afford.
Sure. Therefore I wrote "Fortunately" above :-)
And it is even a small advantage with serial execution: If I am going to
fill a matrix anyway there is no need to zero out the memory first.