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 OpenChain to FileStdio transport, and relevant test with BP5 en… #3049

Merged
merged 1 commit into from
Feb 8, 2022
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
65 changes: 65 additions & 0 deletions source/adios2/toolkit/transport/file/FileStdio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,71 @@ void FileStdio::Open(const std::string &name, const Mode openMode,
}
}

void FileStdio::OpenChain(const std::string &name, Mode openMode,
const helper::Comm &chainComm, const bool async)
{
auto lf_AsyncOpenWrite = [&](const std::string &name) -> FILE * {
errno = 0;
return std::fopen(name.c_str(), "wb");
};

int token = 1;
m_Name = name;
CheckName();

if (chainComm.Rank() > 0)
{
chainComm.Recv(&token, 1, chainComm.Rank() - 1, 0,
"Chain token in FileStdio::OpenChain");
}

m_OpenMode = openMode;
switch (m_OpenMode)
{
case (Mode::Write):
if (async)
{
m_IsOpening = true;
m_OpenFuture =
std::async(std::launch::async, lf_AsyncOpenWrite, name);
}
else
{
errno = 0;
m_File = std::fopen(name.c_str(), "wb");
}
break;
case (Mode::Append):
errno = 0;
m_File = std::fopen(name.c_str(), "rwb");
// m_File = std::fopen(name.c_str(), "a+b");
std::fseek(m_File, 0, SEEK_END);
break;
case (Mode::Read):
errno = 0;
m_File = std::fopen(name.c_str(), "rb");
break;
default:
helper::Throw<std::ios_base::failure>(
"Toolkit", "transport::file::FileStdio", "Open",
"unknown open mode for file " + m_Name);
}

if (!m_IsOpening)
{
CheckFile(
"couldn't open file " + m_Name +
", check permissions or path existence, in call to stdio open");
m_IsOpen = true;
}

if (chainComm.Rank() < chainComm.Size() - 1)
{
chainComm.Isend(&token, 1, chainComm.Rank() + 1, 0,
"Sending Chain token in FileStdio::OpenChain");
}
}

void FileStdio::SetBuffer(char *buffer, size_t size)
{
if (!m_File)
Expand Down
4 changes: 4 additions & 0 deletions source/adios2/toolkit/transport/file/FileStdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class FileStdio : public Transport
void Open(const std::string &name, const Mode openMode,
const bool async = false) final;

void OpenChain(const std::string &name, Mode openMode,
const helper::Comm &chainComm,
const bool async = false) final;

void SetBuffer(char *buffer, size_t size) final;

void Write(const char *buffer, size_t size, size_t start = MaxSizeT) final;
Expand Down
2 changes: 1 addition & 1 deletion testing/adios2/engine/bp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ bp_gtest_add_tests_helper(WriteReadADIOS2 MPI_ALLOW)
async_gtest_add_tests_helper(WriteReadADIOS2 MPI_ALLOW)

bp_gtest_add_tests_helper(WriteReadADIOS2fstream MPI_ALLOW)
bp3_bp4_gtest_add_tests_helper(WriteReadADIOS2stdio MPI_ALLOW)
bp_gtest_add_tests_helper(WriteReadADIOS2stdio MPI_ALLOW)
bp_gtest_add_tests_helper(WriteReadAsStreamADIOS2 MPI_ALLOW)
bp_gtest_add_tests_helper(WriteReadAsStreamADIOS2_Threads MPI_ALLOW)
bp_gtest_add_tests_helper(WriteReadAttributes MPI_ALLOW)
Expand Down
18 changes: 12 additions & 6 deletions testing/adios2/engine/bp/TestBPWriteReadADIOS2stdio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ TEST_F(BPWriteReadTestADIOS2stdio, ADIOS2BPWriteRead1D8)
}
io.AddTransport("file", {{"Library", "stdio"}});

adios2::Engine bpReader = io.Open(fname, adios2::Mode::Read);
adios2::Engine bpReader =
io.Open(fname, adios2::Mode::ReadRandomAccess);

auto var_iString = io.InquireVariable<std::string>("iString");
EXPECT_TRUE(var_iString);
Expand Down Expand Up @@ -530,7 +531,8 @@ TEST_F(BPWriteReadTestADIOS2stdio, ADIOS2BPWriteRead2D2x4)
}
io.AddTransport("file", {{"Library", "stdio"}});

adios2::Engine bpReader = io.Open(fname, adios2::Mode::Read);
adios2::Engine bpReader =
io.Open(fname, adios2::Mode::ReadRandomAccess);

auto var_iString = io.InquireVariable<std::string>("iString");
EXPECT_TRUE(var_iString);
Expand Down Expand Up @@ -877,7 +879,8 @@ TEST_F(BPWriteReadTestADIOS2stdio, ADIOS2BPWriteRead2D4x2)
}
io.AddTransport("file", {{"Library", "stdio"}});

adios2::Engine bpReader = io.Open(fname, adios2::Mode::Read);
adios2::Engine bpReader =
io.Open(fname, adios2::Mode::ReadRandomAccess);

auto var_i8 = io.InquireVariable<int8_t>("i8");
EXPECT_TRUE(var_i8);
Expand Down Expand Up @@ -1213,7 +1216,8 @@ TEST_F(BPWriteReadTestADIOS2stdio, ADIOS2BPWriteRead2D4x2_ReadMultiSteps)
}
io.AddTransport("file", {{"Library", "stdio"}});

adios2::Engine bpReader = io.Open(fname, adios2::Mode::Read);
adios2::Engine bpReader =
io.Open(fname, adios2::Mode::ReadRandomAccess);

auto var_i8 = io.InquireVariable<int8_t>("i8");
EXPECT_TRUE(var_i8);
Expand Down Expand Up @@ -1538,7 +1542,8 @@ TEST_F(BPWriteReadTestADIOS2stdio, ADIOS2BPWriteRead2D4x2_MultiStepsOverflow)
}
io.AddTransport("file", {{"Library", "stdio"}});

adios2::Engine bpReader = io.Open(fname, adios2::Mode::Read);
adios2::Engine bpReader =
io.Open(fname, adios2::Mode::ReadRandomAccess);

auto var_i8 = io.InquireVariable<int8_t>("i8");
auto var_i16 = io.InquireVariable<int16_t>("i16");
Expand Down Expand Up @@ -1639,7 +1644,8 @@ TEST_F(BPWriteReadTestADIOS2stdio, OpenEngineTwice)
bpWriter.Close();

EXPECT_NO_THROW(io.Open(fname, adios2::Mode::Write));
EXPECT_THROW(io.Open(fname, adios2::Mode::Read), std::invalid_argument);
EXPECT_THROW(io.Open(fname, adios2::Mode::ReadRandomAccess),
std::invalid_argument);
}
}

Expand Down