replacement of fortran loops by memcpy

replacement of fortran loops by memcpy

I face some difficulties with some optimizations performed by the ifort compiler.

If i write this subroutine :

      subroutine zmv (ia,ib,n)
C-------------------------------------------------------------------

	C            move the content of a table to another

	C            ib should be left of ia in memory

	      integer   ia(*),ib(*),i,n

	C

	      do i=1,N

	        ib(i)=ia(i)

	      enddo
      return

	      end

The thing is that using O3 option, ifort will replace my loop by a intel_fast_memcpy while nothing prevent me from doing this :  

      program test

	     

	      implicit none

	     

	      integer i,n

	      parameter (n=10)

	      integer Z(n)

	     

	c     Initialize the content of the array   
      do i=1,10
        Z(i) = i

	      enddo

	     

	c     Move the 6 to 10th value to the 3rd to 7th
      call zmv(Z(6),Z(3),5)

	     

	c     Print the result     

	      write(*,'(99g)')(Z(i),i=1,n)

	     

	      end

As one can see, in the zmv subroutine call, the ia and ib array are overlapping (ib being left of ia). In this case, according to the C documentation, and as seen in a much more complicated exemple, nothing guarantee me that the copy will be correctly performed. A much safer way would have been to use memmove.

So I was wondering why ifort does this? Is my call to zmv subroutine somehow not compliant with fortran standard?

publicaciones de 3 / 0 nuevos
Último envío
Para obtener más información sobre las optimizaciones del compilador, consulte el aviso sobre la optimización.
Best Reply

Your program is not standards-compliant. zmv by itself is ok, but when combined with the call that causes overlap of the ia and ib arguments, you violate the rules against dummy aliasing. You could try compiling with -assume dummy_alias - that should disable this optimization.

Steve - Intel Developer Support

Thanks !

That solved the problem

Deje un comentario

Por favor inicie sesión para agregar un comentario. ¿No es socio? Únase ya