fab.tools.compiler#

This file contains the base class for any compiler, and derived classes for gcc, gfortran, icc, ifort

Classes

CCompiler(name, exec_name, suite, version_regex)

This is the base class for a C compiler.

Compiler(name, exec_name, suite, ...[, mpi, ...])

This is the base class for any compiler.

Craycc([name, exec_name])

Class for the native Cray C compiler.

Crayftn([name, exec_name])

Class for the native Cray Fortran compiler.

FortranCompiler(name, exec_name, suite, ...)

This is the base class for a Fortran compiler.

Gcc([name, exec_name, mpi])

Class for GNU's gcc compiler.

Gfortran([name, exec_name])

Class for GNU's gfortran compiler.

Icc([name, exec_name])

Class for the Intel's icc compiler.

Icx([name, exec_name])

Class for the Intel's new llvm based icx compiler.

Ifort([name, exec_name])

Class for Intel's ifort compiler.

Ifx([name, exec_name])

Class for Intel's new ifx compiler.

Nvc([name, exec_name])

Class for Nvidia's nvc compiler.

Nvfortran([name, exec_name])

Class for Nvidia's nvfortran compiler.

class fab.tools.compiler.Compiler(name, exec_name, suite, version_regex, category, mpi=False, compile_flag=None, output_flag=None, openmp_flag=None, version_argument=None, availability_option=None)#

This is the base class for any compiler. It provides flags for

  • compilation only (-c),

  • naming the output file (-o),

  • OpenMP

Parameters:
  • name (str) – name of the compiler.

  • exec_name (Union[str, Path]) – name of the executable to start.

  • suite (str) – name of the compiler suite this tool belongs to.

  • version_regex (str) – A regular expression that allows extraction of the version number from the version output of the compiler. The version is taken from the first group of a match.

  • category (Category) – the Category (C_COMPILER or FORTRAN_COMPILER).

  • mpi (bool) – whether the compiler or linker support MPI. (default: False)

  • compile_flag (Optional[str]) – the compilation flag to use when only requesting compilation (not linking). (default: None)

  • output_flag (Optional[str]) – the compilation flag to use to indicate the name of the output file (default: None)

  • openmp_flag (Optional[str]) – the flag to use to enable OpenMP. If no flag is specified, it is assumed that the compiler does not support OpenMP. (default: None)

  • availability_option (Union[str, List[str], None]) – a command line option for the tool to test if the tool is available on the current system. Defaults to –version. (default: None)

property mpi: bool#
Returns:

whether this compiler supports MPI or not.

property openmp: bool#
Returns:

compiler’s OpenMP support.

property openmp_flag: str#
Returns:

compiler argument to enable OpenMP.

property compile_flag: str#
Returns:

the flag to indicate compilation only (not linking).

property output_flag: str#
Returns:

compiler argument for output file.

get_hash(profile=None)#
Return type:

int

Returns:

hash of compiler name and version.

get_flags(profile=None)#

Determines the flags to be used.

Return type:

List[str]

Returns:

the flags to be used with this tool.

get_all_commandline_options(config, input_file, output_file, add_flags=None)#

This function returns all command line options for a compiler (but not the executable name). It is used by a compiler wrapper to pass the right flags to the wrapper. This base implementation adds the input and output filename (including the -o flag), the flag to only compile (and not link), and if required openmp.

Parameters:
  • input_file (Path) – the name of the input file.

  • output_file (Path) – the name of the output file.

  • config (BuildConfig) – The BuildConfig, from which compiler profile and OpenMP status are taken.

  • add_flags (Optional[List[str]]) – additional flags for the compiler. (default: None)

Return type:

List[str]

Returns:

all command line options for compilation.

compile_file(input_file, output_file, config, add_flags=None)#

Compiles a file. It will add the flag for compilation-only automatically, as well as the output directives. The current working directory for the command is set to the folder where the source file lives when compile_file is called. This is done to stop the compiler inserting folder information into the mod files, which would cause them to have different checksums depending on where they live.

Parameters:
  • input_file (Path) – the path of the input file.

  • output_file (Path) – the path of the output file.

  • config (BuildConfig) – The BuildConfig, from which compiler profile and OpenMP status are taken.

  • add_flags (Optional[List[str]]) – additional compiler flags. (default: None)

check_available()#

