Skip to content

Commit

Permalink
support for specifying a restart directory
Browse files Browse the repository at this point in the history
  • Loading branch information
Sigfried Haering authored and trevilo committed Jun 27, 2024
1 parent f87bef1 commit 98d13e2
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 10 deletions.
17 changes: 13 additions & 4 deletions src/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#include "io.hpp"

#include <hdf5.h>
#include <sys/stat.h>
#include <sys/types.h>

#include "M2ulPhyS.hpp"
#include "utils.hpp"
Expand Down Expand Up @@ -268,7 +270,8 @@ void M2ulPhyS::restart_files_hdf5(string mode, string inputFileName) {
return;
}

void partitioning_file_hdf5(std::string mode, MPI_Groups *groupsMPI, int nelemGlobal, Array<int> &partitioning) {
void partitioning_file_hdf5(std::string mode, MPI_Groups *groupsMPI, int nelemGlobal, Array<int> &partitioning,
std::string pathName) {
MPI_Comm TPSCommWorld = groupsMPI->getTPSCommWorld();
const bool rank0 = groupsMPI->isWorldRoot();
const int nprocs = groupsMPI->getTPSWorldSize();
Expand All @@ -281,8 +284,10 @@ void partitioning_file_hdf5(std::string mode, MPI_Groups *groupsMPI, int nelemGl
// hid_t file, dataspace, data_soln;
hid_t file = -1, dataspace;
herr_t status;
std::string fileName("partition");
fileName += "." + std::to_string(nprocs) + "p.h5";
std::string fileNameEnd("partition");
fileNameEnd += "." + std::to_string(nprocs) + "p.h5";
std::string fileName;
fileName = pathName + fileNameEnd;

assert((mode == "read") || (mode == "write"));

Expand Down Expand Up @@ -402,7 +407,7 @@ void read_variable_data_hdf5(hid_t file, string varName, size_t index, double *d
H5Dclose(data_soln);
}

IOOptions::IOOptions() : output_dir_("output"), restart_mode_("standard") {}
IOOptions::IOOptions() : output_dir_("output"), restart_dir_("./"), restart_mode_("standard") {}

void IOOptions::read(TPS::Tps *tps, std::string prefix) {
std::string basename;
Expand All @@ -417,8 +422,12 @@ void IOOptions::read(TPS::Tps *tps, std::string prefix) {
tps->getInput((basename + "/exitCheckFreq").c_str(), exit_check_frequency_, 500);
assert(exit_check_frequency_ > 0);

tps->getInput((basename + "/restartBase").c_str(), restart_dir_, std::string("./"));
tps->getInput((basename + "/restartMode").c_str(), restart_mode_, std::string("standard"));
setRestartFlags();

int status = mkdir(restart_dir_.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
if (status == 0) std::cout << "created restartBase directory: " << restart_dir_ << endl;
}

void IOOptions::setRestartFlags() {
Expand Down
5 changes: 3 additions & 2 deletions src/io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ class IOOptions {

int exit_check_frequency_ = 500;

std::string restart_dir_;
std::string restart_mode_;

bool restart_variable_order_ = false;
bool restart_serial_read_ = false;
bool restart_serial_write_ = false;
Expand Down Expand Up @@ -362,5 +362,6 @@ void write_variable_data_hdf5(hid_t group, std::string varName, hid_t dataspace,
* @todo Refactor this function to make it more generic and fit better
* into the IODataOrganizer paradigm.
*/
void partitioning_file_hdf5(std::string mode, MPI_Groups *groupsMPI, int nelemGlobal, mfem::Array<int> &partitioning);
void partitioning_file_hdf5(std::string mode, MPI_Groups *groupsMPI, int nelemGlobal, mfem::Array<int> &partitioning,
std::string fileName = "./");
#endif // IO_HPP_
3 changes: 2 additions & 1 deletion src/loMachIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ void LoMachSolver::restart_files_hdf5(string mode, string inputFileName) {
}
serialName = inputFileName;
} else {
serialName = "restart_";
serialName = loMach_opts_.io_opts_.restart_dir_;
serialName.append("/restart_");
serialName.append(loMach_opts_.io_opts_.output_dir_);
serialName.append(".sol.h5");
}
Expand Down
14 changes: 11 additions & 3 deletions src/mesh_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,17 @@ void MeshBase::initializeMesh() {
// nelemGlobal_ = mesh->GetNE();
if (rank0_) grvy_printf(ginfo, "Total # of mesh elements = %i\n", nelemGlobal_);

string restartDir;
restartDir = loMach_opts_->io_opts_.restart_dir_;
restartDir += "/";

if (nprocs_ > 1) {
if (loMach_opts_->io_opts_.restart_serial_read_) {
assert(serial_mesh_->Conforming());
partitioning_ = Array<int>(serial_mesh_->GeneratePartitioning(nprocs_, defaultPartMethod), nelemGlobal_);
partitioning_file_hdf5("write", groupsMPI, nelemGlobal_, partitioning_);
partitioning_file_hdf5("write", groupsMPI, nelemGlobal_, partitioning_, restartDir);
} else {
partitioning_file_hdf5("read", groupsMPI, nelemGlobal_, partitioning_);
partitioning_file_hdf5("read", groupsMPI, nelemGlobal_, partitioning_, restartDir);
}
}

Expand All @@ -203,12 +207,16 @@ void MeshBase::initializeMesh() {
serial_mesh_->UniformRefinement();
}

string restartDir;
restartDir = loMach_opts_->io_opts_.restart_dir_;
restartDir += "/";

// generate partitioning file (we assume conforming meshes)
nelemGlobal_ = serial_mesh_->GetNE();
if (nprocs_ > 1) {
assert(serial_mesh_->Conforming());
partitioning_ = Array<int>(serial_mesh_->GeneratePartitioning(nprocs_, defaultPartMethod), nelemGlobal_);
if (rank0_) partitioning_file_hdf5("write", groupsMPI, nelemGlobal_, partitioning_);
if (rank0_) partitioning_file_hdf5("write", groupsMPI, nelemGlobal_, partitioning_, restartDir);
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,13 @@ void Orthogonalize(Vector &v, MPI_Comm comm) {
v -= global_sum / static_cast<double>(global_size);
}

bool copyFile(const char *SRC, const char *DEST) {
std::ifstream src(SRC, std::ios::binary);
std::ofstream dest(DEST, std::ios::binary);
dest << src.rdbuf();
return src && dest;
}

namespace mfem {
GradientVectorGridFunctionCoefficient::GradientVectorGridFunctionCoefficient(const GridFunction *gf)
: MatrixCoefficient((gf) ? gf->VectorDim() : 0) {
Expand Down
2 changes: 2 additions & 0 deletions src/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ void scalarGrad3D(ParGridFunction &u, ParGridFunction &gu);
void vectorGrad3DV(FiniteElementSpace *fes, Vector u, Vector *gu, Vector *gv, Vector *gw);
void scalarGrad3DV(FiniteElementSpace *fes, FiniteElementSpace *vfes, Vector u, Vector *gu);

bool copyFile(const char *SRC, const char *DEST);

/// Eliminate essential BCs in an Operator and apply to RHS.
/// rename this to something sensible "ApplyEssentialBC" or something
void EliminateRHS(Operator &A, ConstrainedOperator &constrainedA, const Array<int> &ess_tdof_list, Vector &x, Vector &b,
Expand Down

0 comments on commit 98d13e2

Please sign in to comment.