- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm trying some code a bit like this:
module mm
interface
subroutine anything
end subroutine
end interface
contains
subroutine multiplygrid(a, b, c)
real, allocatable, dimension(:,:,:), intent(out) :: a
real, allocatable, dimension(:,:,:), intent(in) :: b, c
integer :: x, y, z
do z = 1, size(a, DIM=3)
do y = 1, size(a, DIM=2)
do x = 1, size(a, DIM=1)
a(x,y,z) = b(x,y,z)*c(x,y,z)
call anything
end do
end do
end do
end subroutine
end module
If I try to optimise this with"ifort -O -S prog.F90" (12.0.5.220) and then look at the generated code, I notice that the address calculations are liftedout of the inner loop by the optimizer for "b" and "c", but the ones for "a" stay in the inner loop suggesting the compiler thinks that the subroutine might reallocate the array. I know this kind of reflects the intents of the arguments, but I was wondering if anyone couldclarify if this is right as my understanding of the standard (I find it a hard to understand document so might be wrong) is that once something is passed to an argument you are not supposed to use the external name for it unless it isexplicitely a"pointer". If the behaviour is right, does anyone know of an option to let the compiler know it is safe to do the optimization as it would if there was no call?
Thanks.
module mm
interface
subroutine anything
end subroutine
end interface
contains
subroutine multiplygrid(a, b, c)
real, allocatable, dimension(:,:,:), intent(out) :: a
real, allocatable, dimension(:,:,:), intent(in) :: b, c
integer :: x, y, z
do z = 1, size(a, DIM=3)
do y = 1, size(a, DIM=2)
do x = 1, size(a, DIM=1)
a(x,y,z) = b(x,y,z)*c(x,y,z)
call anything
end do
end do
end do
end subroutine
end module
If I try to optimise this with"ifort -O -S prog.F90" (12.0.5.220) and then look at the generated code, I notice that the address calculations are liftedout of the inner loop by the optimizer for "b" and "c", but the ones for "a" stay in the inner loop suggesting the compiler thinks that the subroutine might reallocate the array. I know this kind of reflects the intents of the arguments, but I was wondering if anyone couldclarify if this is right as my understanding of the standard (I find it a hard to understand document so might be wrong) is that once something is passed to an argument you are not supposed to use the external name for it unless it isexplicitely a"pointer". If the behaviour is right, does anyone know of an option to let the compiler know it is safe to do the optimization as it would if there was no call?
Thanks.
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If the subroutine is PURE then it may be possible to preserve some optimizations.
If it is host associated CONTAINS (and PURE)subroutine, optimization opportunities may be better.
Jim Dempsey
If it is host associated CONTAINS (and PURE)subroutine, optimization opportunities may be better.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In a case like this the directive !dec$ ivdep may do the job for you if you put it before the DO X loop. It tells the compiler that it shouldn't bother about data dependencies within the scope of this loop. I also recommend to use -vec-report to get more explanation from the compiler.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Also consider:
do z = 1, size(a, DIM=3)
do y = 1, size(a, DIM=2)
do x = 1, size(a, DIM=1)
a(x,y,z) = b(x,y,z)*c(x,y,z)
end do
end do
end do
do z = 1, size(a, DIM=3)
do y = 1, size(a, DIM=2)
do x = 1, size(a, DIM=1)
call anything
end do
end do
end do
.or.
do z = 1, size(a, DIM=3)
do y = 1, size(a, DIM=2)
do x = 1, size(a, DIM=1)
a(x,y,z) = b(x,y,z)*c(x,y,z)
end do
do x = 1, size(a, DIM=1)
call anything
end do end do
end do
Jim Dempsey
do z = 1, size(a, DIM=3)
do y = 1, size(a, DIM=2)
do x = 1, size(a, DIM=1)
a(x,y,z) = b(x,y,z)*c(x,y,z)
end do
end do
end do
do z = 1, size(a, DIM=3)
do y = 1, size(a, DIM=2)
do x = 1, size(a, DIM=1)
call anything
end do
end do
end do
.or.
do z = 1, size(a, DIM=3)
do y = 1, size(a, DIM=2)
do x = 1, size(a, DIM=1)
a(x,y,z) = b(x,y,z)*c(x,y,z)
end do
do x = 1, size(a, DIM=1)
call anything
end do end do
end do
Jim Dempsey
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page