avoid memory leak with MPI-IO
This commit is contained in:
@ -44,7 +44,7 @@ using namespace LAMMPS_NS;
|
|||||||
|
|
||||||
/* ---------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
ReadRestart::ReadRestart(LAMMPS *lmp) : Command(lmp) {}
|
ReadRestart::ReadRestart(LAMMPS *lmp) : Command(lmp), mpiio(nullptr) {}
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
@ -110,8 +110,7 @@ void ReadRestart::command(int narg, char **arg)
|
|||||||
}
|
}
|
||||||
fp = fopen(hfile.c_str(),"rb");
|
fp = fopen(hfile.c_str(),"rb");
|
||||||
if (fp == nullptr)
|
if (fp == nullptr)
|
||||||
error->one(FLERR,"Cannot open restart file {}: {}",
|
error->one(FLERR,"Cannot open restart file {}: {}", hfile, utils::getsyserror());
|
||||||
hfile, utils::getsyserror());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// read magic string, endian flag, format revision
|
// read magic string, endian flag, format revision
|
||||||
@ -336,8 +335,7 @@ void ReadRestart::command(int narg, char **arg)
|
|||||||
procfile.replace(procfile.find("%"),1,fmt::format("{}",icluster));
|
procfile.replace(procfile.find("%"),1,fmt::format("{}",icluster));
|
||||||
fp = fopen(procfile.c_str(),"rb");
|
fp = fopen(procfile.c_str(),"rb");
|
||||||
if (fp == nullptr)
|
if (fp == nullptr)
|
||||||
error->one(FLERR,"Cannot open restart file {}: {}",
|
error->one(FLERR,"Cannot open restart file {}: {}", procfile, utils::getsyserror());
|
||||||
procfile, utils::getsyserror());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int procsperfile;
|
int procsperfile;
|
||||||
@ -401,7 +399,7 @@ void ReadRestart::command(int narg, char **arg)
|
|||||||
|
|
||||||
// clean-up memory
|
// clean-up memory
|
||||||
|
|
||||||
delete [] file;
|
delete[] file;
|
||||||
memory->destroy(buf);
|
memory->destroy(buf);
|
||||||
|
|
||||||
// for multiproc or MPI-IO files:
|
// for multiproc or MPI-IO files:
|
||||||
@ -525,8 +523,9 @@ void ReadRestart::command(int narg, char **arg)
|
|||||||
MPI_Barrier(world);
|
MPI_Barrier(world);
|
||||||
|
|
||||||
if (comm->me == 0)
|
if (comm->me == 0)
|
||||||
utils::logmesg(lmp," read_restart CPU = {:.3f} seconds\n",
|
utils::logmesg(lmp," read_restart CPU = {:.3f} seconds\n",MPI_Wtime()-time1);
|
||||||
MPI_Wtime()-time1);
|
|
||||||
|
delete mpiio;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
@ -599,7 +598,7 @@ void ReadRestart::header()
|
|||||||
if (me == 0)
|
if (me == 0)
|
||||||
utils::logmesg(lmp," restart file = {}, LAMMPS = {}\n",
|
utils::logmesg(lmp," restart file = {}, LAMMPS = {}\n",
|
||||||
version,lmp->version);
|
version,lmp->version);
|
||||||
delete [] version;
|
delete[] version;
|
||||||
|
|
||||||
// we have no forward compatibility, thus exit with error
|
// we have no forward compatibility, thus exit with error
|
||||||
|
|
||||||
@ -638,7 +637,7 @@ void ReadRestart::header()
|
|||||||
} else if (flag == UNITS) {
|
} else if (flag == UNITS) {
|
||||||
char *style = read_string();
|
char *style = read_string();
|
||||||
if (strcmp(style,update->unit_style) != 0) update->set_units(style);
|
if (strcmp(style,update->unit_style) != 0) update->set_units(style);
|
||||||
delete [] style;
|
delete[] style;
|
||||||
|
|
||||||
} else if (flag == NTIMESTEP) {
|
} else if (flag == NTIMESTEP) {
|
||||||
update->ntimestep = read_bigint();
|
update->ntimestep = read_bigint();
|
||||||
@ -772,9 +771,9 @@ void ReadRestart::header()
|
|||||||
atom->create_avec(style,nargcopy,argcopy,1);
|
atom->create_avec(style,nargcopy,argcopy,1);
|
||||||
if (comm->me ==0)
|
if (comm->me ==0)
|
||||||
utils::logmesg(lmp," restoring atom style {} from restart\n",style);
|
utils::logmesg(lmp," restoring atom style {} from restart\n",style);
|
||||||
for (int i = 0; i < nargcopy; i++) delete [] argcopy[i];
|
for (int i = 0; i < nargcopy; i++) delete[] argcopy[i];
|
||||||
delete [] argcopy;
|
delete[] argcopy;
|
||||||
delete [] style;
|
delete[] style;
|
||||||
|
|
||||||
} else if (flag == NATOMS) {
|
} else if (flag == NATOMS) {
|
||||||
atom->natoms = read_bigint();
|
atom->natoms = read_bigint();
|
||||||
@ -889,7 +888,7 @@ void ReadRestart::type_arrays()
|
|||||||
double *mass = new double[atom->ntypes+1];
|
double *mass = new double[atom->ntypes+1];
|
||||||
read_double_vec(atom->ntypes,&mass[1]);
|
read_double_vec(atom->ntypes,&mass[1]);
|
||||||
atom->set_mass(mass);
|
atom->set_mass(mass);
|
||||||
delete [] mass;
|
delete[] mass;
|
||||||
|
|
||||||
} else error->all(FLERR,
|
} else error->all(FLERR,
|
||||||
"Invalid flag in type arrays section of restart file");
|
"Invalid flag in type arrays section of restart file");
|
||||||
@ -910,7 +909,7 @@ void ReadRestart::force_fields()
|
|||||||
if (flag == PAIR) {
|
if (flag == PAIR) {
|
||||||
style = read_string();
|
style = read_string();
|
||||||
force->create_pair(style,1);
|
force->create_pair(style,1);
|
||||||
delete [] style;
|
delete[] style;
|
||||||
if (comm->me ==0)
|
if (comm->me ==0)
|
||||||
utils::logmesg(lmp," restoring pair style {} from restart\n",
|
utils::logmesg(lmp," restoring pair style {} from restart\n",
|
||||||
force->pair_style);
|
force->pair_style);
|
||||||
@ -926,7 +925,7 @@ void ReadRestart::force_fields()
|
|||||||
} else if (flag == BOND) {
|
} else if (flag == BOND) {
|
||||||
style = read_string();
|
style = read_string();
|
||||||
force->create_bond(style,1);
|
force->create_bond(style,1);
|
||||||
delete [] style;
|
delete[] style;
|
||||||
if (comm->me ==0)
|
if (comm->me ==0)
|
||||||
utils::logmesg(lmp," restoring bond style {} from restart\n",
|
utils::logmesg(lmp," restoring bond style {} from restart\n",
|
||||||
force->bond_style);
|
force->bond_style);
|
||||||
@ -935,7 +934,7 @@ void ReadRestart::force_fields()
|
|||||||
} else if (flag == ANGLE) {
|
} else if (flag == ANGLE) {
|
||||||
style = read_string();
|
style = read_string();
|
||||||
force->create_angle(style,1);
|
force->create_angle(style,1);
|
||||||
delete [] style;
|
delete[] style;
|
||||||
if (comm->me ==0)
|
if (comm->me ==0)
|
||||||
utils::logmesg(lmp," restoring angle style {} from restart\n",
|
utils::logmesg(lmp," restoring angle style {} from restart\n",
|
||||||
force->angle_style);
|
force->angle_style);
|
||||||
@ -944,7 +943,7 @@ void ReadRestart::force_fields()
|
|||||||
} else if (flag == DIHEDRAL) {
|
} else if (flag == DIHEDRAL) {
|
||||||
style = read_string();
|
style = read_string();
|
||||||
force->create_dihedral(style,1);
|
force->create_dihedral(style,1);
|
||||||
delete [] style;
|
delete[] style;
|
||||||
if (comm->me ==0)
|
if (comm->me ==0)
|
||||||
utils::logmesg(lmp," restoring dihedral style {} from restart\n",
|
utils::logmesg(lmp," restoring dihedral style {} from restart\n",
|
||||||
force->dihedral_style);
|
force->dihedral_style);
|
||||||
@ -953,7 +952,7 @@ void ReadRestart::force_fields()
|
|||||||
} else if (flag == IMPROPER) {
|
} else if (flag == IMPROPER) {
|
||||||
style = read_string();
|
style = read_string();
|
||||||
force->create_improper(style,1);
|
force->create_improper(style,1);
|
||||||
delete [] style;
|
delete[] style;
|
||||||
if (comm->me ==0)
|
if (comm->me ==0)
|
||||||
utils::logmesg(lmp," restoring improper style {} from restart\n",
|
utils::logmesg(lmp," restoring improper style {} from restart\n",
|
||||||
force->improper_style);
|
force->improper_style);
|
||||||
@ -1117,7 +1116,7 @@ void ReadRestart::magic_string()
|
|||||||
MPI_Bcast(str,n,MPI_CHAR,0,world);
|
MPI_Bcast(str,n,MPI_CHAR,0,world);
|
||||||
if (strcmp(str,MAGIC_STRING) != 0)
|
if (strcmp(str,MAGIC_STRING) != 0)
|
||||||
error->all(FLERR,"Invalid LAMMPS restart file");
|
error->all(FLERR,"Invalid LAMMPS restart file");
|
||||||
delete [] str;
|
delete[] str;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
@ -1164,7 +1163,7 @@ void ReadRestart::check_eof_magic()
|
|||||||
if (strcmp(str,MAGIC_STRING) != 0)
|
if (strcmp(str,MAGIC_STRING) != 0)
|
||||||
error->all(FLERR,"Incomplete or corrupted LAMMPS restart file");
|
error->all(FLERR,"Incomplete or corrupted LAMMPS restart file");
|
||||||
|
|
||||||
delete [] str;
|
delete[] str;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user