Loading...
Searching...
No Matches
scratchpad_abstract.h File Reference

Abstract base class for scratchpad memory used during engine computations. More...

`#include <memory>`
Include dependency graph for scratchpad_abstract.h:
This graph shows which files directly or indirectly include this file:

## Classes

struct | gridfire::engine::scratch::AbstractScratchPad
| Abstract base struct for engine scratchpad memory. More...

## Namespaces

namespace | gridfire
namespace | gridfire::engine
namespace | gridfire::engine::scratch
| Scratchpad memory management for computational engines.

## Detailed Description

Abstract base class for scratchpad memory used during engine computations.

This header defines the AbstractScratchPad interface, which provides a common contract for temporary working memory (scratchpads) used by computational engines. Scratchpads are designed to store intermediate results, cached computations, or pre-allocated buffers that can be reused across multiple computational steps, improving performance by avoiding repeated memory allocations.

Purpose
  The scratchpad pattern allows engines to:
  - Pre-allocate working memory once and reuse it across iterations
  - Store intermediate computational results between solver steps
  - Enable efficient cloning for parallel execution contexts
  - Provide a type-erased interface for heterogeneous scratchpad management

Examples
  // Define a concrete scratchpad for a specific engine
  class MyScratchPad : public gridfire::engine::scratch::AbstractScratchPad {
  public:
  MyScratchPad() : initialized_(false) {}
  void initialize(size_t size) {
  buffer_.resize(size);
  initialized_ = true;
  }
  [[nodiscard]] bool is_initialized() const override {
  return initialized_;
  }
  [[nodiscard]] std::unique_ptr<AbstractScratchPad> clone() const override {
  auto copy = std::make_unique<MyScratchPad>();
  copy->buffer_ = buffer_;
  copy->initialized_ = initialized_;
  return copy;
  }
  private:
  std::vector<double> buffer_;
  bool initialized_;
  };
  // Usage in an engine context
  auto scratch = std::make_unique<MyScratchPad>();
  scratch->initialize(1024);
  if (scratch->is_initialized()) {
  // Use scratchpad for computations
  auto parallel_scratch = scratch->clone(); // Clone for parallel worker
  }
  gridfire::engine::scratch::AbstractScratchPad
  Abstract base struct for engine scratchpad memory.
  Definition scratchpad_abstract.h:82
  gridfire::engine::scratch::AbstractScratchPad::is_initialized
  virtual bool is_initialized() const =0
  Check whether the scratchpad has been properly initialized.
  gridfire::engine::scratch::AbstractScratchPad::clone
  virtual std::unique_ptr< AbstractScratchPad > clone() const =0
  Create a deep copy of this scratchpad.