PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

CUDA-x86.

if statements

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



Joined: 24 Feb 2011
Posts: 22

PostPosted: Fri May 20, 2011 2:27 am    Post subject: if statements Reply with quote

Is it possible to use fortran if, then, else statements in

a) !$acc region
b) !$acc data region

with PGI Version 10.5?

e.g. a)
Code:

!$acc region
...
IF (logical-expression-1) THEN
   statements-1
ELSE IF (logical-expression-2) THEN
   statements-2
ELSE
   statements-ELSE
END IF
...
!$acc end region


e.g. b)
Code:

!$acc data region
...
IF (logical-expression-1) THEN
   statements-1
ELSE IF (logical-expression-2) THEN
   statements-2
ELSE
   statements-ELSE
END IF
...
!$acc region
   do i=1,k
    ......
   end do
!$acc end region
!$acc end data region


Thank you!
Back to top
View user's profile
mkcolg



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

PostPosted: Fri May 20, 2011 7:57 am    Post subject: Reply with quote

Hi elephant,

Quote:
a) !$acc region
Sure. If statements can be part of the device kernel. The caveat is that your performance may suffer due to divergence. GPU Threads are organized in groups called 'warps'. Each thread in a warp executes the same instructions at the same time, just on different data (SIMD, single instructions multiple data). So if your threads diverge by taking different paths in an if statement, all the threads still need to execute the same instructions. This means that some of the threads will need throw away the instruction and wait for there turn. While they issue their instructions, the other threads will need to wait.

So if statements are fine so long as all the threads in a warp take the same path. Otherwise, you'll hurt your performance.

Quote:
b) !$acc data region
Doesn't matter since the if statement in this case is host code. Any host code can be used within a data region. The only thing to keep in mind is which copy of the data, host or device, you are acting on. For example, if you copyin an array via a data region, then set the array to some value in the host code, the device code will not be set. You would then need to use the "!$acc update device" directive to copy the new value of the array to the device.

Hope this helps,
Mat
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