SENSEI
A frame work for generic in situ analytics
ADIOS2AnalysisAdaptor.h
1 #ifndef ADIOS2AnalysisAdaptor_h
2 #define ADIOS2AnalysisAdaptor_h
3 
4 #include "AnalysisAdaptor.h"
5 #include "DataRequirements.h"
6 #include "MeshMetadata.h"
7 
8 #include <ADIOS2Schema.h>
9 
10 #include <vector>
11 #include <string>
12 #include <mpi.h>
13 
14 /// @cond
15 namespace senseiADIOS2
16 {
17 struct AdiosHandle;
18 class DataObjectCollectionSchema;
19 }
20 
21 class svtkDataObject;
22 class svtkCompositeDataSet;
23 
24 namespace pugi { class xml_node; }
25 /// @endcond
26 
27 namespace sensei
28 {
29 /// The write side of the ADIOS2 transport
30 class SENSEI_EXPORT ADIOS2AnalysisAdaptor : public AnalysisAdaptor
31 {
32 public:
33  /// constructs a new ADIOS2AnalysisAdaptor instance.
34  static ADIOS2AnalysisAdaptor* New();
35 
36  senseiTypeMacro(ADIOS2AnalysisAdaptor, AnalysisAdaptor);
37 
38  /// @name runtime configuration
39  /// @{
40 
41  /// initialize from an XML representation
42  int Initialize(pugi::xml_node &parent);
43 
44  /// Add name value pairs to be passed to ADIOS
45  void AddParameter(const std::string &key, const std::string &value);
46 
47  /// Set the ADIOS2 engine.
48  void SetEngineName(const std::string &engineName)
49  { this->EngineName = engineName; }
50 
51  /// Get the ADIOS2 engine.
52  std::string GetEngineName() const
53  { return this->EngineName; }
54 
55  /** Set the filename. Default value is "sensei.bp" which is suitable for use
56  * with streams or transport engines such as SST. When writing files to disk
57  * using the BP4 engine one could SetStepsPerFile to prevent all steps being
58  * accumulated in a single file. In this case one should also use a printf
59  * like format specifier compatible with an int type in the file name. For
60  * example "sensei_%04d.bp".
61  */
62  void SetFileName(const std::string &filename)
63  { this->FileName = filename; }
64 
65  /// Returns the filename.
66  std::string GetFileName() const
67  { return this->FileName; }
68 
69  /** Set the number of time steps to store in each file. The default value is
70  * 0 which results in all the steps landing in a single file. If set to
71  * non-zero then multiple files per run are created each with this number of
72  * steps. An ordinal file index is incorporated in the file name. See notes
73  * in SetFileName for details on specifying the format specifier.
74  */
75  void SetStepsPerFile(long steps)
76  { this->StepsPerFile = steps; }
77 
78 
79  /** Adds a set of sensei::DataRequirements, typically this will come from an XML
80  * configuratiopn file. Data requirements tell the adaptor what to fetch from
81  * the simulation and write to disk. If none are given then all available
82  * data is fetched and written.
83  */
84  int SetDataRequirements(const DataRequirements &reqs);
85 
86  /** Add an indivudal data requirement. Data requirements tell the adaptor
87  * what to fetch from the simulation and write to disk. If none are given
88  * then all available data is fetched and written.
89 
90  * @param[in] meshName the name of the mesh to fetch and write
91  * @param[in] association the type of data array to fetch and write
92  * vtkDataObject::POINT or vtkDataObject::CELL
93  * @param[in] arrays a list of arrays to fetch and write
94  * @returns zero if successful.
95  */
96  int AddDataRequirement(const std::string &meshName,
97  int association, const std::vector<std::string> &arrays);
98 
99  /** Controls how many calls to Execute do nothing between actual I/O and
100  * streaming.
101  */
102  int SetFrequency(long frequency);
103 
104  /// @}
105 
106  /// Invokes ADIOS2 based I/O or streaming.
107  bool Execute(DataAdaptor* data, DataAdaptor** result) override;
108 
109  /// Shut down and clean up including flushing and closing all streams and files.
110  int Finalize() override;
111 
112 protected:
115 
116  // intializes ADIOS2 in no-xml mode
117  int InitializeADIOS2();
118 
119  // tells ADIOS what we will write
120  int DefineVariables(const std::vector<MeshMetadataPtr> &metadata);
121 
122  // initializes the output stream, and in the case of writing
123  // file series advances to the next file in the series.
124  int UpdateStream();
125 
126  // writes the data collection
127  int WriteTimestep(unsigned long timeStep, double time,
128  const std::vector<MeshMetadataPtr> &metadata,
129  const std::vector<svtkCompositeDataSetPtr> &dobjects);
130 
131  // shuts down ADIOS2
132  int FinalizeADIOS2();
133 
134  // fetch meshes and metadata objects from the simulation
135  int FetchFromProducer(sensei::DataAdaptor *da,
136  std::vector<svtkCompositeDataSetPtr> &objects,
137  std::vector<MeshMetadataPtr> &metadata);
138 
139  senseiADIOS2::DataObjectCollectionSchema *Schema;
140  sensei::DataRequirements Requirements;
141  std::string EngineName;
142  std::string FileName;
143  senseiADIOS2::AdiosHandle Handles;
144  adios2_adios *Adios;
145  std::vector<std::pair<std::string,std::string>> Parameters;
146  long StepsPerFile;
147  long StepIndex;
148  long FileIndex;
149  long Frequency;
150 
151 private:
153  void operator=(const ADIOS2AnalysisAdaptor&) = delete;
154 };
155 
156 }
157 
158 #endif
std::string GetFileName() const
Returns the filename.
Definition: ADIOS2AnalysisAdaptor.h:66
std::string GetEngineName() const
Get the ADIOS2 engine.
Definition: ADIOS2AnalysisAdaptor.h:52
int Initialize(MPI_Comm comm, const std::string &fileName, InTransitDataAdaptor *&dataAdaptor)
Creates a sensei::ConfigurableAnalysis adaptor and sensei::InTransitDataAdaptor based on a SENSEI XML...
The base class for data consumers.
Definition: AnalysisAdaptor.h:24
The write side of the ADIOS2 transport.
Definition: ADIOS2AnalysisAdaptor.h:30
void SetStepsPerFile(long steps)
Set the number of time steps to store in each file.
Definition: ADIOS2AnalysisAdaptor.h:75
void SetEngineName(const std::string &engineName)
Set the ADIOS2 engine.
Definition: ADIOS2AnalysisAdaptor.h:48
This is a helper class that handles the common task of specifying the set of meshes and arrays rqeuir...
Definition: DataRequirements.h:25
SENSEI.
Definition: ADIOS2AnalysisAdaptor.h:27
Definition: ADIOS2DataAdaptor.h:10
Base class that defines the interface for fetching data from a simulation.
Definition: DataAdaptor.h:25
void SetFileName(const std::string &filename)
Set the filename.
Definition: ADIOS2AnalysisAdaptor.h:62