HDF5FrameWriter Class Reference#

DiFfRG: DiFfRG::HDF5FrameWriter Class Reference
DiFfRG
Discretization Framework for functional Renormalization Group flows

Writes staged HDF5 frames on a single background thread. More...

#include <hdf5_writer.hh>

Public Member Functions

 HDF5FrameWriter (unsigned int queue_depth)
 
 ~HDF5FrameWriter () noexcept
 
 HDF5FrameWriter (const HDF5FrameWriter &)=delete
 
HDF5FrameWriter & operator= (const HDF5FrameWriter &)=delete
 
bool asynchronous () const noexcept
 
void submit (HDF5Frame frame, FrameTimings *timings=nullptr)
 Hand a frame over, blocking while the queue is full.
 
void drain ()
 
void finish ()
 
FrameTimings worker_totals () const
 

Private Member Functions

void loop ()
 
void rethrow_stored ()
 

Private Attributes

const unsigned int depth
 
std::mutex mutex
 
std::condition_variable producer_condition
 
std::condition_variable consumer_condition
 
std::deque< HDF5Frame > queue
 
bool stopping = false
 
bool writing = false
 a frame has been popped but not finished
 
bool finished = false
 
std::exception_ptr stored_exception
 
FrameTimings worker_timings
 
std::thread worker
 

Detailed Description

Writes staged HDF5 frames on a single background thread.

One writer serves every HDF5Output of a run. That is a correctness requirement, not a tuning choice: HDF5 here is built without thread safety, so all of its API calls must be serialised, and confining them to one thread is the cheapest way to guarantee that.

Each frame is still opened, written, flushed and closed on its own, so the file stays readable while the run continues and a crash leaves a complete prefix of frames behind. What the thread buys is that the integrator no longer waits for any of it.

Backpressure blocks rather than drops: a producer that outruns the disk waits, and no scientific data is ever discarded.

Constructor & Destructor Documentation

◆ HDF5FrameWriter() [1/2]

DiFfRG::HDF5FrameWriter::HDF5FrameWriter ( unsigned int queue_depth)
explicit
Parameters
queue_depthHow many frames may be in flight. 0 runs every frame inline on the calling thread and starts no thread at all – the synchronous behaviour, kept because a hard abort can otherwise lose the frames still queued.

◆ ~HDF5FrameWriter()

DiFfRG::HDF5FrameWriter::~HDF5FrameWriter ( )
noexcept

◆ HDF5FrameWriter() [2/2]

DiFfRG::HDF5FrameWriter::HDF5FrameWriter ( const HDF5FrameWriter & )
delete

Member Function Documentation

◆ asynchronous()

bool DiFfRG::HDF5FrameWriter::asynchronous ( ) const
inlinenoexcept

◆ drain()

void DiFfRG::HDF5FrameWriter::drain ( )

Wait for the queue to empty, then rethrow the first worker error, if any.

◆ finish()

void DiFfRG::HDF5FrameWriter::finish ( )

Drain and join. Idempotent; safe to call before destruction.

◆ loop()

void DiFfRG::HDF5FrameWriter::loop ( )
private

◆ operator=()

HDF5FrameWriter & DiFfRG::HDF5FrameWriter::operator= ( const HDF5FrameWriter & )
delete

◆ rethrow_stored()

void DiFfRG::HDF5FrameWriter::rethrow_stored ( )
private

◆ submit()

void DiFfRG::HDF5FrameWriter::submit ( HDF5Frame frame,
FrameTimings * timings = nullptr )

Hand a frame over, blocking while the queue is full.

Rethrows a stored worker error first, so a failure surfaces on the thread that can act on it. timings is charged the blocking wait only – the write itself is deliberately not charged to the frame, because it no longer sits on the frame's critical path.

◆ worker_totals()

FrameTimings DiFfRG::HDF5FrameWriter::worker_totals ( ) const

Work done by the writer thread so far, off the critical path.

Member Data Documentation

◆ consumer_condition

std::condition_variable DiFfRG::HDF5FrameWriter::consumer_condition
private

◆ depth

const unsigned int DiFfRG::HDF5FrameWriter::depth
private

◆ finished

bool DiFfRG::HDF5FrameWriter::finished = false
private

◆ mutex

std::mutex DiFfRG::HDF5FrameWriter::mutex
mutableprivate

◆ producer_condition

std::condition_variable DiFfRG::HDF5FrameWriter::producer_condition
private

◆ queue

std::deque<HDF5Frame> DiFfRG::HDF5FrameWriter::queue
private

◆ stopping

bool DiFfRG::HDF5FrameWriter::stopping = false
private

◆ stored_exception

std::exception_ptr DiFfRG::HDF5FrameWriter::stored_exception
private

◆ worker

std::thread DiFfRG::HDF5FrameWriter::worker
private

◆ worker_timings

FrameTimings DiFfRG::HDF5FrameWriter::worker_timings
private

◆ writing

bool DiFfRG::HDF5FrameWriter::writing = false
private

a frame has been popped but not finished


The documentation for this class was generated from the following file:
  • /home/runner/work/DiFfRG_current/DiFfRG_current/DiFfRG/include/DiFfRG/discretization/data/hdf5_writer.hh