Specifying Code Sections to Run on the Host and Target

In this step, you will look at the code section defined to run on both the host and target.

Find the following code:

  #pragma offload target(mic) mandatory \
                             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 block finds the first ten even numbers and then stores those numbers into an array. At the start of the code block is the offloadpragma. The compiler interprets this pragma to compile the following code block to run on both the host and target.

While the instruction sets are similar, the host and targets do not share the same system memory. Therefore, the variables used by the code block must exist in both the host and target. To ensure that the variable exist on both the host and target, the directive uses parameter specifiers to define the variables to copy between the host and target.

Although the compiler by default compiles the code into an application that runs on both the host and target, you can also compile the same code into an application that runs on just the host only. In the next step, you will compile the source code into and application that runs on the host only.

Next: Running Guided Auto-parallelization


Submit feedback on this help topic