Merge pull request #2395 from rbberger/collected-small-fixes

Fixes issues found via Static Code Analysis and from bug reports
This commit is contained in:
Axel Kohlmeyer 2020-09-30 19:23:52 -04:00 committed by GitHub
commit 6928e79883
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 65 additions and 37 deletions

4
.github/CODEOWNERS vendored
View File

@ -114,6 +114,7 @@ src/info.* @akohlmey @rbberger
src/timer.* @akohlmey
src/min* @sjplimp @stanmoore1
src/utils.* @akohlmey @rbberger
src/math_eigen_impl.h @jewettaij
# tools
tools/msi2lmp/* @akohlmey
@ -134,6 +135,9 @@ cmake/presets/*.cmake @junghans @rbberger @akohlmey
# python
python/* @rbberger
# fortran
fortran/* @akohlmey
# docs
doc/utils/*/* @rbberger
doc/Makefile @rbberger

View File

@ -1,7 +1,8 @@
# preset that will enable clang/clang++ with support for MPI and OpenMP (on Linux boxes)
# preset that will enable Intel compilers with support for MPI and OpenMP (on Linux boxes)
set(CMAKE_CXX_COMPILER "icpc" CACHE STRING "" FORCE)
set(CMAKE_C_COMPILER "icc" CACHE STRING "" FORCE)
set(CMAKE_Fortran_COMPILER "ifort" CACHE STRING "" FORCE)
set(MPI_CXX "icpc" CACHE STRING "" FORCE)
set(MPI_CXX_COMPILER "mpicxx" CACHE STRING "" FORCE)
unset(HAVE_OMP_H_INCLUDE CACHE)
@ -12,5 +13,6 @@ set(OpenMP_C_LIB_NAMES "omp" CACHE STRING "" FORCE)
set(OpenMP_CXX "icpc" CACHE STRING "" FORCE)
set(OpenMP_CXX_FLAGS "-qopenmp" CACHE STRING "" FORCE)
set(OpenMP_CXX_LIB_NAMES "omp" CACHE STRING "" FORCE)
set(OpenMP_Fortran_FLAGS "-qopenmp" CACHE STRING "" FORCE)
set(OpenMP_omp_LIBRARY "libiomp5.so" CACHE PATH "" FORCE)

View File

@ -663,6 +663,7 @@ The singularity sub-directory contains container definitions files
that can be used to build container images for building and testing
LAMMPS on specific OS variants using the `Singularity <https://sylabs.io>`_
container software. Contributions for additional variants are welcome.
For more details please see the README.md file in that folder.
----------

View File

@ -74,7 +74,6 @@ void PairLineLJ::compute(int eflag, int vflag)
double xi[2],xj[2],fi[2],dxi,dxj,dyi,dyj;
int *ilist,*jlist,*numneigh,**firstneigh;
evdwl = 0.0;
ev_init(eflag,vflag);
double **x = atom->x;

View File

@ -74,7 +74,6 @@ void PairTriLJ::compute(int eflag, int vflag)
double dc1[3],dc2[3],dc3[3];
int *ilist,*jlist,*numneigh,**firstneigh;
evdwl = 0.0;
ev_init(eflag,vflag);
AtomVecTri::Bonus *bonus = avec->bonus;

View File

