TECA
The Toolkit for Extreme Climate Analysis
teca_space_time_executive.h
1 #ifndef teca_space_time_executive_h
2 #define teca_space_time_executive_h
3 
4 #include "teca_shared_object.h"
5 #include "teca_algorithm_executive.h"
6 #include "teca_metadata.h"
7 #include "teca_mpi.h"
8 
9 #include <vector>
10 
11 TECA_SHARED_OBJECT_FORWARD_DECL(teca_space_time_executive)
12 
13 /** An executive that generates requests such that the upstream or user defined
14  * index space is partitoned using a fixed partition size and spatially across MPI
15  * ranks. Set the partition size to 0 to use only the spatial partitioning.
16  *
17  * This executive uses the following meta data keys:
18  *
19  * | Key | Description |
20  * | ---- | ----------- |
21  * | whole_extent | The spatial extent to partiton. Partitionaing is |
22  * | ^ | applied such that each MPI rank has a unique subset to |
23  * | ^ | process |
24  * | index_initializer_key -| holds the name of the key that tells how |
25  * | ^ | many indices are available. the named key |
26  * | ^ | must also be present and should conatin the |
27  * | ^ | number of indices available |
28  * | index_request_key | holds the name of the key used to request |
29  * | ^ | a specific inclusive range of indices [i0, i1]. |
30  * | ^ | Requests are generated with this name set to |
31  * | ^ | a specific inclusive range of indices to be |
32  * | ^ | processed. Some upstream algorithm is |
33  * | ^ | expected to produce the data associated |
34  * | ^ | with the requested index extent. |
35  *
36  */
38 {
39 public:
40  TECA_ALGORITHM_EXECUTIVE_STATIC_NEW(teca_space_time_executive)
41 
42  int initialize(MPI_Comm comm, const teca_metadata &md) override;
43  teca_metadata get_next_request() override;
44 
45  /** Set the number of partitions to partition the spatial extent into. If set
46  * to a value less than one, the number of MPI ranks is used. If set to a
47  * number greater or equal to one and less than the number of MPI ranks, a
48  * warning is issued but processing will continue. The default is zero,
49  * resulting in one partition per MPI rank.
50  */
51  void set_number_of_spatial_partitions(long n_partitions);
52 
53  /** Set the number of partitions to partition the temporal extent into. Use
54  * set_time_partition_size to control the partition size rather then the number.
55  */
56  void set_number_of_temporal_partitions(long n_partitions);
57 
58  /** Set the partition size to use when partitioning the temporal extent.
59  * Setting to less than one results in a spatial only partitioning. When
60  * greater or equal to one the value will be used to determine the number
61  * of temporal partitions.
62  *
63  * When the total number of time steps is not evenly devided by the
64  * temporal partition size, the final request will specify the remainder of
65  * steps.
66  *
67  * @param[in] n_steps the number of indices to request per request.
68  */
69  void set_temporal_partition_size(long n_steps);
70 
71  /// Set the time step to process
72  void set_time_step(long s);
73 
74  /// Set the first index in the series to process.The default is 0.
75  void set_first_step(long s);
76 
77  /** set the last index in the series to process. default is -1. negative
78  * number results in the last available time step being used.
79  */
80  void set_last_step(long s);
81 
82  /** Set the extent to partition and process. The default is to partition
83  * and process the whole_extent.
84  */
85  void set_extent(unsigned long *ext);
86  void set_extent(const std::vector<unsigned long> &ext);
87 
88  /** Set the spatial bounds to partition and process. The default is to
89  * partition and process the entire domain.
90  */
91  void set_bounds(double *bounds);
92  void set_bounds(const std::vector<double> &bounds);
93 
94  /** Set a list of arrays to include in upstream requests. This provides a
95  * means of pulling data through the pipeline when the upstream algorithms
96  * do not do this automatically or to pull additional arrays.
97  */
98  void set_arrays(const std::vector<std::string> &arrays);
99 
100  /** Condigures the executive to make one request per time step using the
101  * index_request_key as the teca_index_executive would. This could be used
102  * parallelize exsiting algorithms over space and time.
103  */
105  {
106  this->number_of_temporal_partitions = 0;
107  this->temporal_partition_size = 1;
108  this->index_executive_compatability = 1;
109  }
110 
111  /// A flag that enables/disables partitioning in the x-direction
112  void set_partition_x(int val) { this->partition_x = val; }
113 
114  /// A flag that enables/disables partitioning in the y-direction
115  void set_partition_y(int val) { this->partition_y = val; }
116 
117  /// A flag that enables/disables partitioning in the z-direction
118  void set_partition_z(int val) { this->partition_z = val; }
119 
120  /// Sets the minimum block size in the x-direction
121  void set_minimum_block_size_x(unsigned long val)
122  { this->minimum_block_size_x = std::max(1ul, val); }
123 
124  /// Sets the minimum block size in the y-direction
125  void set_minimum_block_size_y(unsigned long val)
126  { this->minimum_block_size_y = std::max(1ul, val); }
127 
128  /// Sets the minimum block size in the z-direction
129  void set_minimum_block_size_z(unsigned long val)
130  { this->minimum_block_size_z = std::max(1ul, val); }
131 
132 protected:
134 
135 private:
136  std::vector<teca_metadata> requests;
137  std::string index_initializer_key;
138  std::string index_request_key;
139  long first_step;
140  long last_step;
141  long number_of_spatial_partitions;
142  long number_of_temporal_partitions;
143  long temporal_partition_size;
144  int index_executive_compatability;
145  int partition_x;
146  int partition_y;
147  int partition_z;
148  unsigned long minimum_block_size_x;
149  unsigned long minimum_block_size_y;
150  unsigned long minimum_block_size_z;
151  std::vector<unsigned long> extent;
152  std::vector<double> bounds;
153  std::vector<std::string> arrays;
154 };
155 
156 #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
Definition: teca_space_time_executive.h:38
void set_partition_z(int val)
A flag that enables/disables partitioning in the z-direction.
Definition: teca_space_time_executive.h:118
void set_extent(unsigned long *ext)
void set_first_step(long s)
Set the first index in the series to process.The default is 0.
void set_temporal_partition_size(long n_steps)
void set_minimum_block_size_z(unsigned long val)
Sets the minimum block size in the z-direction.
Definition: teca_space_time_executive.h:129
void set_arrays(const std::vector< std::string > &arrays)
void set_minimum_block_size_y(unsigned long val)
Sets the minimum block size in the y-direction.
Definition: teca_space_time_executive.h:125
void set_time_step(long s)
Set the time step to process.
void set_partition_x(int val)
A flag that enables/disables partitioning in the x-direction.
Definition: teca_space_time_executive.h:112
void set_number_of_spatial_partitions(long n_partitions)
void enable_index_executive_compatibility()
Definition: teca_space_time_executive.h:104
void set_partition_y(int val)
A flag that enables/disables partitioning in the y-direction.
Definition: teca_space_time_executive.h:115
void set_number_of_temporal_partitions(long n_partitions)
void set_minimum_block_size_x(unsigned long val)
Sets the minimum block size in the x-direction.
Definition: teca_space_time_executive.h:121
void set_bounds(double *bounds)
p_teca_error_handler error_handler TECA_EXPORT
The global error handler instance.