| 1 |
/* |
| 2 |
* SPDX-FileCopyrightText: 2026 Oak Ridge National Laboratory and Contributors |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: Apache-2.0 |
| 5 |
*/ |
| 6 |
|
| 7 |
#include "InlineIO.h" |
| 8 |
|
| 9 |
InlineIO::InlineIO(const Settings &s, MPI_Comm comm) |
| 10 |
{ |
| 11 |
std::string writerName = "writer"; |
| 12 |
std::string readerName = "reader"; |
| 13 |
|
| 14 |
ad = adios2::ADIOS(s.configfile, comm); |
| 15 |
inlineIO = ad.DeclareIO("inlineIO"); |
| 16 |
|
| 17 |
auto params = inlineIO.Parameters(); |
| 18 |
if (params.find("writerID") != params.end()) |
| 19 |
{ |
| 20 |
writerName = params["writerID"]; |
| 21 |
} |
| 22 |
if (params.find("readerID") != params.end()) |
| 23 |
{ |
| 24 |
readerName = params["readerID"]; |
| 25 |
} |
| 26 |
|
| 27 |
if (!inlineIO.InConfigFile()) |
| 28 |
{ |
| 29 |
inlineIO.SetEngine("Inline"); |
| 30 |
inlineIO.SetParameters({{"writerID", writerName}, {"readerID", readerName}}); |
| 31 |
} |
| 32 |
|
| 33 |
// define T as 2D global array |
| 34 |
varT = |
| 35 |
inlineIO.DefineVariable<double>("T", |
| 36 |
// Global dimensions |
| 37 |
{s.gndx, s.gndy}, |
| 38 |
// starting offset of the local array in the global space |
| 39 |
{s.offsx, s.offsy}, |
| 40 |
// local size, could be defined later using SetSelection() |
| 41 |
{s.ndx, s.ndy}); |
| 42 |
|
| 43 |
inlineWriter = inlineIO.Open(writerName, adios2::Mode::Write, comm); |
| 44 |
inlineReader = inlineIO.Open(readerName, adios2::Mode::Read, comm); |
| 45 |
|
| 46 |
// Promise that we are not going to change the variable sizes nor add new |
| 47 |
// variables |
| 48 |
inlineWriter.LockWriterDefinitions(); |
| 49 |
inlineReader.LockReaderSelections(); |
| 50 |
} |
| 51 |
|
| 52 |
InlineIO::~InlineIO() |
| 53 |
{ |
| 54 |
inlineWriter.Close(); |
| 55 |
inlineReader.Close(); |
| 56 |
} |
| 57 |
|
| 58 |
void InlineIO::write(const HeatTransfer &ht) |
| 59 |
{ |
| 60 |
inlineWriter.BeginStep(); |
| 61 |
v = ht.data_noghost(); |
| 62 |
inlineWriter.Put<double>(varT, v.data()); |
| 63 |
inlineWriter.EndStep(); |
| 64 |
} |
| 65 |
|
| 66 |
const double *InlineIO::read(bool firstStep) |
| 67 |
{ |
| 68 |
adios2::StepStatus status = inlineReader.BeginStep(adios2::StepMode::Read); |
| 69 |
if (status != adios2::StepStatus::OK) |
| 70 |
{ |
| 71 |
return nullptr; |
| 72 |
} |
| 73 |
|
| 74 |
auto blocksInfo = inlineReader.BlocksInfo(varT, inlineReader.CurrentStep()); |
| 75 |
// in this example we're only expecting one block |
| 76 |
if (blocksInfo.size() != 1) |
| 77 |
{ |
| 78 |
throw std::runtime_error("InlineIO::read found incorrect number of blocks"); |
| 79 |
} |
| 80 |
|
| 81 |
auto &info = blocksInfo[0]; |
| 82 |
varT.SetBlockSelection(info.BlockID); |
| 83 |
inlineReader.Get(varT, info); |
| 84 |
inlineReader.EndStep(); |
| 85 |
|
| 86 |
// now we can get the pointer with info.Data() |
| 87 |
return info.Data(); |
| 88 |
} |