From 7e7a448a08714a8a83bdb00f5c6f9b194905d1e6 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 24 Apr 2021 21:33:36 -0400 Subject: [PATCH] remove the old versions of the utility function and use the new --- lib/atc/LammpsInterface.cpp | 4 ++- src/REPLICA/neb.cpp | 5 +-- src/RIGID/fix_rigid.cpp | 2 +- src/RIGID/fix_rigid_small.cpp | 2 +- src/SPIN/neb_spin.cpp | 5 +-- src/comm.cpp | 68 ----------------------------------- src/comm.h | 3 -- src/read_data.cpp | 30 ++++++++-------- src/variable.cpp | 2 +- 9 files changed, 27 insertions(+), 94 deletions(-) diff --git a/lib/atc/LammpsInterface.cpp b/lib/atc/LammpsInterface.cpp index 5727af1904..b123331ee7 100644 --- a/lib/atc/LammpsInterface.cpp +++ b/lib/atc/LammpsInterface.cpp @@ -26,6 +26,7 @@ #include "bond.h" // bond potentials #include "comm.h" // #include "fix.h" +#include "utils.h" // ATC includes #include "ATC_Error.h" @@ -47,6 +48,7 @@ using std::pair; using std::string; using std::set; using LAMMPS_NS::bigint; +using LAMMPS_NS::utils::read_lines_from_file; namespace ATC { @@ -236,7 +238,7 @@ std::string LammpsInterface::read_file(std::string filename) const std::stringstream s; bool eof = false; while ( ! eof) { - eof = lammps_->comm->read_lines_from_file(fp,1,MAXLINE,buffer); + eof = read_lines_from_file(fp,1,MAXLINE,buffer,comm_rank(),lammps_->world); s << buffer; } fclose(fp); diff --git a/src/REPLICA/neb.cpp b/src/REPLICA/neb.cpp index 7183bdd168..295e97dee8 100644 --- a/src/REPLICA/neb.cpp +++ b/src/REPLICA/neb.cpp @@ -436,9 +436,10 @@ void NEB::readfile(char *file, int flag) while (nread < nlines) { nchunk = MIN(nlines-nread,CHUNK); if (flag == 0) - eofflag = comm->read_lines_from_file_universe(fp,nchunk,MAXLINE,buffer); + eofflag = utils::read_lines_from_file(fp,nchunk,MAXLINE,buffer, + universe->me,universe->uworld); else - eofflag = comm->read_lines_from_file(fp,nchunk,MAXLINE,buffer); + eofflag = utils::read_lines_from_file(fp,nchunk,MAXLINE,buffer,me,world); if (eofflag) error->all(FLERR,"Unexpected end of NEB file"); buf = buffer; diff --git a/src/RIGID/fix_rigid.cpp b/src/RIGID/fix_rigid.cpp index 3cd4f5dbc8..2ec8821666 100644 --- a/src/RIGID/fix_rigid.cpp +++ b/src/RIGID/fix_rigid.cpp @@ -2302,7 +2302,7 @@ void FixRigid::readfile(int which, double *vec, int nread = 0; while (nread < nlines) { nchunk = MIN(nlines-nread,CHUNK); - eofflag = comm->read_lines_from_file(fp,nchunk,MAXLINE,buffer); + eofflag = utils::read_lines_from_file(fp,nchunk,MAXLINE,buffer,me,world); if (eofflag) error->all(FLERR,"Unexpected end of fix rigid file"); buf = buffer; diff --git a/src/RIGID/fix_rigid_small.cpp b/src/RIGID/fix_rigid_small.cpp index 14bd9f7a55..2cd87c45dc 100644 --- a/src/RIGID/fix_rigid_small.cpp +++ b/src/RIGID/fix_rigid_small.cpp @@ -2475,7 +2475,7 @@ void FixRigidSmall::readfile(int which, double **array, int *inbody) int nread = 0; while (nread < nlines) { nchunk = MIN(nlines-nread,CHUNK); - eofflag = comm->read_lines_from_file(fp,nchunk,MAXLINE,buffer); + eofflag = utils::read_lines_from_file(fp,nchunk,MAXLINE,buffer,me,world); if (eofflag) error->all(FLERR,"Unexpected end of fix rigid/small file"); buf = buffer; diff --git a/src/SPIN/neb_spin.cpp b/src/SPIN/neb_spin.cpp index 88a0ffc402..1761f73323 100644 --- a/src/SPIN/neb_spin.cpp +++ b/src/SPIN/neb_spin.cpp @@ -430,9 +430,10 @@ void NEBSpin::readfile(char *file, int flag) while (nread < nlines) { nchunk = MIN(nlines-nread,CHUNK); if (flag == 0) - eofflag = comm->read_lines_from_file_universe(fp,nchunk,MAXLINE,buffer); + eofflag = utils::read_lines_from_file(fp,nchunk,MAXLINE,buffer, + universe->me,universe->uworld); else - eofflag = comm->read_lines_from_file(fp,nchunk,MAXLINE,buffer); + eofflag = utils::read_lines_from_file(fp,nchunk,MAXLINE,buffer,me,world); if (eofflag) error->all(FLERR,"Unexpected end of neb/spin file"); buf = buffer; diff --git a/src/comm.cpp b/src/comm.cpp index 6d3f72d9c0..aa51c0484f 100644 --- a/src/comm.cpp +++ b/src/comm.cpp @@ -1240,71 +1240,3 @@ void Comm::rendezvous_stats(int n, int nout, int nrvous, int nrvous_out, utils::logmesg(lmp,mesg); } } - -/* ---------------------------------------------------------------------- - proc 0 reads Nlines from file into buf and bcasts buf to all procs - caller allocates buf to max size needed - each line is terminated by newline, even if last line in file is not - return 0 if successful, 1 if get EOF error before read is complete -------------------------------------------------------------------------- */ - -int Comm::read_lines_from_file(FILE *fp, int nlines, int maxline, char *buf) -{ - int m; - - if (me == 0) { - m = 0; - for (int i = 0; i < nlines; i++) { - if (!fgets(&buf[m],maxline,fp)) { - m = 0; - break; - } - m += strlen(&buf[m]); - } - if (m) { - if (buf[m-1] != '\n') strcpy(&buf[m++],"\n"); - m++; - } - } - - MPI_Bcast(&m,1,MPI_INT,0,world); - if (m == 0) return 1; - MPI_Bcast(buf,m,MPI_CHAR,0,world); - return 0; -} - -/* ---------------------------------------------------------------------- - proc 0 reads Nlines from file into buf and bcasts buf to all procs - caller allocates buf to max size needed - each line is terminated by newline, even if last line in file is not - return 0 if successful, 1 if get EOF error before read is complete -------------------------------------------------------------------------- */ - -int Comm::read_lines_from_file_universe(FILE *fp, int nlines, int maxline, - char *buf) -{ - int m; - - int me_universe = universe->me; - MPI_Comm uworld = universe->uworld; - - if (me_universe == 0) { - m = 0; - for (int i = 0; i < nlines; i++) { - if (!fgets(&buf[m],maxline,fp)) { - m = 0; - break; - } - m += strlen(&buf[m]); - } - if (m) { - if (buf[m-1] != '\n') strcpy(&buf[m++],"\n"); - m++; - } - } - - MPI_Bcast(&m,1,MPI_INT,0,uworld); - if (m == 0) return 1; - MPI_Bcast(buf,m,MPI_CHAR,0,uworld); - return 0; -} diff --git a/src/comm.h b/src/comm.h index d283144501..0bcd23cd8a 100644 --- a/src/comm.h +++ b/src/comm.h @@ -114,9 +114,6 @@ class Comm : protected Pointers { int (*)(int, char *, int &, int *&, char *&, void *), int, char *&, int, void *, int statflag=0); - int read_lines_from_file(FILE *, int, int, char *); - int read_lines_from_file_universe(FILE *, int, int, char *); - // extract data useful to other classes virtual void *extract(const char *, int &) {return nullptr;} diff --git a/src/read_data.cpp b/src/read_data.cpp index c0085f19d1..6ea22264cd 100644 --- a/src/read_data.cpp +++ b/src/read_data.cpp @@ -1226,7 +1226,7 @@ void ReadData::atoms() while (nread < natoms) { nchunk = MIN(natoms-nread,CHUNK); - eof = comm->read_lines_from_file(fp,nchunk,MAXLINE,buffer); + eof = utils::read_lines_from_file(fp,nchunk,MAXLINE,buffer,me,world); if (eof) error->all(FLERR,"Unexpected end of data file"); atom->data_atoms(nchunk,buffer,id_offset,mol_offset,toffset,shiftflag,shift); nread += nchunk; @@ -1282,7 +1282,7 @@ void ReadData::velocities() while (nread < natoms) { nchunk = MIN(natoms-nread,CHUNK); - eof = comm->read_lines_from_file(fp,nchunk,MAXLINE,buffer); + eof = utils::read_lines_from_file(fp,nchunk,MAXLINE,buffer,me,world); if (eof) error->all(FLERR,"Unexpected end of data file"); atom->data_vels(nchunk,buffer,id_offset); nread += nchunk; @@ -1324,7 +1324,7 @@ void ReadData::bonds(int firstpass) while (nread < nbonds) { nchunk = MIN(nbonds-nread,CHUNK); - eof = comm->read_lines_from_file(fp,nchunk,MAXLINE,buffer); + eof = utils::read_lines_from_file(fp,nchunk,MAXLINE,buffer,me,world); if (eof) error->all(FLERR,"Unexpected end of data file"); atom->data_bonds(nchunk,buffer,count,id_offset,boffset); nread += nchunk; @@ -1398,7 +1398,7 @@ void ReadData::angles(int firstpass) while (nread < nangles) { nchunk = MIN(nangles-nread,CHUNK); - eof = comm->read_lines_from_file(fp,nchunk,MAXLINE,buffer); + eof = utils::read_lines_from_file(fp,nchunk,MAXLINE,buffer,me,world); if (eof) error->all(FLERR,"Unexpected end of data file"); atom->data_angles(nchunk,buffer,count,id_offset,aoffset); nread += nchunk; @@ -1472,7 +1472,7 @@ void ReadData::dihedrals(int firstpass) while (nread < ndihedrals) { nchunk = MIN(ndihedrals-nread,CHUNK); - eof = comm->read_lines_from_file(fp,nchunk,MAXLINE,buffer); + eof = utils::read_lines_from_file(fp,nchunk,MAXLINE,buffer,me,world); if (eof) error->all(FLERR,"Unexpected end of data file"); atom->data_dihedrals(nchunk,buffer,count,id_offset,doffset); nread += nchunk; @@ -1546,7 +1546,7 @@ void ReadData::impropers(int firstpass) while (nread < nimpropers) { nchunk = MIN(nimpropers-nread,CHUNK); - eof = comm->read_lines_from_file(fp,nchunk,MAXLINE,buffer); + eof = utils::read_lines_from_file(fp,nchunk,MAXLINE,buffer,me,world); if (eof) error->all(FLERR,"Unexpected end of data file"); atom->data_impropers(nchunk,buffer,count,id_offset,ioffset); nread += nchunk; @@ -1613,7 +1613,7 @@ void ReadData::bonus(bigint nbonus, AtomVec *ptr, const char *type) while (nread < natoms) { nchunk = MIN(natoms-nread,CHUNK); - eof = comm->read_lines_from_file(fp,nchunk,MAXLINE,buffer); + eof = utils::read_lines_from_file(fp,nchunk,MAXLINE,buffer,me,world); if (eof) error->all(FLERR,"Unexpected end of data file"); atom->data_bonus(nchunk,buffer,ptr,id_offset); nread += nchunk; @@ -1739,7 +1739,7 @@ void ReadData::mass() char *next; char *buf = new char[ntypes*MAXLINE]; - int eof = comm->read_lines_from_file(fp,ntypes,MAXLINE,buf); + int eof = utils::read_lines_from_file(fp,ntypes,MAXLINE,buf,me,world); if (eof) error->all(FLERR,"Unexpected end of data file"); char *original = buf; @@ -1759,7 +1759,7 @@ void ReadData::paircoeffs() char *next; char *buf = new char[ntypes*MAXLINE]; - int eof = comm->read_lines_from_file(fp,ntypes,MAXLINE,buf); + int eof = utils::read_lines_from_file(fp,ntypes,MAXLINE,buf,me,world); if (eof) error->all(FLERR,"Unexpected end of data file"); char *original = buf; @@ -1785,7 +1785,7 @@ void ReadData::pairIJcoeffs() int nsq = ntypes * (ntypes+1) / 2; char *buf = new char[nsq * MAXLINE]; - int eof = comm->read_lines_from_file(fp,nsq,MAXLINE,buf); + int eof = utils::read_lines_from_file(fp,nsq,MAXLINE,buf,me,world); if (eof) error->all(FLERR,"Unexpected end of data file"); char *original = buf; @@ -1811,7 +1811,7 @@ void ReadData::bondcoeffs() char *next; char *buf = new char[nbondtypes*MAXLINE]; - int eof = comm->read_lines_from_file(fp,nbondtypes,MAXLINE,buf); + int eof = utils::read_lines_from_file(fp,nbondtypes,MAXLINE,buf,me,world); if (eof) error->all(FLERR,"Unexpected end of data file"); char *original = buf; @@ -1836,7 +1836,7 @@ void ReadData::anglecoeffs(int which) char *next; char *buf = new char[nangletypes*MAXLINE]; - int eof = comm->read_lines_from_file(fp,nangletypes,MAXLINE,buf); + int eof = utils::read_lines_from_file(fp,nangletypes,MAXLINE,buf,me,world); if (eof) error->all(FLERR,"Unexpected end of data file"); char *original = buf; @@ -1862,7 +1862,7 @@ void ReadData::dihedralcoeffs(int which) char *next; char *buf = new char[ndihedraltypes*MAXLINE]; - int eof = comm->read_lines_from_file(fp,ndihedraltypes,MAXLINE,buf); + int eof = utils::read_lines_from_file(fp,ndihedraltypes,MAXLINE,buf,me,world); if (eof) error->all(FLERR,"Unexpected end of data file"); char *original = buf; @@ -1892,7 +1892,7 @@ void ReadData::impropercoeffs(int which) char *next; char *buf = new char[nimpropertypes*MAXLINE]; - int eof = comm->read_lines_from_file(fp,nimpropertypes,MAXLINE,buf); + int eof = utils::read_lines_from_file(fp,nimpropertypes,MAXLINE,buf,me,world); if (eof) error->all(FLERR,"Unexpected end of data file"); char *original = buf; @@ -1922,7 +1922,7 @@ void ReadData::fix(int ifix, char *keyword) bigint nread = 0; while (nread < nline) { nchunk = MIN(nline-nread,CHUNK); - eof = comm->read_lines_from_file(fp,nchunk,MAXLINE,buffer); + eof = utils::read_lines_from_file(fp,nchunk,MAXLINE,buffer,me,world); if (eof) error->all(FLERR,"Unexpected end of data file"); modify->fix[ifix]->read_data_section(keyword,nchunk,buffer,id_offset); nread += nchunk; diff --git a/src/variable.cpp b/src/variable.cpp index ac225230cf..9cbbbc13d2 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -5176,7 +5176,7 @@ int VarReader::read_peratom() bigint nread = 0; while (nread < nlines) { nchunk = MIN(nlines-nread,CHUNK); - eof = comm->read_lines_from_file(fp,nchunk,MAXLINE,buffer); + eof = utils::read_lines_from_file(fp,nchunk,MAXLINE,buffer,me,world); if (eof) return 1; char *buf = buffer;