Fast multidimensional Arrays
Daniel Kozak via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Aug 29 06:59:15 PDT 2016
Dne 29.8.2016 v 11:53 Steinhagelvoll via Digitalmars-d-learn napsal(a):
> 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
It is unfair to compare different backend:
gfortran -O3 -o test test.f90
[kozak at dajinka ~]$ time ./test
real 0m2.072s
user 0m2.053s
sys 0m0.013s
gdc -O3 -o test test.d
[kozak at dajinka ~]$ time ./test
real 0m1.655s
user 0m1.640s
sys 0m0.010s
Obviously ifort can use some special instruction on your CPU
More information about the Digitalmars-d-learn
mailing list