adios2::Variable metadata going out of scope with SST engine
Created by: stevenwalton
I have a SST reader where I am updating a map map<string, adios2::Variable<double>>
(sstReadVars
) and after the stream ends I am writing the data to a bp file.
My problem is that the metadata, specifically the Shape, gets overwritten by the time I can write to a bp file. This does not matter if my sstReader.Close()
is after I am done reading from the stream (current location) or after I write to the bp file. The data always gets overwritten in the same place, after the while condition breaks (while(sstReader.BeginStep() == adios2::StepStatus::OK)
). The values for the metadata seem to be reinitialized with garbage. Data within adios2::Params
(variables
) appears to maintain metadata after the close.
I have included my reader code below and commented the code to be relevant to the issue at hand.
I can get around this by creating different vectors or maps to hold that data, this is also noted in comments of relevant lines. As is, the code below produces the correct output. Comments of what I expected to be able to do are left in.
#include <iostream>
#include <vector>
#include <stdlib.h>
#include <adios2.h>
#include <mpi.h>
int main(int argc, char* argv[])
{
MPI_Init(&argc, &argv);
int rank, size;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
adios2::ADIOS adios(MPI_COMM_WORLD, adios2::DebugON);
std::size_t iteration = 0;
//**********************************************************//
// Receive over SST
//**********************************************************//
std::map<std::string, std::vector<double>> vars;
adios2::IO sstRIO = adios.DeclareIO("sstIO");
sstRIO.SetEngine("SST");
std::string fName = "mySSTStream";
adios2::Engine sstReader = sstRIO.Open(fName, adios2::Mode::Read);
std::map<std::string, adios2::Variable<double>> sstReadVars; // What I want to call for my metadata
std::map<std::string, adios2::Params> variables;
std::map<std::string, adios2::Params>::iterator it;
std::map<std::string, std::vector<std::size_t>> myShape; // Needed to keep shape
while(sstReader.BeginStep() == adios2::StepStatus::OK)
{
variables = sstRIO.AvailableVariables();
for ( auto elem : variables )
{
std::string name = elem.first;
sstReadVars[name] = sstRIO.InquireVariable<double>(name);
vars[name];
sstReader.Get<double>(sstReadVars[name], vars[name]);
myShape[name] = sstReadVars[name].Shape(); // Line needed to maintain metadata
}
sstReader.EndStep();
iteration++;
// Metadata is correct here
}
// Metadata is out of scope HERE. Metadata is garbage
// variables metadata is correct here
sstReader.Close();
//**********************************************************//
// Write to new bp file
//**********************************************************//
std::string file = "foo.bp";
adios2::IO bpWIO = adios.DeclareIO("BPWrite");
bpWIO.SetEngine("BPFile");
std::vector<adios2::Variable<double>> bpWriteVars;
for ( auto elem : variables )
{
std::string name = elem.first;
//std::size_t size = sstReadVars[name].Shape().size(); // Results in correct size
std::size_t size = myShape[name].size();
//std::vector<std::size_t> globalDims = sstReadVars[name].Shape(); // How I wanted to get my dimensions. Results in garbage values but the resultant vector is the correct size
std::vector<std::size_t> offset(size, 0);
//std::vector<std::size_t> localDims = sstReadVars[name].Shape(); // Again results in bad data
bpWriteVars.emplace_back(
bpWIO.DefineVariable<double>(name,
myShape[name],//globalDims,
offset,
myShape[name]));//localDims));
}
adios2::Engine bpWriter = bpWIO.Open(file, adios2::Mode::Write);
bpWriter.BeginStep();
// variables maintains proper metadata
for ( auto i = 0; i < variables.size(); ++i )
{
std::string name = it -> first;
bpWriter.Put<double>(bpWriteVars[i], vars[name].data());
}
bpWriter.EndStep();
bpWriter.Close();
// Can place sstReader.Close() here with no change
MPI_Finalize();
return 0;
}
Stream is being produced my cloverleaf example in https://github.com/stevenwalton/ascent and being run on Ubuntu 16.04.