LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
line_timeout.h File Reference

options.timeout: one wall-clock budget per top-level solve, on a per-THREAD deadline stack. More...

#include <chrono>
#include <cmath>
#include <cstdio>
#include <limits>
#include <string>
#include <vector>
#include "line/util/error.h"
Include dependency graph for line_timeout.h:

Go to the source code of this file.

Classes

struct  line::util::timeout_detail::Frame
class  line::util::TimeoutScope
 The RAII frame timeout_arm returns. More...

Namespaces

namespace  line
 Conservation laws of a layered queueing network, enumerated from its structure.
namespace  line::util
namespace  line::util::timeout_detail

Functions

std::vector< Frame > & line::util::timeout_detail::stack ()
double line::util::timeout_detail::elapsed (const Frame &f)
double line::util::timeout_remaining ()
 Seconds left on the innermost armed budget; +Inf when none is armed.
bool line::util::timeout_armed ()
 Whether any budget is armed on this thread.
bool line::util::timeout_exceeded ()
 The checkpoint: true when the innermost budget has run out, marking it tripped.
bool line::util::timeout_tripped ()
 Whether the innermost budget was tripped by a checkpoint or by timeout_trip.
void line::util::timeout_trip ()
 Mark the innermost budget tripped without reading the clock: for an external engine that REPORTS it stopped on the budget (LDES stoppingReason == "max_time", a JSIM run given -maxtime).
void line::util::timeout_check (const char *where)
 The raising checkpoint, for a computation with no valid partial result: throws LINE:numerical:Timeout naming where when the budget has run out.
int line::util::timeout_kill_seconds (double grace=30.0)
 The hard kill bound of a child process under the armed budget: the remaining seconds plus grace, rounded up, as MATLAB's lineTimeoutKillPrefix builds timeout -k 5 ceil(remaining+30).
int line::util::timeout_kill_bound (int explicit_seconds, double grace=30.0)
 The kill bound of a child that also has a bound of its OWN (explicit_seconds, not positive = none): the tighter of the two, 0 when neither is set.
void line::util::timeout_raise_if_killed_on_budget (const std::string &who)
 A child process was killed on its bound: raise LINE:numerical:Timeout when the armed budget is what ran out (a killed child wrote no result, so there is no partial one), and return otherwise so the caller reports its own bound.
TimeoutScope line::util::timeout_arm (double budget)
 Arm budget seconds for the scope's lifetime, capped by the outer frame's remaining time.
void line::util::timeout_warn (const std::string &solver, double budget)
 The one warning a solve that stopped on its budget prints, MATLAB's flagTimeout text, on stderr as every other [LINE] Warning here.

Detailed Description

options.timeout: one wall-clock budget per top-level solve, on a per-THREAD deadline stack.

The C++ twin of MATLAB's lineTimeoutArm / lineTimeoutRemaining / lineTimeoutExceeded / lineTimeoutTripped / lineTimeoutTrip, the JAR's jline.util.LineTimeout and Python's line_solver._timeutil. The contract:

  • timeout_arm(budget) pushes a frame whose budget is min(budget, the outer frame's remaining time) and returns an RAII scope that pops it. A non-finite or non-positive budget pushes NOTHING, so an unbudgeted inner solve keeps reading its caller's frame and never restarts the clock.
  • timeout_exceeded() is the CHECKPOINT: true when the top frame's budget has run out, and it marks that frame TRIPPED as it says so.
  • The result flag (AvgTable::timed_out, "timedOut" on the CLI wire) is read from the TRIPPED LATCH, never from "elapsed > budget": a run that finished its loop and then overran in post-processing returned its full answer and is not flagged.
  • Popping a tripped frame trips its parent, so the latch reaches the outermost scope that reports it.

THREAD-LOCAL, NOT GLOBAL: two solves on two threads with different budgets never read each other's deadline (the JAR's static deadline did). A worker thread a solver spawns starts with an EMPTY stack, so a solver that fans out hands each worker the remaining budget explicitly (see ldes_engine_solve).

The clock is steady_clock, compared as an elapsed double against a double budget, so neither a clock step nor a huge budget can overflow it.

timeout_check(where) is the raising form, for the computations that have NO valid partial result – a state space cut short, an exact recursion stopped mid-population – and it raises LINE:numerical:Timeout.

Definition in file line_timeout.h.