pyccel.commands.epyccel module#
File containing functions for calling Pyccel interactively (epyccel and epyccel_seq)
- pyccel.commands.epyccel.epyccel(function_class_or_module, *, language='fortran', compiler_family=None, compiler_config=None, flags=None, wrapper_flags=None, debug=None, include=(), libdir=(), libs=(), folder=None, mpi=False, openmp=False, verbose=0, time_execution=False, developer_mode=False, conda_warnings='basic', context_dict=None, comm=None, root=0, bcast=True)[source]#
Accelerate Python function or module using Pyccel in “embedded” mode.
This function accelerates a Python function or module using Pyccel in “embedded” mode. It generates optimized code in the specified language (default is ‘fortran’) and compiles it for improved performance. Please be aware that only one of the parameters compiler_family and compiler_config may be provided.
- Parameters:
function_class_or_module (function | class | module | str) – Python function, class, or module to be accelerated. If a string is passed then it is assumed to be the code from a module which should be accelerated. The module must be capable of running as a standalone file so it must include any necessary import statements.
language ({'fortran', 'c', 'python'}) – Language of generated code (default: ‘fortran’).
compiler_family ({'GNU', 'intel', 'PGI', 'nvidia', 'LLVM'}, optional) – Compiler family for which Pyccel uses a default configuration (default: ‘GNU’).
compiler_config (pathlib.Path | str, optional) – Path to a JSON file containing a compiler configuration (overrides compiler_family).
flags (iterable of str, optional) – Compiler flags.
wrapper_flags (iterable of str, optional) – Compiler flags for the wrapper.
debug (bool, optional) – Indicates whether the file should be compiled in debug mode. The default value is taken from the environment variable PYCCEL_DEBUG_MODE. If no such environment variable exists then the default is False.
include (tuple, optional) – Additional include directories for the compiler.
libdir (tuple, optional) – Additional library directories for the compiler.
libs (tuple, optional) – Additional libraries to link with.
folder (str, optional) – Output folder for the compiled code.
mpi (bool, default=False) – If True, use MPI for parallel execution.
openmp (bool, default=False) – If True, use OpenMP for parallel execution.
verbose (int, default=0) – Set the level of verbosity to see additional information about the Pyccel process.
time_execution (bool) – Time the execution of Pyccel’s internal stages.
developer_mode (bool, default=False) – If True, set error mode to developer.
conda_warnings ({'off', 'basic', 'verbose'}) – Specify the level of Conda warnings to display (default: ‘basic’).
context_dict (dict[str, obj], optional) – A dictionary containing any Python objects from the calling scope which should be made available to the translated code. By default any objects that are used in the body of the function are made available, as well as any global objects. If the argument is provided then these objects will be treated as additional to the default arguments.
comm (mpi4py.MPI.Comm, optional) – MPI communicator for calling Pyccel in parallel mode (default: None) (for parallel mode).
root (int, optional) – MPI rank of process in charge of accelerating code (default: 0) (for parallel mode).
bcast ({True, False}) – If False, only root process loads accelerated function/module (default: True) (for parallel mode).
- Returns:
Accelerated function, class or module.
- Return type:
object
See also
epyccel_seq
The version of this function called in a sequential context.
Examples
>>> def one(): return 1 >>> from pyccel import epyccel >>> one_f = epyccel(one, language='fortran') >>> one_c = epyccel(one, language='c')
- pyccel.commands.epyccel.epyccel_seq(function_class_or_module, *, language='fortran', compiler_family=None, compiler_config=None, flags=None, wrapper_flags=None, debug=None, include=(), libdir=(), libs=(), folder=None, mpi=False, openmp=False, openacc=False, verbose=0, time_execution=False, conda_warnings='basic', context_dict=None)[source]#
Accelerate Python function or module using Pyccel in “embedded” mode.
This function accelerates a Python function or module using Pyccel in “embedded” mode. It generates optimized code in the specified language (default is ‘fortran’) and compiles it for improved performance. Please be aware that only one of the parameters compiler_family and compiler_config may be provided.
- Parameters:
function_class_or_module (function | class | module | str) – Python function, class, or module to be accelerated. If a string is passed then it is assumed to be the code from a module which should be accelerated. The module must be capable of running as a standalone file so it must include any necessary import statements.
language ({'fortran', 'c', 'python'}) – Language of generated code (default: ‘fortran’).
compiler_family (str, optional) – Compiler family for which Pyccel uses a default configuration (default: ‘GNU’).
compiler_config (pathlib.Path | str, optional) – Path to a JSON file containing a compiler configuration (overrides compiler_family).
flags (str, optional) – Compiler flags.
wrapper_flags (str, optional) – Flags to be passed to the wrapper code generator.
debug (bool, optional) – Whether the file should be compiled in debug mode. The default value is taken from the environment variable PYCCEL_DEBUG_MODE. If no such environment variable exists then the default is False.
include (tuple, optional) – Additional include directories for the compiler.
libdir (tuple, optional) – Additional library directories for the compiler.
libs (tuple, optional) – Additional libraries.
folder (str, optional) – Output folder for the compiled code.
mpi (bool, default=False) – If True, use MPI for parallel execution.
openmp (bool, default=False) – If True, use OpenMP for parallel execution.
openacc (bool, default=False) – If True, use OpenACC for parallel execution.
verbose (int, default=0) – Set the level of verbosity to see additional information about the Pyccel process.
time_execution (bool) – Time the execution of Pyccel’s internal stages.
conda_warnings ({'off', 'basic', 'verbose'}) – Specify the level of Conda warnings to display (default: ‘basic’).
context_dict (dict[str, obj], optional) – A dictionary containing any Python objects from the calling scope which should be made available to the translated code. By default any objects that are used in the body of the function are made available, as well as any global objects. If the argument is provided then these objects will be treated as additional to the default arguments.
- Returns:
Return accelerated Python module and function.
- Return type:
object
- pyccel.commands.epyccel.get_source_code_and_context(func_or_class)[source]#
Get the source code and context from a function or a class.
Get a string containing the source code of a function from a function object or the source code of a class from a class object. Excessive indenting is stripped away.
Additionally retrieve the information about the variables that are available in the calling context. This can allow certain constants such as type hints to be defined outside of the function passed to epyccel.
- Parameters:
func_or_class (Function | type) – A Python function or class.
- Returns:
code (list[str]) – A list of strings containing the lines of the source code.
context_dict (dict[str, object]) – A dictionary containing any objects defined in the context which may be useful for the function.
- Raises:
TypeError – A type error is raised if the object passed to the function is not callable.