Intel® C++ Compiler XE 13.1 User and Reference Guides

Calling Functions on the CPU to Modify the Coprocessor's Execution Environment

This topic only applies to Intel® Many Integrated Core Architecture (Intel® MIC Architecture).

Some CPU APIs have offload equivalents, each of which take two additional arguments to specify the target type and target number, defined by the following arguments:

target_type

target_type is static. It is recommended to use the following pre-defined default:

DEFAULT_TARGET_TYPE

target_number

The specific coprocessor to target.

An expression whose value is interpreted as follows:

-1

This value specifies execution on the target. The runtime system chooses the specific target. Execution on the CPU is not allowed. If the correct target hardware needed to run the offloaded program is not available on the system, the program fails with an error message.

>=0

A value greater than or equal to zero specifies execution on a specific target. The number of the specific target is determined as follows:

target=target-number % number_of_targets

If the correct target hardware needed to run the offloaded program is not available on the system, the program fails with an error message.

<-1

This value is reserved.

For example, in a system with four targets:

  • specifying 2 or 6 tells the runtime systems to execute the code on target 2, because both 2 % 4 and 6 % 4 equal 2.

  • Specifying 1000 tells the runtime systems to execute the code on target 0, because 1000 % 4 = 0.

The offload.h header file defines all the function calls that can be made from the CPU to affect the coprocessor's environment.

This topic uses the CPU API omp_set_num_threads and its offload variations as an example.

Example

CPU API
void omp_set_num_threads (int num_threads);
Offload API
void omp_set_num_threads_target (TARGET_TYPE target_type, int target_number, int num_threads);
#include "offload.h"
#include "omp.h"

int main()
{
        int value, result;

        value = 66;
        omp_set_num_threads_target(TARGET_MIC, 0, value);
        #pragma offload target(mic) out(result)
        #pragma omp parallel
        #pragma omp master
        result = omp_get_num_threads();

        printf("Number of threads on target %d\n", result);
        if (result != value) {
          printf("failed1 result=%d, value=%d\n", result, value);
          return 1;
        }
        return 0;
}

See Also


Submit feedback on this help topic