Skip to content

A per-context fill-reuse switch (ctx->fill_reuse) - #44

Merged
maurymarkowitz merged 1 commit into
maurymarkowitz:mainfrom
stevenmburns:per-context-fill-reuse
Nov 21, 2026
Merged

maurymarkowitz merged 1 commit into
maurymarkowitz:mainfrom
stevenmburns:per-context-fill-reuse

Conversation

@stevenmburns

Copy link
Copy Markdown
Contributor

OPENNEC_FILL_REUSE is read at every fill, and the environment is process-wide. So a program that embeds OpenNEC and runs several solves at once, such as a server or a Python binding solving with the GIL released, can't let one solve turn reuse off while another keeps it on.

This adds the choice to the context: ctx->fill_reuse.

  • 0 is calloc's default, so nothing changes unless a caller sets it: the environment variable decides, then the build default, exactly as now.
  • 1 turns reuse on, and -1 turns it off, for that context alone, whatever the environment says.
  • Builds without OpenMP have no reuse path, so 1 is ignored there.
  • onec never sets it, so the CLI is unchanged.

The change is three lines in fill_wire_observers plus the field in internals.h.

Test. fill_reuse_state.c gains two modes, ctx-on and ctx-off. check_fill_reuse_sampling.py runs each on the small_repeated case with the environment set the opposite way:

  • ctx-off under OPENNEC_FILL_REUSE=1 must leave no reuse cache;
  • ctx-on under OPENNEC_FILL_REUSE=0 must build one.

On Linux, with OpenMP and OpenBLAS, all 9 sampling cases pass. With the matrix.c change backed out, both new modes fail, so the check can tell.

Our use: pyopennec (Python bindings for OpenNEC) exposes it as Structure(..., fill_reuse=None | True | False), so the antennaknobs server can give each request its own choice.

Thanks for 2.4.2. Fill reuse is a big step.

🤖 Generated with Claude Code

OPENNEC_FILL_REUSE is read at every fill and the environment is
process-wide, so an embedding that runs several solves at once (a server,
a binding with the GIL released) cannot let one solve choose differently
from another. ctx->fill_reuse is that choice: 0 (calloc's default) leaves it
to OPENNEC_FILL_REUSE and then the build default exactly as before, 1 turns
reuse on and -1 off for this context alone. Builds without OpenMP have no
reuse path, so 1 is ignored there. onec never sets it, so its behaviour is
unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SKce1zVChRtJMQadEiWtJY
stevenmburns added a commit to stevenmburns/pyopennec that referenced this pull request Nov 20, 2026
OpenNEC reads OPENNEC_FILL_REUSE at every fill, and the environment is
process-wide, so a server with several solves in flight cannot let one
request say no. The submodule moves to pyopennec-base-2.4.2 at c9cbff8,
which adds OpenNEC's ctx->fill_reuse (sent upstream as
maurymarkowitz/OpenNEC#44), and Structure takes fill_reuse=None|True|False
into it: None leaves the environment and the build to decide as before.

tests/test_fill_reuse.py proves it bitwise: with the environment pointing
the other way, fill_reuse=False equals OPENNEC_FILL_REUSE=0's answer and
True equals =1's, and on/off differ (reuse engaged), so the comparison can
fail. 114 passed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SKce1zVChRtJMQadEiWtJY
stevenmburns added a commit to stevenmburns/pyopennec that referenced this pull request Nov 21, 2026
OpenNEC reads OPENNEC_FILL_REUSE at every fill, and the environment is
process-wide, so a server with several solves in flight cannot let one
request say no. The submodule moves to pyopennec-base-2.4.2 at c9cbff8,
which adds OpenNEC's ctx->fill_reuse (sent upstream as
maurymarkowitz/OpenNEC#44), and Structure takes fill_reuse=None|True|False
into it: None leaves the environment and the build to decide as before.

tests/test_fill_reuse.py proves it bitwise: with the environment pointing
the other way, fill_reuse=False equals OPENNEC_FILL_REUSE=0's answer and
True equals =1's, and on/off differ (reuse engaged), so the comparison can
fail. 114 passed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SKce1zVChRtJMQadEiWtJY
@maurymarkowitz
maurymarkowitz merged commit 941493a into maurymarkowitz:main Nov 21, 2026
6 checks passed
@maurymarkowitz

Copy link
Copy Markdown
Owner

Excellent idea! Merging...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants