In article <>,
says...
[ ... ]
> Standard vector class templates are for *flexible* arrays of any type.
> Each of the vectors in a vector of vectors could have different lengths.
> They will only cause you trouble
> if you really need *rigid*, *rectangular* arrays of numbers.
> In which case, standard valarray class templates are a better choice.
This may be true, but I've yet to see real evidence of it.
[ ... ]
> It depends upon the implementation
> but valarrays were designed for the kind of optimizations
> that are required for high performance numerical applications.
Yes and no -- valarrays were really designed to work well with vector
machines (which ARE used primarily for high-performance numerical
applications). Unfortunately, they generally do NOT work particularly
well with most current architectures.
The basic difference is simple: on a vector machine, you generally want
to apply a single operation to an entire array at a time, then apply the
next operation to the entire array, and so on until you've applied all
the operations you need to the entire array. The basic definition of a
vector machine is that it can apply a single operation to a number of
elements in parallel. The prototypical vector machine is the Cray,
which has 3 sets of 64 registers each -- it can be loading one set of 64
registers, applying a single operation to another set of 64, and storing
the third set of 64 all at the same time. A valarray fits this pattern
beautifully, so with a machine like this, you _should_ get excellent
efficiency with it.
The basic problem with this design is that it requires a LOT of
bandwidth to memory. A typical modern machine has an extremely fast
CPU, but the main memory is a LOT slower, with a cache to make up the
difference. On a machine like this, optimal usage is almost exactly the
opposite -- you want to load a single value, apply _all_ your operations
to it, then go on to the next value. On such a machine, most of the
operations supported by valarray perform quite poorly, and the only way
to get decent performance is to treat a valarray just about like a
vector.
--
Later,
Jerry.
The universe is a figment of its own imagination.