Intel® Fortran Compiler 16.0 User and Reference Guide
This topic only applies to Intel® Many Integrated Core Architecture (Intel® MIC Architecture).
You can write functions that you intend to run on a target, and sections of offloaded code, to take advantage of target-specific functions.
When the compiler generates code for the coprocessor, it defines the macro __MIC__. You can write target-specific code within a !DIR$ if defined __MIC__ section.
Do not use coprocessor-specific directives inside the statement following a !DIR$ OMP OFFLOAD statement. You can, however, use them in a subprogram called from the directive.
The implementation of the class F32vec is specialized for the CPU and the coprocessor. The offloaded code can use the specialized version if it runs on the coprocessor. If the offload fails and the construct runs on the CPU, it uses the CPU version.
!DIR$ ATTRIBUTES OFFLOAD : mic :: foo integer function foo() implicit none !DIR$ if defined (__MIC__) foo = 1 ! Code is running on coprocessor !DIR$ else foo = 0 ! Code is running on host !DIR$ endif end function foo program main implicit none ! Local variables integer :: result integer :: foo !DIR$ ATTRIBUTES OFFLOAD : mic :: foo ! Call foo on host result = foo() ! Print results if ( result ) then write (*,*) "Code ran on coprocessor" else write (*,*) "Code ran on host" end if ! Call foo on MIC !DIR$ OFFLOAD TARGET(mic) result = foo() ! Print results if ( result ) then write (*,*) "Code ran on coprocessor" else write (*,*) "Code ran on host" end if end program main