Debian Codegraph @

packages/seacas/libraries/ioss/src/adios/AdiosWrapper.C

raw
1 // Copyright(C) 1999-2020, 2024 National Technology & Engineering Solutions
2 // of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
3 // NTESS, the U.S. Government retains certain rights in this software.
4 //
5 // See packages/seacas/LICENSE for details
6
7 #include "adios/AdiosWrapper.h"
8
9 #include <algorithm>
10
11 namespace Ioad {
12
13 AdiosWrapper::AdiosWrapper(Ioss_MPI_Comm comm, const std::string &filename, bool is_input,
14 unsigned long rank, const Ioss::PropertyManager &properties)
15 #if ADIOS2_USE_MPI
16 : adios2::ADIOS(comm),
17 #else
18 : adios2::ADIOS(),
19 #endif
20 adios2::IO(IOInit(properties, is_input)), adios2::Engine(EngineInit(filename, is_input)),
21 m_Rank(rank), m_Communicator(comm), m_OpenStep(false)
22 {
23 }
24
25 adios2::IO AdiosWrapper::IOInit(const Ioss::PropertyManager &properties, bool is_input)
26 {
27 adios2::IO bpio = this->ADIOS::DeclareIO("io");
28 std::string engine = "BPFile";
29 std::string transport = "File";
30 std::string library = "POSIX";
31 adios2::Params transport_parameters = {{"Library", "POSIX"}};
32 // Set engine based on properties
33 if (is_input && properties.exists("Engine_in")) {
34 engine = properties.get("Engine_in").get_string();
35 }
36 if (!is_input && properties.exists("Engine_out")) {
37 engine = properties.get("Engine_out").get_string();
38 }
39 if (engine == "") {
40 // By default, use BPFile. This is the default in ADIOS, but this enforces that
41 // if the default changes in ADIOS, it doesn't change here.
42 engine = "bpfile";
43 }
44 std::transform(engine.begin(), engine.end(), engine.begin(), ::tolower);
45 bpio.SetEngine(engine);
46 // TODO: See if there is a way to avoid hardcoding this list
47 // of engines (and possibly engines have multiple corresponding
48 // strings).
49 if (engine == "bpfile" || engine == "hdf5") {
50 m_IsStreaming = false;
51 }
52 else {
53 m_IsStreaming = true;
54 }
55 // Set transport based on properties
56 if (properties.exists("Transport")) {
57 transport = properties.get("Transport").get_string();
58 }
59 // if(transport == "File") // Leave transport parameters to default value.
60 if (transport == "WAN") {
61 transport_parameters = {{"Library", "ZMQ"}, {"IPAddress", "127.0.0.1"}};
62 }
63 else if (transport == "InSituMPI") {
64 transport_parameters = {};
65 }
66 else if (transport == "SST") {
67 transport_parameters = {{"MarshalMethod", "BP"}};
68 }
69 // Set transport parameters based on properties
70 if (properties.exists("Library")) {
71 transport_parameters["Library"] = properties.get("Library").get_string();
72 }
73 if (properties.exists("IPAddress")) {
74 transport_parameters["IPAddress"] = properties.get("IPAddress").get_string();
75 }
76 if (properties.exists("MarshalMethod")) {
77 transport_parameters["MarshalMethod"] = properties.get("MarshalMethod").get_string();
78 }
79 if (properties.exists("verbose")) {
80 transport_parameters["verbose"] = properties.get("verbose").get_string();
81 }
82 bpio.AddTransport(transport, transport_parameters);
83 // TODO: Add support for passing parameters, such as "num_threads".
84 return bpio;
85 }
86
87 adios2::Engine AdiosWrapper::EngineInit(const std::string &filename, bool is_input)
88 {
89 adios2::Mode mode = adios2::Mode::Read;
90 if (!is_input) {
91 mode = adios2::Mode::Write;
92 }
93 return this->IO::Open(filename, mode);
94 }
95
96 AdiosWrapper::~AdiosWrapper()
97 {
98 EndStep();
99 this->Engine::Close();
100 }
101
102 adios2::StepStatus AdiosWrapper::BeginStep()
103 {
104 if (!m_OpenStep) {
105 adios2::StepStatus status = this->Engine::BeginStep();
106 if (status == adios2::StepStatus::OK) {
107 m_OpenStep = true;
108 }
109 return status;
110 }
111 // Either we called `BeginStep()` successfully or we didn't need to. Either
112 // way, there was no issue.
113 return adios2::StepStatus::OK;
114 }
115
116 void AdiosWrapper::EndStep()
117 {
118 if (m_OpenStep) {
119 this->Engine::EndStep();
120 m_OpenStep = false;
121 }
122 }
123
124 std::string AdiosWrapper::EncodeMetaVariable(const std::string &meta_name,
125 const std::string &variable_name) const
126 {
127 if (!variable_name.empty()) {
128 return variable_name + m_MetaSeparator + meta_name;
129 }
130 else {
131 return meta_name;
132 }
133 }
134
135 std::pair<std::string, std::string> AdiosWrapper::DecodeMetaName(std::string name) const
136 {
137 std::size_t pos = 0;
138 std::string meta;
139 pos = name.rfind(m_MetaSeparator);
140 if (pos != std::string::npos && pos != name.size() - 1) {
141 meta = name.substr(pos + m_MetaSeparator.size());
142 name = name.substr(0, pos);
143 }
144 return std::make_pair(name, meta);
145 }
146
147 } // namespace Ioad