Skip to content

Commit

Permalink
remove the old versions of the utility function and use the new
Browse files Browse the repository at this point in the history
  • Loading branch information
akohlmey committed Apr 25, 2021
1 parent 8e5e995 commit 7e7a448
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 94 deletions.
4 changes: 3 additions & 1 deletion lib/atc/LammpsInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "bond.h" // bond potentials
#include "comm.h" //
#include "fix.h"
#include "utils.h"

// ATC includes
#include "ATC_Error.h"
Expand All @@ -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 {

Expand Down Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions src/REPLICA/neb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/RIGID/fix_rigid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/RIGID/fix_rigid_small.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions src/SPIN/neb_spin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
68 changes: 0 additions & 68 deletions src/comm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
3 changes: 0 additions & 3 deletions src/comm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;}

Expand Down
30 changes: 15 additions & 15 deletions src/read_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 7e7a448

Please sign in to comment.