Allocating Memory for Parts of Arrays

This topic only applies to Intel® Many Integrated Core Architecture (Intel® MIC Architecture).

This topic discusses using the alloc modifier with the offload set of pragmas

The alloc modifier contains an array section reference. When you specify it, then the allocation on the coprocessor is limited to that shape of array. Only unit stride is allowed in the section. When a section has a rank greater than one, the second and subsequent index expressions must specify all elements at that dimension. The array section must be contiguous.

Data is transferred into that portion of the array specified by the in or out expression. Thus memory allocation and the data transfer can use separate array slice references.

When the lower bound of the first dimension of a section used in the alloc modifier is non-zero, then the memory allocation begins with that element. The memory preceding the lower bound is unallocated and should not be referenced by your program. By not referencing it, you enable a smaller section of the array to be transferred to the coprocessor without requiring that the entire array be allocated.


In the following example,
  • The alloc(p[5:1000]) modifier allocates 1000 elements on the coprocessor.

  • The first usable element has index 5 and the last has index 1004. Thus only elements 5 through 1004 are accessible on the coprocessor.

  • Data transfer is specified by the in(p[10:100] clause.

    100 elements are transferred into the allocated memory in the range p[10] through p[109].

int *p;
//  1000 elements allocated. Data transferred into p[10:100]
#pragma offload … in ( p[10:100] : alloc(p[5:1000]) )
{ … }

typedef int ARRAY[4][4];
p = malloc(…);

// On the coprocessor, 16 elements are allocated for an array of shape 5x4.
// The first row is unallocated.
// Data is transferred into row 2 only
#pragma offload … in ( (*p)[2][:] :  alloc([1:4][:]) )
{ … }
For more complete information about compiler optimizations, see our Optimization Notice.