libMesh/libmesh — pull request #349 by dschwen (2014-09-16 02:34:26+00:00)
Title: Just in time compilation for Function Parser

This patch adds some JIT support to FParser. It gets stuff done, but 'm warning you, it ain't pretty. The gist of it is, I'm building a small temp file with C source generated from the FParser byte code. Then this is compiled into a temp .so file (launching a compiler using the ```system()``` command (bear with me). The .so is loaded using ```dlopen``` etc. This should work on Mac (tested) and Linux (guessed). All the steps in the JIT process are set up to fail gracefully (Eval then falls back to the byte code interpreter). The subset of commands supported is the same as the autodiff stuff supports.

I'm seeing speedups of 5x for a still relatively simple function. The motivation for the patch are super long free energies with tons of derivatives, evaluated for every residual/jacobian construction, needed in a current project (I will try to gather real life performance comparisons).

Using ```system()``` is a bit rough, especially when we have cool frameworks like LLVM, that provide libraries for JIT stuff. I've played with those and they are not very portable ATM. For example the moose clang 3.3 (rather old) is compiled with g++ and the resulting LLVM libs are not binary compatible with clang generated code. Plus we'd be excluding g++ folks anyways. Compile times for these tiny snippets are of the order of 100ms, and I'm caching the binaries (I'm calculating sha1 hashes of the bytecode).

Anyhow, fire away!