Initiating an Offload

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))
  for (k=0; k < MAXSZ; k++) {
      if ( all_Vals[k] % 2 == 0 ) {
        E_vals[numEs] = all_Vals[k];
        numEs++;
      }
  }

This code excerpt finds the even numbers and then puts those numbers into an array. The code excerpt begins with #pragma offload . The compiler builds the code block to run on both the host and target

While the instruction sets for the host and targets 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 and the target. To ensure that they do, the pragmas use specifiers to define the variables to copy between the host and target.

  • The in specifier defines a variable as strictly an input to the target. The value is not copied back to the host.

  • The out specifier defines a variable as strictly an output of the target. The host does not copy the variable to the target.

  • The inout specifier defines a variable that is both copied from the host to the target and back from the target to the host.

The pragma also has the target (mic:target_number) specifier to direct the code to a specific target in a system with multiple targets.

When the main program has offload constructs, by default the compiler builds an application that runs on both the host and target. However, you can also build the same source code to run on just the CPU, using the negative form of the [Q]offload compiler option.

For more complete information about compiler optimizations, see our Optimization Notice.