PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

CUDA-x86.

Zero-based index for device data

 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling
View previous topic :: View next topic  
Author Message
Tuan



Joined: 11 Jun 2009
Posts: 233

PostPosted: Tue Nov 06, 2012 9:12 am    Post subject: Zero-based index for device data Reply with quote

Hi,
When I allocate an array as
Code:
real, dimension(:), allocatable, device: arr_J, arr_I

allocate(J(0:10000))
allocate(I(10001))

and when I use these arrays inside the kernel, would the kernel know which one is zero-based index?
Quote:

attributes(device) mykernel()
ii = .... // detect index

use arr_J(ii) !!! --> zero-based or not???
use arr_I(ii)
end

or I have to pass the information explicitly like this

Quote:

attributes(device) mykernel(arr_J, arr_I, size)
real, dimension(0:size), device: arr_J
real, dimension(size), device: arr_I

ii = .... // detect index

use arr_J(ii) !!! --> zero-based or not???
use arr_I(ii)
end


Thanks,
Tuan
Back to top
View user's profile
mkcolg



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

PostPosted: Tue Nov 06, 2012 9:49 am    Post subject: Reply with quote

Hi Tuan,

Since these are allocatable arrays and hence have a F90 array descriptor which contains the bounds information, you shouldn't need to pass this information. Are you encountering an error?

- Mat
Back to top
View user's profile
Tuan



Joined: 11 Jun 2009
Posts: 233

PostPosted: Thu Nov 08, 2012 7:58 am    Post subject: Reply with quote

Hi Mat,
I didn't have a runtime error. But in CPU, suppose the memory address is
Quote:
arr_J[0] at address 100
arr_J[1] at address 101


if I don't pass the dimension explicitly to the function, say
Code:
function foo(arr_J)
  real, dimension(:) :: arr_J
 
  arr_J(1) = 10
end function

the first element of the zero-based allocated array arr_J(1) will be interpreted as location 100. So, I don't know how it works with GPU data.

UPDATE: The above fact maybe wrong. Please correct me! Based on your answer, it means that the dimension information is kept with 'allocatable' array, so it doesn't matter if we pass the explicit dimension information or not to the function that use this 'allocatable' array?
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling 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