Append mode incompatible with Span Put() API – BP4 and BP5 both affected #3656
Closed
Description
Describe the bug
Trying to use the Span API in an engine opened with Append mode will lead to this error:
terminate called after throwing an instance of 'std::invalid_argument'
what(): [Wed Jun 07 15:43:29 2023] [ADIOS2 EXCEPTION] <Core> <Engine> <CheckOpenModes> : Engine open mode not valid for for variable somevariable, in call to Variable<T>::Span Put
To Reproduce
#include <adios2.h>
#include <numeric>
int main(int argsc, char **argsv)
{
constexpr size_t num_items = 100;
std::string engine = "bp5";
std::string filename = "append." + engine;
// Creating a file with append mode works fine
{
adios2::ADIOS adios;
auto IO = adios.DeclareIO("asdf");
IO.SetEngine(engine);
auto engine = IO.Open(filename, adios2::Mode::Append);
engine.BeginStep();
{
auto var = IO.DefineVariable<int>(
"somevariable", {num_items}, {0}, {num_items});
std::vector<int> data(num_items);
std::iota(data.begin(), data.end(), 0);
engine.Put(var, data.data());
}
engine.EndStep();
engine.Close();
}
// Appending to the file with normal Put() works too
{
adios2::ADIOS adios;
auto IO = adios.DeclareIO("asdf");
IO.SetEngine(engine);
auto engine = IO.Open(filename, adios2::Mode::Append);
engine.BeginStep();
{
auto var = IO.DefineVariable<int>(
"somevariable", {num_items}, {0}, {num_items});
std::vector<int> data(num_items);
std::iota(data.begin(), data.end(), 0);
engine.Put(var, data.data());
}
engine.EndStep();
engine.Close();
}
// Appending to the file with span Put() will crash
{
adios2::ADIOS adios;
auto IO = adios.DeclareIO("asdf");
IO.SetEngine(engine);
auto engine = IO.Open(filename, adios2::Mode::Append);
engine.BeginStep();
{
auto var = IO.DefineVariable<int>(
"somevariable", {num_items}, {0}, {num_items});
auto span = engine.Put(var);
int *ptr = &span[0];
std::iota(ptr, ptr + num_items, 0);
engine.EndStep();
}
engine.Close();
}
}
cmake_minimum_required(VERSION 3.12.0)
project(adios2_testing)
find_package(ADIOS2 REQUIRED)
add_executable(main main.cpp)
target_link_libraries(main PRIVATE adios2::cxx11)
Replacing bp5
with bp4
gives the same type of error.
Expected behavior
The open mode verification should recognize the Append mode for Span-based Put.
Desktop (please complete the following information):
- OS/Platform: generic Linux
- Build: Gcc 11.3.0, ADIOS2 v2.9.0
Following up
Was the issue fixed? Please report back.
Metadata
Assignees
Labels
No labels
Activity