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

clean up OpenChain(), so that Append mode work properly #2796

Merged
merged 1 commit into from
Jul 21, 2021
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
36 changes: 14 additions & 22 deletions source/adios2/toolkit/transport/file/FileFStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ void FileFStream::OpenChain(const std::string &name, Mode openMode,
ProfilerStop("open");
};

bool createOnAppend = true;
int token = 1;
m_Name = name;
CheckName();
Expand All @@ -120,11 +119,6 @@ void FileFStream::OpenChain(const std::string &name, Mode openMode,
{
chainComm.Recv(&token, 1, chainComm.Rank() - 1, 0,
"Chain token in FileFStream::OpenChain");
if (openMode == Mode::Write)
{
openMode = Mode::Append;
createOnAppend = false;
}
}

m_OpenMode = openMode;
Expand All @@ -140,28 +134,26 @@ void FileFStream::OpenChain(const std::string &name, Mode openMode,
else
{
ProfilerStart("open");
m_FileStream.open(name, std::fstream::out | std::fstream::binary |
std::fstream::trunc);
if (chainComm.Rank() == 0)
{
m_FileStream.open(name, std::fstream::out |
std::fstream::binary |
std::fstream::trunc);
}
else
{
m_FileStream.open(name,
std::fstream::out | std::fstream::binary);
}
ProfilerStop("open");
}
break;

case (Mode::Append):
ProfilerStart("open");

if (createOnAppend)
{
m_FileStream.open(name, std::fstream::in | std::fstream::out |
std::fstream::binary);
m_FileStream.seekp(0, std::ios_base::end);
}
else
{
m_FileStream.open(name, std::fstream::in | std::fstream::out |
std::fstream::binary);
m_FileStream.seekp(0, std::ios_base::beg);
}

m_FileStream.open(name, std::fstream::in | std::fstream::out |
std::fstream::binary);
m_FileStream.seekp(0, std::ios_base::end);
ProfilerStop("open");
break;

Expand Down
31 changes: 15 additions & 16 deletions source/adios2/toolkit/transport/file/FilePOSIX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ void FilePOSIX::OpenChain(const std::string &name, Mode openMode,
return FD;
};

bool createOnAppend = true;
int token = 1;
m_Name = name;
CheckName();
Expand All @@ -143,11 +142,6 @@ void FilePOSIX::OpenChain(const std::string &name, Mode openMode,
{
chainComm.Recv(&token, 1, chainComm.Rank() - 1, 0,
"Chain token in FilePOSIX::OpenChain");
if (openMode == Mode::Write)
{
openMode = Mode::Append;
createOnAppend = false;
}
}

m_OpenMode = openMode;
Expand All @@ -157,7 +151,8 @@ void FilePOSIX::OpenChain(const std::string &name, Mode openMode,
case (Mode::Write):
if (async && chainComm.Size() == 1)
{
// only single process open can do it asynchronously
// only when process is a single writer, can create the file
// asynchronously, otherwise other processes are waiting on it
m_IsOpening = true;
m_OpenFuture =
std::async(std::launch::async, lf_AsyncOpenWrite, name);
Expand All @@ -166,8 +161,16 @@ void FilePOSIX::OpenChain(const std::string &name, Mode openMode,
{
ProfilerStart("open");
errno = 0;
m_FileDescriptor =
open(m_Name.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0666);
if (chainComm.Rank() == 0)
{
m_FileDescriptor =
open(m_Name.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0666);
}
else
{
m_FileDescriptor = open(m_Name.c_str(), O_WRONLY, 0666);
lseek(m_FileDescriptor, 0, SEEK_SET);
}
m_Errno = errno;
ProfilerStop("open");
}
Expand All @@ -176,19 +179,15 @@ void FilePOSIX::OpenChain(const std::string &name, Mode openMode,
case (Mode::Append):
ProfilerStart("open");
errno = 0;

if (createOnAppend)
if (chainComm.Rank() == 0)
{
m_FileDescriptor = open(m_Name.c_str(), O_RDWR | O_CREAT, 0777);
lseek(m_FileDescriptor, 0, SEEK_END);
m_FileDescriptor = open(m_Name.c_str(), O_RDWR | O_CREAT, 0666);
}
else
{
/* This case runs on rank > 0 when called with Write mode */
m_FileDescriptor = open(m_Name.c_str(), O_RDWR);
lseek(m_FileDescriptor, 0, SEEK_SET);
}

lseek(m_FileDescriptor, 0, SEEK_END);
m_Errno = errno;
ProfilerStop("open");
break;
Expand Down