// A class for wrapping matrix operations with dependency information to speed up execution #ifndef DEPENDENCY_MANAGER_H #define DEPENDENCY_MANAGER_H #include "ATC_TypeDefs.h" #include "MatrixLibrary.h" #include "ATC_Error.h" #include "MPI_Wrappers.h" namespace ATC { class InterscaleManager; /** memory type */ enum MemoryType { TEMPORARY = 0, PERSISTENT }; /** * @class DependencyManager * @brief Base class for defining objects that manage the dependencies of various objects */ class DependencyManager { public: // used as a friend so it can perform a depth-first search to have safe deletions of managed dependencies friend class InterscaleManager; // constructor DependencyManager() : needReset_(true), isFixed_(false), memoryType_(TEMPORARY), dfsFound_(false) {}; // destructor virtual ~DependencyManager() {}; /** registration by other PerAtomQuantity objects */ void register_dependence(DependencyManager * dependentQuantity) {dependentQuantities_.insert(dependentQuantity);}; /** removes dependencies from the set */ void remove_dependence(DependencyManager * dependentQuantity) {dependentQuantities_.erase(dependentQuantity);}; /** check if a reset is required */ bool need_reset() const {return needReset_ && !isFixed_;}; /** propagate need to reset to to dependencies */ void propagate_reset() { if (!isFixed_) { std::set::iterator it; for (it = dependentQuantities_.begin(); it != dependentQuantities_.end(); it++) (*it)->force_reset(); } }; /** actions associated with indicating this quantity requires a reset */ void set_reset() { needReset_ = true; } /** flip this object to needing a reset, and get dependencies */ void force_reset() { set_reset(); propagate_reset(); } /** force quantity to be held fixed, enables dependent quantity to be used as persistent storage */ void fix_quantity() {isFixed_ = true;}; /** unfix the quantity */ void unfix_quantity() { if (isFixed_) { isFixed_ = false; if (needReset_) propagate_reset(); } }; /** check on the memory type of the quantity */ MemoryType memory_type() const {return memoryType_;}; /** set the memory type of the quantity */ void set_memory_type(MemoryType memoryType) {memoryType_ = memoryType;}; protected: /** list of dependent atomic quantities */ std::set dependentQuantities_; /** flag for needing a recent */ // mutable is applied because there can be internal updates because we update when needed rather than when pushed mutable bool needReset_; /** flag for if quantity is being held fixed */ bool isFixed_; /** flag for if the quantity is temporary (per-run) */ MemoryType memoryType_; /** flag for if the node has been found in depth-first search */ bool dfsFound_; }; /** * @class MatrixDependencyManager * @brief Class for defining objects that manage the dependencies of matrices */ // Matrix class T, underlying type U template