Intel® Fortran Compiler Classic and Intel® Fortran Compiler Developer Guide and Reference

ID 767251
Date 7/13/2023
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

Function Annotations and the SIMD Directive for Vectorization

This topic presents specific Fortran language features that better help to vectorize code.

NOTE:

The SIMD vectorization feature is available for both Intel® microprocessors and non-Intel microprocessors. Vectorization may call library routines that can result in additional performance gain on Intel® microprocessors than on non-Intel microprocessors. The vectorization can also be affected by certain options, such as /arch (Windows), -m (Linux and macOS), or [Q]x.

The !DIR$ ATTRIBUTES ALIGN:n directive enables you to overcome hardware alignment constraints. The restrict qualifier and the auto-vectorization hints address the stylistic issues due to lexical scope, data dependency, and ambiguity resolution. The SIMD feature's directive allows you to enforce vectorization of loops.

You can use the !DIR$ ATTRIBUTES VECTOR[:clauses]::function-name-listdirective to vectorize user-defined functions and loops. For SIMD usage, a function with the VECTOR attribute is called from a loop that is being vectorized.

You can use the and declarations to provide a user-defined vector implementation for a function.

The usage model of the VECTOR attribute takes a small section of code generated for the function ( VECTORLENGTH ) of the array and exploits SIMD parallelism. The implementation of task parallelism is done at the call site.

The following table summarizes the language features that help vectorize your code:

Language Feature

Description

!DIR$ ATTRIBUTES ALIGN : n :: var

Directs the compiler to align the variable to an n-byte boundary. Address of the variable is address mod n=0.

 

Directs the compiler to align the variable to an n-byte boundary with offset off within each n-byte boundary. Address of the variable is address mod n=off.

__declspec(vector) (Windows)

__attribute__(vector) (Linux and macOS)

Combines with the map operation at the call site to provide the data parallel semantics. When multiple instances of the vector declaration are invoked in a parallel context, the execution order among them is not sequenced.

!DIR$ ATTRIBUTES VECTOR [: clauses] :: function-name-list

Provides data parallel semantics by combining with the vectorized operations or loops at the call site. When multiple instances of the vector declaration are invoked in a parallel context, the execution order among them is not sequenced. The clauses are:

  • PROCESSOR

  • VECTORLENGTH

  • LINEAR

  • UNIFORM

  • [NO]MASK

restrict

Permits the disambiguator flexibility in alias assumptions, which enables more vectorization.

 
  • simd-clauses (optional): one or more of the clauses allowed for the vector attribute

__assume_aligned(a,n)

Instructs the compiler to assume that array a is aligned on an n-byte boundary; used in cases where the compiler has failed to obtain alignment information.

__assume(cond)

Instructs the compiler to assume that the represented condition is true where the keyword appears. Typically used for conveying properties that the compiler can take advantage of for generating more efficient code, such as alignment information.

The following table summarizes the auto-vectorization hints that help vectorize your code:

Hint

Description

!DIR$ IVDEP

Instructs the compiler to ignore assumed vector dependencies.

!DIR$ VECTOR [ALWAYS]

Specifies how to vectorize the loop and indicates that efficiency heuristics should be ignored. Using the ASSERT keyword with the VECTOR [ALWAYS] directive generates an error-level assertion message if the compiler efficiency heuristics indicate that the loop cannot be vectorized. Use DIR$ IVDEP to ignore the assumed dependencies.

!DIR$ NOVECTOR

Specifies that the loop should never be vectorized.

NOTE:

Some directives are available for both Intel® microprocessors and non-Intel microprocessors, but may perform additional optimizations for Intel® microprocessors than for non-Intel microprocessors.

The following table summarizes the user-mandated directives that help vectorize your code:

User-Mandated Directive

Description

!DIR$ SIMD

Enforces vectorization of loops.

SIMD Directive (OpenMP)

Requires and controls SIMD vectorization of loops.