Debian Codegraph @

examples/simulations/heatTransfer/write/IO_adios2.cpp

raw
1 /*
2 * SPDX-FileCopyrightText: 2026 Oak Ridge National Laboratory and Contributors
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include "IO.h"
8
9 #include <string>
10
11 #include "adios2.h"
12
13 adios2::ADIOS ad;
14 adios2::Engine bpWriter;
15 adios2::Variable<double> varT;
16 adios2::Variable<unsigned int> varGndx;
17
18 IO::IO(const Settings &s, MPI_Comm comm)
19 {
20 m_outputfilename = s.outputfile;
21
22 ad = adios2::ADIOS(s.configfile, comm);
23
24 adios2::IO bpio = ad.DeclareIO("writer");
25 if (!bpio.InConfigFile())
26 {
27 // if not defined by user, we can change the default settings
28 // BPFile is the default engine
29 bpio.SetEngine("BPFile");
30 bpio.SetParameters({{"num_threads", "1"}});
31
32 // ISO-POSIX file output is the default transport (called "File")
33 // Passing parameters to the transport
34 #ifdef _WIN32
35 bpio.AddTransport("File", {{"Library", "stdio"}});
36 #else
37 bpio.AddTransport("File", {{"Library", "posix"}});
38 #endif
39 }
40
41 // define T as 2D global array
42 varT = bpio.DefineVariable<double>("T",
43 // Global dimensions
44 {s.gndx, s.gndy},
45 // starting offset of the local array in the global space
46 {s.offsx, s.offsy},
47 // local size, could be defined later using SetSelection()
48 {s.ndx, s.ndy});
49
50 bpWriter = bpio.Open(m_outputfilename, adios2::Mode::Write, comm);
51
52 // Promise that we are not going to change the variable sizes nor add new
53 // variables
54 bpWriter.LockWriterDefinitions();
55 }
56
57 IO::~IO() { bpWriter.Close(); }
58
59 void IO::write(int step, const HeatTransfer &ht, const Settings &s, MPI_Comm comm)
60 {
61 // using PutDeferred() you promise the pointer to the data will be intact
62 // until the end of the output step.
63 // We need to have the vector object here not to destruct here until the end
64 // of function.
65 // added support for MemorySelection
66 bpWriter.BeginStep();
67 std::vector<double> v = ht.data_noghost();
68 bpWriter.Put<double>(varT, v.data());
69 bpWriter.EndStep();
70 }