Commit 72bbabce authored by jrgissing's avatar jrgissing
Browse files

randnpos: reduce overzealous pointer usage

parent 9abf5c09
Loading
Loading
Loading
Loading
+7 −6
Original line number Diff line number Diff line
@@ -839,10 +839,10 @@ void CreateAtoms::lattice_mask()
{
  int i,j,temp,irand,nboxme;
  if (nprocs > 1) {
    int *allnlattpts = new int[nprocs]();
    int *allnboxmes = new int[nprocs]();
    int allnlattpts[nprocs];
    int allnboxmes[nprocs];

   MPI_Allgather(&nlattpts, 1, MPI_INT, allnlattpts, 1, MPI_INT, world);
   MPI_Allgather(&nlattpts, 1, MPI_INT, &allnlattpts, 1, MPI_INT, world);

   if (me == 0) {
     int total_lattpts = 0;
@@ -868,13 +868,14 @@ void CreateAtoms::lattice_mask()
        allNmask[irand] = temp;
      }

      for (i = 0; i < nprocs; i++)
        allnboxmes[i] = 0;

      for (i = 0; i < randnpos; i++)
        allnboxmes[allNmask[i]]++;
    }

    MPI_Scatter(allnboxmes, 1, MPI_INT, &nboxme, 1, MPI_INT, 0, world);
    delete [] allnlattpts;
    delete [] allnboxmes;
    MPI_Scatter(&allnboxmes, 1, MPI_INT, &nboxme, 1, MPI_INT, 0, world);
  } else {
    if (randnpos > nlattpts)
       error->one(FLERR,"Attempting to insert more particles than available lattice points");
+3 −3
Original line number Diff line number Diff line
@@ -40,6 +40,9 @@ class CreateAtoms : protected Pointers {
  char *vstr,*xstr,*ystr,*zstr;
  char *xstr_copy,*ystr_copy,*zstr_copy;

  int nlattpts,randnpos,randnflag;
  int *Nmask;                 // used to insert N number of particles on lattice

  class Molecule *onemol;
  class RanMars *ranmol;
  class RanMars *ranbox;
@@ -52,9 +55,6 @@ class CreateAtoms : protected Pointers {
  void add_lattice();
  void lattice_mask();
  void add_molecule(double *, double * = NULL);
  int nlattpts;                // number of eligible lattice points
  int *Nmask;                  // used to insert N number of particles on lattice
  int randnpos,randnflag;
  int vartest(double *);       // evaluate a variable with new atom position
};