Suresh Seetharam wrote:
>Hi,
>
>I am using fortran 90 compiler on our unix system.
>
>
>I had a question regarding the efficiency of 3D matrices e.g.
>
>dimension (:,:,:) :: tensor
>
>
>Is the above less efficient computationally compared to
>
>dimension(:,:) :: tensor
>
>This is because I am at present using 3D matrices for my finite element code.
>I attach an extract from my code here.
>
> !- upper triangle
> if (flowindx(4) > 1) then
> m = sum_f*(sum_f-flowindx(4))+(sum_f-flowindx(4))+1 !**
>fix the position
> do r = 1, flowindx(4)-1
> do i = 1, flowindx(4)-r
> do j = 1, nnelt
> do l = 1, nnelt
> K(m+i,j,l) = K(m+i,j,l) + cdd * Ki(j,l) &
> & * constkcdcd(i+1)
> end do
> end do
> end do
> m=m+sum_f+1
> end do
> end if
>
>When I do profiling using Sun Workshop I came to realise that the K matrix
>above took nearly 20% of the entire processing time for a typical problem where
>flowindx(4)=20. However, the above is the easiest way I can code based on my
>knowledge.
>
Iteration counts of 19 (and smaller) for the I loop are pretty small for
optimal performance. Otherwise, this loop construct looks fine. If it
is easy for you to understand, all the better.
>
>One of my friends suggested vectorisation of the above to make it more
>
Vectorizing a code involves writing it in such a way that a compiler can
detect that use of vector hardware instructions is possible. This is
already "vector" code. I put a subroutine wrapper around this code and
ran it through our compiler with vectorization enabled (which is the
default). The I loop was vectorized, the J loop was streamed (or
multi-threaded, if you prefer that term), and the L loop was unrolled.
If the code segment takes 20% of the total time, I assume that NNELT is
very large, or this code is referenced many times. If NNELT is large,
you might get better performance forcing vectorization on the J loop,
but that will be pretty dependent on the hardware platform.
>efficient. I think looking at the above piece of code I may spend a long time
>vectorising them (my own limitation). My question really is, is it worth
>spending time to vectorise the above if what my friend says is true. Or is it
>
No. You should not spend time changing the code. It's fine as is. You
might spend time complaining to your compiler vendor about why this code
is not automatically vectorized. I'm assuming your system had some
vector hardware support, but that's the case with most processors these
days.
Cheers,
Bill
>possible that in fortran 90 the compiler doesn't worry whether it is vectorised
>or not considering that it has an inbuilt capability to handle such problems.
>
>My knowledge in this area is limited, therefore, would greatly appreciate any
>views/suggestions.
>
>Thanks in advance.
>
>
>With very best regards,
>Suresh
>
>
--
Bill Long [log in to unmask]
Fortran Technical Support & voice: 651-605-9024
Bioinformatics Software Development fax: 651-605-9142
Cray Inc., 1340 Mendota Heights Rd., Mendota Heights, MN, 55120
|