Intel® Fortran Compiler 16.0 User and Reference Guide

Placing Variables and Functions on the Coprocessor

These attributes ensure that variables and functions are available on the coprocessor.

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

The statement following the offload directive is converted into an outlined function that runs on the coprocessor. This code is permitted to call other functions. To ensure that these called functions are also available on the coprocessor, you must specify one of the following special function attributes, using the ATTRIBUTES OFFLOAD directive:

!DIR$ ATTRIBUTES OFFLOAD: target-name :: routine-name[ , routine-name] ...

!DIR$ ATTRIBUTES OFFLOAD: target-name :: variable-name[ , variable-name] ...

All functions in the program are always compiled for the CPU and are available to be called on the CPU. However, only functions marked with the special attribute are available to be called by offloaded code, and only these functions can be called on the coprocessor.

Global variables are treated in a similar fashion. All global variables are always present in the CPU code. But only global variables with the target attribute are compiled into the binary offloaded to the coprocessor.

Compiling only functions and data explicitly marked with the target attribute into the Intel® MIC Architecture binary ensures that the code on the coprocessor is as small as possible.

The compiler issues warnings for functions and data referenced within offloaded code that do not have the target attribute.

Example

module offload_test
public

!DIR$ ATTRIBUTES OFFLOAD:mic :: global_value
integer :: global_value

contains
    !DIR$ ATTRIBUTES OFFLOAD:mic :: incr_global
    integer function incr_global
    global_value = global_value + 1
    incr_global = global_value
    return
    end function incr_global
end module offload_test

program main
 use offload_test
  integer i
  i = incr_global()
  print *, "global = ", global_value, "i = ", i, " (should be the same)"

Note

The presence of a function call within an offloaded construct with a target attribute does not automatically declare that function as available on that target. The function definition must include the appropriate target attribute to ensure that the function is available on the target.

Note

The definition and all declarations of a variable or function with a target attribute must be consistent with each other across all compilation units.

See Also