vector expression question.
Tim Prince
n8tm@aol.com
Thu Nov 17 19:46:00 GMT 2011
On 11/17/2011 2:30 PM, Mike Kumbera wrote:
> I would like to start out with I'm not sure if this is a bug or not... The program bellow computes xser and x and I expected them to have the same answer. They didn't.
> The results with 4.6.1 were xser(:) = 2 and x(:)=1.
>
> Should vector operations like x(i)=x(i)+1 act like it was looping over the values of i in a do loop or act like an atomic assignment statement x=x+1? I didn't see anything glaring in my
> reference books and the commercial compilers are split on the results.
>
> intel 10 x=1...
> Intel 11 x=2...
> Intel 12 x=2...
> Gnu 4.6.1 x=1...
> pathscale x=1...
> pgi (all version) x=2...
> sun studio 12.1 x=1...
>
> -----
>
> program test
>
> integer, parameter :: n = 10
> integer :: i(n) = (/ 1, 2, 3, 4, 5, 5, 4, 3, 2, 1/)
> integer x(5),xser(5)
>
> ! cumaddin
> xser = 0;
> do j = 1, n
> xser (i (j)) = xser (i (j)) + 1
> enddo
> write (*,*) xser
>
> x = 0;
> x(i) = x(i) + 1 ! same as the loop above
> write (*,*) x
>
> end program test
>
If you persuade a compiler to vectorize such a situation, you have no
control over the order of assignments. I expect the compilers which got
the same result as for sequential execution did so by refusing to vectorize.
--
Tim Prince
More information about the Fortran
mailing list