compile_extension_module¶
-
dolfin.compilemodules.compilemodule.
compile_extension_module
(*args, **kwargs)¶ Just In Time compile DOLFIN C++ code into a Python module.
- Arguments
- code
- C++ code which implements any function or C++ class. Any function or class available in the C++ DOLFIN namespace can be used and/or subclassed. All typemaps from the original Python interface are available, making it possible to interface with for example NumPy for Array<double/int> arguments. Source which is not wrapped in a dolfin namespace will be automatically wrapped.
- module_name
- Force a name of the module. If not set a name based on the hex representation of the code will be used.
- additional_declarations
- Additional SWIG declarations can be passed using this argument.
- additional_system_headers :
- System headers needed to compile the generated can be included using this argument. The headers are passed using a list of ‘str’
- mpi_comm
- An mpi communicator used to determine what processors should compile the module. By default mpi_world_comm is used, but could also accept mpi_group communicators.
Returns
The JIT compiled extension moduleExamples of usage
The following toy example shows how one can use compiled extension modules to access low level PETSc routines:
from numpy import arange code = ''' namespace dolfin { void PETSc_exp(std::shared_ptr<dolfin::PETScVector> vec) { Vec x = vec->vec(); assert(x); VecExp(x); } } ''' ext_module = compile_extension_module(code, additional_system_headers=["petscvec.h"]) comm = mpi_comm_world() vec = PETScVector(comm, 10) vec[:] = arange(10) print vec[-1] ext_module.PETSc_exp(vec) print vec[-1]