Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug fix] SegFault when a variable that is part of a derived expression doesn't have data #4394

Merged
merged 3 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/adios2/engine/bp5/BP5Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ void BP5Writer::ComputeDerivedVariables()
// extract the dimensions and data for each variable
VariableBase *varBase = itVariable->second.get();
auto mvi = WriterMinBlocksInfo(*varBase);
if (mvi->BlocksInfo.size() == 0)
if (!mvi || mvi->BlocksInfo.size() == 0)
{
computeDerived = false;
break;
Expand Down
36 changes: 36 additions & 0 deletions testing/adios2/derived/TestBPDerivedCorrectness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,42 @@ class DerivedCorrectnessP : public DerivedCorrectness,
adios2::DerivedVarType GetThreads() { return GetParam(); };
};

TEST_P(DerivedCorrectnessP, BasicCorrectnessTest)
{
adios2::DerivedVarType mode = GetParam();
adios2::ADIOS adios;
adios2::IO bpOut = adios.DeclareIO("BPNoData");
EXPECT_THROW(bpOut.DefineDerivedVariable("derived", "x= var1 \n sqrt(x)", mode),
std::invalid_argument);

const size_t N = 10;
std::default_random_engine generator;
std::uniform_real_distribution<float> distribution(0.0, 10.0);
std::vector<float> simArray1(N);
std::vector<float> simArray2(N);
for (size_t i = 0; i < N; ++i)
simArray1[i] = distribution(generator);

auto U = bpOut.DefineVariable<float>("var1", {N}, {0}, {N});
auto V = bpOut.DefineVariable<float>("var2", {N}, {0}, {N});
bpOut.DefineDerivedVariable("derived", "x= var1 \n sqrt(x)", mode);
adios2::Engine bpFileWriter = bpOut.Open("BPNoData.bp", adios2::Mode::Write);

bpFileWriter.BeginStep();
bpFileWriter.Put(V, simArray1.data());
bpFileWriter.EndStep();
bpFileWriter.Close();

// check that no derived data was written
adios2::IO bpIn = adios.DeclareIO("BPReadExpression");
adios2::Engine bpFileReader = bpIn.Open("BPNoData.bp", adios2::Mode::Read);
bpFileReader.BeginStep();
auto derVar = bpIn.InquireVariable<float>("derived");
EXPECT_FALSE(derVar);
bpFileReader.EndStep();
bpFileReader.Close();
}

TEST_P(DerivedCorrectnessP, ScalarFunctionsCorrectnessTest)
{
const size_t Nx = 10, Ny = 3, Nz = 6;
Expand Down