Fast multidimensional Arrays

rikki cattermole via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Aug 29 03:20:56 PDT 2016


On 29/08/2016 9:53 PM, Steinhagelvoll wrote:
> Hello,
>
> I'm trying to find a fast way to use multi dimensional arrays. For this
> I implemented a matrix multiplication and compared the times for
> different ways. As a reference I used a Fortran90 implementation.
>
> Fortran reference: http://pastebin.com/Hd5zTHVJ
> ifort test.f90  -o testf && time ./testf
> real    0m0.680s
> user    0m0.672s
> sys     0m0.008s
>
> ifort -O3 test.f90 -o testf && time ./testf
> real    0m0.235s
> user    0m0.228s
> sys     0m0.004s
>
> ifort -check all test.f90  -o testf && time ./testf
>         1000
>
> real    0m34.993s
> user    0m35.012s
> sys     0m0.008s
>
>
> For D it tried a number of different ways:
>
> NDSlice: http://pastebin.com/nUbMnt8B
> real    0m35.922s
> user    0m35.888s
> sys    0m0.008
>
>
> 1D Arrays: http://pastebin.com/R7CJFybK
> dmd -boundscheck=off -O test.d && time ./test
> real    0m4.415s
> user    0m4.412s
> sys    0m0.004s
>
> ldc2 -O3 test.d && time ./test
> real    0m4.261s
> user    0m4.252s
> sys    0m0.004s
>
> 2D Arrays: http://pastebin.com/4CuB4Y0c
>
> dmd -boundscheck=off -O nd_test.d && time ./nd_test
> real    0m3.565s
> user    0m3.560s
> sys    0m0.004s
>
>
> ldc2 -O3 nd_test.d && time ./nd_test
> real    0m3.568s
> user    0m3.560s
> sys    0m0.004s
>
> None of them is even close to the Fortran implementation, only when I
> enable all check in Fortran it seems to be equal to Ndslice. Is there a
> speedy way to use multi-dimensional matrices?
>
> Kind regards
>
> Matthias

By the looks you're not running the tests more then once.
Druntime initialization could be effecting this.

Please execute each test (without memory allocation) 10000 times atleast 
and then report back what they are.

Something like https://dlang.org/phobos/std_datetime.html#.benchmark 
will be very helpful.


More information about the Digitalmars-d-learn mailing list