Intel® C++ Compiler 16.0 User and Reference Guide

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.

Example

In the following example,
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];
ARRAY *p;
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][:]) )
{ … }

See Also