Checks if the compiler is available. While the method in the Tools base class would be sufficient (when using –version), in case of a compiler we also want to store the compiler version. So, re-implement check_available in a way that will automatically store the compiler version for later usage.

Return type:

bool

Returns:

whether the compiler is available or not. We do this by requesting the compiler version.

get_version()#

Try to get the version of the given compiler.

Expects a version in a certain part of the –version output, which must adhere to the n.n.n format, with at least 2 parts.

Return type:

Tuple[int, ...]

Returns:

a tuple of at least 2 integers, representing the version e.g. (6, 10, 1) for version ‘6.10.1’.

Raises:

RuntimeError – if the compiler was not found, or if it returned an unrecognised output from the version command.

run_version_command(version_command='--version')#

Run the compiler’s command to get its version.

Parameters:

version_command (Optional[str]) – The compiler argument used to get version info. (default: '--version')

Return type:

str

Returns:

The output from the version command.

Raises:

RuntimeError – if the compiler was not found, or raised an error.

get_version_string()#

Get a string representing the version of the given compiler.

Return type:

str

Returns:

a string of at least 2 numeric version components, i.e. major.minor[.patch, …]

Raises:

RuntimeError – if the compiler was not found, or if it returned an unrecognised output from the version command.

class fab.tools.compiler.CCompiler(name, exec_name, suite, version_regex, mpi=False, compile_flag=None, output_flag=None, openmp_flag=None, version_argument=None, availability_option=None)#

This is the base class for a C compiler. It just sets the category of the compiler as convenience.

Parameters:
  • name (str) – name of the compiler.

  • exec_name (str) – name of the executable to start.

  • suite (str) – name of the compiler suite.

  • version_regex (str) – A regular expression that allows extraction of the version number from the version output of the compiler.

  • mpi (bool) – whether the compiler or linker support MPI. (default: False)

  • compile_flag (Optional[str]) – the compilation flag to use when only requesting compilation (not linking). (default: None)

  • output_flag (Optional[str]) – the compilation flag to use to indicate the name of the output file (default: None)

  • openmp_flag (Optional[str]) – the flag to use to enable OpenMP (default: None)

class fab.tools.compiler.FortranCompiler(name, exec_name, suite, version_regex, mpi=False, compile_flag=None, output_flag=None, openmp_flag=None, version_argument=None, module_folder_flag=None, syntax_only_flag=None)#

This is the base class for a Fortran compiler. It is a compiler that needs to support a module output path and support for syntax-only compilation (which will only generate the .mod files).

Parameters:
  • name (str) – name of the compiler.

  • exec_name (str) – name of the executable to start.

  • suite (str) – name of the compiler suite.

  • version_regex (str) – A regular expression that allows extraction of the version number from the version output of the compiler.

  • mpi (bool) – whether MPI is supported by this compiler or not. (default: False)

  • compile_flag (Optional[str]) – the compilation flag to use when only requesting compilation (not linking). (default: None)

  • output_flag (Optional[str]) – the compilation flag to use to indicate the name of the output file (default: None)

  • openmp_flag (Optional[str]) – the flag to use to enable OpenMP (default: None)

  • module_folder_flag (Optional[str]) – the compiler flag to indicate where to store created module files. (default: None)

  • syntax_only_flag (Optional[str]) – flag to indicate to only do a syntax check. The side effect is that the module files are created. (default: None)

property has_syntax_only: bool#
Returns:

whether this compiler supports a syntax-only feature.

set_module_output_path(path)#

Sets the output path for modules.

Params path:

the path to the output directory.

get_all_commandline_options(config, input_file, output_file, add_flags=None, syntax_only=False)#

This function returns all command line options for a Fortran compiler (but not the executable name). It is used by a compiler wrapper to pass the right flags to the wrapper. This Fortran-specific implementation adds the module- and syntax-only flags (as required) to the standard compiler flags.

Parameters:
  • input_file (Path) – the name of the input file.

  • output_file (Path) – the name of the output file.

  • config (BuildConfig) – The BuildConfig, from which compiler profile and OpenMP status are taken.

  • add_flags (Optional[List[str]]) – additional flags for the compiler. (default: None)

  • syntax_only (Optional[bool]) – if set, the compiler will only do a syntax check (default: False)

Return type:

List[str]

Returns:

all command line options for Fortran compilation.

compile_file(input_file, output_file, config, add_flags=None, syntax_only=False)#

