Appearance
cellpack::loader::Run
Module contract · All interfaces
At a glance
pub struct Run<'a> { /* private fields */ }A prepared run: the loader bound to an access sequence, a ring and its planning mode.
The run holds the ring’s generation, the token its leases and waits check, and keeps the loader’s busy flag set. It is the producer handle: Run::run executes on the calling thread while consumers take batches through Run::wait from other threads. Dropping an unstarted run cancels it; dropping any run frees the loader.
Start with for_each_batch for local consumption. With run + wait, production and consumption must overlap; a full ring blocks the producer until leases are released.
Try it
FIXED EXAMPLE RUST / CPU
Deliver ordered batches
Two output schemas share each requested position. Missing dimensions use the schema default; present sparse zeros stay zero.
mod common;
use std::error::Error;
use std::sync::Arc;
use cellpack::loader::{
DataSourceBuilder, Dtype, IoBackend, Loader, LoaderConfig,
OutputSchema, Planning, Replicate, Ring,
};
fn main() -> Result<(), Box<dyn Error>> {
let mut builder = DataSourceBuilder::new(5, 4096)?.direct_io(false);
builder.add_cpk(common::fixture()?, &[0, 1, 2, 3])?;
let source = Arc::new(builder.build()?);
let schemas = vec![
OutputSchema::dense(1, vec![3, 1, 4], Dtype::F32)?.with_default(f64::NAN),
OutputSchema::dense(2, vec![0, 2], Dtype::F64)?,
];
let loader = Loader::new(source, schemas, LoaderConfig {
workers: 2, backend: IoBackend::Pread, slot_cells: 2,
..LoaderConfig::default()
})?;
let cells = [3u32, 0, 2, 3, 1];
let accesses = Replicate::new(cells, 2)?;
let ring = Arc::new(Ring::allocate(loader.ring_layout(2, 1))?);
let run = loader.prepare(&accesses, ring, Planning::None)?;
let stats = run.for_each_batch(|batch| {
let panel: Vec<f32> = batch.region(0).chunks_exact(4)
.map(|v| f32::from_ne_bytes(v.try_into().unwrap())).collect();
println!("positions {}..{}: panel {panel:?}",
batch.first_position(), batch.first_position() + batch.rows() as u64);
Ok(())
})?;
println!("delivered: {} positions, {} accesses", cells.len(), stats.counters.accesses);
Ok(())
}
positions 0..2: panel [0.0, 8.0, NaN, 1.0, 2.0, NaN]
positions 2..4: panel [6.0, 0.0, NaN, 0.0, 8.0, NaN]
positions 4..5: panel [0.0, 0.0, NaN]
delivered: 5 positions, 10 accessesMember index
8 of 8 members
generationThe ring generation this run opened its slots under; leases are tied to it, so batches of one run are never confused with another’s.ringThe ring the run produces into.batchesSlots of the run.snapshotThe workers’ statistics so far, while the run executes: summed per worker as last published (every 1024 completed positions), with the elapsed time of the live execution; profiled runs add the sites they record.cancelCancels the run: wakes every waiting worker and consumer. A no-op once the ring belongs to a later run, so a stale handle cannot abort it.runExecutes the producer on the calling thread and returns the workers’ statistics.waitThe slot of batch batch , once every output in it is written; none past the end. Batch b belongs to rank b % world , and a rank may ask only for its own batches; an error cancels the run.for_each_batchLocal consumption of every rank’s batches in order. Raw rank consumers may instead call wait(rank, batch) while the run executes.
Methods and associated constants
generation
pub fn generation(&self) -> u64The ring generation this run opened its slots under; leases are tied to it, so batches of one run are never confused with another’s.
ring
The ring the run produces into.
batches
Slots of the run.
snapshot
The workers’ statistics so far, while the run executes: summed per worker as last published (every 1024 completed positions), with the elapsed time of the live execution; profiled runs add the sites they record.
cancel
pub fn cancel(&self)Cancels the run: wakes every waiting worker and consumer. A no-op once the ring belongs to a later run, so a stale handle cannot abort it.
run
Executes the producer on the calling thread and returns the workers’ statistics.
A panic in a worker or a plan thread is caught and reported as Error::WorkerPanic; any error cancels the run. The ring’s producer is released before returning, so the ring can serve a later run once every slot of this one has been consumed.
Result
Executes production on the calling thread. Consumers must execute concurrently when the sequence can fill the ring.
wait
The slot of batch batch, once every output in it is written; none past the end. Batch b belongs to rank b % world, and a rank may ask only for its own batches; an error cancels the run.
Parameters
| Parameter | Meaning and constraints |
|---|---|
rank | Owner rank; batch b belongs to b % world. |
batch | Global batch index within this run, not an input cell ID. |
Result
A lease after the batch is published, or None beyond the end. Retaining a lease prevents its slot from being overwritten.
for_each_batch
pub fn for_each_batch<F>(&self, consume: F) -> Result<RunStats>where
F: FnMut(&BatchLease) -> Result<()>,Local consumption of every rank’s batches in order. Raw rank consumers may instead call wait(rank, batch) while the run executes.
Result
Final run statistics after scoped production and ordered consumption. Batch bytes are borrowed only for the callback duration.
Implemented traits
Contract reference
See the module reference for semantic input/output rules, units, allocation, mutation, failure behavior, and lifetime requirements. Declarations and documented members are synchronized from the crate source.