In this step, you will open the source code in your favorite editor to see how the code determines if the system has a coprocessor and then count the number of coprocessors.
Open the source code in your favorite code editor.
Find the following code:
#ifdef __INTEL_OFFLOAD
printf(" Checking for Intel® MIC Architecture (Target CPU)devices...\n\n");
num_devices = _Offload_number_of_devices();
printf(" Number of Target devices installed: %d\n\n",num_devices);
#endif
In this code block, the directive contains the predefined macro __INTEL_OFFLOAD. This macro is defined by the compiler to run the code block on the CPU and the coprocessor. The compiler by default will compile the code block within this directive. You can exclude the directive and the code by using the no-offload compiler option to compile the code into an application that runs on just the CPU. Excluding this directive is useful when you want to ensure that your code works before offloading the code to the coprocessor.
Later in this tutorial, you will exclude this directive when you compile the same source code with the no-offload compiler option.
Also within the directive is the code to determine if the system has a running coprocessor and the number of running coprocessors. The _Offload_number_of_devices function returns the number of running coprocessors in the system. If the system does not have any running coprocessors, the function returns -1. You can also use the return value to direct a code section to run on a specific coprocessor if the system contains multiple coprocessors.
In the next step, you will see a section of the source code defined to run on both the host CPU and coprocessor.