PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

Free OpenACC Webinar

Setting initital valuesof an array to zero

 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Accelerator Programming
View previous topic :: View next topic  
Author Message
KarlW



Joined: 12 Jan 2009
Posts: 23

PostPosted: Wed Sep 14, 2011 8:11 am    Post subject: Setting initital valuesof an array to zero Reply with quote

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:
Code:
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
Back to top
View user's profile
mkcolg



Joined: 30 Jun 2004
Posts: 6218
Location: The Portland Group Inc.

PostPosted: Wed Sep 14, 2011 3:08 pm    Post subject: Reply with quote

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:
Code:

!$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.
Code:

!$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
Back to top
View user's profile
KarlW



Joined: 12 Jan 2009
Posts: 23

PostPosted: Wed Sep 14, 2011 11:33 pm    Post subject: Reply with quote

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).

Code:
arrayname=0.0


with

Code:
!$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.
Back to top
View user's profile
KarlW



Joined: 12 Jan 2009
Posts: 23

PostPosted: Thu Sep 15, 2011 12:19 am    Post subject: Reply with quote

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:

Code:
!$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

Code:
!$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.
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    PGI User Forum Forum Index -> Accelerator Programming All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © phpBB Group