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

Added a test to address issue 2500: case of inquiring variables by wr… #2683

Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions testing/adios2/engine/bp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ gtest_add_tests_helper(StepsInSituLocalArray MPI_ALLOW BP Engine.BP. .BP4
gtest_add_tests_helper(InquireVariableException MPI_ALLOW BP Engine.BP. .BP4
WORKING_DIRECTORY ${BP4_DIR}
)
gtest_add_tests_helper(InquireDefine MPI_ALLOW BP Engine.BP. .BP4
WORKING_DIRECTORY ${BP4_DIR}
)

# FileStream is BP4 + StreamReader=true
gtest_add_tests_helper(StepsInSituGlobalArray MPI_ALLOW BP Engine.BP. .FileStream
Expand Down
192 changes: 192 additions & 0 deletions testing/adios2/engine/bp/TestBPInquireDefine.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
//
// Created by ganyush on 4/23/21.
//
/*
* Distributed under the OSI-approved Apache License, Version 2.0. See
* accompanying file Copyright.txt for details.
*/
#include <cstdint>
#include <cstring>

#include <limits>
#include <stdexcept>

#include <adios2.h>
#include <adios2/common/ADIOSTypes.h>

#include <gtest/gtest.h>

class ADIOSInquireDefineTest : public ::testing::Test
{
public:
ADIOSInquireDefineTest() = default;
};

TEST_F(ADIOSInquireDefineTest, Read)
{
std::string filename = "ADIOSInquireDefine.bp";

// Number of steps
const std::size_t NSteps = 4;
int mpiRank = 0, mpiSize = 1;

#if ADIOS2_USE_MPI
MPI_Comm_rank(MPI_COMM_WORLD, &mpiRank);
MPI_Comm_size(MPI_COMM_WORLD, &mpiSize);
#endif

// Write test data using BP
{
#if ADIOS2_USE_MPI
adios2::ADIOS adios(MPI_COMM_WORLD);
#else
adios2::ADIOS adios;
#endif
adios2::IO ioWrite = adios.DeclareIO("TestIOWrite");
ioWrite.SetEngine("Filestream");

adios2::Engine engine = ioWrite.Open(filename, adios2::Mode::Write);
// Number of elements per process
const std::size_t Nx = 10;
adios2::Dims shape{static_cast<unsigned int>(mpiSize * Nx)};
adios2::Dims start{static_cast<unsigned int>(mpiRank * Nx)};
adios2::Dims count{static_cast<unsigned int>(Nx)};

std::vector<int32_t> Ints0 = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
std::vector<int32_t> Ints1 = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
std::vector<int32_t> Ints2 = {2, 2, 2, 2, 2, 2, 2, 2, 2, 2};
std::vector<int32_t> Ints3 = {3, 3, 3, 3, 3, 3, 3, 3, 3, 3};
for (size_t step = 0; step < NSteps; ++step)
{
engine.BeginStep();
if (step == 0) {
if (!ioWrite.InquireVariable<int>("variable0")){
auto var0 =
ioWrite.DefineVariable<int32_t>("variable0", shape, start, count);
engine.Put(var0, Ints0.data());
}

}else if (step == 1){
if (!ioWrite.InquireVariable<int>("variable1")){
auto var1 =
ioWrite.DefineVariable<int32_t>("variable1", shape, start, count);
engine.Put(var1, Ints1.data());
}
}else if (step == 2){
if (!ioWrite.InquireVariable<int>("variable2")){
auto var2 =
ioWrite.DefineVariable<int32_t>("variable2", shape, start, count);
engine.Put(var2, Ints2.data());
}
}else if (step == 3){
if (!ioWrite.InquireVariable<int>("variable3")){
auto var3 =
ioWrite.DefineVariable<int32_t>("variable3", shape, start, count);
engine.Put(var3, Ints3.data());
}
}
engine.EndStep();
}
engine.Close();

#if ADIOS2_USE_MPI
MPI_Barrier(MPI_COMM_WORLD);
#endif
adios2::IO ioRead = adios.DeclareIO("TestIORead");
ioRead.SetEngine("Filestream");
adios2::Engine engine_s = ioRead.Open(filename, adios2::Mode::Read);
EXPECT_TRUE(engine_s);
try
{
for (size_t step = 0; step < NSteps; step++)
{
engine_s.BeginStep();
adios2::Variable<int> var0 =
ioRead.InquireVariable<int>("variable0");
adios2::Variable<int> var1 =
ioRead.InquireVariable<int>("variable1");
adios2::Variable<int> var2 =
ioRead.InquireVariable<int>("variable2");
adios2::Variable<int> var3 =
ioRead.InquireVariable<int>("variable3");

if (step == 0)
{
EXPECT_TRUE(var0);
EXPECT_FALSE(var1);
EXPECT_FALSE(var2);
EXPECT_FALSE(var3);
}
else if (step == 1)
{
EXPECT_FALSE(var0);
EXPECT_TRUE(var1);
EXPECT_FALSE(var2);
EXPECT_FALSE(var3);
}
else if (step == 2)
{
EXPECT_FALSE(var0);
EXPECT_FALSE(var1);
EXPECT_TRUE(var2);
EXPECT_FALSE(var3);
}
else if (step == 3)
{
EXPECT_FALSE(var0);
EXPECT_FALSE(var1);
EXPECT_FALSE(var2);
EXPECT_TRUE(var3);
}
if (var0)
{
std::vector<int> res;
var0.SetSelection({{Nx * mpiRank}, {Nx}});
engine_s.Get<int>(var0, res, adios2::Mode::Sync);
EXPECT_EQ(res, Ints0);
}
if (var1)
{
std::vector<int> res;
var1.SetSelection({{Nx * mpiRank}, {Nx}});
engine_s.Get<int>(var1, res, adios2::Mode::Sync);
EXPECT_EQ(res, Ints1);
}
if (var2)
{
std::vector<int> res;
var2.SetSelection({{Nx * mpiRank}, {Nx}});
engine_s.Get<int>(var2, res, adios2::Mode::Sync);
EXPECT_EQ(res, Ints2);
}
if (var3)
{
std::vector<int> res;
var3.SetSelection({{Nx * mpiRank}, {Nx}});
engine_s.Get<int>(var3, res, adios2::Mode::Sync);
EXPECT_EQ(res, Ints3);
}
engine_s.EndStep();
}
}
catch (std::exception &e)
{
std::cout << "Exception " << e.what() << std::endl;
}
engine_s.Close();
}
}

int main(int argc, char **argv)
{
#if ADIOS2_USE_MPI
MPI_Init(nullptr, nullptr);
#endif
::testing::InitGoogleTest(&argc, argv);
int result = RUN_ALL_TESTS();
#if ADIOS2_USE_MPI
MPI_Finalize();
#endif

return result;
}