Compiles a file. This basically re-implements compile_file of the base class, but passes the syntax_only flag in

Parameters:
  • input_file (Path) – the name of the input file.

  • output_file (Path) – the name of the output file.

  • config (BuildConfig) – The BuildConfig, from which compiler profile and OpenMP status are taken.

  • add_flags (Optional[List[str]]) – additional flags for the compiler. (default: None)

  • syntax_only (Optional[bool]) – if set, the compiler will only do a syntax check (default: False)

class fab.tools.compiler.Gcc(name='gcc', exec_name='gcc', mpi=False)#

Class for GNU’s gcc compiler.

Parameters:
  • name (str) – name of this compiler. (default: 'gcc')

  • exec_name (str) – name of the executable. (default: 'gcc')

  • mpi (bool) – whether the compiler supports MPI. (default: False)

class fab.tools.compiler.Gfortran(name='gfortran', exec_name='gfortran')#

Class for GNU’s gfortran compiler.

Parameters:
  • name (str) – name of this compiler. (default: 'gfortran')

  • exec_name (str) – name of the executable. (default: 'gfortran')

  • mpi – whether the compiler supports MPI.

class fab.tools.compiler.Icc(name='icc', exec_name='icc')#

Class for the Intel’s icc compiler.

Parameters:
  • name (str) – name of this compiler. (default: 'icc')

  • exec_name (str) – name of the executable. (default: 'icc')

  • mpi – whether the compiler supports MPI.

class fab.tools.compiler.Ifort(name='ifort', exec_name='ifort')#

Class for Intel’s ifort compiler.

Parameters:
  • name (str) – name of this compiler. (default: 'ifort')

  • exec_name (str) – name of the executable. (default: 'ifort')

  • mpi – whether the compiler supports MPI.

class fab.tools.compiler.Icx(name='icx', exec_name='icx')#

Class for the Intel’s new llvm based icx compiler.

Parameters:
  • name (str) – name of this compiler. (default: 'icx')

  • exec_name (str) – name of the executable. (default: 'icx')

class fab.tools.compiler.Ifx(name='ifx', exec_name='ifx')#

Class for Intel’s new ifx compiler.

Parameters:
  • name (str) – name of this compiler. (default: 'ifx')

  • exec_name (str) – name of the executable. (default: 'ifx')

class fab.tools.compiler.Nvc(name='nvc', exec_name='nvc')#

Class for Nvidia’s nvc compiler. Note that the ‘-’ in the Nvidia version number is ignored, e.g. 23.5-0 would return ‘23.5’.

Parameters:
  • name (str) – name of this compiler. (default: 'nvc')

  • exec_name (str) – name of the executable. (default: 'nvc')

class fab.tools.compiler.Nvfortran(name='nvfortran', exec_name='nvfortran')#

Class for Nvidia’s nvfortran compiler. Note that the ‘-’ in the Nvidia version number is ignored, e.g. 23.5-0 would return ‘23.5’.

Parameters:
  • name (str) – name of this compiler. (default: 'nvfortran')

  • exec_name (str) – name of the executable. (default: 'nvfortran')

class fab.tools.compiler.Craycc(name='craycc-cc', exec_name='cc')#

Class for the native Cray C compiler. Since cc is actually a compiler wrapper, follow the naming scheme of a compiler wrapper and call it: craycc-cc.

Cray has two different compilers. Older ones have as version number:

Cray C : Version 8.7.0 Tue Jul 23, 2024 07:39:46

Newer compiler (several lines, the important one):

Cray clang version 15.0.1 (66f7391d6a03cf932f321b9f6b1d8612ef5f362c)

We use the beginning (“cray c”) to identify the compiler, which works for both cray c and cray clang. Then we ignore non-numbers, to reach the version number which is then extracted.

Parameters:
  • name (str) – name of this compiler. (default: 'craycc-cc')

  • exec_name (str) – name of the executable. (default: 'cc')

class fab.tools.compiler.Crayftn(name='crayftn-ftn', exec_name='ftn')#

Class for the native Cray Fortran compiler. Since ftn is actually a compiler wrapper, follow the naming scheme of Cray compiler wrapper and call it crayftn-ftn.

Parameters:
  • name (str) – name of this compiler. (default: 'crayftn-ftn')

  • exec_name (str) – name of the executable. (default: 'ftn')