Explicit-shape/assumed-size vs. allocatable arrays.
Janne Blomqvist
blomqvist.janne@gmail.com
Sat Jun 16 19:11:00 GMT 2007
Bart Oldeman wrote:
> Last summer, when introducing allocatable arrays into some research code
> that used to be all F77, I observed that GFortran generated considerably
> slower code using allocatable arrays than when passing them to a
> subroutine that uses explicit shape or assumed size arrays. The
> descriptor stride gets in the way a little.
It's true that in some cases the descriptor gets in the way. However,
your benchmark code is flawed in that you should do a warm-up run before
starting the timing.
When I do that, I get on 1.8 GHz K8 (eyeball-avg of 3 runs):
With -O0 -march=athlon64 -mfpmath=sse -ftree-vectorize
4.1:
Array syntax: 3.90
Explicit-shape: 3.42
Allocatable: 3.86
4.2:
Array syntax: 3.92
Explicit-shape: 3.40
Allocatable: 3.75
trunk:
Array syntax: 3.90
Explicit-shape: 3.40
Allocatable: 3.80
With -O3 -funroll-loops -march=athlon64 -mfpmath=sse -ftree-vectorize
-ffast-math
4.1:
Array syntax: 1.80
Explicit-shape: 1.69
Allocatable: 1.73
4.2:
Array syntax: 1.65
Explicit-shape: 1.70
Allocatable: 1.64
trunk:
Array syntax: 1.56
Explicit-shape: 1.54
Allocatable: 1.57
So there is a slight advantage to the explicit shape case. Why, I don't
know. Now, the funny thing is that if I remove the warm-up run (just a
call to the add subroutine), and first do the loop in the main program,
the vectorizer can no longer vectorize the loop?!
I also added a third test doing the loop using array syntax; in all
cases the result was about equal to the other results for all 3 compiler
versions I tested. So at least for simple loops the scalarizer works
just fine.
--
Janne Blomqvist
More information about the Fortran
mailing list