num_server.hpp 4.9 KB
Newer Older
1
/** ExaTN::Numerics: Numerical server
2
REVISION: 2019/06/05
3
4
5
6

Copyright (C) 2018-2019 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2019 Oak Ridge National Laboratory (UT-Battelle) **/

7
8
9
10
11
12
13
14
15
16
17
/** Rationale:
 (a) Numerical server provides basic tensor network processing functionality:
     + Opening/closing TAProL scopes (top scope 0 "GLOBAL" is open automatically);
     + Creation/destruction of named vector spaces and their named subspaces;
     + Registration/retrieval of external data;
     + Registration/retrieval of external tensor methods;
     + Submission for processing of individual tensor operations and tensor networks.
 (b) Processing of individual tensor operations and tensor networks has asynchronous semantics:
     Submit TensorOperation/TensorNetwork for processing, then synchronize on the tensor-result.
**/

18
19
#ifndef EXATN_NUMERICS_NUM_SERVER_HPP_
#define EXATN_NUMERICS_NUM_SERVER_HPP_
20
21

#include "tensor_basic.hpp"
22
#include "space_register.hpp"
23
24
#include "tensor.hpp"
#include "tensor_operation.hpp"
25
#include "tensor_network.hpp"
26

27
28
29
#include "tensor_method.hpp"
#include "Identifiable.hpp"

30
#include <memory>
31
#include <string>
32
#include <stack>
33
#include <map>
34

35
36
using exatn::Identifiable;

37
38
39
40
namespace exatn{

namespace numerics{

41
class NumServer{
42
43
44

public:

45
 NumServer();
46
47
48
49
50
 NumServer(const NumServer &) = delete;
 NumServer & operator=(const NumServer &) = delete;
 NumServer(NumServer &&) noexcept = default;
 NumServer & operator=(NumServer &&) noexcept = default;
 ~NumServer() = default;
51

52
53
 /** Registers an external tensor method. **/
 void registerTensorMethod(std::shared_ptr<TensorMethod<Identifiable>> method);
54

55
56
57
58
59
60
61
62
 /** Retrieves a registered external tensor method. **/
 std::shared_ptr<TensorMethod<Identifiable>> getTensorMethod(const std::string & tag);

 /** Registers an external data packet. **/
 void registerExternalData(const std::string & tag, std::shared_ptr<BytePacket> packet);

 /** Retrieves a registered external data packet. **/
 std::shared_ptr<BytePacket> getExternalData(const std::string & tag);
63

64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86

 /** Opens a new (child) TAProL scope and returns its id. **/
 ScopeId openScope(const std::string & scope_name); //new scope name

 /** Closes the currently open TAProL scope and returns its parental scope id. **/
 ScopeId closeScope();


 /** Creates a named vector space, returns its registered id, and,
     optionally, a non-owning pointer to it. **/
 SpaceId createVectorSpace(const std::string & space_name,            //in: vector space name
                           DimExtent space_dim,                       //in: vector space dimension
                           const VectorSpace ** space_ptr = nullptr); //out: non-owning pointer to the created vector space

 /** Destroys a previously created named vector space. **/
 void destroyVectorSpace(const std::string & space_name); //in: name of the vector space to destroy
 void destroyVectorSpace(SpaceId space_id);               //in: id of the vector space to destroy


 /** Creates a named subspace of a named vector space,
     returns its registered id, and, optionally, a non-owning pointer to it. **/
 SubspaceId createSubspace(const std::string & subspace_name,           //in: subspace name
                           const std::string & space_name,              //in: containing vector space name
87
                           const std::pair<DimOffset,DimOffset> bounds, //in: range of basis vectors defining the created subspace
88
89
                           const Subspace ** subspace_ptr = nullptr);   //out: non-owning pointer to the created subspace

90
 /** Destroys a previously created named subspace of a named vector space. **/
91
92
93
 void destroySubspace(const std::string & subspace_name); //in: name of the subspace to destroy
 void destroySubspace(SubspaceId subspace_id);

94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109

 /** Submits an individual tensor operation for processing. **/
 int submit(std::shared_ptr<TensorOperation> operation);
 /** Submits a tensor network for processing (evaluating the tensor-result). **/
 int submit(std::shared_ptr<TensorNetwork> network);

 /** Synchronizes all tensor operations on a given tensor. **/
 bool sync(const Tensor & tensor,
           bool wait = false);
 /** Synchronizes execution of a specific tensor operation. **/
 bool sync(const TensorOperation & operation,
           bool wait = false);
 /** Synchronizes execution of a specific tensor network. **/
 bool sync(const TensorNetwork & network,
           bool wait = false);

110
111
112
private:

 SpaceRegister space_register_; //register of vector spaces and their named subspaces
113
 std::unordered_map<std::string,SpaceId> subname2id_; //maps a subspace name to its parental vector space id
114

115
116
 std::map<std::string,std::shared_ptr<TensorMethod<Identifiable>>> ext_methods_; //external tensor methods
 std::map<std::string,std::shared_ptr<BytePacket>> ext_data_; //external data
117

118
 std::stack<std::pair<std::string,ScopeId>> scopes_; //TAProL scope stack: {Scope name, Scope Id}
119

120
121
122
123
124
125
};

} //namespace numerics

} //namespace exatn

126
#endif //EXATN_NUMERICS_NUM_SERVER_HPP_