Quantcast
Channel: Intel® C++ Compiler
Viewing all articles
Browse latest Browse all 1616

Specifying Code Sections to Run on the Host and Target

$
0
0

In this step, you will look 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.

The mandatory clause reinforces the implied default and specifies the required execution on the target. Execution on the host is not allowed. If the target is not available, the program fails with an error message.

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 targets. To ensure that the variable exist in both the host and target, the offload pragma uses parameter specifiers to define the variables to copy between the host and targets.

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

  • The out specifier defines the variable as strictly an output of the target. The variable is not copied from the host to the target. The variable is only copied from the target to the host.

  • The inout specifier defines the variable that is both copied to and from 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 the host only. In the next step, you will compile the source code into an application the runs on the host only.

Next: Running Guided Auto-parallelization

Inglés

Viewing all articles
Browse latest Browse all 1616

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>