Skip to content

Commit

Permalink
Fix ulimit test
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Mar 6, 2024
1 parent 929b594 commit 19395b0
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
9 changes: 8 additions & 1 deletion include/openPMD/Iteration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,19 @@ class Iteration : public Attributable

/**
* @brief Has the iteration been closed?
* A closed iteration may not (yet) be reopened.
*
* @return Whether the iteration has been closed.
*/
bool closed() const;

/**
* @brief Has the iteration been parsed yet?
If not, it will contain no structure yet.
*
* @return Whether the iteration has been parsed.
*/
bool parsed() const;

/**
* @brief Has the iteration been closed by the writer?
* Background: Upon calling Iteration::close(), the openPMD API
Expand Down
14 changes: 14 additions & 0 deletions src/Iteration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,20 @@ bool Iteration::closed() const
throw std::runtime_error("Unreachable!");
}

bool Iteration::parsed() const
{
switch (get().m_closed)
{
case CloseStatus::ParseAccessDeferred:
return false;
case CloseStatus::Open:
case CloseStatus::ClosedInFrontend:
case CloseStatus::Closed:
return true;
}
throw std::runtime_error("Unreachable!");
}

bool Iteration::closedByWriter() const
{
using bool_type = unsigned char;
Expand Down
9 changes: 8 additions & 1 deletion src/helper/list_series.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ std::ostream &listSeries(Series &series, bool const longer, std::ostream &out)

for (auto &[index, i] : series.snapshots())
{
i.open();
if (!i.parsed())
{
i.open();
}
if (longer)
out << index << " ";

Expand All @@ -135,6 +138,10 @@ std::ostream &listSeries(Series &series, bool const longer, std::ostream &out)
[](std::pair<std::string, ParticleSpecies> const &p) {
return p.first;
});
if (!i.closed())
{
i.close();
}
}

if (longer)
Expand Down
14 changes: 14 additions & 0 deletions test/SerialIOTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#ifdef __unix__
#include <dirent.h>
#include <fcntl.h>
#include <sys/resource.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
Expand Down Expand Up @@ -153,6 +154,13 @@ TEST_CASE("char_roundtrip", "[serial]")
void write_and_read_many_iterations(
std::string const &ext, bool intermittentFlushes)
{
#ifdef __unix__
struct rlimit rlim;
getrlimit(RLIMIT_NOFILE, &rlim);
auto old_soft_limit = rlim.rlim_cur;
rlim.rlim_cur = 512;
setrlimit(RLIMIT_NOFILE, &rlim);
#endif
// the idea here is to trigger the maximum allowed number of file handles,
// e.g., the upper limit in "ulimit -n" (default: often 1024). Once this
// is reached, files should be closed automatically for open iterations
Expand All @@ -165,6 +173,7 @@ void write_and_read_many_iterations(
auxiliary::getEnvNum("OPENPMD_TEST_NFILES_MAX", 1030);
std::string filename =
"../samples/many_iterations/many_iterations_%T." + ext;
// std::cout << "WRITE " << filename << std::endl;

Check notice

Code scanning / CodeQL

Commented-out code Note test

This comment appears to contain commented-out code.

std::vector<float> data(10);
std::iota(data.begin(), data.end(), 0.);
Expand All @@ -187,6 +196,7 @@ void write_and_read_many_iterations(
}
// ~Series intentionally not yet called

// std::cout << "READ " << filename << std::endl;

Check notice

Code scanning / CodeQL

Commented-out code Note test

This comment appears to contain commented-out code.
Series read(
filename, Access::READ_ONLY, "{\"defer_iteration_parsing\": true}");
for (auto iteration : read.iterations)
Expand All @@ -212,6 +222,10 @@ void write_and_read_many_iterations(

Series list(filename, Access::READ_ONLY);
helper::listSeries(list);
#ifdef __unix__
rlim.rlim_cur = old_soft_limit;
setrlimit(RLIMIT_NOFILE, &rlim);
#endif
}

TEST_CASE("write_and_read_many_iterations", "[serial]")
Expand Down

0 comments on commit 19395b0

Please sign in to comment.