Intel® C++ Compiler XE 13.1 User and Reference Guides
This topic only applies to Intel® Many Integrated Core Architecture (Intel® MIC Architecture).
You can place the offload pragma before any statement, including a compound statement. The statement prefixed with the offload pragma can also be an OpenMP* parallel pragma.
For example:
#pragma offload target(mic : target_id) \
in(all_Vals : length(MAXSZ)) \
inout(numEs) out(E_vals : length(MAXSZ/2))
for (k=0; k < MAXSZ; k++) {
if ( all_Vals[k] % 2 == 0 ) {
E_vals[numEs] = all_Vals[k];
numEs++;
}
}
This code excerpt finds the first ten even numbers and then puts those numbers into an array. At the start of the code excerpt is the offload pragma. The compiler builds the code block to run on both the CPU and coprocessor.
While the instruction sets for the host CPU and coprocessors are similar, they do not share the same system memory. This means that the variables used by the code block must exist on both the host CPU and coprocessor. To ensure that they do, the pragmas use specifiers to define the variables to copy between the host CPU and coprocessor.
The in specifier defines a variable as strictly an input to the coprocessor. The value is not copied back to the host CPU.
The out specifier defines a variable as strictly an output of the coprocessor. The host CPU does not copy the variable to the coprocessor.
The inout specifier defines a variable that is both copied from the host CPU to the coprocessor and back from the coprocessor to the host CPU.
The pragma also has the target (mic:target_number) specifier to direct the code to a specific coprocessor in a system with multiple coprocessors.
Although by default the compiler builds an application that runs on both the host CPU and coprocessor, you can also build the same source code to run on just the CPU, using the -no-offload compiler option.