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

no error when getting a variable that doesn't exist in current step #1387

Open
germasch opened this issue Apr 26, 2019 · 4 comments
Open

no error when getting a variable that doesn't exist in current step #1387

germasch opened this issue Apr 26, 2019 · 4 comments
Assignees

Comments

@germasch
Copy link
Contributor

To reproduce:

TEST_F(ADIOS2_CXX11_API_IO, StreamingWrite)
{
    adios2::Engine writer = m_Io.Open("xxx.bp", adios2::Mode::Write);

    double x[3];
    auto var = m_Io.DefineVariable<double>("x", {3}, {0}, {3});
    for (int step = 0; step < 3; step++) {
      x[0] = 10 + step;
      x[1] = 20 + step;
      x[2] = 30 + step;
      writer.BeginStep();
      if (step > 0) {
	writer.Put(var, x);
      }
      writer.EndStep();
    }
    writer.Close();
}

TEST_F(ADIOS2_CXX11_API_IO, StreamingRead)
{
    adios2::Engine reader = m_Io.Open("xxx.bp", adios2::Mode::Read);

    double x[3];
    auto var = m_Io.InquireVariable<double>("x");
    for (int step = 0; step < 3; step++) {
      reader.BeginStep();
      reader.Get(var, x);
      reader.EndStep();
      printf("step %d: %g %g %g\n", step, x[0], x[1], x[2]);
    }
    reader.Close();
}

The second test, when run, gives

[ RUN      ] ADIOS2_CXX11_API_IO.StreamingRead
step 0: 6.95312e-310 2.19424e-314 5.2286e-310
step 1: 11 21 31
step 2: 12 22 32
[       OK ] ADIOS2_CXX11_API_IO.StreamingRead (2 ms)

The file doesn't contain the variable x in step 0, so I don't expect it to read anything (ie, non-initialized nonsense in x is fine), but I do expect to get some kind of an error when the Get call does not succeed.

@williamfgc
Copy link
Contributor

williamfgc commented Apr 26, 2019

@germasch "safe" code can be written by only doing a Get if the variable returned by InquireVariable is true. adios2 doesn't handle internal references/pointers to the user in an "unsafe" mode. We pass objects that can be used safely/unsafely by using/not-using the bool operator. In any case, after the refactoring separation proposed in #1384 the exception should be thrown by BeginStep since InquireVariable is requested in a Random access fashion (before BeginStep). The latter won't work with streaming engines. InquireVariable should be called between BeginStep/EndStep, for portability and intended "step" scope.

Safe streaming mode:

adios2::Engine reader = m_Io.Open("xxx.bp", adios2::Mode::Read);
double x[3];
for (int step = 0; step < 3; step++) {
    reader.BeginStep(); //streaming mode
    auto var = m_Io.InquireVariable<double>("x"); //check x for current step only  
    if(var) reader.Get(var, x);  //safe using bool operator of var
    reader.EndStep();
    printf("step %d: %g %g %g\n", step, x[0], x[1], x[2]);
}
    reader.Close();

Now, I agree, if the variable doesn't exist Get should be throwing an exception. But in this case, we are passing a valid Variable object due to mixing random access and streaming modes. Hence, I agree with @pnorbert in that the separation is required as it also allows to distinguish portable (file and streaming) and non-portable (file only) code across engines.

@williamfgc
Copy link
Contributor

williamfgc commented Apr 26, 2019

Related to #1384 . Will refactor using lazy evaluation to separate random access (file engines only) from step-by-step BeginStep/EndStep (all engines) usage.

@germasch
Copy link
Contributor Author

Okay, so I hadn't realized it's that closely related to #1384, I thought I was doing something valid. Let me comment there.

@williamfgc
Copy link
Contributor

This is good, actually showing code allow us to see how enforcing a certain behavior will look like. Thanks.

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

No branches or pull requests

2 participants