Boost logo

Boost :

From: Toon Knapen (toon.knapen_at_[hidden])
Date: 2001-12-28 12:32:58


rwgk wrote:

> Attached is a modified version of multiarray.cpp and results
> with the following compilers:
>
> Visual C++ 6.0 (probably Service Pack 5)
> Win32 CodeWarrior 7.0
> gcc 3.0.2 under RedHat 7.1 (Intel Xeon)
> Compaq cxx (EDG 2.40) (Tru64 Unix, Alpha chip)
> IRIX CC (EDG 2.38) (MIPS R5000 chip)
>
> multiarray.cpp includes an additional test:
>
> int multiarray_3D_collection (MultiArray3D& A)
> {
> boost::array<MultiArray3D::index,3> i;
> // Assign values to the elements
> int values = 0;
> for(i[0] = 0; i[0] != size; ++i[0])
> for(i[1] = 0; i[1] != size; ++i[1])
> for(i[2] = 0; i[2] != size; ++i[2])
> A(i) = values++;
> //...
> }
>
> This performs consistently better than the test that is advertised
> so prominently in the multi_array documentation. However, in general
> there is still a significant abstraction penalty.

It makes already big difference though. So I guess the []-indexing is
not optimal for numerics. But as Ron already mentioned, multi-array is
not limited to numerics and the interface is nice. We just need to be
sure that we have performant methods that are frequently used in numerics.

>
> The multi_array interface is very appealing. However, I believe that
> acceptance in the general community will also depend to a large degree
> on performance considerations. I am wondering if there aren't ways of
> making it easier for the compilers to generate faster code. One idea
> would be to provide optional fast access methods for special but
> common cases.
>
> Included in the modified multiarray.cpp is a template c_index_1d that
> generates the code for converting n-dim indices to a 1-d index, given
> 0
> bases, and strides 1. This performs consistently better than
> multi_array::operator(). Visual C++ removes the (remaining)
> abstraction
> penalty entirely. Could specialized access methods like this be
> integrated into the library?

Wooaw. The speedup is amazing.
It breaks encapsulation though ;-( (as you need a pointer to the
underlying data). But indeed, we could think of a way to integrate this
type of access within the library such that it does not break
encapsulation anymore.

BTW : I'm surprised by the VC++ results and disappointed by cxx.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk