Skip to content

Instantly share code, notes, and snippets.

@keichi
Last active December 17, 2018 23:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keichi/2afd215e9da0200d2dbf4bd142f1095a to your computer and use it in GitHub Desktop.
Save keichi/2afd215e9da0200d2dbf4bd142f1095a to your computer and use it in GitHub Desktop.
#include <adios2.h>
void write(adios2::ADIOS &adios)
{
adios2::IO outIO = adios.DeclareIO("Output");
adios2::Engine writer = outIO.Open("test.bp", adios2::Mode::Write);
auto var = outIO.DefineVariable<double>("v", {1, 3}, {0, 0}, {1, 3});
std::vector<double> buf(10 * 3, 0.0);
for (int i = 0; i < buf.size(); i++) {
buf[i] = i;
}
std::cout << "Writing:" << std::endl;
for (size_t i = 1; i <= 10; i++) {
writer.BeginStep();
var.SetShape({i, 3});
var.SetSelection({{0, 0}, {i, 3}});
std::cout << "Step " << i << " shape (" << var.Shape()[0] << ", "
<< var.Shape()[1] << ")" << std::endl;
writer.Put(var, buf.data());
writer.EndStep();
}
writer.Close();
}
void read(adios2::ADIOS &adios)
{
adios2::IO inIO = adios.DeclareIO("Input");
adios2::Engine reader = inIO.Open("test.bp", adios2::Mode::Read);
std::cout << "Reading:" << std::endl;
int i = 0;
while (true) {
adios2::StepStatus status =
reader.BeginStep(adios2::StepMode::NextAvailable);
if (status != adios2::StepStatus::OK) {
break;
}
auto var = inIO.InquireVariable<double>("v");
std::cout << "Step " << i << " shape (" << var.Shape()[0] << ", "
<< var.Shape()[1] << ")" << std::endl;
i++;
}
reader.Close();
}
int main(int argc, char *argv[])
{
MPI_Init(&argc, &argv);
adios2::ADIOS adios(MPI_COMM_WORLD);
write(adios);
read(adios);
MPI_Finalize();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment