ROL
ROL::VectorWorkspace Class Reference

Provides a "smart" cloning manager to be used a member variable in a class and called in the member function of the same class. More...

#include <ROL_VectorWorkspace.hpp>

Detailed Description

Provides a "smart" cloning manager to be used a member variable in a class and called in the member function of the same class.

VectorWorkspace::clone( const Vector& x ) and VectorWorkspace::clone( const Ptr<Vector>& x )

Will allocate new memory of a clone of x if needed and return a pointer to the clone. A new clone is considered to be needed only if these is not a previously allocated compatible vector stored in the VectorWorkspace.

Compatibility is determined by derived type (typeid::hash_code) and vector dimension. Together these form a VectorKey. When cloning a vector inside a member function, VectorWorkspace will identify it's VectorKey type. If such a type exists in the database, with will then refer to the associated VectorStack that is specific to the VectorKey type.

The VectorStack will be searched for the first available dynamically allocated vector which has no external references to it and return a pointer to it. If no such vector exists, a new one will be cloned and added to the stack. When the local pointers to the VectorStack elements go out of scope at the end of the member function, the reference counts are decremented and the vectors become available for use again.

NOTE: Stored clones will have a reference count of 2 when there are no external pointers to the same object.

It should also be possible use a single VectorWorkspace in multiple levels of nested objects.

The concept could probably also generalize to the MPI setting where node locality is an additional distinguishing qualifier for cloning.


The documentation for this class was generated from the following file: