TECA
The Toolkit for Extreme Climate Analysis
teca_algorithm_executive.h
1 #ifndef teca_algorithm_executive_h
2 #define teca_algorithm_executive_h
3 
4 #include "teca_metadata.h"
5 #include "teca_mpi.h"
6 #include "teca_shared_object.h"
7 
8 TECA_SHARED_OBJECT_FORWARD_DECL(teca_algorithm_executive)
9 
10 /* this is a convenience macro to be used to declare a static
11  * New method that will be used to construct new objects in
12  * shared_ptr's. This manages the details of interoperability
13  * with std C++11 shared pointer
14  */
15 #define TECA_ALGORITHM_EXECUTIVE_STATIC_NEW(T) \
16  \
17  \
18 /** Allocate a new T */ \
19 static p_##T New() \
20 { \
21  return p_##T(new T); \
22 } \
23  \
24 std::shared_ptr<T> shared_from_this() \
25 { \
26  return std::static_pointer_cast<T>( \
27  teca_algorithm_executive::shared_from_this()); \
28 } \
29  \
30 std::shared_ptr<T const> shared_from_this() const \
31 { \
32  return std::static_pointer_cast<T const>( \
33  teca_algorithm_executive::shared_from_this()); \
34 }
35 
36 
37 
38 /// Base class and default implementation for executives.
39 /**
40  * Algorithm executives can control pipeline execution by providing
41  * a series of requests. this allows for the executive to act as a load
42  * balancer. the executive can for example partition requests across
43  * spatial data, time steps, or file names. in an MPI parallel
44  * setting the executive could coordinate this partitioning amongst
45  * the ranks. However, the only requirement of an algorithm executive
46  * is that it provide at least one non-empty request.
47  *
48  * The default implementation creates a single trivially non-empty
49  * request containing the key "__request_empty = 0". This will cause
50  * the pipeline to be executed once but will result in no data being
51  * requested. Therefore when the default implementation is used
52  * upstream algorithms must fill in the requests further to pull
53  * data as needed.
54  */
56  : public std::enable_shared_from_this<teca_algorithm_executive>
57 {
58 public:
59  static p_teca_algorithm_executive New()
60  { return p_teca_algorithm_executive(new teca_algorithm_executive); }
61 
62  virtual ~teca_algorithm_executive() {}
63 
64  // initialize requests from the given metadata object.
65  // this is a place where work partitioning across MPI
66  // ranks can occur
67  virtual int initialize(MPI_Comm comm, const teca_metadata &md);
68 
69  // get the next request until all requests have been
70  // processed. an empty request is returned.
71  virtual teca_metadata get_next_request();
72 
73  // set/get verbosity level
74  void set_verbose(int a_verbose) { this->verbose = a_verbose; }
75  int get_verbose() const { return this->verbose; }
76 
77 protected:
78  teca_algorithm_executive() : verbose(0) {}
81  teca_algorithm_executive &operator=(const teca_algorithm_executive &) = default;
82  teca_algorithm_executive &operator=(teca_algorithm_executive &&) = default;
83 
84 private:
85  int verbose;
86  teca_metadata m_request;
87 };
88 
89 #endif
teca_metadata
A generic container for meta data in the form of name=value pairs.
Definition: teca_metadata.h:18
teca_algorithm_executive
Base class and default implementation for executives.
Definition: teca_algorithm_executive.h:55
teca_shared_object.h