In this step, you will look at a section of the source code that is defined to run on both the CPU and the coprocessor.
Find the following code:
!DIR$ OFFLOAD BEGIN target(mic : target_id) &
inout(numEs) in(all_Vals) out(E_vals)
do k = 1, MAXSZ
if ( MODULO(all_Vals(k),2) == 0 ) then
numEs = numEs + 1
E_vals(numEs) = all_Vals(k)
endif
enddo
!DIR$ END OFFLOAD
This code block finds the first ten even numbers and then puts those numbers into an array. At the start and end of the code block is the OFFLOAD directive. The compiler interprets this directive to compile the following 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 in both the host CPU and coprocessor. To ensure that the variable exist in both the host CPU and coprocessor, the directives use parameter specifiers to define the variables to copy between the host CPU and coprocessor.
The in specifier defines the variable as strictly an input to the coprocessor. The value is not copied back to the host CPU.
The out specifier defines the variable as strictly an output of the coprocessor. The host CPU does not copy the variable to the coprocessor.
The inout specifier defines the variable that is both copied to and from the host CPU and coprocessor.
The directive also has the target parameter to direct the code to a specific coprocessor in a system with multiple coprocessors.
Although the compiler by default compiles the source code into an application that runs on both the host CPU and coprocessor, you can also compile the same source code into an application that runs on just the CPU. In the next step, you will compile the source code into an application that runs only on the CPU.