TECA
The Toolkit for Extreme Climate Analysis
teca_spatial_executive.h
1 #ifndef teca_spatial_executive_h
2 #define teca_spatial_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_spatial_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_spatial_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 temporal extent into. Use
46  * set_time_partition_size to control the partition size rather then the number.
47  */
48  void set_number_of_temporal_partitions(long n_partitions);
49 
50  /** Set the partition size to use when partitioning the temporal extent.
51  * Setting to less than one results in a spatial only partitioning. When
52  * greater or equal to one the value will be used to determine the number
53  * of temporal partitions.
54  *
55  * When the total number of time steps is not evenly devided by the
56  * temporal partition size, the final request will specify the remainder of
57  * steps.
58  *
59  * @param[in] n_steps the number of indices to request per request.
60  */
61  void set_temporal_partition_size(long n_steps);
62 
63  /// Set the time step to process
64  void set_time_step(long s);
65 
66  /// Set the first index in the series to process.The default is 0.
67  void set_first_step(long s);
68 
69  /** set the last index in the series to process. default is -1. negative
70  * number results in the last available time step being used.
71  */
72  void set_last_step(long s);
73 
74  /** Set the extent to partition and process. The default is to partition
75  * and process the whole_extent.
76  */
77  void set_extent(unsigned long *ext);
78  void set_extent(const std::vector<unsigned long> &ext);
79 
80  /** Set the spatial bounds to partition and process. The default is to
81  * partition and process the entire domain.
82  */
83  void set_bounds(double *bounds);
84  void set_bounds(const std::vector<double> &bounds);
85 
86  /** Set a list of arrays to include in upstream requests. This provides a
87  * means of pulling data through the pipeline when the upstream algorithms
88  * do not do this automatically or to pull additional arrays.
89  */
90  void set_arrays(const std::vector<std::string> &arrays);
91 
92  /** Condigures the executive to make one request per time step using the
93  * index_request_key as the teca_index_executive would. This could be used
94  * parallelize exsiting algorithms over space and time.
95  */
97  {
98  this->number_of_temporal_partitions = 0;
99  this->temporal_partition_size = 1;
100  this->index_executive_compatability = 1;
101  }
102 
103  /// A flag that enables/disables partitioning in the x-direction
104  void set_partition_x(int val) { this->partition_x = val; }
105 
106  /// A flag that enables/disables partitioning in the y-direction
107  void set_partition_y(int val) { this->partition_y = val; }
108 
109  /// A flag that enables/disables partitioning in the z-direction
110  void set_partition_z(int val) { this->partition_z = val; }
111 
112  /// Sets the minimum block size in the x-direction
113  void set_minimum_block_size_x(unsigned long val)
114  { this->minimum_block_size_x = std::max(1ul, val); }
115 
116  /// Sets the minimum block size in the y-direction
117  void set_minimum_block_size_y(unsigned long val)
118  { this->minimum_block_size_y = std::max(1ul, val); }
119 
120  /// Sets the minimum block size in the z-direction
121  void set_minimum_block_size_z(unsigned long val)
122  { this->minimum_block_size_z = std::max(1ul, val); }
123 
124 protected:
126 
127 private:
128  std::vector<teca_metadata> requests;
129  std::string index_initializer_key;
130  std::string index_request_key;
131  long first_step;
132  long last_step;
133  long number_of_temporal_partitions;
134  long temporal_partition_size;
135  int index_executive_compatability;
136  int partition_x;
137  int partition_y;
138  int partition_z;
139  unsigned long minimum_block_size_x;
140  unsigned long minimum_block_size_y;
141  unsigned long minimum_block_size_z;
142  std::vector<unsigned long> extent;
143  std::vector<double> bounds;
144  std::vector<std::string> arrays;
145 };
146 
147 #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_spatial_executive.h:38
void enable_index_executive_compatibility()
Definition: teca_spatial_executive.h:96
void set_time_step(long s)
Set the time step to process.
void set_first_step(long s)
Set the first index in the series to process.The default is 0.
void set_minimum_block_size_y(unsigned long val)
Sets the minimum block size in the y-direction.
Definition: teca_spatial_executive.h:117
void set_minimum_block_size_x(unsigned long val)
Sets the minimum block size in the x-direction.
Definition: teca_spatial_executive.h:113
void set_partition_z(int val)
A flag that enables/disables partitioning in the z-direction.
Definition: teca_spatial_executive.h:110
void set_extent(unsigned long *ext)
void set_minimum_block_size_z(unsigned long val)
Sets the minimum block size in the z-direction.
Definition: teca_spatial_executive.h:121
void set_temporal_partition_size(long n_steps)
void set_partition_x(int val)
A flag that enables/disables partitioning in the x-direction.
Definition: teca_spatial_executive.h:104
void set_last_step(long s)
void set_number_of_temporal_partitions(long n_partitions)
void set_partition_y(int val)
A flag that enables/disables partitioning in the y-direction.
Definition: teca_spatial_executive.h:107
void set_bounds(double *bounds)
void set_arrays(const std::vector< std::string > &arrays)
p_teca_error_handler error_handler TECA_EXPORT
The global error handler instance.