port read/write_restart to use the platform namespace
This commit is contained in:
@ -35,7 +35,6 @@
|
|||||||
#include "update.h"
|
#include "update.h"
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <dirent.h>
|
|
||||||
|
|
||||||
#include "lmprestart.h"
|
#include "lmprestart.h"
|
||||||
|
|
||||||
@ -117,6 +116,7 @@ void ReadRestart::command(int narg, char **arg)
|
|||||||
magic_string();
|
magic_string();
|
||||||
endian();
|
endian();
|
||||||
format_revision();
|
format_revision();
|
||||||
|
check_eof_magic();
|
||||||
|
|
||||||
// read header info which creates simulation box
|
// read header info which creates simulation box
|
||||||
|
|
||||||
@ -557,20 +557,16 @@ std::string ReadRestart::file_search(const std::string &inpfile)
|
|||||||
if (loc != std::string::npos) {
|
if (loc != std::string::npos) {
|
||||||
// convert pattern to equivalent regexp
|
// convert pattern to equivalent regexp
|
||||||
pattern.replace(loc,1,"\\d+");
|
pattern.replace(loc,1,"\\d+");
|
||||||
struct dirent *ep;
|
|
||||||
DIR *dp = opendir(dirname.c_str());
|
|
||||||
if (dp == nullptr)
|
|
||||||
error->one(FLERR,"Cannot open directory {} to search for restart file: {}",
|
|
||||||
dirname, utils::getsyserror());
|
|
||||||
|
|
||||||
while ((ep = readdir(dp))) {
|
if (!platform::path_is_directory(dirname))
|
||||||
std::string candidate(ep->d_name);
|
error->one(FLERR,"Cannot open directory {} to search for restart file: {}",dirname);
|
||||||
|
|
||||||
|
for (const auto &candidate : platform::list_directory(dirname)) {
|
||||||
if (utils::strmatch(candidate,pattern)) {
|
if (utils::strmatch(candidate,pattern)) {
|
||||||
bigint num = ATOBIGINT(utils::strfind(candidate.substr(loc),"\\d+").c_str());
|
bigint num = ATOBIGINT(utils::strfind(candidate.substr(loc),"\\d+").c_str());
|
||||||
if (num > maxnum) maxnum = num;
|
if (num > maxnum) maxnum = num;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
closedir(dp);
|
|
||||||
if (maxnum < 0) error->one(FLERR,"Found no restart file matching pattern");
|
if (maxnum < 0) error->one(FLERR,"Found no restart file matching pattern");
|
||||||
filename.replace(filename.find('*'),1,std::to_string(maxnum));
|
filename.replace(filename.find('*'),1,std::to_string(maxnum));
|
||||||
}
|
}
|
||||||
@ -1084,11 +1080,11 @@ void ReadRestart::file_layout()
|
|||||||
flag = read_int();
|
flag = read_int();
|
||||||
}
|
}
|
||||||
|
|
||||||
// if MPI-IO file, broadcast the end of the header offste
|
// if MPI-IO file, broadcast the end of the header offset
|
||||||
// this allows all ranks to compute offset to their data
|
// this allows all ranks to compute offset to their data
|
||||||
|
|
||||||
if (mpiioflag) {
|
if (mpiioflag) {
|
||||||
if (me == 0) headerOffset = ftell(fp);
|
if (me == 0) headerOffset = platform::ftell(fp);
|
||||||
MPI_Bcast(&headerOffset,1,MPI_LMP_BIGINT,0,world);
|
MPI_Bcast(&headerOffset,1,MPI_LMP_BIGINT,0,world);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1152,10 +1148,12 @@ void ReadRestart::check_eof_magic()
|
|||||||
// read magic string at end of file and restore file pointer
|
// read magic string at end of file and restore file pointer
|
||||||
|
|
||||||
if (me == 0) {
|
if (me == 0) {
|
||||||
long curpos = ftell(fp);
|
bigint curpos = platform::ftell(fp);
|
||||||
fseek(fp,(long)-n,SEEK_END);
|
platform::fseek(fp,platform::END_OF_FILE);
|
||||||
|
bigint offset = platform::ftell(fp) - n;
|
||||||
|
platform::fseek(fp,offset);
|
||||||
utils::sfread(FLERR,str,sizeof(char),n,fp,nullptr,error);
|
utils::sfread(FLERR,str,sizeof(char),n,fp,nullptr,error);
|
||||||
fseek(fp,curpos,SEEK_SET);
|
platform::fseek(fp,curpos);
|
||||||
}
|
}
|
||||||
|
|
||||||
MPI_Bcast(str,n,MPI_CHAR,0,world);
|
MPI_Bcast(str,n,MPI_CHAR,0,world);
|
||||||
|
|||||||
@ -595,7 +595,7 @@ void WriteRestart::file_layout(int send_size)
|
|||||||
// this allows all ranks to compute offset to their data
|
// this allows all ranks to compute offset to their data
|
||||||
|
|
||||||
if (mpiioflag) {
|
if (mpiioflag) {
|
||||||
if (me == 0) headerOffset = ftell(fp);
|
if (me == 0) headerOffset = platform::ftell(fp);
|
||||||
MPI_Bcast(&headerOffset,1,MPI_LMP_BIGINT,0,world);
|
MPI_Bcast(&headerOffset,1,MPI_LMP_BIGINT,0,world);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user