14 const std::string& file_base)
16 typedef struct stat Stat;
22 if (stat(folder_name.c_str(),&st) != 0)
23 if ( (mkdir(folder_name.c_str(),S_IRWXU | S_IRWXG | S_IRWXO) != 0) and
27 <<
"Failed to create restart directory: " << folder_name;
39 bool location_succeeded =
true;
40 char location_cstr[20];
41 snprintf(location_cstr,20,
"%d.r",
Chi::mpi.location_id);
43 std::string file_name = folder_name + std::string(
"/") +
44 file_base + std::string(location_cstr);
47 ofile.open(file_name, std::ios::out | std::ios::binary | std::ios::trunc);
49 if (not ofile.is_open())
52 <<
"Failed to create restart file: " << file_name;
54 location_succeeded =
false;
59 ofile.write((
char*)&phi_old_size,
sizeof(
size_t));
61 ofile.write((
char*)&val,
sizeof(
double));
69 bool global_succeeded =
true;
70 MPI_Allreduce(&location_succeeded,
80 <<
"Successfully wrote restart data: "
81 << folder_name + std::string(
"/") +
82 file_base + std::string(
"X.r");
85 <<
"Failed to write restart data: "
86 << folder_name + std::string(
"/") +
87 file_base + std::string(
"X.r");
93 const std::string& file_base)
102 bool location_succeeded =
true;
103 char location_cstr[20];
104 snprintf(location_cstr,20,
"%d.r",
Chi::mpi.location_id);
106 std::string file_name = folder_name + std::string(
"/") +
107 file_base + std::string(location_cstr);
110 ifile.open(file_name, std::ios::in | std::ios::binary );
112 if (not ifile.is_open())
115 location_succeeded =
false;
119 size_t number_of_unknowns;
120 ifile.read((
char*)&number_of_unknowns,
sizeof(
size_t));
122 if (number_of_unknowns != phi_old_local_.size())
124 location_succeeded =
false;
129 std::vector<double> temp_phi_old(phi_old_local_.size(), 0.0);
132 while (not ifile.eof())
134 ifile.read((
char*)&temp_phi_old[v],
sizeof(
double));
138 if (v != (number_of_unknowns+1))
140 location_succeeded =
false;
144 phi_old_local_ = std::move(temp_phi_old);
153 bool global_succeeded =
true;
154 MPI_Allreduce(&location_succeeded,
162 if (global_succeeded)
Chi::log.
Log() <<
"Successfully read restart data";
165 <<
"Failed to read restart data: "
166 << folder_name + std::string(
"/") +
167 file_base + std::string(
"X.r");
static chi::MPI_Info & mpi
LogStream Log(LOG_LVL level=LOG_0)
void WriteRestartData(const std::string &folder_name, const std::string &file_base)
std::vector< double > phi_old_local_
void ReadRestartData(const std::string &folder_name, const std::string &file_base)