Commit feadeec2 authored by Dmitry I. Lyakh's avatar Dmitry I. Lyakh

Merge branch 'devel_dil' into devel

parents 9bb9867a 98291d6d
Pipeline #110167 failed with stage
/** ExaTN::Numerics: General client header
REVISION: 2020/07/01
REVISION: 2020/07/06
Copyright (C) 2018-2020 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2020 Oak Ridge National Laboratory (UT-Battelle) **/
......@@ -519,8 +519,8 @@ inline bool evaluateTensorNetworkSync(const ProcessGroup & process_group, //in:
{return numericalServer->evaluateTensorNetworkSync(process_group,name,network);}
/** Synchronizes all outstanding update operations on a given tensor
specified by its symbolic name. **/
/** Synchronizes all outstanding update operations on a given tensor specified by
its symbolic name. If ProcessGroup is not provided, defaults to the local process.**/
inline bool sync(const std::string & name, //in: tensor name
bool wait = true) //in: wait versus test for completion
{return numericalServer->sync(name,wait);}
......@@ -551,7 +551,8 @@ inline bool evaluateSync(const ProcessGroup & process_group, //in: chosen group
return success;}
/** Synchronizes all outstanding operations on a given tensor network object. **/
/** Synchronizes all outstanding operations on a given tensor network object.
If ProcessGroup is not provided, defaults to the local process. **/
inline bool sync(TensorNetwork & network, //in: finalized tensor network
bool wait = true) //in: wait versus test for completion
{return numericalServer->sync(network,wait);}
......@@ -588,7 +589,8 @@ inline bool evaluateSync(const ProcessGroup & process_group, //in: chosen group
return success;}
/** Synchronizes all outstanding operations on a given tensor. **/
/** Synchronizes all outstanding operations on a given tensor.
If ProcessGroup is not provided, defaults to the local process. **/
inline bool sync(const Tensor & tensor, //in: tensor
bool wait = true) //in: wait versus test for completion
{return numericalServer->sync(tensor,wait);}
......@@ -599,7 +601,8 @@ inline bool sync(const ProcessGroup & process_group, //in: chosen group of MPI
{return numericalServer->sync(process_group,tensor,wait);}
/** Synchronizes all outstanding tensor operations in the current scope (barrier). **/
/** 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);}
......
/** ExaTN::Numerics: Numerical server
REVISION: 2020/07/02
REVISION: 2020/07/06
Copyright (C) 2018-2020 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2020 Oak Ridge National Laboratory (UT-Battelle) **/
......@@ -484,7 +484,7 @@ bool NumServer::submit(const ProcessGroup & process_group,
destroy_slice->setTensorOperand(input_slice.second);
submitted = submit(destroy_slice); if(!submitted) return false;
}
if(serialize) sync(getCurrentProcessGroup()); //debug
if(serialize) sync(); //debug
input_slices.clear();
} //loop over tensor operations
//Erase intermediate tensor slices once all tensor operations have been executed:
......@@ -570,7 +570,7 @@ bool NumServer::submit(const ProcessGroup & process_group,
bool NumServer::sync(const Tensor & tensor, bool wait)
{
return sync(getDefaultProcessGroup(),tensor,wait);
return sync(getCurrentProcessGroup(),tensor,wait);
}
bool NumServer::sync(const ProcessGroup & process_group, const Tensor & tensor, bool wait)
......@@ -593,7 +593,7 @@ bool NumServer::sync(TensorOperation & operation, bool wait) //`Local synchroniz
bool NumServer::sync(TensorNetwork & network, bool wait)
{
return sync(getDefaultProcessGroup(),network,wait);
return sync(getCurrentProcessGroup(),network,wait);
}
bool NumServer::sync(const ProcessGroup & process_group, TensorNetwork & network, bool wait)
......@@ -603,7 +603,7 @@ bool NumServer::sync(const ProcessGroup & process_group, TensorNetwork & network
bool NumServer::sync(bool wait)
{
return sync(getDefaultProcessGroup(),wait);
return sync(getCurrentProcessGroup(),wait);
}
bool NumServer::sync(const ProcessGroup & process_group, bool wait)
......@@ -621,7 +621,7 @@ bool NumServer::sync(const ProcessGroup & process_group, bool wait)
bool NumServer::sync(const std::string & name, bool wait)
{
return sync(getDefaultProcessGroup(),name,wait);
return sync(getCurrentProcessGroup(),name,wait);
}
bool NumServer::sync(const ProcessGroup & process_group, const std::string & name, bool wait)
......
/** ExaTN::Numerics: Numerical server
REVISION: 2020/07/01
REVISION: 2020/07/06
Copyright (C) 2018-2020 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2020 Oak Ridge National Laboratory (UT-Battelle) **/
......@@ -239,7 +239,8 @@ public:
std::shared_ptr<Tensor> accumulator); //inout: tensor accumulator (result)
/** Synchronizes all update operations on a given tensor.
Changing wait to FALSE, only tests for completion. **/
Changing wait to FALSE, only tests for completion.
If ProcessGroup is not provided, defaults to the local process. **/
bool sync(const Tensor & tensor,
bool wait = true);
bool sync(const ProcessGroup & process_group,
......@@ -251,21 +252,24 @@ public:
bool sync(TensorOperation & operation,
bool wait = true);
/** Synchronizes execution of a specific tensor network.
Changing wait to FALSE, only tests for completion. **/
Changing wait to FALSE, only tests for completion.
If ProcessGroup is not provided, defaults to the local process. **/
bool sync(TensorNetwork & network,
bool wait = true);
bool sync(const ProcessGroup & process_group,
TensorNetwork & network,
bool wait = true);
/** Synchronizes execution of all outstanding tensor operations.
Changing wait to FALSE, only tests for completion. **/
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(const ProcessGroup & process_group,
bool wait = true);
/** HIGHER-LEVEL WRAPPERS **/
/** Synchronizes all outstanding update operations on a given tensor. **/
/** Synchronizes all outstanding update operations on a given tensor.
If ProcessGroup is not provided, defaults to the local process. **/
bool sync(const std::string & name, //in: tensor name
bool wait = true); //in: wait versus test for completion
bool sync(const ProcessGroup & process_group,
......
......@@ -129,7 +129,7 @@ TEST(NumServerTester, ExamplarExaTN)
z2.reset();
//Synchronize ExaTN server:
exatn::sync();
exatn::sync(all_processes);
exatn::resetRuntimeLoggingLevel(0);
}
#endif
......
......@@ -31,6 +31,7 @@ add_library(${LIBRARY_NAME}
network_builder_mps.cpp
network_builder_tree.cpp
network_build_factory.cpp
contraction_seq_optimizer.cpp
contraction_seq_optimizer_dummy.cpp
contraction_seq_optimizer_heuro.cpp
contraction_seq_optimizer_greed.cpp
......
/** ExaTN::Numerics: Tensor contraction sequence optimizer: Base
REVISION: 2020/07/06
Copyright (C) 2018-2020 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2020 Oak Ridge National Laboratory (UT-Battelle) **/
#include "contraction_seq_optimizer.hpp"
#include "tensor_network.hpp"
#include "metis_graph.hpp"
namespace exatn{
namespace numerics{
std::unordered_map<std::string,std::pair<MetisGraph,std::list<ContrTriple>>> ContractionSeqOptimizer::cached_contr_seqs_;
bool ContractionSeqOptimizer::cacheContractionSequence(const TensorNetwork & network)
{
auto res = cached_contr_seqs_.emplace(network.getName(),
std::make_pair(MetisGraph(network),network.exportContractionSequence()));
return res.second;
}
bool ContractionSeqOptimizer::eraseContractionSequence(const TensorNetwork & network)
{
auto num_deleted = cached_contr_seqs_.erase(network.getName());
return (num_deleted == 1);
}
const std::list<ContrTriple> * ContractionSeqOptimizer::findContractionSequence(const TensorNetwork & network)
{
auto iter = cached_contr_seqs_.find(network.getName());
if(iter != cached_contr_seqs_.end()){
MetisGraph network_graph(network);
if(network_graph == iter->second.first) return &(iter->second.second);
};
return nullptr;
}
} //namespace numerics
} //namespace exatn
/** ExaTN::Numerics: Tensor contraction sequence optimizer
REVISION: 2019/11/08
REVISION: 2020/07/06
Copyright (C) 2018-2019 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2019 Oak Ridge National Laboratory (UT-Battelle) **/
Copyright (C) 2018-2020 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2020 Oak Ridge National Laboratory (UT-Battelle) **/
/** Rationale:
**/
......@@ -14,6 +14,7 @@ Copyright (C) 2018-2019 Oak Ridge National Laboratory (UT-Battelle) **/
#include <list>
#include <memory>
#include <unordered_map>
#include <functional>
namespace exatn{
......@@ -28,6 +29,7 @@ struct ContrTriple{
};
class TensorNetwork;
class MetisGraph;
class ContractionSeqOptimizer{
......@@ -46,6 +48,27 @@ public:
virtual double determineContractionSequence(const TensorNetwork & network,
std::list<ContrTriple> & contr_seq,
std::function<unsigned int ()> intermediate_num_generator) = 0;
/** Caches the determined pseudo-optimal tensor contraction sequence for a given
tensor network for a later retrieval for the same tensor networks. Returns TRUE
on success, FALSE in case this tensor network has already been cached before. **/
static bool cacheContractionSequence(const TensorNetwork & network); //in: tensor network with a determined tensor contraction sequence
/** Erases the previously cached tensor contraction sequence for a given tensor
network and returns TRUE, or returns FALSE in case it has not been cached before. **/
static bool eraseContractionSequence(const TensorNetwork & network); //in: tensor network
/** Retrieves a previously cached tensor contraction sequence for a given tensor
network. Returns nullptr in case it has not been cached before. **/
static const std::list<ContrTriple> * findContractionSequence(const TensorNetwork & network); //in: tensor network
private:
/** Cached tensor contraction sequences. **/
static std::unordered_map<std::string, //tensor network name
std::pair<MetisGraph, //METIS graph of the tensor network
std::list<ContrTriple> //tensor contraction sequence
>> cached_contr_seqs_;
};
using createContractionSeqOptimizerFn = std::unique_ptr<ContractionSeqOptimizer> (*)(void);
......
/** ExaTN::Numerics: Graph k-way partitioning via METIS
REVISION: 2020/05/19
REVISION: 2020/07/06
Copyright (C) 2018-2020 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2020 Oak Ridge National Laboratory (UT-Battelle) **/
......@@ -11,6 +11,7 @@ Copyright (C) 2018-2020 Oak Ridge National Laboratory (UT-Battelle) **/
#include <iostream>
#include <unordered_map>
#include <algorithm>
#include <tuple>
#include <cmath>
#include <cassert>
......@@ -191,6 +192,19 @@ MetisGraph::MetisGraph(const MetisGraph & parent, //in: parti
}
bool operator==(const MetisGraph & lhs, const MetisGraph & rhs)
{
return std::tie(lhs.num_vertices_,lhs.xadj_,lhs.adjncy_,lhs.vwgt_,lhs.adjwgt_,lhs.renumber_)
== std::tie(rhs.num_vertices_,rhs.xadj_,rhs.adjncy_,rhs.vwgt_,rhs.adjwgt_,rhs.renumber_);
}
bool operator!=(const MetisGraph & lhs, const MetisGraph & rhs)
{
return !(lhs == rhs);
}
void MetisGraph::clearPartitions()
{
tpwgts_.clear();
......
/** ExaTN::Numerics: Graph k-way partitioning via METIS
REVISION: 2020/05/19
REVISION: 2020/07/06
Copyright (C) 2018-2020 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2020 Oak Ridge National Laboratory (UT-Battelle) **/
......@@ -63,6 +63,10 @@ public:
MetisGraph & operator=(MetisGraph &&) noexcept = default;
~MetisGraph() = default;
/** Compares two METIS graphs for equality/inequality. **/
friend bool operator==(const MetisGraph & lhs, const MetisGraph & rhs);
friend bool operator!=(const MetisGraph & lhs, const MetisGraph & rhs);
/** Clears the current partitioning. **/
void clearPartitions();
......@@ -142,6 +146,9 @@ private:
idx_t num_cross_edges_; //number of cross edges in the edge cut
};
bool operator==(const MetisGraph & lhs, const MetisGraph & rhs);
bool operator!=(const MetisGraph & lhs, const MetisGraph & rhs);
} //namespace numerics
} //namespace exatn
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment