Intel® C++ Compiler 19.0 Developer Guide and Reference
This topic only applies when targeting Intel® Many Integrated Core Architecture (Intel® MIC Architecture).
This topic is deprecated because it contains information related to Intel® Cilk™ Plus, which is a deprecated feature. This topic will be removed in a future release.
You can write code that should not be built when the target is a CPU-only executable.
By default, the compiler defines the macro __INTEL_OFFLOAD. You can write code within an #ifdef __INTEL_OFFLOAD section when the source code is customized for running on the coprocessor heterogeneously.
For example, you can use this macro to protect code on the host that should only be executed for an offload build, such as calls to the omp_set_num_threads_target family of APIs in offload.h.
The section for the host compiler works only when you compile with the [Q]offload compiler option with the keyword optional.
#include <stdio.h>
__declspec(target(mic)) void print()
{
#ifdef __INTEL_OFFLOAD
#ifdef __MIC__
printf("Using offload compiler : Hello from the coprocessor\n");
fflush(0);
#elif __TARGET_ARCH_MIC
printf("Using offload compiler : Hello from the coprocessor\n");
fflush(0);
#else /* !__MIC__ and !__TARGET_ARCH_MIC */
printf("Using offload compiler : Hello from the CPU\n");
#endif /* __MIC__ */
#else /* !__INTEL_OFFLOAD */
printf("Using host compiler : Hello from the CPU\n");
#endif /* __INTEL_OFFLOAD */
}
int main()
{
#pragma offload target(mic)
print();
}