SENSEI
A frame work for generic in situ analytics
AnalysisAdaptor.h
1 #ifndef sensei_AnalysisAdaptor_h
2 #define sensei_AnalysisAdaptor_h
3 
4 #include "senseiConfig.h"
5 #include <svtkObjectBase.h>
6 #include <mpi.h>
7 
8 namespace sensei
9 {
10 class DataAdaptor;
11 
12 /** The base class for data consumers. Implementors will override ::Eexcute,
13  * and ::Finalize and can choose to implement an Initialze method. In ::Execute
14  * the sensei::DataAdaptor API is used to fetch simulation data. The fetched
15  * data is transformed as needed by the underlying processing, movement or I/O
16  * library. Simulations invoke in situ processing by calling the ::Execute
17  * method. Typically simulations will make use of the
18  * sensei::ConfigurableAnalysis.
19  *
20  * An analysis adaptor can optionally return a sensei::DataAdaptor instance
21  * from ::Execute. Such an output may be used for further analysis or provide
22  * feedback and other control information back to the simulation itself.
23  */
24 class SENSEI_EXPORT AnalysisAdaptor : public svtkObjectBase
25 {
26 public:
27  senseiBaseTypeMacro(AnalysisAdaptor, svtkObjectBase);
28 
29  /// Prints the current state of the adaptor.
30  void PrintSelf(ostream& os, svtkIndent indent) override;
31 
32  /** Set the MPI communicator to be used by the adaptor.
33  * The default communicator is a duplicate of MPI_COMMM_WORLD, giving
34  * each adaptor a unique communication space. Users wishing to override
35  * this should set the communicator before doing anything else. Derived
36  * classes should use the communicator returned by GetCommunicator.
37  */
38  virtual int SetCommunicator(MPI_Comm comm);
39 
40  /// returns the MPI communicator to be used for all communication
41  MPI_Comm GetCommunicator() { return this->Comm; }
42 
43  /** Set the level of verbosity of console output. The environment variable
44  * `SENSEI_VERBOSE` provides the initial value if set. Otherwise the default
45  * is 0.
46  */
47  virtual void SetVerbose(int val){ this->Verbose = val; }
48 
49  /// Get the level of verbosity of console output.
50  virtual int GetVerbose(){ return this->Verbose; }
51 
52  /** When set the analysis should buffer the simulation data and run in the
53  * background returning to the simulation immediately. This mode requires
54  * MPI_THREAD_MULTIPLE and each thread must use a different communictor
55  * or serialize the calls to MPI collectives. The environment variable
56  * `SENSEI_ASYNCHRONOUS` provides the initial value. Oterwise the default
57  * is 0.
58  */
59  virtual void SetAsynchronous(int val){ this->Asynchronous = val; }
60 
61  /// Get asynchronous mode.
62  virtual int GetAsynchronous(){ return this->Asynchronous; }
63 
64  /// values controling device selection
65  enum {DEVICE_HOST=-1, DEVICE_AUTO=-2};
66 
67  /** Set the device that the analysis should run on. A value of DEVICE_HOST
68  * (-1) indicates that the analysis should run on the host while a value
69  * greater or equal to 0 specifies the device explicitly. The special value
70  * of DEVICE_AUTO (-2) is reserved for automatic device selection. The
71  * environment variable `SENSEI_DEVICE_ID` provides the initial value.
72  * Otherwise the default is DEVICE_HOST. See ::GetDeviceId for an explanation
73  * of the automatic device selection algorithm.
74  */
75  virtual void SetDeviceId(int val){ this->DeviceId = val; }
76 
77  /** Get the device that the analysis should run on. When ::SetDeviceId has
78  * the special value of DEVICE_AUTO (-2) the * following algorithm is used:
79  * ```
80  * DeviceId = ( MPI rank % DevicesInUse * DeviceStride + DeviceStart ) % DevicesPerNode
81  * ```
82  * See ::SetDeviceId.
83  */
84  virtual int GetDeviceId();
85 
86  /** Set the number of devices to use per node. This value can be smaller than
87  * the number of actual devices but should not exceed it. The environment
88  * variable `SENSEI_DEVICES_TO_USE` provides the initial value. Otherwise the
89  * default is the number of actual devices available. See ::SetDeviceId for
90  * an explanation of automatic device selection.
91  */
92  virtual void SetDevicesToUse(int val){ this->DevicesToUse = val; }
93 
94  /// Get the number of devices to use per node.
95  virtual int GetDevicesToUse(){ return this->DevicesToUse; }
96 
97  /** Set the first on node device to use in automatic device selection. The
98  * environment variable `SENSEI_DEVICE_START` provides the initial value.
99  * Otherwise the default is 0. See ::SetDeviceId for an explanation of
100  * automatic device selection.
101  */
102  virtual void SetDeviceStart(int val){ this->DeviceStart = val; }
103 
104  /// Get the first device to use
105  virtual int GetDeviceStart(){ return this->DeviceStart; }
106 
107  /** Set the number of devices to skip in automatic device selection. The
108  * environment variable `SENSEI_DEVICE_STRIDE` provides the initial value.
109  * Otherwise the default is 0. See ::SetDeviceId for an explanation of
110  * automatic device selection.
111  */
112  virtual void SetDeviceStride(int val){ this->DeviceStride = val; }
113 
114  /// Get the number of devices to skip
115  virtual int GetDeviceStride(){ return this->DeviceStride; }
116 
117 
118  /** Invokes in situ processing, data movement or I/O. The simulation will
119  * call this method when data is ready to be processed. Callers will pass a
120  * simulation specific sensei::DataAdaptor that can be used to fetch the
121  * needed simulation data for processing. Callers pass a non-null address to
122  * a pointer to a sensei::DataAdaptor to signal that output is desired if it
123  * is available. In that case a newly allocated data adaptor instance is
124  * returned in the pointer. This data adaptor can be used to fetch the
125  * output. The caller trakes ownership of the returned data adaptor instance
126  * and must call Delete on it when finished. Callers that do not want the
127  * output data should pass nullptr to signal that it is not needed.
128  *
129  * @param [in] dataIn the simulation provided data adaptor used to fetch data
130  * for processing
131  * @param [out] dataOut the address of a pointer to a data adaptor that could
132  * be used to fetch data from the analysis. This should
133  * be null if the caller does not want to access the
134  * output data. If it is not null and if the
135  * implementation can provide output a data, a data
136  * adaptor is allocated and returned via this pointer.
137  * In that case the caller can use the adaptor to fetch
138  * the data. The caller takes ownership of the returned
139  * data adaptor and must call Delete on it when
140  * finished.
141  * @returns false if an error has occurred. Typically this means that in
142  * situ processing is not possible due to misconfiguration or communication
143  * error. In that case callers should abort so as not to waste compute
144  * resources.
145  */
146  virtual bool Execute(DataAdaptor* dataIn, DataAdaptor** dataOut) = 0;
147 
148  /** Clean up and shut down the data consuming library if needed. This method
149  * is called when the run is finsihed clean up and shut down should occur
150  * here rather than in the destructor as MPI may not be available at
151  * desctruction time.
152  *
153  * @returns zero if successful.
154  */
155  virtual int Finalize() { return 0; }
156 
157 protected:
158  AnalysisAdaptor();
159  ~AnalysisAdaptor();
160 
161  AnalysisAdaptor(const AnalysisAdaptor&) = delete;
162  void operator=(const AnalysisAdaptor&) = delete;
163 
164  MPI_Comm Comm;
165  int Verbose;
166  int DeviceId;
167  int DevicesPerNode;
168  int DevicesToUse;
169  int DeviceStart;
170  int DeviceStride;
171  int Asynchronous;
172 };
173 
174 }
175 #endif
virtual int GetAsynchronous()
Get asynchronous mode.
Definition: AnalysisAdaptor.h:62
virtual void SetAsynchronous(int val)
When set the analysis should buffer the simulation data and run in the background returning to the si...
Definition: AnalysisAdaptor.h:59
virtual void SetDeviceId(int val)
Set the device that the analysis should run on.
Definition: AnalysisAdaptor.h:75
The base class for data consumers.
Definition: AnalysisAdaptor.h:24
virtual void SetDeviceStart(int val)
Set the first on node device to use in automatic device selection.
Definition: AnalysisAdaptor.h:102
MPI_Comm GetCommunicator()
returns the MPI communicator to be used for all communication
Definition: AnalysisAdaptor.h:41
virtual int GetDevicesToUse()
Get the number of devices to use per node.
Definition: AnalysisAdaptor.h:95
virtual void SetVerbose(int val)
Set the level of verbosity of console output.
Definition: AnalysisAdaptor.h:47
virtual void SetDeviceStride(int val)
Set the number of devices to skip in automatic device selection.
Definition: AnalysisAdaptor.h:112
virtual void SetDevicesToUse(int val)
Set the number of devices to use per node.
Definition: AnalysisAdaptor.h:92
virtual int GetVerbose()
Get the level of verbosity of console output.
Definition: AnalysisAdaptor.h:50
virtual int GetDeviceStart()
Get the first device to use.
Definition: AnalysisAdaptor.h:105
virtual int Finalize()
Clean up and shut down the data consuming library if needed.
Definition: AnalysisAdaptor.h:155
SENSEI.
Definition: ADIOS2AnalysisAdaptor.h:27
virtual int GetDeviceStride()
Get the number of devices to skip.
Definition: AnalysisAdaptor.h:115
Base class that defines the interface for fetching data from a simulation.
Definition: DataAdaptor.h:25