FAQ: how to perform jit for function evaluations of my optimization problem? - casadi/casadi GitHub Wiki
Take any optimization problem such as rosenbrock
from https://github.com/casadi/casadi/blob/master/docs/examples/
nlpsol
takes a fourth optional argument with options.
If you are using opti, you pass options as second argument to opti.solver
In Matlab, options are given by a struct, in Python options are given by a dictionary.
The jit
option will have the following effect:
- any helper Function that a solver requests (e.g.
nlp_jac_g
to evaluate the constraint Jacobian) will be code-generated to the disk - the code will be compiled into a shared library
- the shared library will be loaded back into CasADi, like
External
By default, a shipped clang-compiler is used, but it appears to be buggy.
We recommend to use your system compiler (shell
).
Examples:
options = struct;
options.jit = true;
options.compiler = 'shell';
options.jit_options.flags = {'-O3'};
options.jit_options.verbose = true;
jit_options = {"flags": ["-O3"], "verbose": True}
options = {"jit": True, "compiler": "shell", "jit_options": jit_options}
On Linux/Mac, this just work if you have gcc
installed.
For Windows, Matlab/Python will need to be started from an environment that has Visual Studio compiler set up. For example, launch Matlab/Python from x64 Native Tools Command Propmt for VS
(Requires Visual C++ components or Build Tools for Visual Studio, available from Visual Studio installer. You also need SDK libraries in order to access stdio and math.).
Which compiler flags to use to make it really fast?
A good choice for GCC is -Ofast -march=native
.
TODO why.
JIT has additional options like
opts.jit_cleanup = false;
opts.jit_temp_suffix = false;
TODO what do they mean?
See also: