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

Raise the limit of open filesi to max in BP file engines #3376

Merged
merged 2 commits into from
Oct 25, 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
1 change: 1 addition & 0 deletions source/adios2/engine/bp3/BP3Reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ void BP3Reader::Init()
// if IO was involved in reading before this flag may be true now
m_IO.m_ReadStreaming = false;

helper::RaiseLimitNoFile();
InitTransports();
InitBuffer();
}
Expand Down
2 changes: 2 additions & 0 deletions source/adios2/engine/bp4/BP4Reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ void BP4Reader::Init()
m_BP4Deserializer.Init(m_IO.m_Parameters, "in call to BP4::Open to write");
InitTransports();

helper::RaiseLimitNoFile();

/* Do a collective wait for the file(s) to appear within timeout.
Make sure every process comes to the same conclusion */
const Seconds timeoutSeconds(
Expand Down
6 changes: 6 additions & 0 deletions source/adios2/engine/bp5/BP5Reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,12 @@ void BP5Reader::InitParameters()
m_Threads = helper::SetWithinLimit(8U / NodeSize, 1U, 8U);
}
}

size_t limit = helper::RaiseLimitNoFile();
if (m_Parameters.MaxOpenFilesAtOnce > limit - 8)
{
m_Parameters.MaxOpenFilesAtOnce = limit - 8;
}
}

bool BP5Reader::SleepOrQuit(const TimePoint &timeoutInstant,
Expand Down
54 changes: 54 additions & 0 deletions source/adios2/helper/adiosSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
#include <system_error>
#include <thread>

#ifndef _WIN32
#include <sys/resource.h> // getrlimits, setrlimits
#include <sys/time.h>
#endif

#include <adios2sys/SystemTools.hxx>

#include "adios2/common/ADIOSTypes.h"
Expand Down Expand Up @@ -187,5 +192,54 @@ unsigned int NumHardwareThreadsPerNode()
return std::thread::hardware_concurrency();
}

size_t RaiseLimitNoFile()
{
#ifdef _WIN32
return _setmaxstdio(8192);
#else
static size_t raisedLimit = 0;
static bool firstCallRaiseLimit = true;

if (firstCallRaiseLimit)
{
struct rlimit limit;
errno = 0;
int err = getrlimit(RLIMIT_NOFILE, &limit);
raisedLimit = limit.rlim_cur;
if (!err)
{
/*std::cout
<< "adios2::helper::RaiseLimitNoFile() found limits soft = "
<< limit.rlim_cur << " hard = " << limit.rlim_max <<
std::endl;*/
if (limit.rlim_cur < limit.rlim_max)
{
limit.rlim_cur = limit.rlim_max;
err = setrlimit(RLIMIT_NOFILE, &limit);
if (!err)
{
getrlimit(RLIMIT_NOFILE, &limit);
raisedLimit = limit.rlim_cur;
/*std::cout << "adios2::helper::RaiseLimitNoFile() set "
"limits soft = "
<< limit.rlim_cur << " hard = " << limit.rlim_max
<< std::endl;*/
}
}
}

if (err)
{
std::cerr << "adios2::helper::RaiseLimitNoFile(soft="
<< limit.rlim_cur << ", hard=" << limit.rlim_max
<< ") failed with error code " << errno << ": "
<< strerror(errno) << std::endl;
}
firstCallRaiseLimit = false;
}
return raisedLimit;
#endif
}

} // end namespace helper
} // end namespace adios2
5 changes: 5 additions & 0 deletions source/adios2/helper/adiosSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ char BPVersion(const std::string &name, helper::Comm &comm,
*/
unsigned int NumHardwareThreadsPerNode();

/** Attempt to raise the limit of number of files opened at once
* Return: the limit on number of open files
*/
size_t RaiseLimitNoFile();

} // end namespace helper
} // end namespace adios2

Expand Down