Setting initital valuesof an array to zero

Hi,

Has anybody else seem significant performance hits when setting the initial values of an array (to be used in a summation of some form) to zero using:

arrayname=0.0

when using the Fortran accelerator compiler

If so, how did you work around this? Obvious solutions I am currently using are looping over the array in an initial separate data region or copying in an initally zeroed array.

Is there perhaps an optimised intrinsic function for this that i am unaware of?

Cheers,

Karl

Hi Karl,

Do you have an example of what you’re seeing? How significant of a performance hit is it?

If you’re doing something like:

!$acc region
  arrayname=0.0
!$acc end region

!$acc region
... code that uses arrayname
!$acc end region

Then you would be copying arrayname out of the first region and then copying back to the device. This would cause a performance hit.

However, if you put arrayname into a data region using a local clause, you can remove the copies altogether. “local” just allocates storage on the device.

!$acc data region local(arrayname)
!$acc region
  arrayname=0.0
!$acc end region

!$acc region
... code that uses arrayname
!$acc end region
!$acc end data region
  • Mat

Dear Mat,

It is the latter case that we are using (an array specified as being local). The compile time reports show that the array is indeed compiling as local so data transfer is not the issue.

It is very large 2 or 3-dimensional arrays that cause the problem and it doesn’t seem to register under the profiling timings (although I have my doubts that I am using the profiler correctly).

arrayname=0.0

with

!$acc data region
!$acc region
!$acc do
  do i =1,leni
    do j=1. lenj
      arrayaname(j,i)=0.0
    end do
  end do
!$acc end region

!$acc region
!$acc do
do i = 1, bignumber
     !stuff
end do
!$acc end region
!$acc end data region

Results in increased performance of a factor of 20 for one of our smaller routines.

On second thoughts there is an obvious flaw with this example: It is zeroing the entire array on each iteration of the outer loop.

However, we have also seen this issue (albeit not as severe, 10x speed-up from the change described below) in situations where we initialised individual elements to zero within the innermost loop before calculation. We corrected this by changing:

!$acc do
do i = 1, numi
  do j=1, numj
    array(j,i) = 0.0
    calculate a
    if a gt cutoff
      array(j,i) = value
    end if
  end do
end do

to

!$acc do
do i = 1, numi
  do j=1, numj
    calculate a
    if a gt cutoff
      array(j,i) = value
    else
      array(j,i) = 0.0
    end if
  end do
end do

Although in hindsight I guess the first example writes to the j,i element twice for every iteration whilst the second only writes once. However the effect on performance seems to be a lot more significant than I would expect from this difference.