@ -123,7 +123,7 @@ void ComputeBodyLocal::compute_local()
int ncount = compute_body(0);
if (ncount > nmax) reallocate(ncount);
size_local_rows = ncount;
ncount = compute_body(1);
compute_body(1);
}
/* ----------------------------------------------------------------------

View File

@ -343,7 +343,6 @@ void ComputeTempBody::compute_vector()
inertia = bonus[body[i]].inertia;
quat = bonus[body[i]].quat;
massone = rmass[i];
// wbody = angular velocity in body frame

View File

@ -447,10 +447,6 @@ double AngleClass2::single(int type, int i1, int i2, int i3)
if (c > 1.0) c = 1.0;
if (c < -1.0) c = -1.0;
double s = sqrt(1.0 - c*c);
if (s < SMALL) s = SMALL;
s = 1.0/s;
double dtheta = acos(c) - theta0[type];
double dtheta2 = dtheta*dtheta;
double dtheta3 = dtheta2*dtheta;

View File

@ -298,7 +298,7 @@ void NEBSpin::run()
fprintf(uscreen,"Step MaxReplicaTorque MaxAtomTorque "
"GradV0 GradV1 GradVc EBF EBR RDT "
"RD1 PE1 RD2 PE2 ... RDN PEN "
"GradV0dottan DN0... GradVNdottan DNN\n");
"GradV0dottan DN0 ... GradVNdottan DNN\n");
} else {
fprintf(uscreen,"Step MaxReplicaTorque MaxAtomTorque "
"GradV0 GradV1 GradVc "

View File

@ -379,7 +379,7 @@ void PairSpinDipoleCut::compute_dipolar(int /* i */, int /* j */, double eij[3],
------------------------------------------------------------------------- */
void PairSpinDipoleCut::compute_dipolar_mech(int /* i */, int /* j */, double eij[3],
double fi[3], double spi[3], double spj[3], double r2inv)
double fi[3], double spi[4], double spj[4], double r2inv)
{
double sisj,sieij,sjeij;
double gigjri4,bij,pre;

View File

@ -453,7 +453,7 @@ void PairSpinDipoleLong::compute_long(int /* i */, int /* j */, double eij[3],
------------------------------------------------------------------------- */
void PairSpinDipoleLong::compute_long_mech(int /* i */, int /* j */, double eij[3],
double bij[4], double fi[3], double spi[3], double spj[3])
double bij[4], double fi[3], double spi[4], double spj[4])
{
double sisj,sieij,sjeij,b2,b3;
double g1,g2,g1b2_g2b3,gigj,pre;

View File

@ -160,9 +160,9 @@ FixIntel::FixIntel(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg)
// if using LRT mode, create the integrate style
if (_lrt) {
char *str;
str = (char *) "verlet/lrt/intel";
update->create_integrate(1,&str,0);
char *cmd[1];
cmd[0] = (char *) "verlet/lrt/intel";
update->create_integrate(1,cmd,0);
}
// error check

View File

@ -184,8 +184,8 @@ void BondSpecial::read_restart(FILE *fp)
allocate();
if (comm->me == 0) {
fread(&factor_lj[1],sizeof(double),atom->nbondtypes,fp);
fread(&factor_coul[1],sizeof(double),atom->nbondtypes,fp);
utils::sfread(FLERR,&factor_lj[1],sizeof(double),atom->nbondtypes,fp,nullptr,error);
utils::sfread(FLERR,&factor_coul[1],sizeof(double),atom->nbondtypes,fp,nullptr,error);
}
MPI_Bcast(&factor_lj[1],atom->nbondtypes,MPI_DOUBLE,0,world);
MPI_Bcast(&factor_coul[1],atom->nbondtypes,MPI_DOUBLE,0,world);

View File

@ -160,13 +160,13 @@ template <int filter_by_type>
void FixPropelSelf::post_force_quaternion(int /* vflag */ )
{
double **f = atom->f;
AtomVecEllipsoid *av = static_cast<AtomVecEllipsoid*>(atom->avec);
int *mask = atom->mask;
int nlocal = atom->nlocal;
int *type = atom->type;
int* ellipsoid = atom->ellipsoid;
AtomVecEllipsoid *av = static_cast<AtomVecEllipsoid*>(atom->style_match("ellipsoid"));
AtomVecEllipsoid::Bonus *bonus = av->bonus;
// Add the active force to the atom force:

View File

@ -152,10 +152,10 @@ void PairCoulSlaterCut::write_restart_settings(FILE *fp)
void PairCoulSlaterCut::read_restart_settings(FILE *fp)
{
if (comm->me == 0) {
fread(&cut_global,sizeof(double),1,fp);
fread(&lamda,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,nullptr,error);
utils::sfread(FLERR,&lamda,sizeof(double),1,fp,nullptr,error);
utils::sfread(FLERR,&offset_flag,sizeof(int),1,fp,nullptr,error);
utils::sfread(FLERR,&mix_flag,sizeof(int),1,fp,nullptr,error);
}
MPI_Bcast(&cut_global,1,MPI_DOUBLE,0,world);
MPI_Bcast(&lamda,1,MPI_DOUBLE,0,world);

View File

@ -78,10 +78,10 @@ FixOMP::FixOMP(LAMMPS *lmp, int narg, char **arg)
#endif
}
#if defined(_OPENMP)
if (nthreads < 1)
error->all(FLERR,"Illegal number of OpenMP threads requested");
#if defined(_OPENMP)
int reset_thr = 0;
#endif
if (nthreads != comm->nthreads) {

View File

@ -78,7 +78,7 @@ double ComputePressureUef::compute_scalar()
addstep(update->ntimestep+1);
int k =0;
scalar = 0;
scalar = 0.0;
if (ext_flags[0]) {
scalar += vector[0];
k++;
@ -92,7 +92,7 @@ double ComputePressureUef::compute_scalar()
k++;
}
scalar /= k;
if (k > 1) scalar /= k;
return scalar;
}

View File

@ -176,7 +176,7 @@ void ChangeBox::command(int narg, char **arg)
int move_atoms = 0;
for (int m = 0; m < nops; m++) {
if (ops[m].style != ORTHO || ops[m].style != TRICLINIC) move_atoms = 1;
if (ops[m].style != ORTHO && ops[m].style != TRICLINIC) move_atoms = 1;
}
// error if moving atoms and there is stored per-atom restart state

View File

@ -36,7 +36,7 @@ using namespace LAMMPS_NS;
ComputePressure::ComputePressure(LAMMPS *lmp, int narg, char **arg) :
Compute(lmp, narg, arg),
vptr(nullptr), id_temp(nullptr)
vptr(nullptr), id_temp(nullptr), pstyle(nullptr)
{
if (narg < 4) error->all(FLERR,"Illegal compute pressure command");
if (igroup) error->all(FLERR,"Compute pressure must use group all");
@ -146,6 +146,7 @@ ComputePressure::~ComputePressure()
delete [] id_temp;
delete [] vector;
delete [] vptr;
delete [] pstyle;
}
/* ---------------------------------------------------------------------- */

View File

@ -1234,12 +1234,11 @@ void Input::shell()
} else if (strcmp(arg[0],"putenv") == 0) {
if (narg < 2) error->all(FLERR,"Illegal shell putenv command");
for (int i = 1; i < narg; i++) {
char *ptr = strdup(arg[i]);
rv = 0;
#ifdef _WIN32
if (ptr != nullptr) rv = _putenv(ptr);
if (arg[i]) rv = _putenv(arg[i]);
#else
if (ptr != nullptr) rv = putenv(ptr);
if (arg[i]) rv = putenv(arg[i]);
#endif
rv = (rv < 0) ? errno : 0;
MPI_Reduce(&rv,&err,1,MPI_INT,MPI_MAX,0,world);

View File

@ -849,6 +849,8 @@ void Jacobi<Scalar, Vector, Matrix, ConstMatrix>::
Dealloc() {
//assert(! is_preallocated);
Dealloc2D(&M);
delete[] max_idx_row;
max_idx_row = nullptr;
Init();
}

View File

@ -368,9 +368,9 @@ void ResetIDs::sort()
// bins are numbered from 0 to Nbins-1
bigint nbins = (bigint) nbinx*nbiny*nbinz;
int nlo = nbins / nprocs;
int nhi = nlo + 1;
int nplo = nprocs - (nbins % nprocs);
bigint nlo = nbins / nprocs;
bigint nhi = nlo + 1;
bigint nplo = nprocs - (nbins % nprocs);
bigint nbinlo = nplo*nlo;
if (me < nplo) {

View File

@ -5,12 +5,12 @@ for [Singularity](https://sylabs.io), suitable for compiling and testing
LAMMPS on a variety of OS variants with support for most standard
packages and - for some of them - also building/spellchecking the manual
in all supported formats. This allows to test and debug LAMMPS code on
different OS variants than what is locally installed on your development
different OS variants without doing a full installation on your development
workstation, e.g. when bugs are reported that can only be reproduced on
a specific OS or with specific (mostly older) versions of tools,
compilers, or libraries.
Ready-to-use container images built from these definition files are
Ready-to-use container images built from some these definition files are
occasionally uploaded to the container library at sylabs.io. They
can be found here: https://cloud.sylabs.io/library/lammps/default/lammps_development#
and will be signed with a GPG key that has the fingerprint:
@ -25,7 +25,7 @@ git clone --depth 500 git://github.com/lammps/lammps.git lammps
mkdir build-centos7
cd build-centos7
sudo singularity build centos7.sif ../tools/singularity/centos7.def
singularity shell centos7.sif
singularity exec centos7.sif bash --login
cmake -C ../cmake/presets/most.cmake ../cmake
make
```
@ -39,7 +39,7 @@ git clone --depth 500 git://github.com/lammps/lammps.git lammps
mkdir build-ubuntu18
cd build-ubuntu18
singularity pull library://lammps/default/lammps_development:ubuntu18.04
singularity shell lammps_development_ubuntu18.04.sif
singularity exec lammps_development_ubuntu18.04.sif bash --login
cmake -C ../cmake/presets/most.cmake ../cmake
make
```

View File

@ -312,6 +312,32 @@ TEST_F(SimpleCommandsTest, Units)
TEST_FAILURE(".*ERROR: Illegal units command.*", lmp->input->one("units unknown"););
}
TEST_F(SimpleCommandsTest, Shell)
{
if (!verbose) ::testing::internal::CaptureStdout();
lmp->input->one("shell putenv TEST_VARIABLE=simpletest");
if (!verbose) ::testing::internal::GetCapturedStdout();
char * test_var = getenv("TEST_VARIABLE");
ASSERT_NE(test_var, nullptr);
ASSERT_THAT(test_var, StrEq("simpletest"));
if (!verbose) ::testing::internal::CaptureStdout();
lmp->input->one("shell putenv TEST_VARIABLE=simpletest");
lmp->input->one("shell putenv TEST_VARIABLE2=simpletest2 OTHER_VARIABLE=2");
if (!verbose) ::testing::internal::GetCapturedStdout();
char * test_var2 = getenv("TEST_VARIABLE2");
char * other_var = getenv("OTHER_VARIABLE");
ASSERT_NE(test_var2, nullptr);
ASSERT_THAT(test_var2, StrEq("simpletest2"));
ASSERT_NE(other_var, nullptr);
ASSERT_THAT(other_var, StrEq("2"));
}
} // namespace LAMMPS_NS
int main(int argc, char **argv)