Skip to content

Intel compilers

Intel produces compilers that produce highly optimized code for their CPUs. As with all compilers, programs compiled with optimization should have their output double-checked for accuracy. If the numeric output is incorrect or lacks the desired accuracy less-aggressive compile options should be tried.

You can load intel compiler toolchains with following commands:

Check available versions and load desired toolchain
  1. Check available versions of intel compiler toolchain
    module spider intel
    
  2. Load the desired version of toolchain
    module load intel/2022b
    

Compilers

The following compilers are available for every toolchain version. You can use man command for more information.

Command
Description
icc C compiler
icpc C++ compiler
ifort Fortran compiler
dpcpp Data Parallel C++ compiler

General compiler optimization flags

Recommended optimization flags

We suggest to use at least following optimization flags for compilation:

icc -O3 -xCORE-AVX512 mycode.c

The Intel compilers optimization flags deliberately mimic many of those used with the GNU family of compilers. The basic optimization flags are summarized below.

Command
Description
-O Optimized compilation
-O2 Recommended by intel, more extensively optimized compilation
-O3 More aggressive than -O2 with longer compile times. Recommended for codes that loops involving intensive floating point calculations.
-Ofast -O3 optimization with extras
-mtune=processor This flag does additional tuning for specific processor types, however it does not generate extra SIMD instructions.The tuning will involve optimizations for processor cache sizes, preferred ordering of instructions, and so on. We suggest to try -mtune=icelake-server or mtune=icelake

SIMD Instructions flags

These flags will produce executables that contain specific SIMD instructions.

Command
Description
-xHost Must be used with at least -O2. Creates an executable that uses SIMD instructions based on the CPU that is compiling the code.
-fast A combination of -Ofast, -ipo, -static (for static linking), and -xHost.
-march Must be used with at least -O2 and specifies the type of SIMD instructions to be generated. When combined with the -ax flag this sets the minimum SIMD instruction set. The values for this flag mimic those from the GNU compilers: sse4.2,avx, avx2, and a large number of avx512 flags.
-axarch This must be used with at least -O2 and -march. The -march flag will produce specific SIMD instructions, and additional SIMD instructions can be supported by adding the -axarch flag. Every function that can be compiled with SIMD instructions will have separate copies created for each instruction set. The executable will auto-detect CPU instruction support at runtime which version to run. The compile times can be very long as functions will be compiled multiple times over and the resulting binary will be large. Several instruction sets can included with this command when comma-separated.

Simple test of compiler

You can simply test the compiler with following Hello World! code:

Simple test of compiler
  1. Copy following code to file:
    #include <stdio.h>
    int main() {
    printf("Hello, World!");
    return 0;
    }
    
  2. Compile the code:
    icc hello.c -o hello.x
    
  3. Run the binary:
    ./hello.x
    
Created by: Martin Blaško