Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29280 Discussions

replacement of fortran loops by memcpy

Matthieu_B_
Beginner
697 Views

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

If i write this subroutine : [fortran]

      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

[/fortran]

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

      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

[/fortran]

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?

0 Kudos
1 Solution
Steven_L_Intel1
Employee
697 Views

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.

View solution in original post

0 Kudos
1 Reply
Steven_L_Intel1
Employee
698 Views

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.

0 Kudos
Reply