|
Bertini 2 d882924 (2026-10-06 19:56 UTC)
Numerical algebraic geometry library (C++ core)
|
Optional faster allocator for GMP/MPFR/MPC limb allocation. More...
Go to the source code of this file.
Namespaces | |
| namespace | bertini |
Functions | |
| void | bertini::InstallFastAllocator () |
| Install the fast multiprecision allocator (idempotent; safe to call more than once). | |
Optional faster allocator for GMP/MPFR/MPC limb allocation.
Adaptive-precision tracking spends roughly half its time in mpfr/mpc allocate/free of small, short-lived limb buffers. Routing GMP's allocator (which mpfr and mpc allocate through) to a fast thread-caching allocator (mimalloc) makes each of those allocations far cheaper, with no change to the numerics – measured ~16% wall-clock on a representative adaptive solve.
This installs an ownership-aware hook via GMP's mp_set_memory_functions, calling mimalloc's mi_* explicitly (mimalloc is built NON-override, so the process malloc is untouched – safe for a Python extension sharing the interpreter with NumPy and other GMP users such as gmpy2). The hook is ownership-aware (mi_is_in_heap_region) so it correctly frees/reallocs GMP objects that were allocated by the default allocator before the hook was installed (e.g. during static init, or by another library imported first) – so it is safe to install at any time.
When built with -DBERTINI2_FAST_ALLOC=OFF (no mimalloc), InstallFastAllocator() is a no-op. At runtime, setting the environment variable BERTINI2_NO_FAST_ALLOC also disables it.