Skip to content

Commit

Permalink
EPU: Delete input files if requested
Browse files Browse the repository at this point in the history
  • Loading branch information
gdsjaar committed Apr 18, 2024
1 parent 3c5ce3c commit d976c30
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 17 deletions.
17 changes: 14 additions & 3 deletions packages/seacas/applications/epu/EP_ExodusFile.C
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright(C) 1999-2021, 2023 National Technology & Engineering Solutions
* Copyright(C) 1999-2021, 2023, 2024 National Technology & Engineering Solutions
* of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
* NTESS, the U.S. Government retains certain rights in this software.
*
Expand Down Expand Up @@ -129,12 +129,23 @@ void Excn::ExodusFile::close_all()
}
}

void Excn::ExodusFile::unlink_temporary_files()
void Excn::ExodusFile::unlink_input_files()
{
fmt::print("\n\tUnlinking {}\n\t ...", filenames_[0]);
for (int p = 0; p < partCount_; p++) {
unlink(filenames_[p].c_str());
}
fmt::print("\n\tUnlinking {}\n\n", filenames_[partCount_ - 1]);
}

void Excn::ExodusFile::handle_temporary_files(bool delete_them)
{
for (int p = 0; p < partCount_; p++) {
if (fileids_[p] >= 0) {
ex_close(fileids_[p]);
unlink(filenames_[p].c_str());
if (delete_them) {
unlink(filenames_[p].c_str());
}
fileids_[p] = -1;
}
}
Expand Down
5 changes: 3 additions & 2 deletions packages/seacas/applications/epu/EP_ExodusFile.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright(C) 1999-2023 National Technology & Engineering Solutions
* Copyright(C) 1999-, 20242024 National Technology & Engineering Solutions
* of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
* NTESS, the U.S. Government retains certain rights in this software.
*
Expand Down Expand Up @@ -30,7 +30,8 @@ namespace Excn {
static int io_word_size() { return ioWordSize_; }
operator int() const;
static int max_name_length() { return maximumNameLength_; }
static void unlink_temporary_files();
static void handle_temporary_files(bool delete_them);
static void unlink_input_files();

private:
int myProcessor_;
Expand Down
32 changes: 27 additions & 5 deletions packages/seacas/applications/epu/EP_SystemInterface.C
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,23 @@ namespace {

Excn::SystemInterface::SystemInterface(int rank) : myRank_(rank) { enroll_options(); }

bool Excn::SystemInterface::remove_file_per_rank_files() const
{
if (removeFilePerRankFiles_) {
if (partCount_ <= 0 && startPart_ == 0 && subcycle_ == -1 && cycle_ == -1) {
return true;
}
else {
fmt::print("\nNot removing the file-per-rank input files due to presence of "
"start/part/subcycle options.\n\n");
return false;
}
}
else {
return false;
}
}

void Excn::SystemInterface::enroll_options()
{
options_.usage("[options] basename");
Expand Down Expand Up @@ -105,6 +122,10 @@ void Excn::SystemInterface::enroll_options()
"\t\tthey are automatically deleted unless -keep_temporary is specified.",
nullptr);

options_.enroll("remove_file_per_rank_files", GetLongOption::NoValue,
"Remove the input file-per-rank files after they have successfully been joined.",
nullptr);

options_.enroll(
"verify_valid_file", GetLongOption::NoValue,
"Reopen the output file right after closing it to verify that the file is valid.\n"
Expand Down Expand Up @@ -374,11 +395,12 @@ bool Excn::SystemInterface::parse_options(int argc, char **argv)
sumSharedNodes_ = options_.retrieve("sum_shared_nodes") != nullptr;
append_ = options_.retrieve("append") != nullptr;

subcycle_ = options_.get_option_value("subcycle", subcycle_);
cycle_ = options_.get_option_value("cycle", cycle_);
subcycleJoin_ = options_.retrieve("join_subcycles") != nullptr;
keepTemporary_ = options_.retrieve("keep_temporary") != nullptr;
verifyValidFile_ = options_.retrieve("verify_valid_file") != nullptr;
subcycle_ = options_.get_option_value("subcycle", subcycle_);
cycle_ = options_.get_option_value("cycle", cycle_);
subcycleJoin_ = options_.retrieve("join_subcycles") != nullptr;
keepTemporary_ = options_.retrieve("keep_temporary") != nullptr;
removeFilePerRankFiles_ = options_.retrieve("remove_file_per_rank_files") != nullptr;
verifyValidFile_ = options_.retrieve("verify_valid_file") != nullptr;

if (options_.retrieve("map") != nullptr) {
mapIds_ = true;
Expand Down
2 changes: 2 additions & 0 deletions packages/seacas/applications/epu/EP_SystemInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ namespace Excn {
bool output_shared_nodes() const { return outputSharedNodes_; }
bool is_auto() const { return auto_; }
bool keep_temporary() const { return keepTemporary_; }
bool remove_file_per_rank_files() const;
bool verify_valid_file() const { return verifyValidFile_; }
int max_open_files() const
{
Expand Down Expand Up @@ -158,6 +159,7 @@ namespace Excn {
bool outputSharedNodes_{false};
bool auto_{false};
bool keepTemporary_{false};
bool removeFilePerRankFiles_{false};
bool verifyValidFile_{false};
bool addNodalCommunicationMap_{false};

Expand Down
6 changes: 3 additions & 3 deletions packages/seacas/applications/epu/EP_Version.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright(C) 1999-2023 National Technology & Engineering Solutions
* Copyright(C) 1999-2024 National Technology & Engineering Solutions
* of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
* NTESS, the U.S. Government retains certain rights in this software.
*
Expand All @@ -11,6 +11,6 @@

static const std::array<std::string, 3> qainfo{
"epu -- E Pluribus Unum",
"6.08",
"2024/03/07",
"6.09",
"2024/04/18",
};
11 changes: 7 additions & 4 deletions packages/seacas/applications/epu/epu.C
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ int main(int argc, char *argv[])

ExodusFile::close_all();
#if ENABLE_PARALLEL_EPU
MPI_Barrier(MPI_COMM_WORLD); // CHECK: ALLOW MPI_COMM_WORLD
MPI_Barrier(MPI_COMM_WORLD); // CHECK: ALLOW MPI_COMM_WORLD
#endif
}
else {
Expand Down Expand Up @@ -664,9 +664,12 @@ int main(int argc, char *argv[])
}
}

if (error == 0 && !interFace.keep_temporary()) {
ExodusFile::unlink_temporary_files();
}
bool delete_temp = error == 0 && !interFace.keep_temporary();
ExodusFile::handle_temporary_files(delete_temp);
}

if (error == 0 && interFace.remove_file_per_rank_files()) {
ExodusFile::unlink_input_files();
}

time_t end_time = std::time(nullptr);
Expand Down

0 comments on commit d976c30

Please sign in to comment.