1 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
2 // Copyright (c) Lawrence Livermore National Security, LLC and other Ascent
3 // Project developers. See top-level LICENSE AND COPYRIGHT files for dates and
4 // other details. No copyright assignment is required to contribute to Ascent.
5 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
6 
7 
8 //-----------------------------------------------------------------------------
9 ///
10 /// file: flow_workspace.hpp
11 ///
12 //-----------------------------------------------------------------------------
13 
14 #ifndef FLOW_WORKSPACE_HPP
15 #define FLOW_WORKSPACE_HPP
16 
17 #include <conduit.hpp>
18 
19 #include <flow_exports.h>
20 #include <flow_config.h>
21 #include <flow_data.hpp>
22 #include <flow_registry.hpp>
23 #include <flow_graph.hpp>
24 #include <sstream>
25 
26 
27 //-----------------------------------------------------------------------------
28 // -- begin flow:: --
29 //-----------------------------------------------------------------------------
30 namespace flow
31 {
32 
33 //-----------------------------------------------------------------------------
34 ///
35 /// Workspace
36 ///
37 //-----------------------------------------------------------------------------
38 
39 //-----------------------------------------------------------------------------
40 class FLOW_API Workspace
41 {
42 public:
43 
44     friend class Graph;
45 
46    // ------------------------------------------------------------------------
47    /// Workspace instance methods
48    // ------------------------------------------------------------------------
49 
50     Workspace();
51    ~Workspace();
52 
53     /// access the filter graph
54     Graph           &graph();
55     /// const access to the filter graph
56     const Graph     &graph() const;
57 
58     /// access the registry
59     Registry        &registry();
60     /// const access to the registry
61     const Registry  &registry() const;
62 
63     /// compute and return the graph traverals
64     void             traversals(conduit::Node &out);
65 
66     /// execute the filter graph.
67     void             execute();
68 
69     /// reset the registry and graph
70     void             reset();
71 
72     /// create human understandable tree that describes the state
73     /// of the workspace
74     void           info(conduit::Node &out) const;
75     /// create json string from info
76     std::string    to_json() const;
77     /// print json version of info
78     void           print() const;
79 
80     /// resets state used to capture timing events
81     void           reset_timing_info();
82     /// return a string of recorded timing events
83     std::string    timing_info() const;
84 
85     // ------------------------------------------------------------------------
86     /// Interface to set and obtain the MPI communicator.
87     ///
88     /// We use an integer handle from MPI_Comm_c2f to avoid
89     /// a header dependency of mpi just for the handle.
90     ///
91     // ------------------------------------------------------------------------
92     void static set_default_mpi_comm(int mpi_comm_id);
93     int  static default_mpi_comm();
94 
95     // ------------------------------------------------------------------------
96     /// filter factory interface
97     // ------------------------------------------------------------------------
98 
99     /// register a new type
100     static void register_filter_type(FilterFactoryMethod fr);
101 
102     /// register a new type
103     static void register_filter_type(const std::string &filter_type_name,
104                                      FilterFactoryMethod fr);
105 
106     /// check if type with given name is registered
107     static bool supports_filter_type(const std::string &filter_type_name);
108 
109     // /// check if type with given factory is registered
110     static bool supports_filter_type(FilterFactoryMethod fr);
111 
112     /// remove type with given name if registered
113     static void remove_filter_type(const std::string &filter_type_name);
114 
115     // /// returns the filter name for a registered filter
116     static std::string filter_type_name(FilterFactoryMethod fr);
117 
118     /// remove all registered types
119     static void clear_supported_filter_types();
120 
121     /// helper to for registering a filter type that does not provide its own
122     /// FilterFactoryMethod
123     template <class T>
register_filter_type()124     static void register_filter_type()
125     {
126         register_filter_type(&CreateFilter<T>);
127     }
128 
129     /// helper for checkeding if a filter type is registered
130     template <class T>
supports_filter_type()131     static bool supports_filter_type()
132     {
133         return supports_filter_type(&CreateFilter<T>);
134     }
135 
136 
137     /// helper for checkeding if a filter type is registered
138     template <class T>
filter_type_name()139     static std::string filter_type_name()
140     {
141         return filter_type_name(&CreateFilter<T>);
142     }
143 
144     void enable_timings(bool enabled);
145 
146 private:
147 
148     static Filter *create_filter(const std::string &filter_type);
149 
150     static int  m_default_mpi_comm;
151 
152     class ExecutionPlan;
153     class FilterFactory;
154 
155     Graph             m_graph;
156     Registry          m_registry;
157     std::stringstream m_timing_info;
158     bool              m_enable_timings;
159 
160 };
161 
162 //-----------------------------------------------------------------------------
163 };
164 //-----------------------------------------------------------------------------
165 // -- end flow:: --
166 //-----------------------------------------------------------------------------
167 
168 
169 #endif
170 //-----------------------------------------------------------------------------
171 // -- end header ifdef guard
172 //-----------------------------------------------------------------------------
173 
174 
175