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  /// Set the list of devices to assign work to
94  void set_device_ids(const std::vector<int> &device_ids);
95 
96 protected:
98 
99 private:
100  std::vector<teca_metadata> requests;
101  std::string index_initializer_key;
102  std::string index_request_key;
103  long start_index;
104  long end_index;
105  long stride;
106  std::vector<unsigned long> extent;
107  std::vector<double> bounds;
108  std::vector<std::string> arrays;
109  std::vector<int> device_ids;
110 };
111 
112 #endif
Base class and default implementation for executives.
Definition: teca_algorithm_executive.h:55
An executive that generates requests using a upstream or user defined index.
Definition: teca_index_executive.h:57
void set_index(long s)
set the index to process
void set_end_index(long s)
void set_extent(unsigned long *ext)
Set the extent to process. The default is taken from whole_extent key.
void set_device_ids(const std::vector< int > &device_ids)
Set the list of devices to assign work to.
void set_bounds(double *bounds)
void set_extent(const std::vector< unsigned long > &ext)
Set the extent to process. The default is taken from whole_extent key.
void set_stride(long s)
Set the stride to process time steps at. The default is 1.
void set_arrays(const std::vector< std::string > &arrays)
Set the list of arrays to process.
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.