Intel® Fortran Compiler 16.0 User and Reference Guide
The auto-parallelization feature of the Intel® Fortran Compiler automatically translates serial portions of the input program into equivalent multithreaded code. Automatic parallelization determines the loops that are good worksharing candidates, performs the dataflow analysis to verify correct parallel execution, and partitions the data for threaded code generation as needed in programming with OpenMP* directives. The OpenMP* and auto-parallelization features provide the performance gains from shared memory on multiprocessor and dual core systems.
The auto-parallelizer analyzes the dataflow of the loops in the application source code and generates multithreaded code for those loops which can safely and efficiently be executed in parallel.
This behavior enables the potential exploitation of the parallel architecture found in symmetric multiprocessor (SMP) systems.
The guided auto-parallelization feature of the Intel® Fortran Compiler helps you locate portions in your serial code that can be parallelized further. You can invoke guidance for parallelization, vectorization, or data transformation using specified compiler options of the [Q]guide series.
Automatic parallelization frees developers from having to:
Find loops that are good worksharing candidates.
Perform the dataflow analysis to verify correct parallel execution.
Partition the data for threaded code generation as is needed in programming with OpenMP* directives.
Although OpenMP* directives enable serial applications to transform into parallel applications quickly, you must explicitly identify specific portions of your application code that contain parallelism and add the appropriate compiler directives. Auto-parallelization, which is triggered by the [Q]parallel option, automatically identifies those loop structures that contain parallelism. During compilation, the compiler automatically attempts to deconstruct the code sequences into separate threads for parallel processing. No other effort is needed.
In order to execute a program that uses auto-parallelization on Linux* OS or OS X* systems, you must include the -parallel compiler option when you compile and link your program.
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* and OS X*), or [Q]x.
Serial code can be divided so that the code can execute concurrently on multiple threads. For example, consider the following serial code example.
Example 1: Original Serial Code |
---|
subroutine ser(a, b, c) integer, dimension(100) :: a, b, c do i=1,100 a(i) = a(i) + b(i) * c(i) enddo end subroutine ser |
The following example illustrates one method showing how the loop iteration space, shown in the previous example, might be divided to execute on two threads.
Example 2: Transformed Parallel Code |
---|
subroutine par(a, b, c) integer, dimension(100) :: a, b, c ! Thread 1 do i=1,50 a(i) = a(i) + b(i) * c(i) enddo ! Thread 2 do i=51,100 a(i) = a(i) + b(i) * c(i) enddo end subroutine par |
Auto-vectorization detects low-level operations in the program that can be done in parallel, and then converts the sequential program to process 2, 4, 8, or (up to) 16 elements in one operation, depending on the data type. In some cases, auto-parallelization and vectorization can be combined for better performance results. For example, in the code below, thread-level parallelism can be exploited in the outermost loop, while instruction-level parallelism can be exploited in the innermost loop.
Example |
---|
DO I = 1, 100 ! Execute groups of iterations in different hreads (TLP) DO J = 1, 32 ! Execute in SIMD style with multimedia extension (ILP) A(J,I) = A(J,I) + 1 ENDDO ENDDO |
With the relatively small effort of adding OpenMP* directives to existing code you can transform a sequential program into a parallel program. The [Q]openmp option must be specifed to enable the OpenMP directives. The following example shows OpenMP* directives within the code.
Example |
---|
!OMP$ PARALLEL PRIVATE(NUM), SHARED (X,A,B,C)
! Defines a parallel region
!OMP$ PARALLEL DO
! Specifies a parallel region that
! implicitly contains a single DO directive
DO I = 1, 1000
NUM = FOO(B(i), C(I))
X(I) = BAR(A(I), NUM)
! Assume FOO and BAR have no other effect
ENDDO
|
Options that use OpenMP* are available for both Intel® and non-Intel microprocessors, but these options may perform additional optimizations on Intel® microprocessors than they perform on non-Intel microprocessors. The list of major, user-visible OpenMP* constructs and features that may perform differently on Intel® microprocessors than on non-Intel microprocessors includes: locks (internal and user visible), the SINGLE construct, barriers (explicit and implicit), parallel loop scheduling, reductions, memory allocation, and thread affinity and binding.
To generate a parallelism report, use the -opt-report-phase=par (Linux* and OS X*) or the /Qopt-report-phase:par option along with the -opt-report= n or /Qopt-report:n option. By default the auto-parallelism report generates a medium level of detail, where n=2. You can use [Q]opt-report option along with the [Q]opt-report-phase option if you want a greater or lesser level of detail. Specifying a value of '5' generates the maximum diagnostic details.
Run the report by entering commands similar to the following:
Operating System | Command |
---|---|
Linux* |
ifort -c -parallel -opt-report-phase=par -opt-report:5 sample.cpp |
OS X* |
ifort -c -parallel -opt-report-phase=par -opt-report:5 sample.cpp |
Windows* |
ifort sample.cpp /c /Qparallel /Qopt-report-phase=par /Qopt-report:5 |
The -c (Linux* and OS X*) or /c (Windows*) prevents linking and instructs the compiler to stop compilation after the object file is generated. The example is compiled without generating an executable.
The output, by default, produces a file with the same name as the object file, with .optrpt extension, and is written into the same directory as the object file. Using the above command-line entries, you will obtain an output file called sample.optrpt. Use the [Q]opt-report-file option to specify any other name for the output file that captures the report results. Use the arguments stdout or stderr to send the optimization report to stdout or stderr.
For more information on options to generate reports see the Optimization Report Options topic.