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

Add support to delete SHM File Transfer files while simulation loads #2644

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/coreneuron/io/nrn_filehandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

#include <iostream>
#include <regex>
#include "coreneuron/io/nrn_filehandler.hpp"
#include "coreneuron/nrnconf.h"

Expand All @@ -30,6 +31,7 @@
std::cerr << "cannot open file '" << filename << "'" << std::endl;
}
nrn_assert(F.is_open());
current_filename = filename;
current_mode = mode;
char version[256];
if (current_mode & std::ios::in) {
Expand Down Expand Up @@ -103,5 +105,13 @@

void FileHandler::close() {
F.close();

// Delete source file if read-mode is enabled and path matches '/dev/shm'
const auto& env = getenv("CORENEURON_SHM_DELETESOURCE");
if ((env == nullptr || std::string(env) != "OFF") && current_mode == std::ios::in &&
sergiorg-hpc marked this conversation as resolved.
Show resolved Hide resolved
std::regex_match(current_filename, std::regex("^/dev/shm/.*_[1-4].dat$"))) {
remove(current_filename.c_str());
current_filename = ""; // Clear the filename

Check warning on line 114 in src/coreneuron/io/nrn_filehandler.cpp

View check run for this annotation

Codecov / codecov/patch

src/coreneuron/io/nrn_filehandler.cpp#L113-L114

Added lines #L113 - L114 were not covered by tests
}
}
} // namespace coreneuron
3 changes: 2 additions & 1 deletion src/coreneuron/io/nrn_filehandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ const int max_line_length = 1024;

class FileHandler {
std::fstream F; //!< File stream associated with reader.
std::ios_base::openmode current_mode; //!< File open mode (not stored in fstream)
std::string current_filename; //!< Filename associated with the file stream.
std::ios_base::openmode current_mode; //!< File open mode (not stored in fstream).
int chkpnt; //!< Current checkpoint number state.
int stored_chkpnt; //!< last "remembered" checkpoint number state.
/** Read a checkpoint line, bump our chkpnt counter, and assert equality.
Expand Down