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

Append mode incompatible with Span Put() API – BP4 and BP5 both affected #3656

Closed
franzpoeschel opened this issue Jun 7, 2023 · 3 comments

Comments

@franzpoeschel
Copy link
Contributor

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.

@eisenhauer
Copy link
Member

Looks like a simple oversight. PR submitted.

@franzpoeschel
Copy link
Contributor Author

Thanks, Greg!

@eisenhauer
Copy link
Member

This should be fixed by #3657.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants