3.7 Options Controlling OpenMP and OpenACC

GCC supports OpenMP extensions to the C, C++, and Fortran languages with the -fopenmp option. Similarly, OpenACC extensions are supported in all three languages with -fopenacc. See OpenMP and OpenACC for an overview of these extensions.

-foffload=disable
-foffload=default
-foffload=target-list

Specify for which OpenMP and OpenACC offload targets code should be generated. The default behavior, equivalent to -foffload=default, is to generate code for all supported offload targets. The -foffload=disable form generates code only for the host fallback, while -foffload=target-list generates code only for the specified comma-separated list of offload targets.

Offload targets are specified in GCC’s internal target-triplet format. You can run the compiler with -v to show the list of configured offload targets under OFFLOAD_TARGET_NAMES.

-foffload-options=options
-foffload-options=target-triplet-list=options

With -foffload-options=options, GCC passes the specified options to the compilers for all enabled offloading targets. You can specify options that apply only to a specific target or targets by using the -foffload-options=target-list=options form. The target-list is a comma-separated list in the same format as for the -foffload= option.

Typical command lines are

-foffload-options='-fno-math-errno -ffinite-math-only' \
        -foffload-options=nvptx-none=-latomic
-foffload-options=amdgcn-amdhsa=-march=gfx906
-fopenacc

Enable handling of OpenACC directives ‘#pragma acc’ in C/C++ and ‘!$acc’ in free-form Fortran and ‘!$acc’, ‘c$acc’ and ‘*$acc’ in fixed-form Fortran. This option implies -pthread, and thus is only supported on targets that have support for -pthread.

-fopenacc-dim=geom

Specify default compute dimensions for parallel offload regions that do not explicitly specify them. The geom value is a triple of ‘:’-separated sizes, in order gang, worker, and vector. A size can be omitted, to use a target-specific default value.

-fopenmp

Enable handling of OpenMP directives ‘#pragma omp’, ‘[[omp::decl(...)]]’, ‘[[omp::directive(...)]]’, and ‘[[omp::sequence(...)]]’ in C/C++. In Fortran, it enables ‘!$omp’ and the conditional compilation sentinel ‘!$’. In fixed source form Fortran, the sentinels can also start with ‘c’ or ‘*’.

This option implies -pthread, and thus is only supported on targets that have support for -pthread. -fopenmp implies -fopenmp-simd.

-fopenmp-simd

Enable handling of OpenMP’s simd, declare simd, declare reduction, assume, ordered, scan and loop directive, and of combined or composite directives with simd as constituent with #pragma omp, [[omp::directive(...)]], [[omp::sequence(...)]] and [[omp::decl(...)]] in C/C++ and !$omp in Fortran. It additionally enables the conditional compilation sentinel ‘!$’ in Fortran. In fixed source form Fortran, the sentinels can also start with ‘c’ or ‘*’. Other OpenMP directives are ignored. Unless -fopenmp is additionally specified, the loop region binds to the current task region, independent of the specified bind clause.

-fopenmp-ompt
-fopenmp-ompt=level

Control how much detail GCC reports to an OMPT tool—a tool that registers callbacks with the OpenMP runtime to observe events such as when a parallel region or worksharing construct starts and ends. The level argument is one of ‘minimal’, ‘basic’, or ‘extended’; -fopenmp-ompt without an argument is equivalent to -fopenmp-ompt=basic. OMPT support itself is always present with -fopenmp; this option only changes how much is reported and at what runtime cost. Requires -fopenmp.

‘minimal’

The level used when -fopenmp-ompt is not specified. Some OpenMP constructs are reported to an OMPT tool as a single combined “encountered” event, so a tool cannot tell how long the construct’s region actually ran. No extra runtime calls are generated beyond what the construct’s semantics already require.

‘basic’

For the single, masked, and master constructs, and for distribute and worksharing-loop (for/do) constructs that use static scheduling, GCC instead reports a separate “begin” event when the region is entered and an “end” event when it is left. This lets an OMPT tool measure the time actually spent in those regions, at the cost of one extra runtime call per region.

‘extended’

In addition to what ‘basic’ reports, report a “dispatch” event each time a new chunk of loop iterations begins within a statically scheduled distribute or worksharing-loop construct (a chunk is the contiguous run of iterations handed to one thread or team at a time). This lets an OMPT tool see how work is actually split across threads, but adds a runtime call for every chunk, which can be measurably slower for loops with many small chunks.

There is no -fno-openmp-ompt: the lowest available level is -fopenmp-ompt=minimal, since OMPT support cannot be disabled outright once -fopenmp is in effect.

-fopenmp-target-simd-clone
-fopenmp-target-simd-clone=device-type

In addition to generating SIMD clones for functions marked with the declare simd directive, GCC also generates clones for functions marked with the OpenMP declare target directive that are suitable for vectorization when this option is in effect. The device-type may be one of none, host, nohost, and any, which correspond to keywords for the device_type clause of the declare target directive; clones are generated for the intersection of devices specified. -fopenmp-target-simd-clone is equivalent to -fopenmp-target-simd-clone=any and -fno-openmp-target-simd-clone is equivalent to -fopenmp-target-simd-clone=none.

At -O2 and higher (but not -Os or -Og) this optimization defaults to -fopenmp-target-simd-clone=nohost; otherwise it is disabled by default.