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            move the content of a table to another

	C            ib should be left of ia in memory

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


	      do i=1,N




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



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


	c     Print the result     




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?

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
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

Leave a Comment

Please sign in to add a comment. Not a member? Join today