TECA
The Toolkit for Extreme Climate Analysis
teca_index_executive.h
1 #ifndef teca_index_executive_h
2 #define teca_index_executive_h
3 
4 #include "teca_config.h"
5 #include "teca_shared_object.h"
6 #include "teca_algorithm_executive.h"
7 #include "teca_metadata.h"
8 #include "teca_mpi.h"
9 
10 #include <vector>
11 
12 TECA_SHARED_OBJECT_FORWARD_DECL(teca_index_executive)
13 
14 /// An executive that generates requests using a upstream or user defined index.
15 /** An extent or bounds to subset by, and list of arrays can be optionally set.
16  * This executive partitions an index set approximately equally accross the
17  * available MPI ranks. Each rank is assigned a unique set of CUDA devices if
18  * CUDA devices are available. Within each rank requests are issued to the
19  * assigned CUDA devices by setting the device_id key in the request. Upstream
20  * algorithms should examine the device_id key and use the given device for
21  * calculaitons. A device_id of -1 indicates that the CPU should be used for
22  * calculations. Algorithms that do not have a CUDA implementation will make
23  * use of the CPU and ignore the device_id field.
24  *
25  * ### Metadata keys:
26  *
27  * #### Requires:
28  *
29  * | Key | Description |
30  * | ---------------------- | ----------- |
31  * | index_initializer_key | holds the name of the key that tells how many |
32  * | | indices are available. the named key must also be |
33  * | | present and should contain the number of indices |
34  * | | available |
35  * | index_request_key | holds the name of the key used to request a |
36  * | | specific index. request are generated with this |
37  * | | name set to a specific index to be processed some |
38  * | | upstream algorithm is expected to produce the |
39  * | | data associated with the given index |
40  *
41  * #### Exports:
42  *
43  * | Key | Description |
44  * | ---------------------- | ----------- |
45  * | index_request_key | The name of the key holding the requested index |
46  * | <index_request_key> | the requested index |
47  * | device_id | the CPU (-1) or CUDA device (0 - n-1 devices) to |
48  * | | use for calculations |
49  * | bounds | the [x0 x1 y0 y1 z0 z1] spatial bounds requested |
50  * | | (optional) |
51  * | extent | the [i0 i1 j0 j1 k0 k1] index space grid extent |
52  * | | requested (optional) |
53  * | arrays | a list of arrays requested (optional) |
54  *
55  */
57 {
58 public:
59  TECA_ALGORITHM_EXECUTIVE_STATIC_NEW(teca_index_executive)
60 
61  int initialize(MPI_Comm comm, const teca_metadata &md) override;
62  teca_metadata get_next_request() override;
63 
64  /// set the index to process
65  void set_index(long s);
66 
67  // Set the first time step in the series to process. The default is 0.
68  void set_start_index(long s);
69 
70  /** Set the last time step in the series to process. default is -1.
71  * negative number results in the last available time step being used.
72  */
73  void set_end_index(long s);
74 
75  /// Set the stride to process time steps at. The default is 1
76  void set_stride(long s);
77 
78  /// Set the extent to process. The default is taken from whole_extent key.
79  void set_extent(unsigned long *ext);
80 
81  /// @copydoc teca_index_executive::set_extent(unsigned long *)
82  void set_extent(const std::vector<unsigned long> &ext);
83 
84  /** Set the bounds to process. If nothing is set then extent as provided by
85  * ::set_extent is used.
86  */
87  void set_bounds(double *bounds);
88  void set_bounds(const std::vector<double> &bounds);
89 
90  /// Set the list of arrays to process
91  void set_arrays(const std::vector<std::string> &arrays);
92 
93 protected:
95 
96 private:
97  std::vector<teca_metadata> requests;
98  std::string index_initializer_key;
99  std::string index_request_key;
100  long start_index;
101  long end_index;
102  long stride;
103  std::vector<unsigned long> extent;
104  std::vector<double> bounds;
105  std::vector<std::string> arrays;
106 };
107 
108 #endif
teca_metadata
A generic container for meta data in the form of name=value pairs.
Definition: teca_metadata.h:21
teca_index_executive
An executive that generates requests using a upstream or user defined index.
Definition: teca_index_executive.h:56
teca_algorithm_executive
Base class and default implementation for executives.
Definition: teca_algorithm_executive.h:53
teca_shared_object.h
teca_error::TECA_EXPORT
p_teca_error_handler error_handler TECA_EXPORT
The global error handler instance.