Well, it's a simple matter of paranthesis:
t_optimized = t2-t1/iterations
is most certainly wrong... You probably mean
t_optimized = (t2-t1)/iterations
With that I get a speed-up of ~2.
A couple of other things I needed to correct/adjust:
- The first loop is wrong, you are trying to set elements out of there boundaries. It should read:
A(j,i) = (-1.0)**(i-j)
- Modern compilers are quite intelligent. They probably notice that you do not vary the input of your function call within the loop body. They can then optimize away your whole loop! To prevent that, I inserted the following line:
do i = 1,iterations
call optimized(A, m, n, x, y1)
x(1:n) = y1
end do
(and the same for y2
). Don't forget to re-initialize x
at the beginning of each benchmark.
- Don't use
;
that much - it is not required unless you want to put multiple statements on one line - Don't use tabs in Fortran - some compilers don't like it - use whitespaces instead