c++ - Different handling of global arrays (malloc vs static) in OMP target -
there 2 ways have global array: use pointer , malloc, or define array:
#omp declare target int garray[10]; int* gvals /*somewhere later:*/ = malloc(10*sizeof(int)); #omp end declare target
i though, these equivalent in handling discovered huge difference: when map them target, gvals mapped. if want values of garray on device have use "target update". bug in current intel compiler or covered in spec? not find specific this.
btw: using local array (no declare target) works intended.
test code:
for(i=0;i<ct;i++){ garray[i]=1;gvals[i]=1; } #pragma omp target map(garray[0:2],gvals[0:2]) { printf("garraytarget(1111): %d%d%d%d\n",garray[0],garray[1],gvals[0],gvals[1]); garray[1]=2;gvals[1]=2; } printf("garrayhost(1212): %d%d%d%d\n",garray[0],garray[1],gvals[0],gvals[1]);
declare target
puts enclosed variables in initial device context (2.9.4 -- declare target
directive):
if list item variable original variable mapped corresponding variable in initial device data environment devices. if original variable initialized, corresponding variable in device data environment initialized same value.
your garray
variable not initialised, therefore device copy not initialised either. becomes part of initial device data environment. map
clause has no effect on garray
because (2.14.5 -- map
clause):
if corresponding list item of original list item in enclosing device data environment, new device data environment uses corresponding list item enclosing device data environment. no additional storage allocated in new device data environment , neither initialization nor assignment performed, regardless of map-type specified.
the initial device data environment enclosing in respect new data environment created target
directive.
as gvals
, following apply (2.14.5 -- map
clause):
if type of variable appearing in array section pointer, reference array, or reference pointer variable implicitly treated if had appeared in
map
clause map-type ofalloc
. corresponding variable assigned address of storage location of corresponding array section in new device data environment.
therefore not bug in intel compiler standard-described behaviour.
Comments
Post a Comment