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

ID 767251
Date 11/07/2023
Public

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

Document Table of Contents

Enable Auto-Parallelization

To enable the auto-parallelizer, use the [Q]parallel option. This option detects parallel loops capable of being executed safely in parallel, and automatically generates multi-threaded code for these loops.

NOTE:
You may need to set the KMP_STACKSIZE environment variable to an appropriately large size to enable parallelization with this option.

NOTE:

Using this option enables parallelization for both Intel® microprocessors and non-Intel microprocessors. The resulting executable may get additional performance gain on Intel® microprocessors than on non-Intel microprocessors. The parallelization can also be affected by certain options, such as /arch (Windows), -m (Linux), or [Q]x.

An example of the command using auto-parallelization is as follows:

Linux

ifort -c -parallel myprog.f

Windows

ifort -c /Qparallel myprog.f

Auto-parallelization uses two specific directives: !DIR$ PARALLEL and !DIR$ NOPARALLEL .

The format of an auto-parallelization compiler directive is below:

!DIR$ <directive>

Because auto-parallelization directives begin with an exclamation point, the directives take the form of comments if you omit the [Q]parallel option.

The !DIR$ PARALLEL directive instructs the compiler to ignore dependencies that it assumes may exist and that would prevent correct parallelization in the immediately following loop. However, if dependencies are proven, they are not ignored. In addition, PARALLEL [ALWAYS] overrides the compiler heuristics that estimate the likelihood that parallelization of a loop increases performance. It allows a loop to be parallelized even if the compiler thinks parallelization may not improve performance. If the ASSERT keyword is added, as in !DIR$ PARALLEL [ALWAYS [ASSERT]], the compiler generates an error-level assertion message saying that the compiler analysis and cost model indicate that the loop cannot be parallelized.

The !DIR$ NOPARALLEL directive disables auto-parallelization.

For example, in the following code, the NOPARALLEL directive disables auto-parallelization.

program main 
parameter (n=100 
integer x(n),a(n) 
!DIR$ NOPARALLEL 
do i=1,n
  x(i) = i 
enddo 
!DIR$ PARALLEL 
do i=1,n
  a( x(i) ) = i 
enddo 
end

See Also