Loading src/exatn/exatn_numerics.hpp +20 −5 Original line number Diff line number Diff line /** ExaTN::Numerics: General client header (free function API) REVISION: 2022/01/17 REVISION: 2022/01/25 Copyright (C) 2018-2022 Dmitry I. Lyakh (Liakh) Copyright (C) 2018-2022 Oak Ridge National Laboratory (UT-Battelle) **/ Loading Loading @@ -417,6 +417,13 @@ inline bool destroyTensors(TensorNetwork & tensor_network) //inout: tensor n inline bool destroyTensorsSync(TensorNetwork & tensor_network) //inout: tensor network {return numericalServer->destroyTensorsSync(tensor_network);} /** Destroys all currently allocated tensors. **/ inline bool destroyTensors() {return numericalServer->destroyTensors();} inline bool destroyTensorsSync() {return numericalServer->destroyTensorsSync();} /** Initializes a tensor to some scalar value. **/ template<typename NumericType> Loading Loading @@ -901,12 +908,20 @@ inline bool sync(const ProcessGroup & process_group, //in: chosen group of MPI p /** Synchronizes all outstanding tensor operations in the current scope (barrier). If ProcessGroup is not provided, defaults to the local process. **/ inline bool sync(bool wait = true) //in: wait versus test for completion {return numericalServer->sync(wait);} inline bool sync(bool wait = true, //in: wait versus test for completion bool clean_garbage = false) //in: activates garbage collection {return numericalServer->sync(wait,clean_garbage);} inline bool sync(const ProcessGroup & process_group, //in: chosen group of MPI processes bool wait = true) //in: wait versus test for completion {return numericalServer->sync(process_group,wait);} bool wait = true, //in: wait versus test for completion bool clean_garbage = false) //in: activates garbage collection {return numericalServer->sync(process_group,wait,clean_garbage);} inline bool syncClean() {return numericalServer->sync(true,true);} inline bool syncClean(const ProcessGroup & process_group) {return numericalServer->sync(process_group,true,true);} /** Normalizes a tensor to a given 2-norm. **/ Loading src/exatn/num_server.cpp +43 −9 Original line number Diff line number Diff line /** ExaTN::Numerics: Numerical server REVISION: 2022/01/17 REVISION: 2022/01/25 Copyright (C) 2018-2022 Dmitry I. Lyakh (Liakh) Copyright (C) 2018-2022 Oak Ridge National Laboratory (UT-Battelle) **/ Loading Loading @@ -1186,19 +1186,19 @@ bool NumServer::sync(const ProcessGroup & process_group, TensorNetwork & network return sync(process_group,*(network.getTensor(0)),wait); //synchronization on the output tensor of the tensor network } bool NumServer::sync(bool wait) bool NumServer::sync(bool wait, bool clean_garbage) { bool success = sync(getCurrentProcessGroup(),wait); bool success = sync(getCurrentProcessGroup(),wait,clean_garbage); #ifdef CUQUANTUM if(comp_backend_ == "cuquantum" && success) tn_exec_handles_.clear(); #endif return success; } bool NumServer::sync(const ProcessGroup & process_group, bool wait) bool NumServer::sync(const ProcessGroup & process_group, bool wait, bool clean_garbage) { if(!process_group.rankIsIn(process_rank_)) return true; //process is not in the group: Do nothing destroyOrphanedTensors(); //garbage collection destroyOrphanedTensors(clean_garbage); //garbage collection auto success = tensor_rt_->sync(wait); if(success){ if(logging_ > 0) logfile_ << "[" << std::fixed << std::setprecision(6) << exatn::Timer::timeInSecHR(getTimeStampStart()) Loading Loading @@ -1628,6 +1628,26 @@ bool NumServer::destroyTensorsSync(TensorNetwork & tensor_network) return success; } bool NumServer::destroyTensors() { bool success = true; while(!tensors_.empty()){ success = destroyTensor(tensors_.begin()->first); if(!success) break; } return success; } bool NumServer::destroyTensorsSync() { bool success = true; while(!tensors_.empty()){ success = destroyTensorSync(tensors_.begin()->first); if(!success) break; } return success; } bool NumServer::initTensorFile(const std::string & name, const std::string & filename) { Loading Loading @@ -3502,17 +3522,21 @@ std::shared_ptr<talsh::Tensor> NumServer::getLocalTensor(const std::string & nam return getLocalTensor(iter->second); } void NumServer::destroyOrphanedTensors() void NumServer::destroyOrphanedTensors(bool force) { //std::cout << "#DEBUG(exatn::NumServer): Destroying orphaned tensors ... "; //debug //std::cout << "#DEBUG(exatn::NumServer): Destroying orphaned tensors:\n" << std::flush; //debug auto iter = implicit_tensors_.begin(); while(iter != implicit_tensors_.end()){ int ref_count = 1; auto tens = tensors_.find(iter->first); if(tens != tensors_.end()) ++ref_count; if(iter->second.use_count() <= ref_count){ auto sh_use_count = iter->second.use_count(); //std::cout << "#DEBUG(exatn::NumServer::destroyOrphanedTensors): Orphan candidate found: ExaTN ref count " // << ref_count << " VS shared_ptr use count " << sh_use_count << ": " // << iter->first << std::endl << std::flush; //debug if(force || sh_use_count <= ref_count){ //std::cout << "#DEBUG(exatn::NumServer::destroyOrphanedTensors): Orphan found with ref count " // << ref_count << ": " << iter->first << std::endl; //debug // << ref_count << ": " << iter->first << std::endl << std::flush; //debug auto tensor_mapper = getTensorMapper(getTensorProcessGroup(iter->first)); std::shared_ptr<TensorOperation> destroy_op = tensor_op_factory_->createTensorOp(TensorOpCode::DESTROY); destroy_op->setTensorOperand(iter->second); Loading @@ -3527,6 +3551,16 @@ void NumServer::destroyOrphanedTensors() return; } void NumServer::printAllocatedTensors() const { std::cout << "#DEBUG(exatn::NumServer::printAllocatedTensors):" << std::endl; for(const auto & tens: tensors_){ std::cout << tens.first << ": Reference count = " << tens.second.use_count() << std::endl; } std::cout << "#END" << std::endl << std::flush; return; } void NumServer::printImplicitTensors() const { std::cout << "#DEBUG(exatn::NumServer::printImplicitTensors):" << std::endl; Loading src/exatn/num_server.hpp +17 −6 Original line number Diff line number Diff line /** ExaTN::Numerics: Numerical server REVISION: 2022/01/17 REVISION: 2022/01/25 Copyright (C) 2018-2022 Dmitry I. Lyakh (Liakh) Copyright (C) 2018-2022 Oak Ridge National Laboratory (UT-Battelle) **/ Loading Loading @@ -446,9 +446,11 @@ public: /** Synchronizes execution of all outstanding tensor operations. Changing wait to FALSE, only tests for completion. If ProcessGroup is not provided, defaults to the local process. **/ bool sync(bool wait = true); bool sync(bool wait = true, bool clean_garbage = false); bool sync(const ProcessGroup & process_group, bool wait = true); bool wait = true, bool clean_garbage = false); /** HIGHER-LEVEL WRAPPERS **/ Loading Loading @@ -628,6 +630,11 @@ public: bool destroyTensorsSync(TensorNetwork & tensor_network); //inout: tensor network /** Destroys all currently allocated tensors. **/ bool destroyTensors(); bool destroyTensorsSync(); /** Initializes a tensor to some scalar value. **/ template<typename NumericType> bool initTensor(const std::string & name, //in: tensor name Loading Loading @@ -1020,7 +1027,10 @@ public: inline double getTimeStampStart() const {return time_start_;} /** DEBUG: Prints all currently existing tensors created implicitly. **/ /** DEBUG: Prints all currently existing (allocated) tensors. **/ void printAllocatedTensors() const; /** DEBUG: Prints all currently existing (allocated) tensors created implicitly. **/ void printImplicitTensors() const; protected: Loading @@ -1034,8 +1044,9 @@ protected: bool sync(TensorOperation & operation, //in: previously submitted tensor operation bool wait = true); /** Destroys orphaned tensors (garbage collection). **/ void destroyOrphanedTensors(); /** Destroys orphaned tensors (garbage collection). Setting <force> to TRUE will force destruction regardless of the use count. **/ void destroyOrphanedTensors(bool force = false); private: Loading src/exatn/tests/NumServerTester.cpp +282 −47 File changed.Preview size limit exceeded, changes collapsed. Show changes Loading
src/exatn/exatn_numerics.hpp +20 −5 Original line number Diff line number Diff line /** ExaTN::Numerics: General client header (free function API) REVISION: 2022/01/17 REVISION: 2022/01/25 Copyright (C) 2018-2022 Dmitry I. Lyakh (Liakh) Copyright (C) 2018-2022 Oak Ridge National Laboratory (UT-Battelle) **/ Loading Loading @@ -417,6 +417,13 @@ inline bool destroyTensors(TensorNetwork & tensor_network) //inout: tensor n inline bool destroyTensorsSync(TensorNetwork & tensor_network) //inout: tensor network {return numericalServer->destroyTensorsSync(tensor_network);} /** Destroys all currently allocated tensors. **/ inline bool destroyTensors() {return numericalServer->destroyTensors();} inline bool destroyTensorsSync() {return numericalServer->destroyTensorsSync();} /** Initializes a tensor to some scalar value. **/ template<typename NumericType> Loading Loading @@ -901,12 +908,20 @@ inline bool sync(const ProcessGroup & process_group, //in: chosen group of MPI p /** Synchronizes all outstanding tensor operations in the current scope (barrier). If ProcessGroup is not provided, defaults to the local process. **/ inline bool sync(bool wait = true) //in: wait versus test for completion {return numericalServer->sync(wait);} inline bool sync(bool wait = true, //in: wait versus test for completion bool clean_garbage = false) //in: activates garbage collection {return numericalServer->sync(wait,clean_garbage);} inline bool sync(const ProcessGroup & process_group, //in: chosen group of MPI processes bool wait = true) //in: wait versus test for completion {return numericalServer->sync(process_group,wait);} bool wait = true, //in: wait versus test for completion bool clean_garbage = false) //in: activates garbage collection {return numericalServer->sync(process_group,wait,clean_garbage);} inline bool syncClean() {return numericalServer->sync(true,true);} inline bool syncClean(const ProcessGroup & process_group) {return numericalServer->sync(process_group,true,true);} /** Normalizes a tensor to a given 2-norm. **/ Loading
src/exatn/num_server.cpp +43 −9 Original line number Diff line number Diff line /** ExaTN::Numerics: Numerical server REVISION: 2022/01/17 REVISION: 2022/01/25 Copyright (C) 2018-2022 Dmitry I. Lyakh (Liakh) Copyright (C) 2018-2022 Oak Ridge National Laboratory (UT-Battelle) **/ Loading Loading @@ -1186,19 +1186,19 @@ bool NumServer::sync(const ProcessGroup & process_group, TensorNetwork & network return sync(process_group,*(network.getTensor(0)),wait); //synchronization on the output tensor of the tensor network } bool NumServer::sync(bool wait) bool NumServer::sync(bool wait, bool clean_garbage) { bool success = sync(getCurrentProcessGroup(),wait); bool success = sync(getCurrentProcessGroup(),wait,clean_garbage); #ifdef CUQUANTUM if(comp_backend_ == "cuquantum" && success) tn_exec_handles_.clear(); #endif return success; } bool NumServer::sync(const ProcessGroup & process_group, bool wait) bool NumServer::sync(const ProcessGroup & process_group, bool wait, bool clean_garbage) { if(!process_group.rankIsIn(process_rank_)) return true; //process is not in the group: Do nothing destroyOrphanedTensors(); //garbage collection destroyOrphanedTensors(clean_garbage); //garbage collection auto success = tensor_rt_->sync(wait); if(success){ if(logging_ > 0) logfile_ << "[" << std::fixed << std::setprecision(6) << exatn::Timer::timeInSecHR(getTimeStampStart()) Loading Loading @@ -1628,6 +1628,26 @@ bool NumServer::destroyTensorsSync(TensorNetwork & tensor_network) return success; } bool NumServer::destroyTensors() { bool success = true; while(!tensors_.empty()){ success = destroyTensor(tensors_.begin()->first); if(!success) break; } return success; } bool NumServer::destroyTensorsSync() { bool success = true; while(!tensors_.empty()){ success = destroyTensorSync(tensors_.begin()->first); if(!success) break; } return success; } bool NumServer::initTensorFile(const std::string & name, const std::string & filename) { Loading Loading @@ -3502,17 +3522,21 @@ std::shared_ptr<talsh::Tensor> NumServer::getLocalTensor(const std::string & nam return getLocalTensor(iter->second); } void NumServer::destroyOrphanedTensors() void NumServer::destroyOrphanedTensors(bool force) { //std::cout << "#DEBUG(exatn::NumServer): Destroying orphaned tensors ... "; //debug //std::cout << "#DEBUG(exatn::NumServer): Destroying orphaned tensors:\n" << std::flush; //debug auto iter = implicit_tensors_.begin(); while(iter != implicit_tensors_.end()){ int ref_count = 1; auto tens = tensors_.find(iter->first); if(tens != tensors_.end()) ++ref_count; if(iter->second.use_count() <= ref_count){ auto sh_use_count = iter->second.use_count(); //std::cout << "#DEBUG(exatn::NumServer::destroyOrphanedTensors): Orphan candidate found: ExaTN ref count " // << ref_count << " VS shared_ptr use count " << sh_use_count << ": " // << iter->first << std::endl << std::flush; //debug if(force || sh_use_count <= ref_count){ //std::cout << "#DEBUG(exatn::NumServer::destroyOrphanedTensors): Orphan found with ref count " // << ref_count << ": " << iter->first << std::endl; //debug // << ref_count << ": " << iter->first << std::endl << std::flush; //debug auto tensor_mapper = getTensorMapper(getTensorProcessGroup(iter->first)); std::shared_ptr<TensorOperation> destroy_op = tensor_op_factory_->createTensorOp(TensorOpCode::DESTROY); destroy_op->setTensorOperand(iter->second); Loading @@ -3527,6 +3551,16 @@ void NumServer::destroyOrphanedTensors() return; } void NumServer::printAllocatedTensors() const { std::cout << "#DEBUG(exatn::NumServer::printAllocatedTensors):" << std::endl; for(const auto & tens: tensors_){ std::cout << tens.first << ": Reference count = " << tens.second.use_count() << std::endl; } std::cout << "#END" << std::endl << std::flush; return; } void NumServer::printImplicitTensors() const { std::cout << "#DEBUG(exatn::NumServer::printImplicitTensors):" << std::endl; Loading
src/exatn/num_server.hpp +17 −6 Original line number Diff line number Diff line /** ExaTN::Numerics: Numerical server REVISION: 2022/01/17 REVISION: 2022/01/25 Copyright (C) 2018-2022 Dmitry I. Lyakh (Liakh) Copyright (C) 2018-2022 Oak Ridge National Laboratory (UT-Battelle) **/ Loading Loading @@ -446,9 +446,11 @@ public: /** Synchronizes execution of all outstanding tensor operations. Changing wait to FALSE, only tests for completion. If ProcessGroup is not provided, defaults to the local process. **/ bool sync(bool wait = true); bool sync(bool wait = true, bool clean_garbage = false); bool sync(const ProcessGroup & process_group, bool wait = true); bool wait = true, bool clean_garbage = false); /** HIGHER-LEVEL WRAPPERS **/ Loading Loading @@ -628,6 +630,11 @@ public: bool destroyTensorsSync(TensorNetwork & tensor_network); //inout: tensor network /** Destroys all currently allocated tensors. **/ bool destroyTensors(); bool destroyTensorsSync(); /** Initializes a tensor to some scalar value. **/ template<typename NumericType> bool initTensor(const std::string & name, //in: tensor name Loading Loading @@ -1020,7 +1027,10 @@ public: inline double getTimeStampStart() const {return time_start_;} /** DEBUG: Prints all currently existing tensors created implicitly. **/ /** DEBUG: Prints all currently existing (allocated) tensors. **/ void printAllocatedTensors() const; /** DEBUG: Prints all currently existing (allocated) tensors created implicitly. **/ void printImplicitTensors() const; protected: Loading @@ -1034,8 +1044,9 @@ protected: bool sync(TensorOperation & operation, //in: previously submitted tensor operation bool wait = true); /** Destroys orphaned tensors (garbage collection). **/ void destroyOrphanedTensors(); /** Destroys orphaned tensors (garbage collection). Setting <force> to TRUE will force destruction regardless of the use count. **/ void destroyOrphanedTensors(bool force = false); private: Loading
src/exatn/tests/NumServerTester.cpp +282 −47 File changed.Preview size limit exceeded, changes collapsed. Show changes