Skip to content

Commit

Permalink
Add support to delete SHM File Transfer files while simulation loads
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiorg-hpc committed Dec 18, 2023
1 parent c483af8 commit f4990e8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/coreneuron/io/nrn_filehandler.cpp
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 @@ void FileHandler::open(const std::string& filename, std::ios::openmode mode) {
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::read_checkpoint_assert() {

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 &&
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
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

0 comments on commit f4990e8

Please sign in to comment.