Matrix mul

Tom S h3r3tic at remove.mat.uni.torun.pl
Sat Nov 22 22:40:08 PST 2008


Don wrote:
> bearophile wrote:
>> While writing code that works on matrices I have found something 
>> curious...
> 
> Here's what I think is going on. AFAIK, D hasn't got any special code 
> for initializing jagged arrays. So
>         auto A = new double[][](N, N);
> involves N+1 memory allocations.
> As well as being slow, this is going to give horrible locality of 
> reference in the memory allocation. You'll suffer cache misses on almost 
> every array access!
> 
> I don't think this has anything to do with bounds checking.

Nah, it's about NaNs :)

Version #1 initializes C to NaN, Version #2 initializes it to 0. The 
'init mats randomly' loop doesn't touch C at all, thus all the latter 
additions leave C at NaN, causing lots of FP exceptions.

We actually had something like this happen in Deadlock a few times in 
the animation subsystem. Brought the framerate down to a single digit :D


-- 
Tomasz Stachowiak
http://h3.team0xf.com/
h3/h3r3tic on #D freenode



More information about the Digitalmars-d mailing list