use new utils::sfread() utility function in several classes

This commit is contained in:
Axel Kohlmeyer
2019-10-17 11:29:08 -04:00
parent 7d1cd63e1d
commit cad6293078
22 changed files with 169 additions and 127 deletions

View File

@ -21,6 +21,7 @@
#include "force.h"
#include "memory.h"
#include "error.h"
#include "utils.h"
using namespace LAMMPS_NS;
@ -334,7 +335,7 @@ void AngleHybrid::write_restart(FILE *fp)
void AngleHybrid::read_restart(FILE *fp)
{
int me = comm->me;
if (me == 0) fread(&nstyles,sizeof(int),1,fp);
if (me == 0) utils::sfread(FLERR,&nstyles,sizeof(int),1,fp,NULL,error);
MPI_Bcast(&nstyles,1,MPI_INT,0,world);
styles = new Angle*[nstyles];
keywords = new char*[nstyles];
@ -343,10 +344,10 @@ void AngleHybrid::read_restart(FILE *fp)
int n,dummy;
for (int m = 0; m < nstyles; m++) {
if (me == 0) fread(&n,sizeof(int),1,fp);
if (me == 0) utils::sfread(FLERR,&n,sizeof(int),1,fp,NULL,error);
MPI_Bcast(&n,1,MPI_INT,0,world);
keywords[m] = new char[n];
if (me == 0) fread(keywords[m],sizeof(char),n,fp);
if (me == 0) utils::sfread(FLERR,keywords[m],sizeof(char),n,fp,NULL,error);
MPI_Bcast(keywords[m],n,MPI_CHAR,0,world);
styles[m] = force->new_angle(keywords[m],0,dummy);
styles[m]->read_restart_settings(fp);

View File

@ -24,6 +24,7 @@
#include "math_const.h"
#include "memory.h"
#include "error.h"
#include "utils.h"
using namespace LAMMPS_NS;
using namespace MathConst;
@ -128,7 +129,7 @@ void AngleZero::read_restart(FILE *fp)
allocate();
if (comm->me == 0) {
fread(&theta0[1],sizeof(double),atom->nangletypes,fp);
utils::sfread(FLERR,&theta0[1],sizeof(double),atom->nangletypes,fp,NULL,error);
}
MPI_Bcast(&theta0[1],atom->nangletypes,MPI_DOUBLE,0,world);

View File

@ -21,6 +21,7 @@
#include "force.h"
#include "memory.h"
#include "error.h"
#include "utils.h"
using namespace LAMMPS_NS;
@ -335,7 +336,7 @@ void BondHybrid::write_restart(FILE *fp)
void BondHybrid::read_restart(FILE *fp)
{
int me = comm->me;
if (me == 0) fread(&nstyles,sizeof(int),1,fp);
if (me == 0) utils::sfread(FLERR,&nstyles,sizeof(int),1,fp,NULL,error);
MPI_Bcast(&nstyles,1,MPI_INT,0,world);
styles = new Bond*[nstyles];
keywords = new char*[nstyles];
@ -344,10 +345,10 @@ void BondHybrid::read_restart(FILE *fp)
int n,dummy;
for (int m = 0; m < nstyles; m++) {
if (me == 0) fread(&n,sizeof(int),1,fp);
if (me == 0) utils::sfread(FLERR,&n,sizeof(int),1,fp,NULL,error);
MPI_Bcast(&n,1,MPI_INT,0,world);
keywords[m] = new char[n];
if (me == 0) fread(keywords[m],sizeof(char),n,fp);
if (me == 0) utils::sfread(FLERR,keywords[m],sizeof(char),n,fp,NULL,error);
MPI_Bcast(keywords[m],n,MPI_CHAR,0,world);
styles[m] = force->new_bond(keywords[m],0,dummy);
styles[m]->read_restart_settings(fp);

View File

@ -23,6 +23,7 @@
#include "comm.h"
#include "memory.h"
#include "error.h"
#include "utils.h"
using namespace LAMMPS_NS;
@ -126,7 +127,7 @@ void BondZero::read_restart(FILE *fp)
allocate();
if (comm->me == 0) {
fread(&r0[1],sizeof(double),atom->nbondtypes,fp);
utils::sfread(FLERR,&r0[1],sizeof(double),atom->nbondtypes,fp,NULL,error);
}
MPI_Bcast(&r0[1],atom->nbondtypes,MPI_DOUBLE,0,world);

View File

@ -21,9 +21,11 @@
#include "force.h"
#include "memory.h"
#include "error.h"
#include "utils.h"
using namespace LAMMPS_NS;
#define EXTRA 1000
/* ---------------------------------------------------------------------- */
@ -319,7 +321,7 @@ void DihedralHybrid::write_restart(FILE *fp)
void DihedralHybrid::read_restart(FILE *fp)
{
int me = comm->me;
if (me == 0) fread(&nstyles,sizeof(int),1,fp);
if (me == 0) utils::sfread(FLERR,&nstyles,sizeof(int),1,fp,NULL,error);
MPI_Bcast(&nstyles,1,MPI_INT,0,world);
styles = new Dihedral*[nstyles];
keywords = new char*[nstyles];
@ -328,10 +330,10 @@ void DihedralHybrid::read_restart(FILE *fp)
int n,dummy;
for (int m = 0; m < nstyles; m++) {
if (me == 0) fread(&n,sizeof(int),1,fp);
if (me == 0) utils::sfread(FLERR,&n,sizeof(int),1,fp,NULL,error);
MPI_Bcast(&n,1,MPI_INT,0,world);
keywords[m] = new char[n];
if (me == 0) fread(keywords[m],sizeof(char),n,fp);
if (me == 0) utils::sfread(FLERR,keywords[m],sizeof(char),n,fp,NULL,error);
MPI_Bcast(keywords[m],n,MPI_CHAR,0,world);
styles[m] = force->new_dihedral(keywords[m],0,dummy);
styles[m]->read_restart_settings(fp);

View File

@ -31,6 +31,7 @@
#include "math_extra.h"
#include "memory.h"
#include "error.h"
#include "utils.h"
#include <map>
@ -735,7 +736,7 @@ void Group::read_restart(FILE *fp)
for (i = 0; i < MAX_GROUP; i++) delete [] names[i];
if (me == 0) fread(&ngroup,sizeof(int),1,fp);
if (me == 0) utils::sfread(FLERR,&ngroup,sizeof(int),1,fp,NULL,error);
MPI_Bcast(&ngroup,1,MPI_INT,0,world);
// use count to not change restart format with deleted groups
@ -747,11 +748,11 @@ void Group::read_restart(FILE *fp)
names[i] = NULL;
continue;
}
if (me == 0) fread(&n,sizeof(int),1,fp);
if (me == 0) utils::sfread(FLERR,&n,sizeof(int),1,fp,NULL,error);
MPI_Bcast(&n,1,MPI_INT,0,world);
if (n) {
names[i] = new char[n];
if (me == 0) fread(names[i],sizeof(char),n,fp);
if (me == 0) utils::sfread(FLERR,names[i],sizeof(char),n,fp,NULL,error);
MPI_Bcast(names[i],n,MPI_CHAR,0,world);
count++;
} else names[i] = NULL;

View File

@ -21,6 +21,7 @@
#include "force.h"
#include "memory.h"
#include "error.h"
#include "utils.h"
using namespace LAMMPS_NS;
@ -316,7 +317,7 @@ void ImproperHybrid::write_restart(FILE *fp)
void ImproperHybrid::read_restart(FILE *fp)
{
int me = comm->me;
if (me == 0) fread(&nstyles,sizeof(int),1,fp);
if (me == 0) utils::sfread(FLERR,&nstyles,sizeof(int),1,fp,NULL,error);
MPI_Bcast(&nstyles,1,MPI_INT,0,world);
styles = new Improper*[nstyles];
keywords = new char*[nstyles];
@ -325,10 +326,10 @@ void ImproperHybrid::read_restart(FILE *fp)
int n,dummy;
for (int m = 0; m < nstyles; m++) {
if (me == 0) fread(&n,sizeof(int),1,fp);
if (me == 0) utils::sfread(FLERR,&n,sizeof(int),1,fp,NULL,error);
MPI_Bcast(&n,1,MPI_INT,0,world);
keywords[m] = new char[n];
if (me == 0) fread(keywords[m],sizeof(char),n,fp);
if (me == 0) utils::sfread(FLERR,keywords[m],sizeof(char),n,fp,NULL,error);
MPI_Bcast(keywords[m],n,MPI_CHAR,0,world);
styles[m] = force->new_improper(keywords[m],0,dummy);
styles[m]->read_restart_settings(fp);

View File

@ -1364,7 +1364,7 @@ int Modify::read_restart(FILE *fp)
// nfix_restart_global = # of restart entries with global state info
int me = comm->me;
if (me == 0) fread(&nfix_restart_global,sizeof(int),1,fp);
if (me == 0) utils::sfread(FLERR,&nfix_restart_global,sizeof(int),1,fp,NULL,error);
MPI_Bcast(&nfix_restart_global,1,MPI_INT,0,world);
// allocate space for each entry
@ -1381,22 +1381,22 @@ int Modify::read_restart(FILE *fp)
int n;
for (int i = 0; i < nfix_restart_global; i++) {
if (me == 0) fread(&n,sizeof(int),1,fp);
if (me == 0) utils::sfread(FLERR,&n,sizeof(int),1,fp,NULL,error);
MPI_Bcast(&n,1,MPI_INT,0,world);
id_restart_global[i] = new char[n];
if (me == 0) fread(id_restart_global[i],sizeof(char),n,fp);
if (me == 0) utils::sfread(FLERR,id_restart_global[i],sizeof(char),n,fp,NULL,error);
MPI_Bcast(id_restart_global[i],n,MPI_CHAR,0,world);
if (me == 0) fread(&n,sizeof(int),1,fp);
if (me == 0) utils::sfread(FLERR,&n,sizeof(int),1,fp,NULL,error);
MPI_Bcast(&n,1,MPI_INT,0,world);
style_restart_global[i] = new char[n];
if (me == 0) fread(style_restart_global[i],sizeof(char),n,fp);
if (me == 0) utils::sfread(FLERR,style_restart_global[i],sizeof(char),n,fp,NULL,error);
MPI_Bcast(style_restart_global[i],n,MPI_CHAR,0,world);
if (me == 0) fread(&n,sizeof(int),1,fp);
if (me == 0) utils::sfread(FLERR,&n,sizeof(int),1,fp,NULL,error);
MPI_Bcast(&n,1,MPI_INT,0,world);
state_restart_global[i] = new char[n];
if (me == 0) fread(state_restart_global[i],sizeof(char),n,fp);
if (me == 0) utils::sfread(FLERR,state_restart_global[i],sizeof(char),n,fp,NULL,error);
MPI_Bcast(state_restart_global[i],n,MPI_CHAR,0,world);
used_restart_global[i] = 0;
@ -1406,7 +1406,7 @@ int Modify::read_restart(FILE *fp)
int maxsize = 0;
if (me == 0) fread(&nfix_restart_peratom,sizeof(int),1,fp);
if (me == 0) utils::sfread(FLERR,&nfix_restart_peratom,sizeof(int),1,fp,NULL,error);
MPI_Bcast(&nfix_restart_peratom,1,MPI_INT,0,world);
// allocate space for each entry
@ -1423,19 +1423,19 @@ int Modify::read_restart(FILE *fp)
// set index = which set of extra data this fix represents
for (int i = 0; i < nfix_restart_peratom; i++) {
if (me == 0) fread(&n,sizeof(int),1,fp);
if (me == 0) utils::sfread(FLERR,&n,sizeof(int),1,fp,NULL,error);
MPI_Bcast(&n,1,MPI_INT,0,world);
id_restart_peratom[i] = new char[n];
if (me == 0) fread(id_restart_peratom[i],sizeof(char),n,fp);
if (me == 0) utils::sfread(FLERR,id_restart_peratom[i],sizeof(char),n,fp,NULL,error);
MPI_Bcast(id_restart_peratom[i],n,MPI_CHAR,0,world);
if (me == 0) fread(&n,sizeof(int),1,fp);
if (me == 0) utils::sfread(FLERR,&n,sizeof(int),1,fp,NULL,error);
MPI_Bcast(&n,1,MPI_INT,0,world);
style_restart_peratom[i] = new char[n];
if (me == 0) fread(style_restart_peratom[i],sizeof(char),n,fp);
if (me == 0) utils::sfread(FLERR,style_restart_peratom[i],sizeof(char),n,fp,NULL,error);
MPI_Bcast(style_restart_peratom[i],n,MPI_CHAR,0,world);
if (me == 0) fread(&n,sizeof(int),1,fp);
if (me == 0) utils::sfread(FLERR,&n,sizeof(int),1,fp,NULL,error);
MPI_Bcast(&n,1,MPI_INT,0,world);
maxsize += n;

View File

@ -25,6 +25,7 @@
#include "memory.h"
#include "error.h"
#include "math_special.h"
#include "utils.h"
using namespace LAMMPS_NS;
using namespace MathSpecial;
@ -277,16 +278,16 @@ void PairBeck::read_restart(FILE *fp)
int me = comm->me;
for (i = 1; i <= atom->ntypes; i++)
for (j = i; j <= atom->ntypes; j++) {
if (me == 0) fread(&setflag[i][j],sizeof(int),1,fp);
if (me == 0) utils::sfread(FLERR,&setflag[i][j],sizeof(int),1,fp,NULL,error);
MPI_Bcast(&setflag[i][j],1,MPI_INT,0,world);
if (setflag[i][j]) {
if (me == 0) {
fread(&AA[i][j],sizeof(double),1,fp);
fread(&BB[i][j],sizeof(double),1,fp);
fread(&aa[i][j],sizeof(double),1,fp);
fread(&alpha[i][j],sizeof(double),1,fp);
fread(&beta[i][j],sizeof(double),1,fp);
fread(&cut[i][j],sizeof(double),1,fp);
utils::sfread(FLERR,&AA[i][j],sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&BB[i][j],sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&aa[i][j],sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&alpha[i][j],sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&beta[i][j],sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&cut[i][j],sizeof(double),1,fp,NULL,error);
}
MPI_Bcast(&AA[i][j],1,MPI_DOUBLE,0,world);
MPI_Bcast(&BB[i][j],1,MPI_DOUBLE,0,world);
@ -316,8 +317,8 @@ void PairBeck::read_restart_settings(FILE *fp)
{
int me = comm->me;
if (me == 0) {
fread(&cut_global,sizeof(double),1,fp);
fread(&mix_flag,sizeof(int),1,fp);
utils::sfread(FLERR,&cut_global,sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&mix_flag,sizeof(int),1,fp,NULL,error);
}
MPI_Bcast(&cut_global,1,MPI_DOUBLE,0,world);
MPI_Bcast(&mix_flag,1,MPI_INT,0,world);

View File

@ -26,6 +26,7 @@
#include "math_const.h"
#include "memory.h"
#include "error.h"
#include "utils.h"
using namespace LAMMPS_NS;
using namespace MathConst;
@ -329,16 +330,16 @@ void PairBorn::read_restart(FILE *fp)
int me = comm->me;
for (i = 1; i <= atom->ntypes; i++)
for (j = i; j <= atom->ntypes; j++) {
if (me == 0) fread(&setflag[i][j],sizeof(int),1,fp);
if (me == 0) utils::sfread(FLERR,&setflag[i][j],sizeof(int),1,fp,NULL,error);
MPI_Bcast(&setflag[i][j],1,MPI_INT,0,world);
if (setflag[i][j]) {
if (me == 0) {
fread(&a[i][j],sizeof(double),1,fp);
fread(&rho[i][j],sizeof(double),1,fp);
fread(&sigma[i][j],sizeof(double),1,fp);
fread(&c[i][j],sizeof(double),1,fp);
fread(&d[i][j],sizeof(double),1,fp);
fread(&cut[i][j],sizeof(double),1,fp);
utils::sfread(FLERR,&a[i][j],sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&rho[i][j],sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&sigma[i][j],sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&c[i][j],sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&d[i][j],sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&cut[i][j],sizeof(double),1,fp,NULL,error);
}
MPI_Bcast(&a[i][j],1,MPI_DOUBLE,0,world);
MPI_Bcast(&rho[i][j],1,MPI_DOUBLE,0,world);
@ -369,10 +370,10 @@ void PairBorn::write_restart_settings(FILE *fp)
void PairBorn::read_restart_settings(FILE *fp)
{
if (comm->me == 0) {
fread(&cut_global,sizeof(double),1,fp);
fread(&offset_flag,sizeof(int),1,fp);
fread(&mix_flag,sizeof(int),1,fp);
fread(&tail_flag,sizeof(int),1,fp);
utils::sfread(FLERR,&cut_global,sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&offset_flag,sizeof(int),1,fp,NULL,error);
utils::sfread(FLERR,&mix_flag,sizeof(int),1,fp,NULL,error);
utils::sfread(FLERR,&tail_flag,sizeof(int),1,fp,NULL,error);
}
MPI_Bcast(&cut_global,1,MPI_DOUBLE,0,world);
MPI_Bcast(&offset_flag,1,MPI_INT,0,world);

View File

@ -28,6 +28,7 @@
#include "memory.h"
#include "error.h"
#include "math_special.h"
#include "utils.h"
using namespace LAMMPS_NS;
using namespace MathConst;
@ -360,16 +361,16 @@ void PairBornCoulDSF::read_restart(FILE *fp)
int me = comm->me;
for (i = 1; i <= atom->ntypes; i++)
for (j = i; j <= atom->ntypes; j++) {
if (me == 0) fread(&setflag[i][j],sizeof(int),1,fp);
if (me == 0) utils::sfread(FLERR,&setflag[i][j],sizeof(int),1,fp,NULL,error);
MPI_Bcast(&setflag[i][j],1,MPI_INT,0,world);
if (setflag[i][j]) {
if (me == 0) {
fread(&a[i][j],sizeof(double),1,fp);
fread(&rho[i][j],sizeof(double),1,fp);
fread(&sigma[i][j],sizeof(double),1,fp);
fread(&c[i][j],sizeof(double),1,fp);
fread(&d[i][j],sizeof(double),1,fp);
fread(&cut_lj[i][j],sizeof(double),1,fp);
utils::sfread(FLERR,&a[i][j],sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&rho[i][j],sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&sigma[i][j],sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&c[i][j],sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&d[i][j],sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&cut_lj[i][j],sizeof(double),1,fp,NULL,error);
}
MPI_Bcast(&a[i][j],1,MPI_DOUBLE,0,world);
MPI_Bcast(&rho[i][j],1,MPI_DOUBLE,0,world);
@ -401,11 +402,11 @@ void PairBornCoulDSF::write_restart_settings(FILE *fp)
void PairBornCoulDSF::read_restart_settings(FILE *fp)
{
if (comm->me == 0) {
fread(&alpha,sizeof(double),1,fp);
fread(&cut_lj_global,sizeof(double),1,fp);
fread(&cut_coul,sizeof(double),1,fp);
fread(&offset_flag,sizeof(int),1,fp);
fread(&mix_flag,sizeof(int),1,fp);
utils::sfread(FLERR,&alpha,sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&cut_lj_global,sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&cut_coul,sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&offset_flag,sizeof(int),1,fp,NULL,error);
utils::sfread(FLERR,&mix_flag,sizeof(int),1,fp,NULL,error);
}
MPI_Bcast(&alpha,1,MPI_DOUBLE,0,world);
MPI_Bcast(&cut_lj_global,1,MPI_DOUBLE,0,world);

View File

@ -26,6 +26,7 @@
#include "math_const.h"
#include "memory.h"
#include "error.h"
#include "utils.h"
using namespace LAMMPS_NS;
using namespace MathConst;
@ -359,16 +360,16 @@ void PairBornCoulWolf::read_restart(FILE *fp)
int me = comm->me;
for (i = 1; i <= atom->ntypes; i++)
for (j = i; j <= atom->ntypes; j++) {
if (me == 0) fread(&setflag[i][j],sizeof(int),1,fp);
if (me == 0) utils::sfread(FLERR,&setflag[i][j],sizeof(int),1,fp,NULL,error);
MPI_Bcast(&setflag[i][j],1,MPI_INT,0,world);
if (setflag[i][j]) {
if (me == 0) {
fread(&a[i][j],sizeof(double),1,fp);
fread(&rho[i][j],sizeof(double),1,fp);
fread(&sigma[i][j],sizeof(double),1,fp);
fread(&c[i][j],sizeof(double),1,fp);
fread(&d[i][j],sizeof(double),1,fp);
fread(&cut_lj[i][j],sizeof(double),1,fp);
utils::sfread(FLERR,&a[i][j],sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&rho[i][j],sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&sigma[i][j],sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&c[i][j],sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&d[i][j],sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&cut_lj[i][j],sizeof(double),1,fp,NULL,error);
}
MPI_Bcast(&a[i][j],1,MPI_DOUBLE,0,world);
MPI_Bcast(&rho[i][j],1,MPI_DOUBLE,0,world);
@ -400,11 +401,11 @@ void PairBornCoulWolf::write_restart_settings(FILE *fp)
void PairBornCoulWolf::read_restart_settings(FILE *fp)
{
if (comm->me == 0) {
fread(&alf,sizeof(double),1,fp);
fread(&cut_lj_global,sizeof(double),1,fp);
fread(&cut_coul,sizeof(double),1,fp);
fread(&offset_flag,sizeof(int),1,fp);
fread(&mix_flag,sizeof(int),1,fp);
utils::sfread(FLERR,&alf,sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&cut_lj_global,sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&cut_coul,sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&offset_flag,sizeof(int),1,fp,NULL,error);
utils::sfread(FLERR,&mix_flag,sizeof(int),1,fp,NULL,error);
}
MPI_Bcast(&alf,1,MPI_DOUBLE,0,world);
MPI_Bcast(&cut_lj_global,1,MPI_DOUBLE,0,world);

View File

@ -22,6 +22,7 @@
#include "math_const.h"
#include "memory.h"
#include "error.h"
#include "utils.h"
using namespace LAMMPS_NS;
using namespace MathConst;
@ -307,14 +308,14 @@ void PairBuck::read_restart(FILE *fp)
int me = comm->me;
for (i = 1; i <= atom->ntypes; i++)
for (j = i; j <= atom->ntypes; j++) {
if (me == 0) fread(&setflag[i][j],sizeof(int),1,fp);
if (me == 0) utils::sfread(FLERR,&setflag[i][j],sizeof(int),1,fp,NULL,error);
MPI_Bcast(&setflag[i][j],1,MPI_INT,0,world);
if (setflag[i][j]) {
if (me == 0) {
fread(&a[i][j],sizeof(double),1,fp);
fread(&rho[i][j],sizeof(double),1,fp);
fread(&c[i][j],sizeof(double),1,fp);
fread(&cut[i][j],sizeof(double),1,fp);
utils::sfread(FLERR,&a[i][j],sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&rho[i][j],sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&c[i][j],sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&cut[i][j],sizeof(double),1,fp,NULL,error);
}
MPI_Bcast(&a[i][j],1,MPI_DOUBLE,0,world);
MPI_Bcast(&rho[i][j],1,MPI_DOUBLE,0,world);
@ -343,10 +344,10 @@ void PairBuck::write_restart_settings(FILE *fp)
void PairBuck::read_restart_settings(FILE *fp)
{
if (comm->me == 0) {
fread(&cut_global,sizeof(double),1,fp);
fread(&offset_flag,sizeof(int),1,fp);
fread(&mix_flag,sizeof(int),1,fp);
fread(&tail_flag,sizeof(int),1,fp);
utils::sfread(FLERR,&cut_global,sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&offset_flag,sizeof(int),1,fp,NULL,error);
utils::sfread(FLERR,&mix_flag,sizeof(int),1,fp,NULL,error);
utils::sfread(FLERR,&tail_flag,sizeof(int),1,fp,NULL,error);
}
MPI_Bcast(&cut_global,1,MPI_DOUBLE,0,world);
MPI_Bcast(&offset_flag,1,MPI_INT,0,world);

View File

@ -26,6 +26,7 @@
#include "math_const.h"
#include "memory.h"
#include "error.h"
#include "utils.h"
using namespace LAMMPS_NS;
using namespace MathConst;
@ -363,15 +364,15 @@ void PairBuckCoulCut::read_restart(FILE *fp)
int me = comm->me;
for (i = 1; i <= atom->ntypes; i++)
for (j = i; j <= atom->ntypes; j++) {
if (me == 0) fread(&setflag[i][j],sizeof(int),1,fp);
if (me == 0) utils::sfread(FLERR,&setflag[i][j],sizeof(int),1,fp,NULL,error);
MPI_Bcast(&setflag[i][j],1,MPI_INT,0,world);
if (setflag[i][j]) {
if (me == 0) {
fread(&a[i][j],sizeof(double),1,fp);
fread(&rho[i][j],sizeof(double),1,fp);
fread(&c[i][j],sizeof(double),1,fp);
fread(&cut_lj[i][j],sizeof(double),1,fp);
fread(&cut_coul[i][j],sizeof(double),1,fp);
utils::sfread(FLERR,&a[i][j],sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&rho[i][j],sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&c[i][j],sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&cut_lj[i][j],sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&cut_coul[i][j],sizeof(double),1,fp,NULL,error);
}
MPI_Bcast(&a[i][j],1,MPI_DOUBLE,0,world);
MPI_Bcast(&rho[i][j],1,MPI_DOUBLE,0,world);
@ -402,11 +403,11 @@ void PairBuckCoulCut::write_restart_settings(FILE *fp)
void PairBuckCoulCut::read_restart_settings(FILE *fp)
{
if (comm->me == 0) {
fread(&cut_lj_global,sizeof(double),1,fp);
fread(&cut_coul_global,sizeof(double),1,fp);
fread(&offset_flag,sizeof(int),1,fp);
fread(&mix_flag,sizeof(int),1,fp);
fread(&tail_flag,sizeof(int),1,fp);
utils::sfread(FLERR,&cut_lj_global,sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&cut_coul_global,sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&offset_flag,sizeof(int),1,fp,NULL,error);
utils::sfread(FLERR,&mix_flag,sizeof(int),1,fp,NULL,error);
utils::sfread(FLERR,&tail_flag,sizeof(int),1,fp,NULL,error);
}
MPI_Bcast(&cut_lj_global,1,MPI_DOUBLE,0,world);
MPI_Bcast(&cut_coul_global,1,MPI_DOUBLE,0,world);

View File

@ -22,6 +22,7 @@
#include "neigh_list.h"
#include "memory.h"
#include "error.h"
#include "utils.h"
using namespace LAMMPS_NS;
@ -244,10 +245,10 @@ void PairCoulCut::read_restart(FILE *fp)
int me = comm->me;
for (i = 1; i <= atom->ntypes; i++)
for (j = i; j <= atom->ntypes; j++) {
if (me == 0) fread(&setflag[i][j],sizeof(int),1,fp);
if (me == 0) utils::sfread(FLERR,&setflag[i][j],sizeof(int),1,fp,NULL,error);
MPI_Bcast(&setflag[i][j],1,MPI_INT,0,world);
if (setflag[i][j]) {
if (me == 0) fread(&cut[i][j],sizeof(double),1,fp);
if (me == 0) utils::sfread(FLERR,&cut[i][j],sizeof(double),1,fp,NULL,error);
MPI_Bcast(&cut[i][j],1,MPI_DOUBLE,0,world);
}
}
@ -271,9 +272,9 @@ void PairCoulCut::write_restart_settings(FILE *fp)
void PairCoulCut::read_restart_settings(FILE *fp)
{
if (comm->me == 0) {
fread(&cut_global,sizeof(double),1,fp);
fread(&offset_flag,sizeof(int),1,fp);
fread(&mix_flag,sizeof(int),1,fp);
utils::sfread(FLERR,&cut_global,sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&offset_flag,sizeof(int),1,fp,NULL,error);
utils::sfread(FLERR,&mix_flag,sizeof(int),1,fp,NULL,error);
}
MPI_Bcast(&cut_global,1,MPI_DOUBLE,0,world);
MPI_Bcast(&offset_flag,1,MPI_INT,0,world);

View File

@ -19,6 +19,7 @@
#include "force.h"
#include "neigh_list.h"
#include "error.h"
#include "utils.h"
using namespace LAMMPS_NS;
@ -145,10 +146,10 @@ void PairCoulDebye::write_restart_settings(FILE *fp)
void PairCoulDebye::read_restart_settings(FILE *fp)
{
if (comm->me == 0) {
fread(&cut_global,sizeof(double),1,fp);
fread(&kappa,sizeof(double),1,fp);
fread(&offset_flag,sizeof(int),1,fp);
fread(&mix_flag,sizeof(int),1,fp);
utils::sfread(FLERR,&cut_global,sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&kappa,sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&offset_flag,sizeof(int),1,fp,NULL,error);
utils::sfread(FLERR,&mix_flag,sizeof(int),1,fp,NULL,error);
}
MPI_Bcast(&cut_global,1,MPI_DOUBLE,0,world);
MPI_Bcast(&kappa,1,MPI_DOUBLE,0,world);

View File

@ -28,6 +28,7 @@
#include "memory.h"
#include "math_const.h"
#include "error.h"
#include "utils.h"
using namespace LAMMPS_NS;
using namespace MathConst;
@ -252,7 +253,7 @@ void PairCoulDSF::read_restart(FILE *fp)
int me = comm->me;
for (i = 1; i <= atom->ntypes; i++)
for (j = i; j <= atom->ntypes; j++) {
if (me == 0) fread(&setflag[i][j],sizeof(int),1,fp);
if (me == 0) utils::sfread(FLERR,&setflag[i][j],sizeof(int),1,fp,NULL,error);
MPI_Bcast(&setflag[i][j],1,MPI_INT,0,world);
}
}
@ -276,10 +277,10 @@ void PairCoulDSF::write_restart_settings(FILE *fp)
void PairCoulDSF::read_restart_settings(FILE *fp)
{
if (comm->me == 0) {
fread(&alpha,sizeof(double),1,fp);
fread(&cut_coul,sizeof(double),1,fp);
fread(&offset_flag,sizeof(int),1,fp);
fread(&mix_flag,sizeof(int),1,fp);
utils::sfread(FLERR,&alpha,sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&cut_coul,sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&offset_flag,sizeof(int),1,fp,NULL,error);
utils::sfread(FLERR,&mix_flag,sizeof(int),1,fp,NULL,error);
}
MPI_Bcast(&alpha,1,MPI_DOUBLE,0,world);
MPI_Bcast(&cut_coul,1,MPI_DOUBLE,0,world);

View File

@ -26,6 +26,7 @@
#include "math_const.h"
#include "memory.h"
#include "error.h"
#include "utils.h"
using namespace LAMMPS_NS;
using namespace MathConst;
@ -248,7 +249,7 @@ void PairCoulWolf::read_restart(FILE *fp)
int me = comm->me;
for (i = 1; i <= atom->ntypes; i++)
for (j = i; j <= atom->ntypes; j++) {
if (me == 0) fread(&setflag[i][j],sizeof(int),1,fp);
if (me == 0) utils::sfread(FLERR,&setflag[i][j],sizeof(int),1,fp,NULL,error);
MPI_Bcast(&setflag[i][j],1,MPI_INT,0,world);
}
}
@ -272,10 +273,10 @@ void PairCoulWolf::write_restart_settings(FILE *fp)
void PairCoulWolf::read_restart_settings(FILE *fp)
{
if (comm->me == 0) {
fread(&alf,sizeof(double),1,fp);
fread(&cut_coul,sizeof(double),1,fp);
fread(&offset_flag,sizeof(int),1,fp);
fread(&mix_flag,sizeof(int),1,fp);
utils::sfread(FLERR,&alf,sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&cut_coul,sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&offset_flag,sizeof(int),1,fp,NULL,error);
utils::sfread(FLERR,&mix_flag,sizeof(int),1,fp,NULL,error);
}
MPI_Bcast(&alf,1,MPI_DOUBLE,0,world);
MPI_Bcast(&cut_coul,1,MPI_DOUBLE,0,world);

View File

@ -27,6 +27,7 @@
#include "random_mars.h"
#include "memory.h"
#include "error.h"
#include "utils.h"
using namespace LAMMPS_NS;
@ -313,13 +314,13 @@ void PairDPD::read_restart(FILE *fp)
int me = comm->me;
for (i = 1; i <= atom->ntypes; i++)
for (j = i; j <= atom->ntypes; j++) {
if (me == 0) fread(&setflag[i][j],sizeof(int),1,fp);
if (me == 0) utils::sfread(FLERR,&setflag[i][j],sizeof(int),1,fp,NULL,error);
MPI_Bcast(&setflag[i][j],1,MPI_INT,0,world);
if (setflag[i][j]) {
if (me == 0) {
fread(&a0[i][j],sizeof(double),1,fp);
fread(&gamma[i][j],sizeof(double),1,fp);
fread(&cut[i][j],sizeof(double),1,fp);
utils::sfread(FLERR,&a0[i][j],sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&gamma[i][j],sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&cut[i][j],sizeof(double),1,fp,NULL,error);
}
MPI_Bcast(&a0[i][j],1,MPI_DOUBLE,0,world);
MPI_Bcast(&gamma[i][j],1,MPI_DOUBLE,0,world);
@ -347,10 +348,10 @@ void PairDPD::write_restart_settings(FILE *fp)
void PairDPD::read_restart_settings(FILE *fp)
{
if (comm->me == 0) {
fread(&temperature,sizeof(double),1,fp);
fread(&cut_global,sizeof(double),1,fp);
fread(&seed,sizeof(int),1,fp);
fread(&mix_flag,sizeof(int),1,fp);
utils::sfread(FLERR,&temperature,sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&cut_global,sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&seed,sizeof(int),1,fp,NULL,error);
utils::sfread(FLERR,&mix_flag,sizeof(int),1,fp,NULL,error);
}
MPI_Bcast(&temperature,1,MPI_DOUBLE,0,world);
MPI_Bcast(&cut_global,1,MPI_DOUBLE,0,world);

View File

@ -21,6 +21,7 @@
#include "comm.h"
#include "random_mars.h"
#include "error.h"
#include "utils.h"
using namespace LAMMPS_NS;
@ -231,12 +232,12 @@ void PairDPDTstat::read_restart(FILE *fp)
int me = comm->me;
for (i = 1; i <= atom->ntypes; i++)
for (j = i; j <= atom->ntypes; j++) {
if (me == 0) fread(&setflag[i][j],sizeof(int),1,fp);
if (me == 0) utils::sfread(FLERR,&setflag[i][j],sizeof(int),1,fp,NULL,error);
MPI_Bcast(&setflag[i][j],1,MPI_INT,0,world);
if (setflag[i][j]) {
if (me == 0) {
fread(&gamma[i][j],sizeof(double),1,fp);
fread(&cut[i][j],sizeof(double),1,fp);
utils::sfread(FLERR,&gamma[i][j],sizeof(double),1,fp,NULL,error);
utils::sfread(FLERR,&cut[i][j],sizeof(double),1,fp,NULL,error);
}
MPI_Bcast(&gamma[i][j],1,MPI_DOUBLE,0,world);
MPI_Bcast(&cut[i][j],1,MPI_DOUBLE,0,world);

View File

@ -17,6 +17,10 @@
#include "lammps.h"
#include "error.h"
#if defined(__linux)
#include <unistd.h> // for readlink
#endif
/*! \file utils.cpp */
/*
@ -127,14 +131,32 @@ void utils::sfgets(const char *srcname, int srcline, char *s, int size,
return;
}
#define MAXFILEBUF 1024
/* like fread() but aborts with an error or EOF is encountered */
void sfread(const char *srcname, int srcline, void *s, size_t size,
void utils::sfread(const char *srcname, int srcline, void *s, size_t size,
size_t num, FILE *fp, const char *filename, Error *error)
{
char inferred_name[MAXFILEBUF];
size_t rv = fread(s,size,num,fp);
if (rv != num) { // something went wrong
std::string errmsg;
// try to figure out the file name from the file pointer
if (!filename) {
// on Linux we can infer the name of the open file from /proc
// otherwise we set it to "(unknown)"
#if defined(__linux)
char procpath[32];
int fd = fileno(fp);
snprintf(procpath,32,"/proc/self/fd/%d",fd);
memset(inferred_name,0,MAXFILEBUF);
readlink(procpath,inferred_name,MAXFILEBUF);
#else
strcpy(inferred_name,"(unknown)");
#endif
filename = inferred_name;
}
if (feof(fp)) {
errmsg = "Unexpected end of file while reading file '";
} else if (ferror(fp)) {

View File

@ -78,7 +78,7 @@ namespace LAMMPS_NS {
* \param size size of data elements read by fread()
* \param num number of data elements read by fread()
* \param fp file pointer used by fread()
* \param filename file name associated with fp (for error message)
* \param filename file name associated with fp (may be NULL; then LAMMPS will try to detect)
* \param error pointer to Error class instance (for abort)
*/
void sfread(const char *srcname, int srcline, void *s, size_t size,