Sundance::TempStack Class Reference

Inheritance diagram for Sundance::TempStack:

Sundance::Noncopyable

List of all members.

Public Member Functions

 TempStack ()
 TempStack (int vecSize)
void pushVectorData (const RCP< Array< double > > &vecData)
RCP< Array< double > > popVectorData ()
RCP< EvalVectorpopVector ()
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_


Detailed Description

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 77 of file SundanceTempStack.hpp.


Constructor & Destructor Documentation

TempStack::TempStack (  ) 

Empty ctor

Definition at line 56 of file SundanceTempStack.cpp.

TempStack::TempStack ( int  vecSize  ) 

Construct with an initial vector size

Definition at line 48 of file SundanceTempStack.cpp.


Member Function Documentation

int Sundance::TempStack::numVecsAccessed (  )  const [inline]

Definition at line 103 of file SundanceTempStack.hpp.

References numVecsAccessed_.

int Sundance::TempStack::numVecsAllocated (  )  const [inline]

Definition at line 106 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 93 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 70 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 65 of file SundanceTempStack.cpp.

References stack_.

Referenced by Sundance::EvalVector::~EvalVector().

void TempStack::resetCounter (  ) 

Definition at line 90 of file SundanceTempStack.cpp.

References numVecsAccessed_, and numVecsAllocated_.

void Sundance::TempStack::setVecSize ( int  vecSize  )  [inline]

int Sundance::TempStack::vecSize (  )  const [inline]

Definition at line 109 of file SundanceTempStack.hpp.

References vecSize_.

Referenced by Sundance::EvalVector::EvalVector().


Member Data Documentation

Definition at line 119 of file SundanceTempStack.hpp.

Referenced by numVecsAccessed(), popVectorData(), and resetCounter().

Definition at line 117 of file SundanceTempStack.hpp.

Referenced by numVecsAllocated(), popVectorData(), and resetCounter().

std::stack<RCP<Array<double> > > Sundance::TempStack::stack_ [private]

Definition at line 115 of file SundanceTempStack.hpp.

Referenced by popVectorData(), and pushVectorData().

Definition at line 113 of file SundanceTempStack.hpp.

Referenced by popVectorData(), setVecSize(), and vecSize().

Site Contact