loki.build.compiler

Functions

clean(filename[, pattern])

Clean up compilation files of previous runs.

compile(filename[, include_dirs, compiler, cwd])

compile_and_load(filename[, cwd, ...])

Just-in-time compile Fortran source code and load the respective module or class.

get_compiler_from_env([env])

Utility function to determine what compiler to use

Classes

Compiler()

Base class for specifying different compiler toolchains.

GNUCompiler()

GNU compiler configuration for gcc and gfortran

NvidiaCompiler()

NVHPC compiler configuration for nvc and nvfortran

clean(filename, pattern=None)

Clean up compilation files of previous runs.

Parameters:
  • filename – Filename that triggered the original compilation.

  • suffixes – Optional list of filetype suffixes to delete.

compile(filename, include_dirs=None, compiler=None, cwd=None)
compile_and_load(filename, cwd=None, f90wrap_kind_map=None, compiler=None)

Just-in-time compile Fortran source code and load the respective module or class.

Both paths, classic subroutine-only and modern module-based are supported via the f2py and f90wrap packages.

Parameters:
  • filename (str) – The source file to be compiled.

  • cwd (str, optional) – Working directory to use for calls to compiler.

  • f90wrap_kind_map (str, optional) – Path to f90wrap KIND_MAP file, containing a Python dictionary in f2py_f2cmap format.

  • compiler (Compiler, optional) – Use the specified compiler to compile the Fortran source code. Defaults to _default_compiler

class Compiler

Bases: object

Base class for specifying different compiler toolchains.

CC = None
CFLAGS = None
F90 = None
F90FLAGS = None
FC = None
FCFLAGS = None
LD = None
LDFLAGS = None
LD_STATIC = None
LDFLAGS_STATIC = None
F2PY_FCOMPILER_TYPE = None
compile_args(source, target=None, include_dirs=None, mod_dir=None, mode='f90')

Generate arguments for the build line.

Parameters:

sourcestr or pathlib.Path

Path to the source file to compile

targetstr or pathlib.Path, optional

Path to the output binary to generate

include_dirslist of str or pathlib.Path, optional

Path of include directories to specify during compile

mod_dirstr or pathlib.Path, optional

Path to directory containing Fortran .mod files

modestr, optional

One of 'f90' (free form), 'f' (fixed form) or 'c'

compile(source, target=None, include_dirs=None, use_c=False, cwd=None)

Execute a build command for a given source.

linker_args(objs, target, shared=True)

Generate arguments for the linker line.

Execute a link command for a given source.

static f90wrap_args(modname, source, kind_map=None)

Generate arguments for the f90wrap utility invocation line.

f90wrap(modname, source, cwd=None, kind_map=None)

Invoke f90wrap command to create wrappers for a given module.

f2py_args(modname, source, libs=None, lib_dirs=None, incl_dirs=None)

Generate arguments for the f2py-f90wrap utility invocation line.

f2py(modname, source, libs=None, lib_dirs=None, incl_dirs=None, cwd=None)

Invoke f90wrap command to create wrappers for a given module.

get_compiler_from_env(env=None)

Utility function to determine what compiler to use

This takes the following environment variables in the given order into account to determine the most likely compiler family: F90, FC, CC.

Currently, GNUCompiler and NvidiaCompiler are available.

The compiler binary and flags can be further overwritten by setting the corresponding environment variables:

  • CC, FC, F90, LD for compiler/linker binary name or path

  • CFLAGS, FCFLAGS, LDFLAGS for compiler/linker flags to use

Parameters:

env (dict, optional) – Use the specified environment (default: os.environ)

Returns:

A compiler object

Return type:

Compiler

class GNUCompiler

Bases: Compiler

GNU compiler configuration for gcc and gfortran

CC = 'gcc'
CFLAGS = ['-g', '-fPIC']
F90 = 'gfortran'
F90FLAGS = ['-g', '-fPIC']
FC = 'gfortran'
FCFLAGS = ['-g', '-fPIC']
LD = 'gfortran'
LDFLAGS = ['-static']
LD_STATIC = 'ar'
LDFLAGS_STATIC = ['src']
F2PY_FCOMPILER_TYPE = 'gnu95'
CC_PATTERN = re.compile('(^|/|\\\\)gcc\\b')
FC_PATTERN = re.compile('(^|/|\\\\)gfortran\\b')
class NvidiaCompiler

Bases: Compiler

NVHPC compiler configuration for nvc and nvfortran

CC = 'nvc'
CFLAGS = ['-g', '-fPIC']
F90 = 'nvfortran'
F90FLAGS = ['-g', '-fPIC']
FC = 'nvfortran'
FCFLAGS = ['-g', '-fPIC']
LD = 'nvfortran'
LDFLAGS = ['-static']
LD_STATIC = 'ar'
LDFLAGS_STATIC = ['src']
F2PY_FCOMPILER_TYPE = 'nv'
CC_PATTERN = re.compile('(^|/|\\\\)nvc\\b')
FC_PATTERN = re.compile('(^|/|\\\\)(pgf9[05]|pgfortran|nvfortran)\\b')