Fortran vs. C Offload Directives and Functions

By Belinda M Liviero,

Published:12/20/2012   Last Updated:12/20/2012

This is a "cheatsheet" comparing the Fortran and C++ offload directives and functions in the context of programming for the Intel® Xeon Phi™ coprocessor

  Fortran (explicit model) C/C++ (explicit model) C/C++ (implicit model)
includes use mic_lib #include offload.h #include cilk.h
functions result = offload_number_of_devices() result =
  result = offload_get_device_number() result =



  omp_set_num_threads_target( TARGET_MIC, mic_num, num_threads) omp_set_num_threads_target( TARGET_MIC, mic_num, num_threads)  
  More APIs can be found in /opt/intel/include/intel64/mic_lib.f90 More APIs can be found in /opt/intel/include/offload.h More APIs can be found in /opt/intel/include/offload.h
environment variables same for Fortran and C++
preprocessor macros same for Fortran and C++ but note - the macros are used with #ifdef MACRO_NAME ...#else ... #endif and require that the Fortran file end in F90 rather than f90 or that the command line includes the -fpp option


Offload next statement

!dir$ offload target

where <statement> is

call subroutine_name(args)


ret_val = function_name(args)

#pragma offload target(mic[:n]) <opt_offload_clauses>

where <statement> is any valid C++ statement including compound statements, for example - if statement, for statement, or simple block statement such as {s1;s2;s3;…}

ret_val =


ret_val =_Cilk_offload_to n function_name(vars)

ret_val =
_Cilk_spawn _Cilk_offload

ret_val =
_Cilk_spawn _Cilk_offload_to
n function_name(args)

Offload enclosed block of code

!dir$ offload begin target


!dir$ end offload

See note above about compound statements  
Offload OpenMP parallel section (or cilk_for construct) !dir$ [omp] offload target(mic[:n]) <opt_offload_clause>



!$omp <end_directive>
#pragma offload target(mic[:n]) <opt_offload_clauses>

#pragma omp<parallel_directive>


ret_val =
_Cilk_offload _Cilk_for
(init-expr; test-expr; incr-expr) {statements}

ret_val =
n _Cilk_for ( init-expr; test-expr; incr-expr) {statements}

Start asynchronous data transfer to Coprocessor

!dir$ offload_transfer <in_offload_clauses> signal(signal_var)

#pragma offload_transfer<in_offload_clauses>
Complete asynchronous data transfer from Coprocessor !dir$ offload_transfer wait(signal_var) <out_offload_clauses> #pragma offload_transfer
Offload wait !dir$ offload_wait(signal_var) #pragma offload_wait(&signal_var)  
Mark a function or subroutine as needing both a host and Coprocessor version !dir$ attributes offload:mic :: routine_name __attribute__ ((target(mic))) function_declaration


function_type C_Cilk_offload function_declaration
Mark a global variable as needing to be allocated memory on both the host and Coprocessor !dir$ attributes offload:mic :: var_name __attribute__ ((target(mic)))variable_declaration

__declspec (target(mic))variable_declaration

_Cilk_shared variable_declaration
Mark everything in the enclosed region as needing both host and Coprocessor versions !dir$ options /offload-attribute-target=mic
!dir$ end options
(Valid only in declarations section of subroutine or function)
#pragma offload_attribute

#pragma offload_attribute(pop)

#pragma offload_attribute
( push, _Cilk_shared)

#pragma offload_attribute

Allocate memory in the shared memory areas for host and Coprocessor    

ptr =
_Offload_shared_malloc (

ptr =




Offload Clauses Used in Directives



where condition evaluates to .true. or .false.


where condition evaluates to 0 or 1







identical in Fortran and C++ in(var_list[:modifiers]) in(var_list[:modifiers])  
out(var_list[:modifiers]) out(var_list[:modifiers])  
inout(var_list[:modifiers]) inout(var_list[:modifiers])  
nocopy(var_list[:modifiers]) nocopy(var_list[:modifiers])  

Modifiers that Can Be Used with In, Out, Inout and Nocopy Clauses

  length(num_elem) length(num_elem)  


where condition evaluates to .true. or .false.


where condition evaluates to 1 or 0


where condition evaluates to .true. or .false.


where condition evaluates to 1 or 0

  align(n) align(n)  
  alloc([first_index:last_index]) alloc([first_index:element_count])  
  into(var_name) into(var_name)  

Product and Performance Information


Intel's compilers may or may not optimize to the same degree for non-Intel microprocessors for optimizations that are not unique to Intel microprocessors. These optimizations include SSE2, SSE3, and SSSE3 instruction sets and other optimizations. Intel does not guarantee the availability, functionality, or effectiveness of any optimization on microprocessors not manufactured by Intel. Microprocessor-dependent optimizations in this product are intended for use with Intel microprocessors. Certain optimizations not specific to Intel microarchitecture are reserved for Intel microprocessors. Please refer to the applicable product User and Reference Guides for more information regarding the specific instruction sets covered by this notice.

Notice revision #20110804