Public Member Functions | |
| TempStack () | |
| TempStack (int vecSize) | |
| void | pushVectorData (const RCP< Array< double > > &vecData) |
| RCP< Array< double > > | popVectorData () |
| RCP< EvalVector > | popVector () |
| void | setVecSize (int vecSize) |
| void | resetCounter () |
| int | numVecsAccessed () const |
| int | numVecsAllocated () const |
| int | vecSize () const |
Private Attributes | |
| int | vecSize_ |
| std::stack< RCP< Array< double > > > | stack_ |
| int | numVecsAllocated_ |
| int | numVecsAccessed_ |
TempStack provides a stack of temporary variables for use during evaluation.
During the course of evaluating an expression, it is often necessary to create temporary variables. For example, in evaluating
a += b*(c+d)
it is required to create three temporaries (ignoring for explanatory purposes any copies made in cases where one of the vectors will be used elsewhere). We can see this by breaking the operation down into the following steps:
1. Create a temporary variable t1 2. Evaluate expression b into t1 3. Create a temporary variable t2 4. Evaluate expression c into t2 3. Create a temporary variable t3 4. Evaluate expression d into t3 5. Carry out t2 += t3 6. Carry out t1 *= t2 7. Carry out a += t1
The number of temporaries required for a given expression will depend on the graph of the expression. In general, we want to create exactly as many temporaries as are needed, and reuse any temporaries that are no longer needed. This is a well-known problem in compiler design, and can be accomplished by maintaining a stack of temporaries. When a new temporary is needed, it is popped from the stack; if the stack is empty, a new temporary is allocated. When a step of a calculation is done, any temporaries used are put back on the stack for further use.
Definition at line 88 of file SundanceTempStack.hpp.
Empty ctor
Definition at line 67 of file SundanceTempStack.cpp.
| TempStack::TempStack | ( | int | vecSize | ) |
Construct with an initial vector size
Definition at line 59 of file SundanceTempStack.cpp.
| int Sundance::TempStack::numVecsAccessed | ( | ) | const [inline] |
Definition at line 114 of file SundanceTempStack.hpp.
References numVecsAccessed_.
| int Sundance::TempStack::numVecsAllocated | ( | ) | const [inline] |
Definition at line 117 of file SundanceTempStack.hpp.
References numVecsAllocated_.
| RCP<EvalVector> Sundance::TempStack::popVector | ( | ) | [inline] |
Get a new vector (which will often reuse stack data)
Definition at line 104 of file SundanceTempStack.hpp.
Referenced by Sundance::EvalVector::applyUnaryOperator(), Sundance::NonlinearUnaryOpEvaluator::evalArgDerivs(), and Sundance::EvalManager::popVector().
| RCP< Array< double > > TempStack::popVectorData | ( | ) |
Pop vector data from the stack
Definition at line 81 of file SundanceTempStack.cpp.
References numVecsAccessed_, numVecsAllocated_, stack_, and vecSize_.
| void TempStack::pushVectorData | ( | const RCP< Array< double > > & | vecData | ) |
Push vector data onto the stack
Definition at line 76 of file SundanceTempStack.cpp.
References stack_.
Referenced by Sundance::EvalVector::~EvalVector().
| void TempStack::resetCounter | ( | ) |
Definition at line 101 of file SundanceTempStack.cpp.
References numVecsAccessed_, and numVecsAllocated_.
| void Sundance::TempStack::setVecSize | ( | int | vecSize | ) | [inline] |
Definition at line 108 of file SundanceTempStack.hpp.
References vecSize(), and vecSize_.
Referenced by Sundance::CurveNormEvaluator::internalEval(), Sundance::DiscreteFuncElementEvaluator::internalEval(), Sundance::CellVectorEvaluator::internalEval(), Sundance::CellDiameterExprEvaluator::internalEval(), Sundance::CoordExprEvaluator::internalEval(), Sundance::SymbolicFuncElementEvaluator::internalEval(), and Sundance::EvalManager::setVecSize().
| int Sundance::TempStack::vecSize | ( | ) | const [inline] |
Definition at line 120 of file SundanceTempStack.hpp.
References vecSize_.
Referenced by Sundance::UserDefOpCommonEvaluator::evalAllComponents(), Sundance::EvalVector::EvalVector(), and setVecSize().
int Sundance::TempStack::numVecsAccessed_ [private] |
Definition at line 130 of file SundanceTempStack.hpp.
Referenced by numVecsAccessed(), popVectorData(), and resetCounter().
int Sundance::TempStack::numVecsAllocated_ [private] |
Definition at line 128 of file SundanceTempStack.hpp.
Referenced by numVecsAllocated(), popVectorData(), and resetCounter().
std::stack<RCP<Array<double> > > Sundance::TempStack::stack_ [private] |
Definition at line 126 of file SundanceTempStack.hpp.
Referenced by popVectorData(), and pushVectorData().
int Sundance::TempStack::vecSize_ [private] |
Definition at line 124 of file SundanceTempStack.hpp.
Referenced by popVectorData(), setVecSize(), and vecSize().