Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,12 @@ struct context_t
size_t fill_reuse_class_count;
size_t fill_reuse_snapshot_count;
bool fill_reuse_skip_cached;
/* The caller's fill-reuse choice for this context: 0 leaves it to
* OPENNEC_FILL_REUSE and then the build default, 1 turns reuse on, -1 off.
* A per-context switch lets several solves in one process choose
* differently; the environment is process-wide. Builds without OpenMP
* have no reuse path, so 1 is ignored there. */
int fill_reuse;
};

/* Internal initialization and cleanup (called by create_context/destroy_context) */
Expand Down
4 changes: 3 additions & 1 deletion src/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,9 @@ static int fill_wire_observers(context_t *ctx, int nrow, complex double *cm, int
#else
int reuse_enabled = 0;
#endif
if (reuse_setting)
if (ctx->fill_reuse)
reuse_enabled = ctx->fill_reuse > 0;
else if (reuse_setting)
reuse_enabled = reuse_setting[0] == '1' && reuse_setting[1] == '\0';
if ((size_t)n > ctx->fill_sources_count) {
wire_source_t *grown = realloc(ctx->fill_sources, (size_t)n * sizeof(*grown));
Expand Down
8 changes: 8 additions & 0 deletions tests/benchmark_tests/check_fill_reuse_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ def main():
if state_probe:
subprocess.run([state_probe, str(deck), "reject" if reject else "reuse"],
env=env, capture_output=True, text=True, check=True)
if state_probe and name == "small_repeated":
# The context's own choice wins over the environment, both ways.
for mode, env_value in (("ctx-off", "1"), ("ctx-on", "0")):
env = os.environ.copy()
env.update(OMP_NUM_THREADS="8", VECLIB_MAXIMUM_THREADS="8",
OPENNEC_FILL_REUSE=env_value)
subprocess.run([state_probe, str(deck), mode], env=env,
capture_output=True, text=True, check=True)
choice = f"{'reject' if reject else 'reuse'}, " if state_probe else ""
print(f"PASS {name}: {choice}1/8 threads, 3 frequencies")
print(f"All {len(cases)} sampling cases passed.")
Expand Down
18 changes: 15 additions & 3 deletions tests/benchmark_tests/fill_reuse_state.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
/* Test-only driver: inspect the retained cache after a complete simulation.
* Link against the same OpenMP libonec.a and backend libraries as onec.
* Usage: fill_reuse_state deck.nec reuse|reject
* Usage: fill_reuse_state deck.nec reuse|reject|ctx-on|ctx-off
* ctx-on and ctx-off set the context's own fill_reuse (1 or -1), which must
* win over OPENNEC_FILL_REUSE: run them with the environment saying the
* opposite.
*/
#include "internals.h"
#include "reporting.h"

int main(int argc, char **argv)
{
if (argc != 3 || (strcmp(argv[2], "reuse") && strcmp(argv[2], "reject")))
if (argc != 3 || (strcmp(argv[2], "reuse") && strcmp(argv[2], "reject") &&
strcmp(argv[2], "ctx-on") && strcmp(argv[2], "ctx-off")))
return 2;
context_t *ctx = create_context();
int ctx_on = strcmp(argv[2], "ctx-on") == 0;
int ctx_off = strcmp(argv[2], "ctx-off") == 0;
if (ctx && (ctx_on || ctx_off))
ctx->fill_reuse = ctx_on ? 1 : -1;
FILE *input = fopen(argv[1], "r");
FILE *output = tmpfile();
if (!ctx || !input || !output) {
Expand All @@ -33,7 +41,11 @@ int main(int argc, char **argv)
int reject = strcmp(argv[2], "reject") == 0;
int ok = rc == 0 && ctx->fill_reuse_snapshot != NULL &&
ctx->fill_reuse_skip_cached == reject;
if (reject)
if (ctx_off)
ok = rc == 0 && ctx->fill_reuse_snapshot == NULL && ctx->fill_reuse_class_ids == NULL;
else if (ctx_on)
ok = rc == 0 && ctx->fill_reuse_snapshot != NULL;
else if (reject)
ok = ok && ctx->fill_reuse_class_ids == NULL && ctx->fill_reuse_class_count == 0;
else
ok = ok && ctx->fill_reuse_class_ids != NULL &&
Expand Down
Loading