From 330f29db0bf3c5f6b3c6c06524fb9235c7bbeaf2 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 4 May 2018 16:26:48 -0400 Subject: [PATCH 01/21] replace variable length arrays in USER-PHONON with new/delete --- src/USER-PHONON/fix_phonon.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/USER-PHONON/fix_phonon.cpp b/src/USER-PHONON/fix_phonon.cpp index cf56117892..3a37c67a38 100644 --- a/src/USER-PHONON/fix_phonon.cpp +++ b/src/USER-PHONON/fix_phonon.cpp @@ -668,7 +668,8 @@ void FixPhonon::postprocess( ) } // to get Phi = KT.G^-1; normalization of FFTW data is done here - double boltz = force->boltz, kbtsqrt[sysdim], TempAve = 0.; + double boltz = force->boltz, TempAve = 0.; + double *kbtsqrt = new double[sysdim]; double TempFac = inv_neval * inv_nTemp; double NormFac = TempFac * double(ntotal); @@ -692,7 +693,7 @@ void FixPhonon::postprocess( ) MPI_Gatherv(Phi_q[0],mynq*fft_dim2*2,MPI_DOUBLE,Phi_all[0],recvcnts,displs,MPI_DOUBLE,0,world); // to collect all basis info and averaged it on root - double basis_root[fft_dim]; + double *basis_root = new double[fft_dim]; if (fft_dim > sysdim) MPI_Reduce(&basis[1][0], &basis_root[sysdim], fft_dim-sysdim, MPI_DOUBLE, MPI_SUM, 0, world); if (me == 0){ // output dynamic matrix by root @@ -772,7 +773,8 @@ void FixPhonon::postprocess( ) } fflush(flog); } - + delete[] kbtsqrt; + delete[] basis_root; } // end of postprocess /* ---------------------------------------------------------------------- From 1d54c93df8dc4951d32735e64c924280af562e73 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 4 May 2018 16:30:52 -0400 Subject: [PATCH 02/21] replace variable length array with new/delete in PNG support of dump image --- src/image.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/image.cpp b/src/image.cpp index 599ac4a091..301a2af88f 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -1065,7 +1065,7 @@ void Image::write_PNG(FILE *fp) png_set_text(png_ptr,info_ptr,text_ptr,1); png_write_info(png_ptr,info_ptr); - png_bytep row_pointers[height]; + png_bytep *row_pointers = new png_bytep[height]; for (int i=0; i < height; ++i) row_pointers[i] = (png_bytep) &writeBuffer[(height-i-1)*3*width]; @@ -1073,6 +1073,7 @@ void Image::write_PNG(FILE *fp) png_write_end(png_ptr, info_ptr); png_destroy_write_struct(&png_ptr, &info_ptr); + delete[] row_pointers; #endif } From b61834f28d16d160005f4319c118c59a104c73fd Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 4 May 2018 16:34:46 -0400 Subject: [PATCH 03/21] replace variable length array with fixed size --- src/REPLICA/neb.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/REPLICA/neb.cpp b/src/REPLICA/neb.cpp index 35225b3c1e..e16c8c49d8 100644 --- a/src/REPLICA/neb.cpp +++ b/src/REPLICA/neb.cpp @@ -588,7 +588,7 @@ void NEB::print_status() MPI_Allgather(&fnorminf,1,MPI_DOUBLE,&fmaxatomInRepl[0],1,MPI_DOUBLE,roots); } - double one[numall]; + double one[7]; one[0] = fneb->veng; one[1] = fneb->plen; one[2] = fneb->nlen; From b11757adb3a0b6cf7f2cdd905f4fbc67667307d0 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 4 May 2018 16:47:29 -0400 Subject: [PATCH 04/21] replace variable length array in fix ipi with new/delete --- src/USER-MISC/fix_ipi.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/USER-MISC/fix_ipi.cpp b/src/USER-MISC/fix_ipi.cpp index 090a330af6..f2e791ff4e 100644 --- a/src/USER-MISC/fix_ipi.cpp +++ b/src/USER-MISC/fix_ipi.cpp @@ -428,7 +428,7 @@ void FixIPI::final_integrate() int nat=bsize/3; double **f= atom->f; - double lbuf[bsize]; + double *lbuf = double[bsize]; // reassembles the force vector from the local arrays int nlocal = atom->nlocal; @@ -440,6 +440,7 @@ void FixIPI::final_integrate() lbuf[3*(atom->tag[i]-1)+2]=f[i][2]*forceconv; } MPI_Allreduce(lbuf,buffer,bsize,MPI_DOUBLE,MPI_SUM,world); + delete[] lbuf; for (int i = 0; i < 9; ++i) vir[i]=0.0; From 5670dc5e6e0da9d6e86aaf5367bc9f5c3cbf6c31 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 4 May 2018 18:09:25 -0400 Subject: [PATCH 05/21] replace variable length array in msm with new/delete --- src/KSPACE/msm.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/KSPACE/msm.cpp b/src/KSPACE/msm.cpp index cc1ea027ee..9f3221449b 100644 --- a/src/KSPACE/msm.cpp +++ b/src/KSPACE/msm.cpp @@ -2261,7 +2261,7 @@ void MSM::restriction(int n) double ***qgrid2 = qgrid[n+1]; int k = 0; - int index[p+2]; + int *index = new int[p+2]; for (int nu=-p; nu<=p; nu++) { if (nu%2 == 0 && nu != 0) continue; phi1d[0][k] = compute_phi(nu*delxinv[n+1]/delxinv[n]); @@ -2317,7 +2317,7 @@ void MSM::restriction(int n) } qgrid2[kp][jp][ip] += q2sum; } - + delete[] index; } /* ---------------------------------------------------------------------- @@ -2348,7 +2348,7 @@ void MSM::prolongation(int n) double ***v5grid2 = v5grid[n+1]; int k = 0; - int index[p+2]; + int *index = new int[p+2]; for (int nu=-p; nu<=p; nu++) { if (nu%2 == 0 && nu != 0) continue; phi1d[0][k] = compute_phi(nu*delxinv[n+1]/delxinv[n]); @@ -2420,7 +2420,7 @@ void MSM::prolongation(int n) } } - + delete[] index; } /* ---------------------------------------------------------------------- From 6dcee30b1ae85920241c5f7f58341c783948fd1a Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 4 May 2018 18:21:22 -0400 Subject: [PATCH 06/21] replace variable length arrays in fix gle with new/delete --- src/USER-MISC/fix_gle.cpp | 81 ++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 36 deletions(-) diff --git a/src/USER-MISC/fix_gle.cpp b/src/USER-MISC/fix_gle.cpp index 5857bafc2e..584b33bfe7 100644 --- a/src/USER-MISC/fix_gle.cpp +++ b/src/USER-MISC/fix_gle.cpp @@ -44,6 +44,7 @@ using namespace FixConst; enum{NOBIAS,BIAS}; enum{CONSTANT,EQUAL,ATOM}; + //#define GLE_DEBUG 1 #define MAXLINE 1024 @@ -62,35 +63,37 @@ namespace GLE { //"stabilized" cholesky decomposition. does a LDL^t decomposition, then sets to zero the negative diagonal elements and gets MM^t void StabCholesky(int n, const double* MMt, double* M) { - double L[n*n], D[n]; + double *L = new double[n*n]; + double *D = new double[n]; - int i,j,k; - for(i=0; i0.?sqrt(D[i]):0.); - } + D[i]=(D[i]>0.0) ? sqrt(D[i]):0.0; + } - for(i=0; i=0; p--) - { - MyMult(n, n, n, SM, EM, TMP); for (int i=0; i=0; p--) { + MyMult(n, n, n, SM, EM, TMP); for (int i=0; i Date: Fri, 4 May 2018 18:32:41 -0400 Subject: [PATCH 07/21] fix newly introduced bug --- src/USER-MISC/fix_ipi.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/USER-MISC/fix_ipi.cpp b/src/USER-MISC/fix_ipi.cpp index f2e791ff4e..c4750ce49e 100644 --- a/src/USER-MISC/fix_ipi.cpp +++ b/src/USER-MISC/fix_ipi.cpp @@ -428,7 +428,7 @@ void FixIPI::final_integrate() int nat=bsize/3; double **f= atom->f; - double *lbuf = double[bsize]; + double *lbuf = new double[bsize]; // reassembles the force vector from the local arrays int nlocal = atom->nlocal; From 477d9feb5cf2d95352080912b9ac7c7aa5f5ff05 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 4 May 2018 18:48:43 -0400 Subject: [PATCH 08/21] replace variable length arrays in fix gcmc with new/delete --- src/MC/fix_gcmc.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/MC/fix_gcmc.cpp b/src/MC/fix_gcmc.cpp index 08fe7de5cb..6221e6d52c 100644 --- a/src/MC/fix_gcmc.cpp +++ b/src/MC/fix_gcmc.cpp @@ -1349,7 +1349,7 @@ void FixGCMC::attempt_molecule_insertion() MathExtra::quat_to_mat(quat,rotmat); double insertion_energy = 0.0; - bool procflag[natoms_per_molecule]; + bool *procflag = new bool[natoms_per_molecule]; for (int i = 0; i < natoms_per_molecule; i++) { MathExtra::matvec(rotmat,onemols[imol]->x[i],molcoords[i]); @@ -1472,6 +1472,7 @@ void FixGCMC::attempt_molecule_insertion() update_gas_atoms_list(); ninsertion_successes += 1.0; } + delete[] procflag; } /* ---------------------------------------------------------------------- @@ -1934,7 +1935,7 @@ void FixGCMC::attempt_molecule_deletion_full() grow_molecule_arrays(nmolq); int m = 0; - int tmpmask[atom->nlocal]; + int *tmpmask = new int[atom->nlocal]; for (int i = 0; i < atom->nlocal; i++) { if (atom->molecule[i] == deletion_molecule) { tmpmask[i] = atom->mask[i]; @@ -1982,6 +1983,7 @@ void FixGCMC::attempt_molecule_deletion_full() if (force->kspace) force->kspace->qsum_qsq(); } update_gas_atoms_list(); + delete[] tmpmask; } /* ---------------------------------------------------------------------- @@ -2426,9 +2428,9 @@ void FixGCMC::update_gas_atoms_list() for (int i = 0; i < nlocal; i++) maxmol = MAX(maxmol,molecule[i]); tagint maxmol_all; MPI_Allreduce(&maxmol,&maxmol_all,1,MPI_LMP_TAGINT,MPI_MAX,world); - double comx[maxmol_all]; - double comy[maxmol_all]; - double comz[maxmol_all]; + double *comx = new double[maxmol_all]; + double *comy = new double[maxmol_all]; + double *comz = new double[maxmol_all]; for (int imolecule = 0; imolecule < maxmol_all; imolecule++) { for (int i = 0; i < nlocal; i++) { if (molecule[i] == imolecule) { @@ -2458,7 +2460,9 @@ void FixGCMC::update_gas_atoms_list() } } } - + delete[] comx; + delete[] comy; + delete[] comz; } else { for (int i = 0; i < nlocal; i++) { if (mask[i] & groupbit) { From 345c212828fa893db28b6c1391cac7933e1a6623 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 4 May 2018 18:55:22 -0400 Subject: [PATCH 09/21] replace variable length arrays in compute basal/atom with new/delete --- src/USER-MISC/compute_basal_atom.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/USER-MISC/compute_basal_atom.cpp b/src/USER-MISC/compute_basal_atom.cpp index 1da43a6baf..4d8627a11f 100644 --- a/src/USER-MISC/compute_basal_atom.cpp +++ b/src/USER-MISC/compute_basal_atom.cpp @@ -204,8 +204,11 @@ void ComputeBasalAtom::compute_peratom() double bond_angle; double norm_j, norm_k; chi[0] = chi[1] = chi[2] = chi[3] = chi[4] = chi[5] = chi[6] = chi[7] = 0; - double x_ij, y_ij, z_ij, x_ik, y_ik, z_ik,x3[n0],y3[n0],z3[n0], - xmean5, ymean5, zmean5, xmean6, ymean6, zmean6, xmean7, ymean7, zmean7; + double x_ij, y_ij, z_ij, x_ik, y_ik, z_ik, xmean5, ymean5, zmean5, + xmean6, ymean6, zmean6, xmean7, ymean7, zmean7; + double *x3 = new double[n0]; + double *y3 = new double[n0]; + double *z3 = new double[n0]; for (j = 0; j < n0; j++) { x_ij = x[i][0]-x[nearest_n0[j]][0]; y_ij = x[i][1]-x[nearest_n0[j]][1]; @@ -411,9 +414,12 @@ void ComputeBasalAtom::compute_peratom() } } } - } - //if there are less than two ~180 degree bond angles, the algorithm returns null - else BPV[i][0] = BPV[i][1] = BPV[i][2] = 0.0; + //if there are less than two ~180 degree bond angles, the algorithm returns null + } else BPV[i][0] = BPV[i][1] = BPV[i][2] = 0.0; + + delete[] x3; + delete[] y3; + delete[] z3; //normalize BPV: double Mag = sqrt(BPV[i][0]*BPV[i][0] + From d24885f80587c6314420633c900aaadd2103a575 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 4 May 2018 19:00:43 -0400 Subject: [PATCH 10/21] replace variable length array in fix lb/momentum with fixed size array --- src/USER-LB/fix_lb_momentum.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/USER-LB/fix_lb_momentum.cpp b/src/USER-LB/fix_lb_momentum.cpp index 6cf2d3bfd0..490b95ef71 100644 --- a/src/USER-LB/fix_lb_momentum.cpp +++ b/src/USER-LB/fix_lb_momentum.cpp @@ -102,8 +102,8 @@ void FixLbMomentum::end_of_step() double masslb,masslbloc; double momentumlbloc[3],momentumlb[3]; double vcmtotal[3]; - int numvel = fix_lb_fluid->numvel; - double etacov[numvel]; + const int numvel = fix_lb_fluid->numvel; + double etacov[19]; // = double etacov[numvel]; i.e. 15 or 19 double rho; if (linear) { From 1b31b4899a86a79aa9a8403f9bd1a296cc2a6fcc Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 4 May 2018 19:06:36 -0400 Subject: [PATCH 11/21] replace variable length arrays in pair style tdpd with new/delete --- src/USER-MESO/pair_edpd.cpp | 1 - src/USER-MESO/pair_tdpd.cpp | 7 ++++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/USER-MESO/pair_edpd.cpp b/src/USER-MESO/pair_edpd.cpp index f1d9c215b4..351637a842 100644 --- a/src/USER-MESO/pair_edpd.cpp +++ b/src/USER-MESO/pair_edpd.cpp @@ -59,7 +59,6 @@ static const char cite_pair_edpd[] = " volume = {51},\n" " pages = {11038--11040}\n" "}\n\n"; -; /* ---------------------------------------------------------------------- */ diff --git a/src/USER-MESO/pair_tdpd.cpp b/src/USER-MESO/pair_tdpd.cpp index 0d0d2a3a0a..b8bbf6d622 100644 --- a/src/USER-MESO/pair_tdpd.cpp +++ b/src/USER-MESO/pair_tdpd.cpp @@ -280,7 +280,9 @@ void PairTDPD::coeff(int narg, char **arg) double power_one = force->numeric(FLERR,arg[4]); double cut_one = force->numeric(FLERR,arg[5]); double cutcc_one = force->numeric(FLERR,arg[6]); - double kappa_one[cc_species],epsilon_one[cc_species],powercc_one[cc_species]; + double *kappa_one = new double[cc_species]; + double *epsilon_one = new double[cc_species]; + double *powercc_one = new double[cc_species]; for(int k=0; knumeric(FLERR,arg[7+3*k]); epsilon_one[k] = force->numeric(FLERR,arg[8+3*k]); @@ -304,6 +306,9 @@ void PairTDPD::coeff(int narg, char **arg) setflag[i][j] = 1; count++; } + delete[] kappa_one; + delete[] epsilon_one; + delete[] powercc_one; if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } From 9a389c946cc9704eaad326027d353325e13d80dc Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 4 May 2018 19:36:57 -0400 Subject: [PATCH 12/21] replace variable length arrays in fix rx of USER-DPD with new/delete --- src/USER-DPD/fix_rx.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/USER-DPD/fix_rx.cpp b/src/USER-DPD/fix_rx.cpp index b8b002a7fa..c370f8abe6 100644 --- a/src/USER-DPD/fix_rx.cpp +++ b/src/USER-DPD/fix_rx.cpp @@ -260,6 +260,7 @@ void FixRX::post_constructor() error->all(FLERR,"fix rx cannot be combined with fix property/atom"); char **tmpspecies = new char*[maxspecies]; + int tmpmaxstrlen = 0; for(int jj=0; jj < maxspecies; jj++) tmpspecies[jj] = NULL; @@ -320,6 +321,7 @@ void FixRX::post_constructor() error->all(FLERR,"Exceeded the maximum number of species permitted in fix rx."); tmpspecies[nUniqueSpecies] = new char[strlen(word)+1]; strcpy(tmpspecies[nUniqueSpecies],word); + tmpmaxstrlen = MAX(tmpmaxstrlen,strlen(word)); nUniqueSpecies++; } word = strtok(NULL, " \t\n\r\f"); @@ -354,9 +356,9 @@ void FixRX::post_constructor() newarg2[0] = id_fix_species_old; newarg2[1] = group->names[igroup]; newarg2[2] = (char *) "property/atom"; + char *str1 = new char[tmpmaxstrlen+3]; + char *str2 = new char[tmpmaxstrlen+6]; for(int ii=0; ii Date: Fri, 4 May 2018 21:13:02 -0400 Subject: [PATCH 13/21] cast implicit string objects to char * for C++ standard compliance --- src/PYTHON/fix_python_move.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PYTHON/fix_python_move.cpp b/src/PYTHON/fix_python_move.cpp index 7331a75db6..b330ab7945 100644 --- a/src/PYTHON/fix_python_move.cpp +++ b/src/PYTHON/fix_python_move.cpp @@ -47,7 +47,7 @@ FixPythonMove::FixPythonMove(LAMMPS *lmp, int narg, char **arg) : PyGILState_STATE gstate = PyGILState_Ensure(); // add current directory to PYTHONPATH - PyObject * py_path = PySys_GetObject("path"); + PyObject * py_path = PySys_GetObject((char *)"path"); PyList_Append(py_path, PY_STRING_FROM_STRING(".")); @@ -136,7 +136,7 @@ void FixPythonMove::init() { PyGILState_STATE gstate = PyGILState_Ensure(); PyObject *py_move_obj = (PyObject *) py_move; - PyObject *py_init = PyObject_GetAttrString(py_move_obj,"init"); + PyObject *py_init = PyObject_GetAttrString(py_move_obj,(char *)"init"); if (!py_init) { PyErr_Print(); PyErr_Clear(); From 7edeccae8034a1c377ded257f1bf8ca78651da2f Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 4 May 2018 21:14:08 -0400 Subject: [PATCH 14/21] replace variable length arrays in fix filer/corotate by Memory::create() / Memory::destroy() --- src/USER-MISC/fix_filter_corotate.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/USER-MISC/fix_filter_corotate.cpp b/src/USER-MISC/fix_filter_corotate.cpp index a5f0e57041..91c7033513 100644 --- a/src/USER-MISC/fix_filter_corotate.cpp +++ b/src/USER-MISC/fix_filter_corotate.cpp @@ -1527,7 +1527,10 @@ void FixFilterCorotate::general_cluster(int index, int index_in_list) //derivative: //dn1dx: - double sum1[3][3*N]; + + double **sum1; + memory->create(sum1,3,3*N,"filter_corotate:sum1"); + for (int i=0; i<3; i++) for (int j=0; j<3*N; j++) sum1[i][j] = 0; @@ -1564,10 +1567,12 @@ void FixFilterCorotate::general_cluster(int index, int index_in_list) dn1dx[i][j] = norm1*sum; } } + memory->destroy(sum1); //dn2dx: norm2 * I3mn2n2T * (I3mn1n1T*sum2 - rkn1pn1rk*dn1dx) - double sum2[3][3*N]; + double **sum2; + memory->create(sum2,3,3*N,"filter_corotate:sum2"); for (int i=0; i<3; i++) for (int j=0; j<3*N; j++) sum2[i][j] = 0; @@ -1618,7 +1623,8 @@ void FixFilterCorotate::general_cluster(int index, int index_in_list) //dn2dx: norm2 * I3mn2n2T * (I3mn1n1T*sum2 - rkn1pn1rk*dn1dx) //sum3 = (I3mn1n1T*sum2 - rkn1pn1rk*dn1dx) - double sum3[3][3*N]; + double **sum3; + memory->create(sum3,3,3*N,"filter_corotate:sum3"); for (int i=0; i<3; i++) for (int j=0; j<3*N; j++) { double sum = 0; @@ -1627,6 +1633,7 @@ void FixFilterCorotate::general_cluster(int index, int index_in_list) sum3[i][j] = sum; } + memory->destroy(sum2); //dn2dx = norm2 * I3mn2n2T * sum3 for (int i=0; i<3; i++) for (int j=0; j<3*N; j++) { @@ -1636,6 +1643,7 @@ void FixFilterCorotate::general_cluster(int index, int index_in_list) dn2dx[i][j] = norm2*sum; } + memory->destroy(sum3); //dn3dx = norm3 * I3mn3n3T * cross double I3mn3n3T[3][3]; //(I_3 - n3n3T) for (int i=0; i<3; i++) { @@ -1644,7 +1652,8 @@ void FixFilterCorotate::general_cluster(int index, int index_in_list) I3mn3n3T[i][i] += 1.0; } - double cross[3][3*N]; + double **cross; + memory->create(cross,3,3*N,"filter_corotate:cross"); for (int j=0; j<3*N; j++) { cross[0][j] = dn1dx[1][j]*n2[2] -dn1dx[2][j]*n2[1] + @@ -1663,6 +1672,7 @@ void FixFilterCorotate::general_cluster(int index, int index_in_list) dn3dx[i][j] = norm3*sum; } + memory->destroy(cross); for (int l=0; l Date: Fri, 4 May 2018 21:41:23 -0400 Subject: [PATCH 15/21] replace variable length array in Molecule class with new/delete --- src/molecule.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/molecule.cpp b/src/molecule.cpp index b03142e984..56e56dab2c 100644 --- a/src/molecule.cpp +++ b/src/molecule.cpp @@ -1111,7 +1111,7 @@ void Molecule::special_generate() { int newton_bond = force->newton_bond; tagint atom1,atom2; - int count[natoms]; + int *count = new int[natoms]; // temporary array for special atoms @@ -1197,6 +1197,7 @@ void Molecule::special_generate() } } } + delete[] count; maxspecial = 0; for (int i = 0; i < natoms; i++) From 974ea3420b18a2f70eda89ba729cb8497985c2ac Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 4 May 2018 21:45:17 -0400 Subject: [PATCH 16/21] replace variable length array in fix drude/transform with new/delete --- src/USER-DRUDE/fix_drude_transform.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/USER-DRUDE/fix_drude_transform.cpp b/src/USER-DRUDE/fix_drude_transform.cpp index 29c1ff8821..bdb5d95acc 100644 --- a/src/USER-DRUDE/fix_drude_transform.cpp +++ b/src/USER-DRUDE/fix_drude_transform.cpp @@ -75,7 +75,7 @@ void FixDrudeTransform::setup(int) { if (!rmass) { if (!mcoeff) mcoeff = new double[ntypes+1]; - double mcoeff_loc[ntypes+1]; + double *mcoeff_loc = new double[ntypes+1]; for (int itype=0; itype<=ntypes; itype++) mcoeff_loc[itype] = 2.; // an impossible value: mcoeff is at most 1. for (int i=0; i::setup(int) { // mcoeff is 2 for non polarizable // 0 < mcoeff < 1 for drude // mcoeff < 0 for core + delete[] mcoeff_loc; } } From d53dc541d8c45d495888d5ab0247b44fc2f24918 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 4 May 2018 21:48:44 -0400 Subject: [PATCH 17/21] avoiding variable length array in pair style comb3 by declaring MAXLIB const --- src/MANYBODY/pair_comb3.cpp | 40 ++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/MANYBODY/pair_comb3.cpp b/src/MANYBODY/pair_comb3.cpp index e38a05c6ed..b4f9c02206 100644 --- a/src/MANYBODY/pair_comb3.cpp +++ b/src/MANYBODY/pair_comb3.cpp @@ -310,10 +310,10 @@ double PairComb3::init_one(int i, int j) void PairComb3::read_lib() { - unsigned int maxlib = 1024; + const unsigned int MAXLIB = 1024; int i,j,k,l,nwords,m; int ii,jj,kk,ll,mm,iii; - char s[maxlib]; + char s[MAXLIB]; char **words = new char*[80]; // open libraray file on proc 0 @@ -327,8 +327,8 @@ void PairComb3::read_lib() } // read and store at the same time - fgets(s,maxlib,fp); - fgets(s,maxlib,fp); + fgets(s,MAXLIB,fp); + fgets(s,MAXLIB,fp); nwords = 0; words[nwords++] = strtok(s," \t\n\r\f"); while ((words[nwords++] = strtok(NULL," \t\n\r\f")))continue; @@ -339,7 +339,7 @@ void PairComb3::read_lib() ccutoff[4] = atof(words[4]); ccutoff[5] = atof(words[5]); - fgets(s,maxlib,fp); + fgets(s,MAXLIB,fp); nwords = 0; words[nwords++] = strtok(s," \t\n\r\f"); while ((words[nwords++] = strtok(NULL," \t\n\r\f")))continue; @@ -351,7 +351,7 @@ void PairComb3::read_lib() ch_a[5] = atof(words[5]); ch_a[6] = atof(words[6]); - fgets(s,maxlib,fp); + fgets(s,MAXLIB,fp); nwords = 0; words[nwords++] = strtok(s," \t\n\r\f"); while ((words[nwords++] = strtok(NULL," \t\n\r\f")))continue; @@ -359,7 +359,7 @@ void PairComb3::read_lib() nsplrad = atoi(words[1]); nspltor = atoi(words[2]); - fgets(s,maxlib,fp); + fgets(s,MAXLIB,fp); nwords = 0; words[nwords++] = strtok(s," \t\n\r\f"); while ((words[nwords++] = strtok(NULL," \t\n\r\f")))continue; @@ -367,7 +367,7 @@ void PairComb3::read_lib() maxy = atoi(words[1]); maxz = atoi(words[2]); - fgets(s,maxlib,fp); + fgets(s,MAXLIB,fp); nwords = 0; words[nwords++] = strtok(s," \t\n\r\f"); while ((words[nwords++] = strtok(NULL," \t\n\r\f")))continue; @@ -376,7 +376,7 @@ void PairComb3::read_lib() maxconj = atoi(words[2]); for (l=0; l Date: Fri, 4 May 2018 22:17:25 -0400 Subject: [PATCH 18/21] address a few cosmetic issues flagged by -Wpedantic --- src/USER-DRUDE/fix_drude_transform.cpp | 4 ++-- src/USER-SMD/fix_smd_integrate_ulsph.h | 2 +- src/USER-UEF/fix_nh_uef.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/USER-DRUDE/fix_drude_transform.cpp b/src/USER-DRUDE/fix_drude_transform.cpp index bdb5d95acc..34742a0683 100644 --- a/src/USER-DRUDE/fix_drude_transform.cpp +++ b/src/USER-DRUDE/fix_drude_transform.cpp @@ -314,6 +314,6 @@ void FixDrudeTransform::unpack_forward_comm(int n, int first, double *b } /* ---------------------------------------------------------------------- */ -template class FixDrudeTransform; -template class FixDrudeTransform; +template class LAMMPS_NS::FixDrudeTransform; +template class LAMMPS_NS::FixDrudeTransform; diff --git a/src/USER-SMD/fix_smd_integrate_ulsph.h b/src/USER-SMD/fix_smd_integrate_ulsph.h index ea4f46ce53..9d954bf529 100644 --- a/src/USER-SMD/fix_smd_integrate_ulsph.h +++ b/src/USER-SMD/fix_smd_integrate_ulsph.h @@ -48,7 +48,7 @@ class FixSMDIntegrateUlsph : public Fix { private: class NeighList *list; protected: - double dtv,dtf, vlimit, vlimitsq;; + double dtv,dtf, vlimit, vlimitsq; int mass_require; bool xsphFlag; bool adjust_radius_flag; diff --git a/src/USER-UEF/fix_nh_uef.h b/src/USER-UEF/fix_nh_uef.h index 43f5bb46a9..0629db5aa1 100644 --- a/src/USER-UEF/fix_nh_uef.h +++ b/src/USER-UEF/fix_nh_uef.h @@ -23,7 +23,7 @@ namespace LAMMPS_NS { // forward declaration namespace UEF_utils { class UEFBox; - }; + } class FixNHUef : public FixNH { public: From b7210e931c01a8e282c2a20fcb985b7677ff10f5 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 4 May 2018 22:26:53 -0400 Subject: [PATCH 19/21] more cosmetic changes to silence pedantic warnings --- src/REPLICA/neb.cpp | 6 ++++-- src/RIGID/fix_rigid.cpp | 2 +- src/USER-MISC/pair_lj_sf_dipole_sf.cpp | 2 +- src/library.cpp | 5 +---- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/REPLICA/neb.cpp b/src/REPLICA/neb.cpp index e16c8c49d8..c9aedf7401 100644 --- a/src/REPLICA/neb.cpp +++ b/src/REPLICA/neb.cpp @@ -303,7 +303,7 @@ void NEB::run() update->minimize->setup(); if (me_universe == 0) { - if (uscreen) + if (uscreen) { if (verbose) { fprintf(uscreen,"Step MaxReplicaForce MaxAtomForce " "GradV0 GradV1 GradVc EBF EBR RDT " @@ -317,7 +317,8 @@ void NEB::run() "EBF EBR RDT " "RD1 PE1 RD2 PE2 ... RDN PEN\n"); } - if (ulogfile) + } + if (ulogfile) { if (verbose) { fprintf(ulogfile,"Step MaxReplicaForce MaxAtomForce " "GradV0 GradV1 GradVc EBF EBR RDT " @@ -331,6 +332,7 @@ void NEB::run() "EBF EBR RDT " "RD1 PE1 RD2 PE2 ... RDN PEN\n"); } + } } print_status(); diff --git a/src/RIGID/fix_rigid.cpp b/src/RIGID/fix_rigid.cpp index 554412330c..3d9e24ced9 100644 --- a/src/RIGID/fix_rigid.cpp +++ b/src/RIGID/fix_rigid.cpp @@ -2342,7 +2342,7 @@ void FixRigid::write_restart_file(char *file) sprintf(outfile,"%s.rigid",file); FILE *fp = fopen(outfile,"w"); if (fp == NULL) { - char str[128]; + char str[192]; sprintf(str,"Cannot open fix rigid restart file %s",outfile); error->one(FLERR,str); } diff --git a/src/USER-MISC/pair_lj_sf_dipole_sf.cpp b/src/USER-MISC/pair_lj_sf_dipole_sf.cpp index cc92bfc30f..523b2ca71a 100644 --- a/src/USER-MISC/pair_lj_sf_dipole_sf.cpp +++ b/src/USER-MISC/pair_lj_sf_dipole_sf.cpp @@ -539,7 +539,7 @@ double PairLJSFDipoleSF::single(int i, int j, int itype, int jtype, double rsq, double &fforce) { double r2inv,r6inv; - double pdotp,pidotr,pjdotr,pre1,delx,dely,delz; + double pdotp,pidotr,pjdotr,delx,dely,delz; double rinv, r3inv,r5inv, rcutlj2inv, rcutcoul2inv,rcutlj6inv; double qtmp,xtmp,ytmp,ztmp,bfac,pqfac,qpfac, ecoul, evdwl; diff --git a/src/library.cpp b/src/library.cpp index 865bf2a0a5..0162c560ce 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -933,7 +933,7 @@ void lammps_gather_atoms_concat(void *ptr, char *name, BEGIN_CAPTURE { - int i,j,offset; + int i,offset; // error if tags are not defined // NOTE: test that name = image or ids is not a 64-bit int in code? @@ -975,7 +975,6 @@ void lammps_gather_atoms_concat(void *ptr, char *name, lmp->memory->create(copy,count*natoms,"lib/gather:copy"); for (i = 0; i < count*natoms; i++) copy[i] = 0; - tagint *tag = lmp->atom->tag; int nlocal = lmp->atom->nlocal; if (count == 1) { @@ -1117,7 +1116,6 @@ void lammps_gather_atoms_subset(void *ptr, char *name, lmp->memory->create(copy,count*ndata,"lib/gather:copy"); for (i = 0; i < count*ndata; i++) copy[i] = 0; - tagint *tag = lmp->atom->tag; int nlocal = lmp->atom->nlocal; if (count == 1) { @@ -1163,7 +1161,6 @@ void lammps_gather_atoms_subset(void *ptr, char *name, lmp->memory->create(copy,count*ndata,"lib/gather:copy"); for (i = 0; i < count*ndata; i++) copy[i] = 0.0; - tagint *tag = lmp->atom->tag; int nlocal = lmp->atom->nlocal; if (count == 1) { From e14b61e4a49d40c275ae7474db911ce4f5be123a Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 5 May 2018 19:51:30 -0400 Subject: [PATCH 20/21] replace variable length array with constant length through making maxLine constant --- src/KIM/pair_kim.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/KIM/pair_kim.cpp b/src/KIM/pair_kim.cpp index 46e843158a..fe638214ba 100644 --- a/src/KIM/pair_kim.cpp +++ b/src/KIM/pair_kim.cpp @@ -1264,15 +1264,15 @@ void *PairKIM::extract(const char *str, int &dim) int ier; int dummyint; int isIndexed = 0; - int maxLine = 1024; + const int MAXLINE = 1024; int rank; int validParam = 0; int numParams; - int *speciesIndex = new int[maxLine]; - char *paramStr = new char[maxLine]; + int *speciesIndex = new int[MAXLINE]; + char *paramStr = new char[MAXLINE]; char *paramName; char *indexStr; - char message[maxLine]; + char message[MAXLINE]; int offset; double* paramPtr; @@ -1354,7 +1354,7 @@ void *PairKIM::extract(const char *str, int &dim) } kim_error(__LINE__,"get_rank",kimerror); - int *shape = new int[maxLine]; + int *shape = new int[MAXLINE]; dummyint = (*pkim).get_shape(paramName, shape, &kimerror); if (kimerror == KIM_STATUS_FAIL) { From 9d6891823aebb96838b4f8b2b7f149027a1e4a8c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 5 May 2018 20:38:22 -0400 Subject: [PATCH 21/21] some more cosmetic changes --- src/GPU/gpu_extra.h | 4 ++-- src/USER-MEAMC/meam.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/GPU/gpu_extra.h b/src/GPU/gpu_extra.h index ddb0b5ceaa..56a4f15f1b 100644 --- a/src/GPU/gpu_extra.h +++ b/src/GPU/gpu_extra.h @@ -61,13 +61,13 @@ namespace GPU_EXTRA { else error->all(FLERR,"Unknown error in GPU library"); } - }; + } inline void gpu_ready(LAMMPS_NS::Modify *modify, LAMMPS_NS::Error *error) { int ifix = modify->find_fix("package_gpu"); if (ifix < 0) error->all(FLERR,"The package gpu command is required for gpu styles"); - }; + } } #endif diff --git a/src/USER-MEAMC/meam.h b/src/USER-MEAMC/meam.h index 8a439a2118..42fd722e01 100644 --- a/src/USER-MEAMC/meam.h +++ b/src/USER-MEAMC/meam.h @@ -255,5 +255,5 @@ static inline double fdiv_zero(const double n, const double d) { return n / d; } -}; +} #endif