pub struct Control {
pub cancelled: Arc<AtomicBool>,
/* private fields */
}Expand description
Cooperative execution control of one solve: a wall-time allowance, a cancellation flag, an optional external poll and optional phase profiling.
The solver calls check before every step and every eight
iterations of the pressure and implicit inner solves, so cancellation is
prompt but not instantaneous. The clock starts when the control is
created. A stop between steps ends the run as cancelled or
wall_time_limit with the last accepted state.
use cfd_craft::solver::Control;
use std::sync::atomic::Ordering;
let control = Control::new(60.0);
assert!(control.check().is_ok());
control.cancelled.store(true, Ordering::Relaxed);
assert_eq!(control.check().unwrap_err(), "cancelled");
// An external poll: any error stops the run as `cancelled`.
let polled = Control::with_poll(60.0, || Err("job deadline".to_string()));
assert_eq!(polled.check().unwrap_err(), "cancelled");Fields§
§cancelled: Arc<AtomicBool>Set to true, from any thread, to request cancellation. Clone the
Arc before starting the solve; the CLI sets it from its SIGINT and
SIGTERM handlers.
Implementations§
Source§impl Control
impl Control
Sourcepub fn new(seconds: f64) -> Self
pub fn new(seconds: f64) -> Self
A control with a wall-time allowance of seconds, counted from now,
and no poll or profiling. Pass the case’s run.wall_time_limit_s to
reproduce the CLI’s limit.
§Panics
If seconds is negative, not finite or too large for a
Duration; validate user input first (Case::check requires a
finite positive run.wall_time_limit_s of at most seven days).
Sourcepub fn with_poll(
seconds: f64,
poll: impl Fn() -> Result<()> + Send + Sync + 'static,
) -> Self
pub fn with_poll( seconds: f64, poll: impl Fn() -> Result<()> + Send + Sync + 'static, ) -> Self
A wall-time allowance plus an external cancellation or deadline poll.
A poll error stops the run as cancelled, or as wall_time_limit when the
poll returns exactly that text. Its own message is not kept, so a run is
never reported as diverged because an external caller stopped it.
§Panics
As new, for an invalid seconds.
Sourcepub fn check(&self) -> Result<()>
pub fn check(&self) -> Result<()>
Ok while the solve may continue. Otherwise the error is exactly
"cancelled" (a poll error other than "wall_time_limit", or the
cancelled flag) or "wall_time_limit" (the poll
returned that text, or the allowance is used up). The poll runs first.
Sourcepub fn elapsed(&self) -> f64
pub fn elapsed(&self) -> f64
Wall seconds since the control was created; reported as the summary’s
elapsed_s.
Sourcepub fn with_profiling(self) -> Self
pub fn with_profiling(self) -> Self
Sourcepub fn span(&self, phase: Phase) -> Span
pub fn span(&self, phase: Phase) -> Span
Start timing phase until the returned Span is dropped. Spans
must finish in nested order on the thread that started them. Without
with_profiling the span is disabled and
costs neither a clock read nor a lock.
Sourcepub fn profile(&self) -> Result<Option<Profile>>
pub fn profile(&self) -> Result<Option<Profile>>
Snapshot after every span has finished; work includes failed attempts.
Ok(None) without with_profiling. An
active or out-of-order span is an error, CFD-B003 profile.active or
CFD-B003 profile.nesting.
use cfd_craft::{profiling::Phase, solver::Control};
assert!(Control::new(10.0).profile().unwrap().is_none());
let control = Control::new(10.0).with_profiling();
drop(control.span(Phase::Monitor));
let profile = control.profile().unwrap().expect("profiling enabled");
assert_eq!(profile.schema_version, "cfd-craft.phase-profile/0.1");
assert_eq!(profile.phases["monitor"].calls, 1);Auto Trait Implementations§
impl !RefUnwindSafe for Control
impl !UnwindSafe for Control
impl Forget for Control
impl Freeze for Control
impl Move for Control
impl Send for Control
impl Sync for Control
impl Unpin for Control
impl UnsafeUnpin for Control
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more