Triggers¶
[[triggers]] (#544) pair a condition on the run with actions. User docs:
Running and controlling jobs.
Decisions¶
- Conditions are kexpr expressions of values already reduced. The
variables are
t,step,dt,walland the latest row of every monitor:[integrals],[[forces]], the reductions of[[probes]]and the values of one-point probes, named<monitor>_<column>. kexpr has no strings, so a monitor's name is part of the variable name rather than an argument (combustor_MAX_T). A condition reads what the monitors wrote;max(T, "combustor")is written as a call but is a monitor too, an internal probe (decision 8). - Evaluated on the host after every step, once that step's probes are written. Probes are now written before the scheduled snapshots and restarts of the step (their files are independent), so a trigger reads this step's values and a restart written at the step carries the state after it; a run resumed from it continues exactly. A monitor written every n steps keeps its value in between; before its first value a condition reading it is false.
- Ranks agree by construction. Probe values live on rank 0, and
walldiffers between ranks, so on a distributed mesh rank 0 evaluates every condition and broadcasts one byte per trigger; every rank then advances the same state machines with the samet. Undistributed runs evaluate locally. A run without triggers does nothing new: no evaluation, no message. Conditions evaluated on the device read rank 0'swallfrom the step's time-step reduction instead. - State machine. A trigger is armed until it fires; it fires once its
condition has held for
forseconds of simulated time, counted from the step it last turned true (a lapse restarts the clock, the hysteresis against chatter). Withrepeat, it re-arms when the condition is false, so it fires on each rising edge rather than every step. Restart attributesTRIGGER_<name>_{FIRINGS,ARMED,HOLDING,SINCE,T_FIRST}carry the state; a restart file without them starts the trigger afresh, as does a remap.STEP_LASTandT_LAST(of the last firing) givemallard ctl statusits "fired at" and decide, across a restart, whether the last trigger to start or stop the statistics stopped them (by step, then by the order triggers act in). - Actions reuse existing paths.
stopis a stop reason liket_stop(final output, a restart, exit status 0);checkpointis the run-control checkpoint;write <prefix>forces that writer once (time-based writers keep their schedule);start statisticsholds[statistics](and its spectra and phases) att_start = infuntil the trigger fires, then starts them ast_startwould, so the averages equal those of a run with thatt_startbit for bit (tested), also across a restart (the first firing's time is restored).stop statisticssets theirt_startto infinity: sampling comparest > t_starton the host and the device alike, so no sample is taken after that step and the averages keep their values; the clocks need no other state.logis an event record;setcalls themallard ctl setpath (Solver::apply_setting), which also checks each setting at setup without applying it, so a refused key is an input error. -
Record. Each firing is a log line and an
eventrecord of kindtriggerwith the trigger's name, firing count and the values its condition read, so a reader can see why it fired. -
Landing on time conditions. The constants a condition compares
twith are read off its bytecode (VAR t, CONST c, <comparison>or the mirror), not from the text, so constant folding and parentheses do not matter. While a trigger can still fire (armed, orrepeat), the next such time joinst_stopand the time-based outputs innext_target_time, which shortens the step to end there; it is rounded up to the nextrtypeso thatt >= cholds at the landing. With steps queued on the device, the time is also a horizon (step_horizon) at which the host takes over and moves on to the next one, as fort_stop, since the device's target is the one the host set. A condition'stcompared with anything else (t - c) is not analyzed. The same analysis letsmallard checkdecide conditions oftalone: constant between the compared times, they are evaluated at each and between each two up tot_stop(W-TRIGGER-NEVER). -
Region reductions in conditions.
max(T, "domain")names a reduction over a region in the condition itself. Before kexpr compiles it, each such call (a reduction's name, a field and a quoted region) becomes a variable: the value of an internal probe of that region, one per region with the union of the fields and reductions its calls read, written every step. The internal probe is an ordinary region probe in every other way, so the step graph stages and reduces it on the device (a trigger reads it) and the values are those a[[probes]]entry of the region gives, bit for bit; it writes no file and is not listed, recorded or set bymallard ctl set. A call no probe of the region can give (a vector, an unknown field or region) is an input error of the condition. Inputs without such calls add no probe.
Measurements¶
A 2D case (38,400 triangles, MUSCL, 400 steps, a 50-point and a 400-point
line probe, forces and integrals; no triggers) gives the same probe,
reduction, force and integral rows, bit for bit, as main before this
change; stepping time over three alternating runs on 2 threads of a loaded
machine was 4.52 s (main) and 4.59 s (this change), within the run-to-run
spread of 4.15-5.06 s.
Not done (#772)¶
[run] t_stop,n_stepsandt_wall_stopas built-in triggers (one code path, shown as triggers in the resolved input); they already share the landing of steps on times with the triggers. Open: showing them in the resolved input changesmallard input resolvefor every existing input, and evaluating them as triggers adds the trigger kernels (and, on a distributed mesh, the host's broadcast) to every run; both need a decision.- Particle counts, run-health values and a steady-state test
(
change(q, over = ...)) in conditions (#1550).