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_config.h"
5 #include "teca_metadata.h"
6 #include "teca_mpi.h"
7 #include "teca_shared_object.h"
8 
9 TECA_SHARED_OBJECT_FORWARD_DECL(teca_algorithm_executive)
10 
11 /* this is a convenience macro to be used to declare a static
12  * New method that will be used to construct new objects in
13  * shared_ptr's. This manages the details of interoperability
14  * with std C++11 shared pointer
15  */
16 #define TECA_ALGORITHM_EXECUTIVE_STATIC_NEW(T) \
17  \
18  \
19 /** Allocate a new T */ \
20 static p_##T New() \
21 { \
22  return p_##T(new T); \
23 } \
24  \
25 std::shared_ptr<T> shared_from_this() \
26 { \
27  return std::static_pointer_cast<T>( \
28  teca_algorithm_executive::shared_from_this()); \
29 } \
30  \
31 std::shared_ptr<T const> shared_from_this() const \
32 { \
33  return std::static_pointer_cast<T const>( \
34  teca_algorithm_executive::shared_from_this()); \
35 }
36 
37 
38 
39 /// Base class and default implementation for executives.
40 /**
41  * Algorithm executives can control pipeline execution by providing a series of
42  * requests. this allows for the executive to act as a load balancer. the
43  * executive can for example partition requests across spatial data, time
44  * steps, or file names. in an MPI parallel setting the executive could
45  * coordinate this partitioning amongst the ranks. However, the only
46  * requirement of an algorithm executive is that it provide at least one
47  * non-empty request.
48  *
49  * The default implementation creates a single request for the first index
50  * specified by the "index_initializer_key" using the "index_request_key" with
51  * "device_id" set to execute on the CPU or GPU (if GPU's are available).
52  */
54  : public std::enable_shared_from_this<teca_algorithm_executive>
55 {
56 public:
57  static p_teca_algorithm_executive New()
58  { return p_teca_algorithm_executive(new teca_algorithm_executive); }
59 
60  virtual ~teca_algorithm_executive() {}
61 
62  // initialize requests from the given metadata object.
63  // this is a place where work partitioning across MPI
64  // ranks can occur
65  virtual int initialize(MPI_Comm comm, const teca_metadata &md);
66 
67  // get the next request until all requests have been
68  // processed. an empty request is returned.
69  virtual teca_metadata get_next_request();
70 
71  // set/get verbosity level
72  void set_verbose(int a_verbose) { this->verbose = a_verbose; }
73  int get_verbose() const { return this->verbose; }
74 
75 protected:
76  teca_algorithm_executive() : verbose(0) {}
79  teca_algorithm_executive &operator=(const teca_algorithm_executive &) = default;
80  teca_algorithm_executive &operator=(teca_algorithm_executive &&) = default;
81 
82 private:
83  int verbose;
84  teca_metadata m_request;
85 };
86 
87 #endif
Base class and default implementation for executives.
Definition: teca_algorithm_executive.h:55
A generic container for meta data in the form of name=value pairs.
Definition: teca_metadata.h:22
p_teca_error_handler error_handler TECA_EXPORT
The global error handler instance.
auto New(size_t n_elem, teca_variant_array::allocator alloc=teca_variant_array::allocator::malloc)
Definition: teca_variant_array_util.h:269