Finding the Number of Targets

In this step, you find the code section that determines the number of targets.

  1. Open the code in your favorite code editor.

  2. Find the following code:

    #ifdef __INTEL_OFFLOAD
       printf(" Checking for Intel® Xeon Phi™ (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 #ifdef pragma contains the predefined macro __INTEL_OFFLOAD. By default when offload language extensions appear in the code, the compiler defines this macro to compile and execute the code block on the host. Otherwise, the compiler does not define the macro and does not compile the code block. You can exclude the offload language extensions and disable defining this macro with the no-offload compiler option to compile the code into an application that runs only on the host. This option is useful when you want to ensure that your code works before using the code on the target.

Later in this tutorial, you will exclude this code block and other offload language extensions when you compile the same code with the no-offload compiler option.

Also within the code block is code to determine if the system has a running target and the quantity of targets. The _Offload_number_of_devices function returns the quantity of installed and running targets. If the system does not have any installed and running targets, the function returns -1.

In the next step, you will find the code section defined to run on both the host and target.

Open the Building the OpenMP Version topic


Submit feedback on this help topic