From 8dad49156d202e45477285db3e3dc2658807c005 Mon Sep 17 00:00:00 2001 From: sjplimp <sjplimp@f3b2605a-c512-4ea7-a41b-209d697bcdaa> Date: Wed, 16 Mar 2011 15:21:59 +0000 Subject: [PATCH] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@5792 f3b2605a-c512-4ea7-a41b-209d697bcdaa --- src/ASPHERE/atom_vec_ellipsoid.cpp | 29 +-- src/COLLOID/atom_vec_colloid.cpp | 28 +-- src/DIPOLE/atom_vec_dipole.cpp | 32 +-- src/GRANULAR/atom_vec_granular.cpp | 37 ++- src/MOLECULE/atom_vec_angle.cpp | 72 +++--- src/MOLECULE/atom_vec_bond.cpp | 49 ++-- src/MOLECULE/atom_vec_full.cpp | 144 +++++------- src/MOLECULE/atom_vec_molecular.cpp | 141 +++++------- src/PERI/atom_vec_peri.cpp | 34 ++- src/USER-EFF/atom_vec_electron.cpp | 38 ++-- src/atom.cpp | 167 +++++++------- src/atom_vec_atomic.cpp | 18 +- src/atom_vec_charge.cpp | 23 +- src/comm.cpp | 112 ++++----- src/memory.cpp | 46 +++- src/memory.h | 342 ++++++++++++++++++++++++++++ src/neigh_bond.cpp | 28 +-- src/neigh_list.cpp | 49 ++-- src/neigh_request.cpp | 2 +- src/neigh_stencil.cpp | 1 - src/neighbor.cpp | 90 ++++---- 21 files changed, 849 insertions(+), 633 deletions(-) diff --git a/src/ASPHERE/atom_vec_ellipsoid.cpp b/src/ASPHERE/atom_vec_ellipsoid.cpp index b6aebdee28..11e90e74d0 100755 --- a/src/ASPHERE/atom_vec_ellipsoid.cpp +++ b/src/ASPHERE/atom_vec_ellipsoid.cpp @@ -66,24 +66,17 @@ void AtomVecEllipsoid::grow(int n) if (nmax < 0 || nmax > MAXSMALLINT) error->one("Per-processor system is too big"); - tag = atom->tag = (int *) - memory->srealloc(atom->tag,nmax*sizeof(int),"atom:tag"); - type = atom->type = (int *) - memory->srealloc(atom->type,nmax*sizeof(int),"atom:type"); - mask = atom->mask = (int *) - memory->srealloc(atom->mask,nmax*sizeof(int),"atom:mask"); - image = atom->image = (int *) - memory->srealloc(atom->image,nmax*sizeof(int),"atom:image"); - x = atom->x = memory->grow_2d_double_array(atom->x,nmax,3,"atom:x"); - v = atom->v = memory->grow_2d_double_array(atom->v,nmax,3,"atom:v"); - f = atom->f = memory->grow_2d_double_array(atom->f,nmax,3,"atom:f"); - - quat = atom->quat = - memory->grow_2d_double_array(atom->quat,nmax,4,"atom:quat"); - angmom = atom->angmom = - memory->grow_2d_double_array(atom->angmom,nmax,3,"atom:angmom"); - torque = atom->torque = - memory->grow_2d_double_array(atom->torque,nmax,3,"atom:torque"); + tag = memory->grow(atom->tag,nmax,"atom:tag"); + type = memory->grow(atom->type,nmax,"atom:type"); + mask = memory->grow(atom->mask,nmax,"atom:mask"); + image = memory->grow(atom->image,nmax,"atom:image"); + x = memory->grow(atom->x,nmax,3,"atom:x"); + v = memory->grow(atom->v,nmax,3,"atom:v"); + f = memory->grow(atom->f,nmax,3,"atom:f"); + + quat = memory->grow(atom->quat,nmax,4,"atom:quat"); + angmom = memory->grow(atom->angmom,nmax,3,"atom:angmom"); + torque = memory->grow(atom->torque,nmax,3,"atom:torque"); if (atom->nextra_grow) for (int iextra = 0; iextra < atom->nextra_grow; iextra++) diff --git a/src/COLLOID/atom_vec_colloid.cpp b/src/COLLOID/atom_vec_colloid.cpp index 19219376b4..601692ac72 100644 --- a/src/COLLOID/atom_vec_colloid.cpp +++ b/src/COLLOID/atom_vec_colloid.cpp @@ -62,23 +62,17 @@ void AtomVecColloid::grow(int n) if (nmax < 0 || nmax > MAXSMALLINT) error->one("Per-processor system is too big"); - tag = atom->tag = (int *) - memory->srealloc(atom->tag,nmax*sizeof(int),"atom:tag"); - type = atom->type = (int *) - memory->srealloc(atom->type,nmax*sizeof(int),"atom:type"); - mask = atom->mask = (int *) - memory->srealloc(atom->mask,nmax*sizeof(int),"atom:mask"); - image = atom->image = (int *) - memory->srealloc(atom->image,nmax*sizeof(int),"atom:image"); - x = atom->x = memory->grow_2d_double_array(atom->x,nmax,3,"atom:x"); - v = atom->v = memory->grow_2d_double_array(atom->v,nmax,3,"atom:v"); - f = atom->f = memory->grow_2d_double_array(atom->f,nmax,3,"atom:f"); - - omega = atom->omega = - memory->grow_2d_double_array(atom->omega,nmax,3,"atom:omega"); - torque = atom->torque = - memory->grow_2d_double_array(atom->torque,nmax,3,"atom:torque"); - + tag = memory->grow(atom->tag,nmax,"atom:tag"); + type = memory->grow(atom->type,nmax,"atom:type"); + mask = memory->grow(atom->mask,nmax,"atom:mask"); + image = memory->grow(atom->image,nmax,"atom:image"); + x = memory->grow(atom->x,nmax,3,"atom:x"); + v = memory->grow(atom->v,nmax,3,"atom:v"); + f = memory->grow(atom->f,nmax,3,"atom:f"); + + omega = memory->grow(atom->omega,nmax,3,"atom:omega"); + torque = memory->grow(atom->torque,nmax,3,"atom:torque"); + if (atom->nextra_grow) for (int iextra = 0; iextra < atom->nextra_grow; iextra++) modify->fix[atom->extra_grow[iextra]]->grow_arrays(nmax); diff --git a/src/DIPOLE/atom_vec_dipole.cpp b/src/DIPOLE/atom_vec_dipole.cpp index 97b3980a4c..4facc8c3a7 100644 --- a/src/DIPOLE/atom_vec_dipole.cpp +++ b/src/DIPOLE/atom_vec_dipole.cpp @@ -61,26 +61,18 @@ void AtomVecDipole::grow(int n) if (nmax < 0 || nmax > MAXSMALLINT) error->one("Per-processor system is too big"); - tag = atom->tag = (int *) - memory->srealloc(atom->tag,nmax*sizeof(int),"atom:tag"); - type = atom->type = (int *) - memory->srealloc(atom->type,nmax*sizeof(int),"atom:type"); - mask = atom->mask = (int *) - memory->srealloc(atom->mask,nmax*sizeof(int),"atom:mask"); - image = atom->image = (int *) - memory->srealloc(atom->image,nmax*sizeof(int),"atom:image"); - x = atom->x = memory->grow_2d_double_array(atom->x,nmax,3,"atom:x"); - v = atom->v = memory->grow_2d_double_array(atom->v,nmax,3,"atom:v"); - f = atom->f = memory->grow_2d_double_array(atom->f,nmax,3,"atom:f"); - - q = atom->q = (double *) - memory->srealloc(atom->q,nmax*sizeof(double),"atom:q"); - mu = atom->mu = - memory->grow_2d_double_array(atom->mu,nmax,3,"atom:mu"); - omega = atom->omega = - memory->grow_2d_double_array(atom->omega,nmax,3,"atom:omega"); - torque = atom->torque = - memory->grow_2d_double_array(atom->torque,nmax,3,"atom:torque"); + tag = memory->grow(atom->tag,nmax,"atom:tag"); + type = memory->grow(atom->type,nmax,"atom:type"); + mask = memory->grow(atom->mask,nmax,"atom:mask"); + image = memory->grow(atom->image,nmax,"atom:image"); + x = memory->grow(atom->x,nmax,3,"atom:x"); + v = memory->grow(atom->v,nmax,3,"atom:v"); + f = memory->grow(atom->f,nmax,3,"atom:f"); + + q = memory->grow(atom->q,nmax,"atom:q"); + mu = memory->grow(atom->mu,nmax,3,"atom:mu"); + omega = memory->grow(atom->omega,nmax,3,"atom:omega"); + torque = memory->grow(atom->torque,nmax,3,"atom:torque"); if (atom->nextra_grow) for (int iextra = 0; iextra < atom->nextra_grow; iextra++) diff --git a/src/GRANULAR/atom_vec_granular.cpp b/src/GRANULAR/atom_vec_granular.cpp index d6cca5043a..960d70b078 100644 --- a/src/GRANULAR/atom_vec_granular.cpp +++ b/src/GRANULAR/atom_vec_granular.cpp @@ -85,29 +85,20 @@ void AtomVecGranular::grow(int n) if (nmax < 0 || nmax > MAXSMALLINT) error->one("Per-processor system is too big"); - tag = atom->tag = (int *) - memory->srealloc(atom->tag,nmax*sizeof(int),"atom:tag"); - type = atom->type = (int *) - memory->srealloc(atom->type,nmax*sizeof(int),"atom:type"); - mask = atom->mask = (int *) - memory->srealloc(atom->mask,nmax*sizeof(int),"atom:mask"); - image = atom->image = (int *) - memory->srealloc(atom->image,nmax*sizeof(int),"atom:image"); - x = atom->x = memory->grow_2d_double_array(atom->x,nmax,3,"atom:x"); - v = atom->v = memory->grow_2d_double_array(atom->v,nmax,3,"atom:v"); - f = atom->f = memory->grow_2d_double_array(atom->f,nmax,3,"atom:f"); - - radius = atom->radius = (double *) - memory->srealloc(atom->radius,nmax*sizeof(double),"atom:radius"); - density = atom->density = (double *) - memory->srealloc(atom->density,nmax*sizeof(double),"atom:density"); - rmass = atom->rmass = (double *) - memory->srealloc(atom->rmass,nmax*sizeof(double),"atom:rmass"); - - omega = atom->omega = - memory->grow_2d_double_array(atom->omega,nmax,3,"atom:omega"); - torque = atom->torque = - memory->grow_2d_double_array(atom->torque,nmax,3,"atom:torque"); + tag = memory->grow(atom->tag,nmax,"atom:tag"); + type = memory->grow(atom->type,nmax,"atom:type"); + mask = memory->grow(atom->mask,nmax,"atom:mask"); + image = memory->grow(atom->image,nmax,"atom:image"); + x = memory->grow(atom->x,nmax,3,"atom:x"); + v = memory->grow(atom->v,nmax,3,"atom:v"); + f = memory->grow(atom->f,nmax,3,"atom:f"); + + radius = memory->grow(atom->radius,nmax,"atom:radius"); + density = memory->grow(atom->density,nmax,"atom:density"); + rmass = memory->grow(atom->rmass,nmax,"atom:rmass"); + + omega = memory->grow(atom->omega,nmax,3,"atom:omega"); + torque = memory->grow(atom->torque,nmax,3,"atom:torque"); if (atom->nextra_grow) for (int iextra = 0; iextra < atom->nextra_grow; iextra++) diff --git a/src/MOLECULE/atom_vec_angle.cpp b/src/MOLECULE/atom_vec_angle.cpp index bd802cbfd4..766dab3a60 100644 --- a/src/MOLECULE/atom_vec_angle.cpp +++ b/src/MOLECULE/atom_vec_angle.cpp @@ -63,50 +63,34 @@ void AtomVecAngle::grow(int n) if (nmax < 0 || nmax > MAXSMALLINT) error->one("Per-processor system is too big"); - tag = atom->tag = (int *) - memory->srealloc(atom->tag,nmax*sizeof(int),"atom:tag"); - type = atom->type = (int *) - memory->srealloc(atom->type,nmax*sizeof(int),"atom:type"); - mask = atom->mask = (int *) - memory->srealloc(atom->mask,nmax*sizeof(int),"atom:mask"); - image = atom->image = (int *) - memory->srealloc(atom->image,nmax*sizeof(int),"atom:image"); - x = atom->x = memory->grow_2d_double_array(atom->x,nmax,3,"atom:x"); - v = atom->v = memory->grow_2d_double_array(atom->v,nmax,3,"atom:v"); - f = atom->f = memory->grow_2d_double_array(atom->f,nmax,3,"atom:f"); - - molecule = atom->molecule = (int *) - memory->srealloc(atom->molecule,nmax*sizeof(int),"atom:molecule"); - - nspecial = atom->nspecial = - memory->grow_2d_int_array(atom->nspecial,nmax,3,"atom:nspecial"); - special = atom->special = - memory->grow_2d_int_array(atom->special,nmax,atom->maxspecial, - "atom:special"); - - num_bond = atom->num_bond = (int *) - memory->srealloc(atom->num_bond,nmax*sizeof(int),"atom:num_bond"); - bond_type = atom->bond_type = - memory->grow_2d_int_array(atom->bond_type,nmax,atom->bond_per_atom, - "atom:bond_type"); - bond_atom = atom->bond_atom = - memory->grow_2d_int_array(atom->bond_atom,nmax,atom->bond_per_atom, - "atom:bond_atom"); - - num_angle = atom->num_angle = (int *) - memory->srealloc(atom->num_angle,nmax*sizeof(int),"atom:num_angle"); - angle_type = atom->angle_type = - memory->grow_2d_int_array(atom->angle_type,nmax,atom->angle_per_atom, - "atom:angle_type"); - angle_atom1 = atom->angle_atom1 = - memory->grow_2d_int_array(atom->angle_atom1,nmax,atom->angle_per_atom, - "atom:angle_atom1"); - angle_atom2 = atom->angle_atom2 = - memory->grow_2d_int_array(atom->angle_atom2,nmax,atom->angle_per_atom, - "atom:angle_atom2"); - angle_atom3 = atom->angle_atom3 = - memory->grow_2d_int_array(atom->angle_atom3,nmax,atom->angle_per_atom, - "atom:angle_atom3"); + tag = memory->grow(atom->tag,nmax,"atom:tag"); + type = memory->grow(atom->type,nmax,"atom:type"); + mask = memory->grow(atom->mask,nmax,"atom:mask"); + image = memory->grow(atom->image,nmax,"atom:image"); + x = memory->grow(atom->x,nmax,3,"atom:x"); + v = memory->grow(atom->v,nmax,3,"atom:v"); + f = memory->grow(atom->f,nmax,3,"atom:f"); + + molecule = memory->grow(atom->molecule,nmax,"atom:molecule"); + + nspecial = memory->grow(atom->nspecial,nmax,3,"atom:nspecial"); + special = memory->grow(atom->special,nmax,atom->maxspecial,"atom:special"); + + num_bond = memory->grow(atom->num_bond,nmax,"atom:num_bond"); + bond_type = memory->grow(atom->bond_type,nmax,atom->bond_per_atom, + "atom:bond_type"); + bond_atom = memory->grow(atom->bond_atom,nmax,atom->bond_per_atom, + "atom:bond_atom"); + + num_angle = memory->grow(atom->num_angle,nmax,"atom:num_angle"); + angle_type = memory->grow(atom->angle_type,nmax,atom->angle_per_atom, + "atom:angle_type"); + angle_atom1 = memory->grow(atom->angle_atom1,nmax,atom->angle_per_atom, + "atom:angle_atom1"); + angle_atom2 = memory->grow(atom->angle_atom2,nmax,atom->angle_per_atom, + "atom:angle_atom2"); + angle_atom3 = memory->grow(atom->angle_atom3,nmax,atom->angle_per_atom, + "atom:angle_atom3"); if (atom->nextra_grow) for (int iextra = 0; iextra < atom->nextra_grow; iextra++) diff --git a/src/MOLECULE/atom_vec_bond.cpp b/src/MOLECULE/atom_vec_bond.cpp index 8493b31ae0..9d0ba86251 100644 --- a/src/MOLECULE/atom_vec_bond.cpp +++ b/src/MOLECULE/atom_vec_bond.cpp @@ -63,36 +63,25 @@ void AtomVecBond::grow(int n) if (nmax < 0 || nmax > MAXSMALLINT) error->one("Per-processor system is too big"); - tag = atom->tag = (int *) - memory->srealloc(atom->tag,nmax*sizeof(int),"atom:tag"); - type = atom->type = (int *) - memory->srealloc(atom->type,nmax*sizeof(int),"atom:type"); - mask = atom->mask = (int *) - memory->srealloc(atom->mask,nmax*sizeof(int),"atom:mask"); - image = atom->image = (int *) - memory->srealloc(atom->image,nmax*sizeof(int),"atom:image"); - x = atom->x = memory->grow_2d_double_array(atom->x,nmax,3,"atom:x"); - v = atom->v = memory->grow_2d_double_array(atom->v,nmax,3,"atom:v"); - f = atom->f = memory->grow_2d_double_array(atom->f,nmax,3,"atom:f"); - - molecule = atom->molecule = (int *) - memory->srealloc(atom->molecule,nmax*sizeof(int),"atom:molecule"); - - nspecial = atom->nspecial = - memory->grow_2d_int_array(atom->nspecial,nmax,3,"atom:nspecial"); - special = atom->special = - memory->grow_2d_int_array(atom->special,nmax,atom->maxspecial, - "atom:special"); - - num_bond = atom->num_bond = (int *) - memory->srealloc(atom->num_bond,nmax*sizeof(int),"atom:num_bond"); - bond_type = atom->bond_type = - memory->grow_2d_int_array(atom->bond_type,nmax,atom->bond_per_atom, - "atom:bond_type"); - bond_atom = atom->bond_atom = - memory->grow_2d_int_array(atom->bond_atom,nmax,atom->bond_per_atom, - "atom:bond_atom"); - + tag = memory->grow(atom->tag,nmax,"atom:tag"); + type = memory->grow(atom->type,nmax,"atom:type"); + mask = memory->grow(atom->mask,nmax,"atom:mask"); + image = memory->grow(atom->image,nmax,"atom:image"); + x = memory->grow(atom->x,nmax,3,"atom:x"); + v = memory->grow(atom->v,nmax,3,"atom:v"); + f = memory->grow(atom->f,nmax,3,"atom:f"); + + molecule = memory->grow(atom->molecule,nmax,"atom:molecule"); + + nspecial = memory->grow(atom->nspecial,nmax,3,"atom:nspecial"); + special = memory->grow(atom->special,nmax,atom->maxspecial,"atom:special"); + + num_bond = memory->grow(atom->num_bond,nmax,"atom:num_bond"); + bond_type = memory->grow(atom->bond_type,nmax,atom->bond_per_atom, + "atom:bond_type"); + bond_atom = memory->grow(atom->bond_atom,nmax,atom->bond_per_atom, + "atom:bond_atom"); + if (atom->nextra_grow) for (int iextra = 0; iextra < atom->nextra_grow; iextra++) modify->fix[atom->extra_grow[iextra]]->grow_arrays(nmax); diff --git a/src/MOLECULE/atom_vec_full.cpp b/src/MOLECULE/atom_vec_full.cpp index 8f9eb97d3d..af09a8edba 100644 --- a/src/MOLECULE/atom_vec_full.cpp +++ b/src/MOLECULE/atom_vec_full.cpp @@ -63,88 +63,68 @@ void AtomVecFull::grow(int n) if (nmax < 0 || nmax > MAXSMALLINT) error->one("Per-processor system is too big"); - tag = atom->tag = (int *) - memory->srealloc(atom->tag,nmax*sizeof(int),"atom:tag"); - type = atom->type = (int *) - memory->srealloc(atom->type,nmax*sizeof(int),"atom:type"); - mask = atom->mask = (int *) - memory->srealloc(atom->mask,nmax*sizeof(int),"atom:mask"); - image = atom->image = (int *) - memory->srealloc(atom->image,nmax*sizeof(int),"atom:image"); - x = atom->x = memory->grow_2d_double_array(atom->x,nmax,3,"atom:x"); - v = atom->v = memory->grow_2d_double_array(atom->v,nmax,3,"atom:v"); - f = atom->f = memory->grow_2d_double_array(atom->f,nmax,3,"atom:f"); - - q = atom->q = (double *) - memory->srealloc(atom->q,nmax*sizeof(double),"atom:q"); - molecule = atom->molecule = (int *) - memory->srealloc(atom->molecule,nmax*sizeof(int),"atom:molecule"); - - nspecial = atom->nspecial = - memory->grow_2d_int_array(atom->nspecial,nmax,3,"atom:nspecial"); - special = atom->special = - memory->grow_2d_int_array(atom->special,nmax,atom->maxspecial, - "atom:special"); - - num_bond = atom->num_bond = (int *) - memory->srealloc(atom->num_bond,nmax*sizeof(int),"atom:num_bond"); - bond_type = atom->bond_type = - memory->grow_2d_int_array(atom->bond_type,nmax,atom->bond_per_atom, - "atom:bond_type"); - bond_atom = atom->bond_atom = - memory->grow_2d_int_array(atom->bond_atom,nmax,atom->bond_per_atom, - "atom:bond_atom"); - - num_angle = atom->num_angle = (int *) - memory->srealloc(atom->num_angle,nmax*sizeof(int),"atom:num_angle"); - angle_type = atom->angle_type = - memory->grow_2d_int_array(atom->angle_type,nmax,atom->angle_per_atom, - "atom:angle_type"); - angle_atom1 = atom->angle_atom1 = - memory->grow_2d_int_array(atom->angle_atom1,nmax,atom->angle_per_atom, - "atom:angle_atom1"); - angle_atom2 = atom->angle_atom2 = - memory->grow_2d_int_array(atom->angle_atom2,nmax,atom->angle_per_atom, - "atom:angle_atom2"); - angle_atom3 = atom->angle_atom3 = - memory->grow_2d_int_array(atom->angle_atom3,nmax,atom->angle_per_atom, - "atom:angle_atom3"); - - num_dihedral = atom->num_dihedral = (int *) - memory->srealloc(atom->num_dihedral,nmax*sizeof(int),"atom:num_dihedral"); - dihedral_type = atom->dihedral_type = - memory->grow_2d_int_array(atom->dihedral_type,nmax,atom->dihedral_per_atom, - "atom:dihedral_type"); - dihedral_atom1 = atom->dihedral_atom1 = - memory->grow_2d_int_array(atom->dihedral_atom1,nmax, - atom->dihedral_per_atom,"atom:dihedral_atom1"); - dihedral_atom2 = atom->dihedral_atom2 = - memory->grow_2d_int_array(atom->dihedral_atom2,nmax, - atom->dihedral_per_atom,"atom:dihedral_atom2"); - dihedral_atom3 = atom->dihedral_atom3 = - memory->grow_2d_int_array(atom->dihedral_atom3,nmax, - atom->dihedral_per_atom,"atom:dihedral_atom3"); - dihedral_atom4 = atom->dihedral_atom4 = - memory->grow_2d_int_array(atom->dihedral_atom4,nmax, - atom->dihedral_per_atom,"atom:dihedral_atom4"); - - num_improper = atom->num_improper = (int *) - memory->srealloc(atom->num_improper,nmax*sizeof(int),"atom:num_improper"); - improper_type = atom->improper_type = - memory->grow_2d_int_array(atom->improper_type,nmax,atom->improper_per_atom, - "atom:improper_type"); - improper_atom1 = atom->improper_atom1 = - memory->grow_2d_int_array(atom->improper_atom1,nmax, - atom->improper_per_atom,"atom:improper_atom1"); - improper_atom2 = atom->improper_atom2 = - memory->grow_2d_int_array(atom->improper_atom2,nmax, - atom->improper_per_atom,"atom:improper_atom2"); - improper_atom3 = atom->improper_atom3 = - memory->grow_2d_int_array(atom->improper_atom3,nmax, - atom->improper_per_atom,"atom:improper_atom3"); - improper_atom4 = atom->improper_atom4 = - memory->grow_2d_int_array(atom->improper_atom4,nmax, - atom->improper_per_atom,"atom:improper_atom4"); + tag = memory->grow(atom->tag,nmax,"atom:tag"); + type = memory->grow(atom->type,nmax,"atom:type"); + mask = memory->grow(atom->mask,nmax,"atom:mask"); + image = memory->grow(atom->image,nmax,"atom:image"); + x = memory->grow(atom->x,nmax,3,"atom:x"); + v = memory->grow(atom->v,nmax,3,"atom:v"); + f = memory->grow(atom->f,nmax,3,"atom:f"); + + q = memory->grow(atom->q,nmax,"atom:q"); + molecule = memory->grow(atom->molecule,nmax,"atom:molecule"); + + nspecial = memory->grow(atom->nspecial,nmax,3,"atom:nspecial"); + special = memory->grow(atom->special,nmax,atom->maxspecial,"atom:special"); + + num_bond = memory->grow(atom->num_bond,nmax,"atom:num_bond"); + bond_type = memory->grow(atom->bond_type,nmax,atom->bond_per_atom, + "atom:bond_type"); + bond_atom = memory->grow(atom->bond_atom,nmax,atom->bond_per_atom, + "atom:bond_atom"); + + num_angle = memory->grow(atom->num_angle,nmax,"atom:num_angle"); + angle_type = memory->grow(atom->angle_type,nmax,atom->angle_per_atom, + "atom:angle_type"); + angle_atom1 = memory->grow(atom->angle_atom1,nmax,atom->angle_per_atom, + "atom:angle_atom1"); + angle_atom2 = memory->grow(atom->angle_atom2,nmax,atom->angle_per_atom, + "atom:angle_atom2"); + angle_atom3 = memory->grow(atom->angle_atom3,nmax,atom->angle_per_atom, + "atom:angle_atom3"); + + num_dihedral = memory->grow(atom->num_dihedral,nmax,"atom:num_dihedral"); + dihedral_type = memory->grow(atom->dihedral_type,nmax, + atom->dihedral_per_atom,"atom:dihedral_type"); + dihedral_atom1 = + memory->grow(atom->dihedral_atom1,nmax,atom->dihedral_per_atom, + "atom:dihedral_atom1"); + dihedral_atom2 = + memory->grow(atom->dihedral_atom2,nmax,atom->dihedral_per_atom, + "atom:dihedral_atom2"); + dihedral_atom3 = + memory->grow(atom->dihedral_atom3,nmax,atom->dihedral_per_atom, + "atom:dihedral_atom3"); + dihedral_atom4 = + memory->grow(atom->dihedral_atom4,nmax,atom->dihedral_per_atom, + "atom:dihedral_atom4"); + + num_improper = memory->grow(atom->num_improper,nmax,"atom:num_improper"); + improper_type = + memory->grow(atom->improper_type,nmax,atom->improper_per_atom, + "atom:improper_type"); + improper_atom1 = + memory->grow(atom->improper_atom1,nmax,atom->improper_per_atom, + "atom:improper_atom1"); + improper_atom2 = + memory->grow(atom->improper_atom2,nmax,atom->improper_per_atom, + "atom:improper_atom2"); + improper_atom3 = + memory->grow(atom->improper_atom3,nmax,atom->improper_per_atom, + "atom:improper_atom3"); + improper_atom4 = + memory->grow(atom->improper_atom4,nmax,atom->improper_per_atom, + "atom:improper_atom4"); if (atom->nextra_grow) for (int iextra = 0; iextra < atom->nextra_grow; iextra++) diff --git a/src/MOLECULE/atom_vec_molecular.cpp b/src/MOLECULE/atom_vec_molecular.cpp index 555e1ed65d..3e809184fa 100644 --- a/src/MOLECULE/atom_vec_molecular.cpp +++ b/src/MOLECULE/atom_vec_molecular.cpp @@ -63,86 +63,67 @@ void AtomVecMolecular::grow(int n) if (nmax < 0 || nmax > MAXSMALLINT) error->one("Per-processor system is too big"); - tag = atom->tag = (int *) - memory->srealloc(atom->tag,nmax*sizeof(int),"atom:tag"); - type = atom->type = (int *) - memory->srealloc(atom->type,nmax*sizeof(int),"atom:type"); - mask = atom->mask = (int *) - memory->srealloc(atom->mask,nmax*sizeof(int),"atom:mask"); - image = atom->image = (int *) - memory->srealloc(atom->image,nmax*sizeof(int),"atom:image"); - x = atom->x = memory->grow_2d_double_array(atom->x,nmax,3,"atom:x"); - v = atom->v = memory->grow_2d_double_array(atom->v,nmax,3,"atom:v"); - f = atom->f = memory->grow_2d_double_array(atom->f,nmax,3,"atom:f"); - - molecule = atom->molecule = (int *) - memory->srealloc(atom->molecule,nmax*sizeof(int),"atom:molecule"); - - nspecial = atom->nspecial = - memory->grow_2d_int_array(atom->nspecial,nmax,3,"atom:nspecial"); - special = atom->special = - memory->grow_2d_int_array(atom->special,nmax,atom->maxspecial, - "atom:special"); - - num_bond = atom->num_bond = (int *) - memory->srealloc(atom->num_bond,nmax*sizeof(int),"atom:num_bond"); - bond_type = atom->bond_type = - memory->grow_2d_int_array(atom->bond_type,nmax,atom->bond_per_atom, - "atom:bond_type"); - bond_atom = atom->bond_atom = - memory->grow_2d_int_array(atom->bond_atom,nmax,atom->bond_per_atom, - "atom:bond_atom"); - - num_angle = atom->num_angle = (int *) - memory->srealloc(atom->num_angle,nmax*sizeof(int),"atom:num_angle"); - angle_type = atom->angle_type = - memory->grow_2d_int_array(atom->angle_type,nmax,atom->angle_per_atom, - "atom:angle_type"); - angle_atom1 = atom->angle_atom1 = - memory->grow_2d_int_array(atom->angle_atom1,nmax,atom->angle_per_atom, - "atom:angle_atom1"); - angle_atom2 = atom->angle_atom2 = - memory->grow_2d_int_array(atom->angle_atom2,nmax,atom->angle_per_atom, - "atom:angle_atom2"); - angle_atom3 = atom->angle_atom3 = - memory->grow_2d_int_array(atom->angle_atom3,nmax,atom->angle_per_atom, - "atom:angle_atom3"); - - num_dihedral = atom->num_dihedral = (int *) - memory->srealloc(atom->num_dihedral,nmax*sizeof(int),"atom:num_dihedral"); - dihedral_type = atom->dihedral_type = - memory->grow_2d_int_array(atom->dihedral_type,nmax,atom->dihedral_per_atom, - "atom:dihedral_type"); - dihedral_atom1 = atom->dihedral_atom1 = - memory->grow_2d_int_array(atom->dihedral_atom1,nmax, - atom->dihedral_per_atom,"atom:dihedral_atom1"); - dihedral_atom2 = atom->dihedral_atom2 = - memory->grow_2d_int_array(atom->dihedral_atom2,nmax, - atom->dihedral_per_atom,"atom:dihedral_atom2"); - dihedral_atom3 = atom->dihedral_atom3 = - memory->grow_2d_int_array(atom->dihedral_atom3,nmax, - atom->dihedral_per_atom,"atom:dihedral_atom3"); - dihedral_atom4 = atom->dihedral_atom4 = - memory->grow_2d_int_array(atom->dihedral_atom4,nmax, - atom->dihedral_per_atom,"atom:dihedral_atom4"); - - num_improper = atom->num_improper = (int *) - memory->srealloc(atom->num_improper,nmax*sizeof(int),"atom:num_improper"); - improper_type = atom->improper_type = - memory->grow_2d_int_array(atom->improper_type,nmax,atom->improper_per_atom, - "atom:improper_type"); - improper_atom1 = atom->improper_atom1 = - memory->grow_2d_int_array(atom->improper_atom1,nmax, - atom->improper_per_atom,"atom:improper_atom1"); - improper_atom2 = atom->improper_atom2 = - memory->grow_2d_int_array(atom->improper_atom2,nmax, - atom->improper_per_atom,"atom:improper_atom2"); - improper_atom3 = atom->improper_atom3 = - memory->grow_2d_int_array(atom->improper_atom3,nmax, - atom->improper_per_atom,"atom:improper_atom3"); - improper_atom4 = atom->improper_atom4 = - memory->grow_2d_int_array(atom->improper_atom4,nmax, - atom->improper_per_atom,"atom:improper_atom4"); + tag = memory->grow(atom->tag,nmax,"atom:tag"); + type = memory->grow(atom->type,nmax,"atom:type"); + mask = memory->grow(atom->mask,nmax,"atom:mask"); + image = memory->grow(atom->image,nmax,"atom:image"); + x = memory->grow(atom->x,nmax,3,"atom:x"); + v = memory->grow(atom->v,nmax,3,"atom:v"); + f = memory->grow(atom->f,nmax,3,"atom:f"); + + molecule = memory->grow(atom->molecule,nmax,"atom:molecule"); + + nspecial = memory->grow(atom->nspecial,nmax,3,"atom:nspecial"); + special = memory->grow(atom->special,nmax,atom->maxspecial,"atom:special"); + + num_bond = memory->grow(atom->num_bond,nmax,"atom:num_bond"); + bond_type = memory->grow(atom->bond_type,nmax,atom->bond_per_atom, + "atom:bond_type"); + bond_atom = memory->grow(atom->bond_atom,nmax,atom->bond_per_atom, + "atom:bond_atom"); + + num_angle = memory->grow(atom->num_angle,nmax,"atom:num_angle"); + angle_type = memory->grow(atom->angle_type,nmax,atom->angle_per_atom, + "atom:angle_type"); + angle_atom1 = memory->grow(atom->angle_atom1,nmax,atom->angle_per_atom, + "atom:angle_atom1"); + angle_atom2 = memory->grow(atom->angle_atom2,nmax,atom->angle_per_atom, + "atom:angle_atom2"); + angle_atom3 = memory->grow(atom->angle_atom3,nmax,atom->angle_per_atom, + "atom:angle_atom3"); + + num_dihedral = memory->grow(atom->num_dihedral,nmax,"atom:num_dihedral"); + dihedral_type = memory->grow(atom->dihedral_type,nmax, + atom->dihedral_per_atom,"atom:dihedral_type"); + dihedral_atom1 = + memory->grow(atom->dihedral_atom1,nmax,atom->dihedral_per_atom, + "atom:dihedral_atom1"); + dihedral_atom2 = + memory->grow(atom->dihedral_atom2,nmax,atom->dihedral_per_atom, + "atom:dihedral_atom2"); + dihedral_atom3 = + memory->grow(atom->dihedral_atom3,nmax,atom->dihedral_per_atom, + "atom:dihedral_atom3"); + dihedral_atom4 = + memory->grow(atom->dihedral_atom4,nmax,atom->dihedral_per_atom, + "atom:dihedral_atom4"); + + num_improper = memory->grow(atom->num_improper,nmax,"atom:num_improper"); + improper_type = + memory->grow(atom->improper_type,nmax,atom->improper_per_atom, + "atom:improper_type"); + improper_atom1 = + memory->grow(atom->improper_atom1,nmax,atom->improper_per_atom, + "atom:improper_atom1"); + improper_atom2 = + memory->grow(atom->improper_atom2,nmax,atom->improper_per_atom, + "atom:improper_atom2"); + improper_atom3 = + memory->grow(atom->improper_atom3,nmax,atom->improper_per_atom, + "atom:improper_atom3"); + improper_atom4 = + memory->grow(atom->improper_atom4,nmax,atom->improper_per_atom, + "atom:improper_atom4"); if (atom->nextra_grow) for (int iextra = 0; iextra < atom->nextra_grow; iextra++) diff --git a/src/PERI/atom_vec_peri.cpp b/src/PERI/atom_vec_peri.cpp index ea3d896466..322fa56ca7 100644 --- a/src/PERI/atom_vec_peri.cpp +++ b/src/PERI/atom_vec_peri.cpp @@ -64,27 +64,19 @@ void AtomVecPeri::grow(int n) if (nmax < 0 || nmax > MAXSMALLINT) error->one("Per-processor system is too big"); - tag = atom->tag = (int *) - memory->srealloc(atom->tag,nmax*sizeof(int),"atom:tag"); - type = atom->type = (int *) - memory->srealloc(atom->type,nmax*sizeof(int),"atom:type"); - mask = atom->mask = (int *) - memory->srealloc(atom->mask,nmax*sizeof(int),"atom:mask"); - image = atom->image = (int *) - memory->srealloc(atom->image,nmax*sizeof(int),"atom:image"); - x = atom->x = memory->grow_2d_double_array(atom->x,nmax,3,"atom:x"); - v = atom->v = memory->grow_2d_double_array(atom->v,nmax,3,"atom:v"); - f = atom->f = memory->grow_2d_double_array(atom->f,nmax,3,"atom:f"); - - vfrac = atom->vfrac = (double *) - memory->srealloc(atom->vfrac,nmax*sizeof(double),"atom:vfrac"); - density = atom->density = (double *) - memory->srealloc(atom->density,nmax*sizeof(double),"atom:density"); - rmass = atom->rmass = (double *) - memory->srealloc(atom->rmass,nmax*sizeof(double),"atom:rmass"); - s0 = atom->s0 = (double *) - memory->srealloc(atom->s0,nmax*sizeof(double),"atom:s0"); - x0 = atom->x0 = memory->grow_2d_double_array(atom->x0,nmax,3,"atom:x0"); + tag = memory->grow(atom->tag,nmax,"atom:tag"); + type = memory->grow(atom->type,nmax,"atom:type"); + mask = memory->grow(atom->mask,nmax,"atom:mask"); + image = memory->grow(atom->image,nmax,"atom:image"); + x = memory->grow(atom->x,nmax,3,"atom:x"); + v = memory->grow(atom->v,nmax,3,"atom:v"); + f = memory->grow(atom->f,nmax,3,"atom:f"); + + vfrac = memory->grow(atom->vfrac,nmax,"atom:vfrac"); + density = memory->grow(atom->density,nmax,"atom:density"); + rmass = memory->grow(atom->rmass,nmax,"atom:rmass"); + s0 = memory->grow(atom->s0,nmax,"atom:s0"); + x0 = memory->grow(atom->x0,nmax,3,"atom:x0"); if (atom->nextra_grow) for (int iextra = 0; iextra < atom->nextra_grow; iextra++) diff --git a/src/USER-EFF/atom_vec_electron.cpp b/src/USER-EFF/atom_vec_electron.cpp index d761d128f5..15de2e1a84 100644 --- a/src/USER-EFF/atom_vec_electron.cpp +++ b/src/USER-EFF/atom_vec_electron.cpp @@ -64,30 +64,20 @@ void AtomVecElectron::grow(int n) else nmax = n; atom->nmax = nmax; - tag = atom->tag = (int *) - memory->srealloc(atom->tag,nmax*sizeof(int),"atom:tag"); - type = atom->type = (int *) - memory->srealloc(atom->type,nmax*sizeof(int),"atom:type"); - mask = atom->mask = (int *) - memory->srealloc(atom->mask,nmax*sizeof(int),"atom:mask"); - image = atom->image = (int *) - memory->srealloc(atom->image,nmax*sizeof(int),"atom:image"); - - x = atom->x = memory->grow_2d_double_array(atom->x,nmax,3,"atom:x"); - v = atom->v = memory->grow_2d_double_array(atom->v,nmax,3,"atom:v"); - f = atom->f = memory->grow_2d_double_array(atom->f,nmax,3,"atom:f"); - - q = atom->q = (double *) - memory->srealloc(atom->q,nmax*sizeof(double),"atom:q"); - spin = atom->spin = (int *) - memory->srealloc(atom->spin,nmax*sizeof(int),"atom:spin"); - eradius = atom->eradius = (double *) - memory->srealloc(atom->eradius,nmax*sizeof(double),"atom:eradius"); - ervel = atom->ervel = (double *) - memory->srealloc(atom->ervel,nmax*sizeof(double),"atom:ervel"); - erforce = atom->erforce = (double *) - memory->srealloc(atom->erforce,nmax*sizeof(double),"atom:erforce"); - + tag = memory->grow(atom->tag,nmax,"atom:tag"); + type = memory->grow(atom->type,nmax,"atom:type"); + mask = memory->grow(atom->mask,nmax,"atom:mask"); + image = memory->grow(atom->image,nmax,"atom:image"); + x = memory->grow(atom->x,nmax,3,"atom:x"); + v = memory->grow(atom->v,nmax,3,"atom:v"); + f = memory->grow(atom->f,nmax,3,"atom:f"); + + q = memory->grow(atom->q,nmax,"atom:q"); + spin = memory->grow(atom->spin,nmax,"atom:spin"); + eradius = memory->grow(atom->eradius,nmax,"atom:eradius"); + ervel = memory->grow(atom->ervel,nmax,"atom:ervel"); + erforce = memory->grow(atom->erforce,nmax,"atom:erforce"); + if (atom->nextra_grow) for (int iextra = 0; iextra < atom->nextra_grow; iextra++) modify->fix[atom->extra_grow[iextra]]->grow_arrays(nmax); diff --git a/src/atom.cpp b/src/atom.cpp index 118a3ce706..7db4daccd8 100644 --- a/src/atom.cpp +++ b/src/atom.cpp @@ -152,83 +152,83 @@ Atom::~Atom() delete avec; delete [] firstgroupname; - memory->sfree(binhead); - memory->sfree(next); - memory->sfree(permute); + memory->destroy(binhead); + memory->destroy(next); + memory->destroy(permute); // delete atom arrays // customize by adding new array - memory->sfree(tag); - memory->sfree(type); - memory->sfree(mask); - memory->sfree(image); - memory->destroy_2d_double_array(x); - memory->destroy_2d_double_array(v); - memory->destroy_2d_double_array(f); - - memory->sfree(q); - memory->destroy_2d_double_array(mu); - memory->destroy_2d_double_array(quat); - memory->destroy_2d_double_array(omega); - memory->destroy_2d_double_array(angmom); - memory->destroy_2d_double_array(torque); - - memory->sfree(radius); - memory->sfree(density); - memory->sfree(rmass); - memory->sfree(vfrac); - memory->sfree(s0); - memory->destroy_2d_double_array(x0); - - memory->sfree(spin); - memory->sfree(eradius); - memory->sfree(ervel); - memory->sfree(erforce); - - memory->sfree(molecule); - - memory->destroy_2d_int_array(nspecial); - memory->destroy_2d_int_array(special); - - memory->sfree(num_bond); - memory->destroy_2d_int_array(bond_type); - memory->destroy_2d_int_array(bond_atom); - - memory->sfree(num_angle); - memory->destroy_2d_int_array(angle_type); - memory->destroy_2d_int_array(angle_atom1); - memory->destroy_2d_int_array(angle_atom2); - memory->destroy_2d_int_array(angle_atom3); - - memory->sfree(num_dihedral); - memory->destroy_2d_int_array(dihedral_type); - memory->destroy_2d_int_array(dihedral_atom1); - memory->destroy_2d_int_array(dihedral_atom2); - memory->destroy_2d_int_array(dihedral_atom3); - memory->destroy_2d_int_array(dihedral_atom4); - - memory->sfree(num_improper); - memory->destroy_2d_int_array(improper_type); - memory->destroy_2d_int_array(improper_atom1); - memory->destroy_2d_int_array(improper_atom2); - memory->destroy_2d_int_array(improper_atom3); - memory->destroy_2d_int_array(improper_atom4); + memory->destroy(tag); + memory->destroy(type); + memory->destroy(mask); + memory->destroy(image); + memory->destroy(x); + memory->destroy(v); + memory->destroy(f); + + memory->destroy(q); + memory->destroy(mu); + memory->destroy(quat); + memory->destroy(omega); + memory->destroy(angmom); + memory->destroy(torque); + + memory->destroy(radius); + memory->destroy(density); + memory->destroy(rmass); + memory->destroy(vfrac); + memory->destroy(s0); + memory->destroy(x0); + + memory->destroy(spin); + memory->destroy(eradius); + memory->destroy(ervel); + memory->destroy(erforce); + + memory->destroy(molecule); + + memory->destroy(nspecial); + memory->destroy(special); + + memory->destroy(num_bond); + memory->destroy(bond_type); + memory->destroy(bond_atom); + + memory->destroy(num_angle); + memory->destroy(angle_type); + memory->destroy(angle_atom1); + memory->destroy(angle_atom2); + memory->destroy(angle_atom3); + + memory->destroy(num_dihedral); + memory->destroy(dihedral_type); + memory->destroy(dihedral_atom1); + memory->destroy(dihedral_atom2); + memory->destroy(dihedral_atom3); + memory->destroy(dihedral_atom4); + + memory->destroy(num_improper); + memory->destroy(improper_type); + memory->destroy(improper_atom1); + memory->destroy(improper_atom2); + memory->destroy(improper_atom3); + memory->destroy(improper_atom4); // delete per-type arrays delete [] mass; delete [] mass_setflag; - memory->destroy_2d_double_array(shape); + memory->destroy(shape); delete [] shape_setflag; delete [] dipole; delete [] dipole_setflag; // delete extra arrays - memory->sfree(extra_grow); - memory->sfree(extra_restart); - memory->destroy_2d_double_array(extra); + memory->destroy(extra_grow); + memory->destroy(extra_restart); + memory->destroy(extra); // delete mapping data structures @@ -300,7 +300,7 @@ void Atom::init() // delete extra array since it doesn't persist past first run if (nextra_store) { - memory->destroy_2d_double_array(extra); + memory->destroy(extra); extra = NULL; nextra_store = 0; } @@ -420,8 +420,7 @@ void Atom::map_init() MPI_Allreduce(&max,&map_tag_max,1,MPI_INT,MPI_MAX,world); if (map_style == 1) { - map_array = (int *) - memory->smalloc((map_tag_max+1)*sizeof(int),"atom:map_array"); + memory->create(map_array,map_tag_max+1,"atom:map_array"); for (int i = 0; i <= map_tag_max; i++) map_array[i] = -1; } else { @@ -605,7 +604,7 @@ void Atom::map_one(int global, int local) void Atom::map_delete() { if (map_style == 1) { - if (map_tag_max) memory->sfree(map_array); + if (map_tag_max) memory->destroy(map_array); } else { if (map_nhash) { delete [] map_bucket; @@ -696,20 +695,21 @@ int Atom::tag_consecutive() int Atom::count_words(const char *line) { int n = strlen(line) + 1; - char *copy = (char *) memory->smalloc(n*sizeof(char),"copy"); + char *copy; + memory->create(copy,n,"atom:copy"); strcpy(copy,line); char *ptr; if (ptr = strchr(copy,'#')) *ptr = '\0'; if (strtok(copy," \t\n\r\f") == NULL) { - memory->sfree(copy); + memory->destroy(copy); return 0; } n = 1; while (strtok(NULL," \t\n\r\f")) n++; - memory->sfree(copy); + memory->destroy(copy); return n; } @@ -1066,7 +1066,7 @@ void Atom::allocate_type_arrays() for (int itype = 1; itype <= ntypes; itype++) mass_setflag[itype] = 0; } if (avec->shape_type) { - shape = memory->create_2d_double_array(ntypes+1,3,"atom:shape"); + memory->create(shape,ntypes+1,3,"atom:shape"); shape_setflag = new int[ntypes+1]; for (int itype = 1; itype <= ntypes; itype++) shape_setflag[itype] = 0; } @@ -1365,11 +1365,11 @@ void Atom::sort() // reallocate per-atom vectors if needed if (nlocal > maxnext) { - memory->sfree(next); - memory->sfree(permute); + memory->destroy(next); + memory->destroy(permute); maxnext = atom->nmax; - next = (int *) memory->smalloc(maxnext*sizeof(int),"atom:next"); - permute = (int *) memory->smalloc(maxnext*sizeof(int),"atom:permute"); + memory->create(next,maxnext,"atom:next"); + memory->create(permute,maxnext,"atom:permute"); } // insure there is one extra atom location at end of arrays for swaps @@ -1497,9 +1497,9 @@ void Atom::setup_sort_bins() // reallocate per-bin memory if needed if (nbins > maxbin) { - memory->sfree(binhead); + memory->destroy(binhead); maxbin = nbins; - binhead = (int *) memory->smalloc(maxbin*sizeof(int),"atom:binhead"); + memory->create(binhead,maxbin,"atom:binhead"); } } @@ -1528,18 +1528,14 @@ void Atom::add_callback(int flag) if (flag == 0) { if (nextra_grow == nextra_grow_max) { nextra_grow_max += DELTA; - extra_grow = (int *) - memory->srealloc(extra_grow,nextra_grow_max*sizeof(int), - "atom:extra_grow"); + memory->grow(extra_grow,nextra_grow_max,"atom:extra_grow"); } extra_grow[nextra_grow] = ifix; nextra_grow++; } else if (flag == 1) { if (nextra_restart == nextra_restart_max) { nextra_restart_max += DELTA; - extra_restart = (int *) - memory->srealloc(extra_restart,nextra_restart_max*sizeof(int), - "atom:extra_restart"); + memory->grow(extra_restart,nextra_restart_max,"atom:extra_restart"); } extra_restart[nextra_restart] = ifix; nextra_restart++; @@ -1619,7 +1615,7 @@ void *Atom::extract(char *name) double Atom::memory_usage() { memlength = DELTA_MEMSTR; - memstr = (char *) memory->smalloc(memlength*sizeof(char),"atom:memstr"); + memory->create(memstr,memlength,"atom:memstr"); memstr[0] = '\0'; double bytes = avec->memory_usage(); @@ -1630,7 +1626,7 @@ double Atom::memory_usage() bytes += map_nhash*sizeof(HashElem); } - memory->sfree(memstr); + memory->destroy(memstr); return bytes; } @@ -1654,8 +1650,7 @@ int Atom::memcheck(const char *str) if (strlen(memstr) + n >= memlength) { memlength += DELTA_MEMSTR; - memstr = (char *) memory->srealloc(memstr,memlength*sizeof(char), - "atom:memstr"); + memory->grow(memstr,memlength,"atom:memstr"); } strcat(memstr,padded); diff --git a/src/atom_vec_atomic.cpp b/src/atom_vec_atomic.cpp index 666ba7bc3f..26bd4d0738 100644 --- a/src/atom_vec_atomic.cpp +++ b/src/atom_vec_atomic.cpp @@ -57,17 +57,13 @@ void AtomVecAtomic::grow(int n) if (nmax < 0 || nmax > MAXSMALLINT) error->one("Per-processor system is too big"); - tag = atom->tag = (int *) - memory->srealloc(atom->tag,nmax*sizeof(int),"atom:tag"); - type = atom->type = (int *) - memory->srealloc(atom->type,nmax*sizeof(int),"atom:type"); - mask = atom->mask = (int *) - memory->srealloc(atom->mask,nmax*sizeof(int),"atom:mask"); - image = atom->image = (int *) - memory->srealloc(atom->image,nmax*sizeof(int),"atom:image"); - x = atom->x = memory->grow_2d_double_array(atom->x,nmax,3,"atom:x"); - v = atom->v = memory->grow_2d_double_array(atom->v,nmax,3,"atom:v"); - f = atom->f = memory->grow_2d_double_array(atom->f,nmax,3,"atom:f"); + tag = memory->grow(atom->tag,nmax,"atom:tag"); + type = memory->grow(atom->type,nmax,"atom:type"); + mask = memory->grow(atom->mask,nmax,"atom:mask"); + image = memory->grow(atom->image,nmax,"atom:image"); + x = memory->grow(atom->x,nmax,3,"atom:x"); + v = memory->grow(atom->v,nmax,3,"atom:v"); + f = memory->grow(atom->f,nmax,3,"atom:f"); if (atom->nextra_grow) for (int iextra = 0; iextra < atom->nextra_grow; iextra++) diff --git a/src/atom_vec_charge.cpp b/src/atom_vec_charge.cpp index 3071d5cf92..4f92be8aed 100644 --- a/src/atom_vec_charge.cpp +++ b/src/atom_vec_charge.cpp @@ -59,20 +59,15 @@ void AtomVecCharge::grow(int n) if (nmax < 0 || nmax > MAXSMALLINT) error->one("Per-processor system is too big"); - tag = atom->tag = (int *) - memory->srealloc(atom->tag,nmax*sizeof(int),"atom:tag"); - type = atom->type = (int *) - memory->srealloc(atom->type,nmax*sizeof(int),"atom:type"); - mask = atom->mask = (int *) - memory->srealloc(atom->mask,nmax*sizeof(int),"atom:mask"); - image = atom->image = (int *) - memory->srealloc(atom->image,nmax*sizeof(int),"atom:image"); - x = atom->x = memory->grow_2d_double_array(atom->x,nmax,3,"atom:x"); - v = atom->v = memory->grow_2d_double_array(atom->v,nmax,3,"atom:v"); - f = atom->f = memory->grow_2d_double_array(atom->f,nmax,3,"atom:f"); - - q = atom->q = (double *) - memory->srealloc(atom->q,nmax*sizeof(double),"atom:q"); + tag = memory->grow(atom->tag,nmax,"atom:tag"); + type = memory->grow(atom->type,nmax,"atom:type"); + mask = memory->grow(atom->mask,nmax,"atom:mask"); + image = memory->grow(atom->image,nmax,"atom:image"); + x = memory->grow(atom->x,nmax,3,"atom:x"); + v = memory->grow(atom->v,nmax,3,"atom:v"); + f = memory->grow(atom->f,nmax,3,"atom:f"); + + q = memory->grow(atom->q,nmax,"atom:q"); if (atom->nextra_grow) for (int iextra = 0; iextra < atom->nextra_grow; iextra++) diff --git a/src/comm.cpp b/src/comm.cpp index 324c9d0546..10f81b6042 100644 --- a/src/comm.cpp +++ b/src/comm.cpp @@ -68,20 +68,18 @@ Comm::Comm(LAMMPS *lmp) : Pointers(lmp) // initialize comm buffers & exchange memory maxsend = BUFMIN; - buf_send = (double *) - memory->smalloc((maxsend+BUFEXTRA)*sizeof(double),"comm:buf_send"); + memory->create(buf_send,maxsend+BUFEXTRA,"comm:buf_send"); maxrecv = BUFMIN; - buf_recv = (double *) - memory->smalloc(maxrecv*sizeof(double),"comm:buf_recv"); + memory->create(buf_recv,maxrecv,"comm:buf_recv"); maxswap = 6; allocate_swap(maxswap); sendlist = (int **) memory->smalloc(maxswap*sizeof(int *),"sendlist"); - maxsendlist = (int *) memory->smalloc(maxswap*sizeof(int),"maxsendlist"); + memory->create(maxsendlist,maxswap,"maxsendlist"); for (int i = 0; i < maxswap; i++) { maxsendlist[i] = BUFMIN; - sendlist[i] = (int *) memory->smalloc(BUFMIN*sizeof(int),"sendlist[i]"); + memory->create(sendlist[i],BUFMIN,"sendlist[i]"); } maxforward_fix = maxreverse_fix = 0; @@ -92,20 +90,20 @@ Comm::Comm(LAMMPS *lmp) : Pointers(lmp) Comm::~Comm() { - if (grid2proc) memory->destroy_3d_int_array(grid2proc); + if (grid2proc) memory->destroy(grid2proc); free_swap(); if (style == MULTI) { free_multi(); - memory->destroy_2d_double_array(cutghostmulti); + memory->destroy(cutghostmulti); } - memory->sfree(maxsendlist); - if (sendlist) for (int i = 0; i < maxswap; i++) memory->sfree(sendlist[i]); + memory->destroy(maxsendlist); + if (sendlist) for (int i = 0; i < maxswap; i++) memory->destroy(sendlist[i]); memory->sfree(sendlist); - memory->sfree(buf_send); - memory->sfree(buf_recv); + memory->destroy(buf_send); + memory->destroy(buf_recv); } /* ---------------------------------------------------------------------- @@ -121,9 +119,9 @@ void Comm::set_procs() if (domain->dimension == 2 && procgrid[2] != 1) error->all("Processor count in z must be 1 for 2d simulation"); - if (grid2proc) memory->destroy_3d_int_array(grid2proc); - grid2proc = memory->create_3d_int_array(procgrid[0],procgrid[1],procgrid[2], - "comm:grid2proc"); + if (grid2proc) memory->destroy(grid2proc); + memory->create(grid2proc,procgrid[0],procgrid[1],procgrid[2], + "comm:grid2proc"); // use MPI Cartesian routines to setup 3d grid of procs // grid2proc[i][j][k] = proc that owns i,j,k location in grid @@ -213,12 +211,11 @@ void Comm::init() if (style == MULTI && multilo == NULL) { allocate_multi(maxswap); - cutghostmulti = - memory->create_2d_double_array(atom->ntypes+1,3,"comm:cutghostmulti"); + memory->create(cutghostmulti,atom->ntypes+1,3,"comm:cutghostmulti"); } if (style == SINGLE && multilo) { free_multi(); - memory->destroy_2d_double_array(cutghostmulti); + memory->destroy(cutghostmulti); } } @@ -1129,13 +1126,10 @@ void Comm::grow_send(int n, int flag) { maxsend = static_cast<int> (BUFFACTOR * n); if (flag) - buf_send = (double *) - memory->srealloc(buf_send,(maxsend+BUFEXTRA)*sizeof(double), - "comm:buf_send"); + memory->grow(buf_send,(maxsend+BUFEXTRA),"comm:buf_send"); else { - memory->sfree(buf_send); - buf_send = (double *) memory->smalloc((maxsend+BUFEXTRA)*sizeof(double), - "comm:buf_send"); + memory->destroy(buf_send); + memory->create(buf_send,maxsend+BUFEXTRA,"comm:buf_send"); } } @@ -1146,9 +1140,8 @@ void Comm::grow_send(int n, int flag) void Comm::grow_recv(int n) { maxrecv = static_cast<int> (BUFFACTOR * n); - memory->sfree(buf_recv); - buf_recv = (double *) memory->smalloc(maxrecv*sizeof(double), - "comm:buf_recv"); + memory->destroy(buf_recv); + memory->create(buf_recv,maxrecv,"comm:buf_recv"); } /* ---------------------------------------------------------------------- @@ -1158,9 +1151,7 @@ void Comm::grow_recv(int n) void Comm::grow_list(int iswap, int n) { maxsendlist[iswap] = static_cast<int> (BUFFACTOR * n); - sendlist[iswap] = (int *) - memory->srealloc(sendlist[iswap],maxsendlist[iswap]*sizeof(int), - "comm:sendlist[iswap]"); + memory->grow(sendlist[iswap],maxsendlist[iswap],"comm:sendlist[iswap]"); } /* ---------------------------------------------------------------------- @@ -1178,12 +1169,10 @@ void Comm::grow_swap(int n) sendlist = (int **) memory->srealloc(sendlist,n*sizeof(int *),"comm:sendlist"); - maxsendlist = (int *) - memory->srealloc(maxsendlist,n*sizeof(int),"comm:maxsendlist"); + memory->grow(maxsendlist,n,"comm:maxsendlist"); for (int i = maxswap; i < n; i++) { maxsendlist[i] = BUFMIN; - sendlist[i] = (int *) - memory->smalloc(BUFMIN*sizeof(int),"comm:sendlist[i]"); + memory->create(sendlist[i],BUFMIN,"comm:sendlist[i]"); } maxswap = n; } @@ -1194,29 +1183,28 @@ void Comm::grow_swap(int n) void Comm::allocate_swap(int n) { - sendnum = (int *) memory->smalloc(n*sizeof(int),"comm:sendnum"); - recvnum = (int *) memory->smalloc(n*sizeof(int),"comm:recvnum"); - sendproc = (int *) memory->smalloc(n*sizeof(int),"comm:sendproc"); - recvproc = (int *) memory->smalloc(n*sizeof(int),"comm:recvproc"); - size_forward_recv = (int *) memory->smalloc(n*sizeof(int),"comm:size"); - size_reverse_send = (int *) memory->smalloc(n*sizeof(int),"comm:size"); - size_reverse_recv = (int *) memory->smalloc(n*sizeof(int),"comm:size"); - slablo = (double *) memory->smalloc(n*sizeof(double),"comm:slablo"); - slabhi = (double *) memory->smalloc(n*sizeof(double),"comm:slabhi"); - firstrecv = (int *) memory->smalloc(n*sizeof(int),"comm:firstrecv"); - pbc_flag = (int *) memory->smalloc(n*sizeof(int),"comm:pbc_flag"); - pbc = (int **) memory->create_2d_int_array(n,6,"comm:pbc"); + memory->create(sendnum,n,"comm:sendnum"); + memory->create(recvnum,n,"comm:recvnum"); + memory->create(sendproc,n,"comm:sendproc"); + memory->create(recvproc,n,"comm:recvproc"); + memory->create(size_forward_recv,n,"comm:size"); + memory->create(size_reverse_send,n,"comm:size"); + memory->create(size_reverse_recv,n,"comm:size"); + memory->create(slablo,n,"comm:slablo"); + memory->create(slabhi,n,"comm:slabhi"); + memory->create(firstrecv,n,"comm:firstrecv"); + memory->create(pbc_flag,n,"comm:pbc_flag"); + memory->create(pbc,n,6,"comm:pbc"); } - /* ---------------------------------------------------------------------- allocation of multi-type swap info ------------------------------------------------------------------------- */ void Comm::allocate_multi(int n) { - multilo = memory->create_2d_double_array(n,atom->ntypes+1,"comm:multilo"); - multihi = memory->create_2d_double_array(n,atom->ntypes+1,"comm:multihi"); + multilo = memory->create(multilo,n,atom->ntypes+1,"comm:multilo"); + multihi = memory->create(multihi,n,atom->ntypes+1,"comm:multihi"); } /* ---------------------------------------------------------------------- @@ -1225,17 +1213,17 @@ void Comm::allocate_multi(int n) void Comm::free_swap() { - memory->sfree(sendnum); - memory->sfree(recvnum); - memory->sfree(sendproc); - memory->sfree(recvproc); - memory->sfree(size_forward_recv); - memory->sfree(size_reverse_send); - memory->sfree(size_reverse_recv); - memory->sfree(slablo); - memory->sfree(slabhi); - memory->sfree(firstrecv); - memory->sfree(pbc_flag); + memory->destroy(sendnum); + memory->destroy(recvnum); + memory->destroy(sendproc); + memory->destroy(recvproc); + memory->destroy(size_forward_recv); + memory->destroy(size_reverse_send); + memory->destroy(size_reverse_recv); + memory->destroy(slablo); + memory->destroy(slabhi); + memory->destroy(firstrecv); + memory->destroy(pbc_flag); memory->destroy_2d_int_array(pbc); } @@ -1245,8 +1233,8 @@ void Comm::free_swap() void Comm::free_multi() { - memory->destroy_2d_double_array(multilo); - memory->destroy_2d_double_array(multihi); + memory->destroy(multilo); + memory->destroy(multihi); } /* ---------------------------------------------------------------------- diff --git a/src/memory.cpp b/src/memory.cpp index b7e4c4dc4b..0f69561210 100644 --- a/src/memory.cpp +++ b/src/memory.cpp @@ -71,6 +71,51 @@ void *Memory::srealloc(void *ptr, int n, const char *name) return ptr; } +/* ---------------------------------------------------------------------- + newer routines +------------------------------------------------------------------------- */ + +void *Memory::smalloc_new(bigint nbytes, const char *name) +{ + if (nbytes == 0) return NULL; + + void *ptr = malloc(nbytes); + if (ptr == NULL) { + char str[128]; + sprintf(str,"Failed to allocate " BIGINT_FORMAT "bytes for array %s", + nbytes,name); + error->one(str); + } + return ptr; +} + +void *Memory::srealloc_new(void *ptr, bigint nbytes, const char *name) +{ + if (nbytes == 0) { + sfree_new(ptr); + return NULL; + } + + ptr = realloc(ptr,nbytes); + if (ptr == NULL) { + char str[128]; + sprintf(str,"Failed to reallocate " BIGINT_FORMAT "bytes for array %s", + nbytes,name); + error->one(str); + } + return ptr; +} + +void Memory::sfree_new(void *ptr) +{ + if (ptr == NULL) return; + free(ptr); +} + +/* ---------------------------------------------------------------------- + older routines +------------------------------------------------------------------------- */ + /* ---------------------------------------------------------------------- create a 1d double array with index from nlo to nhi inclusive ------------------------------------------------------------------------- */ @@ -361,7 +406,6 @@ void Memory::destroy_3d_double_array(double ***array, int n1_offset, sfree(array + n1_offset); } - /* ---------------------------------------------------------------------- create a 3d int array ------------------------------------------------------------------------- */ diff --git a/src/memory.h b/src/memory.h index 8ed2a8e051..3a2a90775c 100644 --- a/src/memory.h +++ b/src/memory.h @@ -14,6 +14,7 @@ #ifndef LMP_MEMORY_H #define LMP_MEMORY_H +#include "lmptype.h" #include "pointers.h" namespace LAMMPS_NS { @@ -22,6 +23,8 @@ class Memory : protected Pointers { public: Memory(class LAMMPS *); + // older routines + void *smalloc(int n, const char *); void sfree(void *); void *srealloc(void *, int n, const char *); @@ -55,6 +58,345 @@ class Memory : protected Pointers { double ****create_4d_double_array(int, int, int, int, const char *); void destroy_4d_double_array(double ****); + + // newer routines + + public: + void *smalloc_new(bigint n, const char *); + void *srealloc_new(void *, bigint n, const char *); + void sfree_new(void *); + + +/* ---------------------------------------------------------------------- + NOTE: to avoid code bloat, only use these for int,double,float,char + otherwise, just use smalloc,srealloc,sfree +------------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- + create a 1d array +------------------------------------------------------------------------- */ + + template <typename TYPE> + TYPE *create(TYPE *&array, int n, const char *name) + { + bigint nbytes = sizeof(TYPE) * n; + array = (TYPE *) smalloc_new(nbytes,name); + return array; + }; + +/* ---------------------------------------------------------------------- + grow or shrink 1d array + if dim is 0, return NULL +------------------------------------------------------------------------- */ + + template <typename TYPE> + TYPE *grow(TYPE *&array, int n, const char *name) + { + if (array == NULL) return create(array,n,name); + if (n == 0) { + destroy(array); + return NULL; + } + + bigint nbytes = sizeof(TYPE) * n; + array = (TYPE *) srealloc_new(array,nbytes,name); + return array; + }; + +/* ---------------------------------------------------------------------- + destroy a 1d array +------------------------------------------------------------------------- */ + + template <typename TYPE> + void destroy(TYPE *array) + { + sfree_new(array); + }; + +/* ---------------------------------------------------------------------- + create a 1d array with index from nlo to nhi inclusive +------------------------------------------------------------------------- */ + + template <typename TYPE> + TYPE *create(TYPE *&array, int nlo, int nhi, const char *name) + { + bigint nbytes = sizeof(TYPE) * (nhi-nlo+1); + array = (TYPE *) smalloc_new(nbytes,name); + array = array-nlo; + return array; + } + +/* ---------------------------------------------------------------------- + destroy a 1d array with index offset +------------------------------------------------------------------------- */ + + template <typename TYPE> + void destroy(TYPE *array, int offset) + { + if (array) sfree_new(array+offset); + } + +/* ---------------------------------------------------------------------- + create a 2d array +------------------------------------------------------------------------- */ + + template <typename TYPE> + TYPE **create(TYPE **&array, int n1, int n2, const char *name) + { + bigint nbytes = sizeof(TYPE) * n1*n2; + TYPE *data = (TYPE *) smalloc_new(nbytes,name); + nbytes = sizeof(TYPE *) * n1; + array = (TYPE **) smalloc_new(nbytes,name); + + int n = 0; + for (int i = 0; i < n1; i++) { + array[i] = &data[n]; + n += n2; + } + return array; + } + +/* ---------------------------------------------------------------------- + grow or shrink 1st dim of a 2d array + last dim must stay the same + if either dim is 0, destroy it and return NULL +------------------------------------------------------------------------- */ + + template <typename TYPE> + TYPE **grow(TYPE **&array, int n1, int n2, const char *name) + { + if (array == NULL) return create(array,n1,n2,name); + if (n1 == 0 || n2 == 0) { + destroy(array); + return NULL; + } + + bigint nbytes = sizeof(TYPE) * n1*n2; + TYPE *data = (TYPE *) srealloc_new(array[0],nbytes,name); + nbytes = sizeof(TYPE *) * n1; + array = (TYPE **) srealloc_new(array,nbytes,name); + + int n = 0; + for (int i = 0; i < n1; i++) { + array[i] = &data[n]; + n += n2; + } + return array; + } + +/* ---------------------------------------------------------------------- + destroy a 2d array +------------------------------------------------------------------------- */ + + template <typename TYPE> + void destroy(TYPE **array) + { + if (array == NULL) return; + sfree_new(array[0]); + sfree_new(array); + } + +/* ---------------------------------------------------------------------- + create a 2d array with 2nd index from n2lo to n2hi inclusive +------------------------------------------------------------------------- */ + + template <typename TYPE> + TYPE **create(TYPE **&array, int n1, int n2lo, int n2hi, + const char *name) + { + int n2 = n2hi - n2lo + 1; + create(array,n1,n2,name); + for (int i = 0; i < n1; i++) array[i] -= n2lo; + return array; + } + +/* ---------------------------------------------------------------------- + destroy a 2d array with 2nd index offset +------------------------------------------------------------------------- */ + + template <typename TYPE> + void destroy(TYPE **array, int offset) + { + if (array == NULL) return; + sfree_new(&array[0][offset]); + sfree_new(array); + } + +/* ---------------------------------------------------------------------- + create a 3d array +------------------------------------------------------------------------- */ + + template <typename TYPE> + TYPE ***create(TYPE ***&array, int n1, int n2, int n3, const char *name) + { + bigint nbytes = sizeof(TYPE) * n1*n2*n3; + TYPE *data = (TYPE *) smalloc_new(nbytes,name); + nbytes = sizeof(TYPE *) * n1*n2; + TYPE **plane = (TYPE **) smalloc_new(nbytes,name); + nbytes = sizeof(TYPE **) * n1; + array = (TYPE ***) smalloc_new(nbytes,name); + + int i,j; + int n = 0; + for (i = 0; i < n1; i++) { + array[i] = &plane[i*n2]; + for (j = 0; j < n2; j++) { + plane[i*n2+j] = &data[n]; + n += n3; + } + } + return array; + } + +/* ---------------------------------------------------------------------- + grow or shrink 1st dim of a 3d array + last 2 dims must stay the same + if any dim is 0, destroy it and return NULL +------------------------------------------------------------------------- */ + + template <typename TYPE> + TYPE ***grow(TYPE ***&array, int n1, int n2, int n3, const char *name) + { + if (array == NULL) return create(array,n1,n2,n3,name); + if (n1 == 0 || n2 == 0 || n3 == 0) { + destroy(array); + return NULL; + } + + bigint nbytes = sizeof(TYPE) * n1*n2*n3; + TYPE *data = (TYPE *) srealloc_new(array[0][0],nbytes,name); + nbytes = sizeof(TYPE *) * n1*n2; + TYPE **plane = (TYPE **) srealloc_new(array[0],nbytes,name); + nbytes = sizeof(TYPE **) * n1; + array = (TYPE ***) srealloc_new(array,nbytes,name); + + int i,j; + int n = 0; + for (i = 0; i < n1; i++) { + array[i] = &plane[i*n2]; + for (j = 0; j < n2; j++) { + plane[i*n2+j] = &data[n]; + n += n3; + } + } + return array; + } + +/* ---------------------------------------------------------------------- + destroy a 3d array +------------------------------------------------------------------------- */ + + template <typename TYPE> + void destroy(TYPE ***array) + { + if (array == NULL) return; + sfree_new(array[0][0]); + sfree_new(array[0]); + sfree_new(array); + } + +/* ---------------------------------------------------------------------- + create a 3d array with 1st index from n1lo to n1hi inclusive +------------------------------------------------------------------------- */ + + template <typename TYPE> + TYPE ***create(TYPE ***&array, int n1lo, int n1hi, + int n2, int n3, const char *name) + { + int n1 = n1hi - n1lo + 1; + create(array,n1,n2,n3,name); + return array-n1lo; + } + +/* ---------------------------------------------------------------------- + free a 3d array with 1st index offset +------------------------------------------------------------------------- */ + + template <typename TYPE> + void destroy(TYPE ***array, int offset) + { + if (array) destroy(array+offset); + } + +/* ---------------------------------------------------------------------- + create a 3d array with + 1st index from n1lo to n1hi inclusive, + 2nd index from n2lo to n2hi inclusive, + 3rd index from n3lo to n3hi inclusive +------------------------------------------------------------------------- */ + + template <typename TYPE> + TYPE ***create(TYPE ***&array, int n1lo, int n1hi, int n2lo, int n2hi, + int n3lo, int n3hi, const char *name) + { + int n1 = n1hi - n1lo + 1; + int n2 = n2hi - n2lo + 1; + int n3 = n3hi - n3lo + 1; + create(array,n1,n2,n3,name); + + for (int i = 0; i < n1*n2; i++) array[0][i] -= n3lo; + for (int i = 0; i < n1; i++) array[i] -= n2lo; + return array-n1lo; + } + +/* ---------------------------------------------------------------------- + free a 3d array with all 3 indices offset +------------------------------------------------------------------------- */ + + template <typename TYPE> + void destroy(TYPE ***array, int n1_offset, int n2_offset, int n3_offset) + { + if (array == NULL) return; + sfree_new(&array[n1_offset][n2_offset][n3_offset]); + sfree_new(&array[n1_offset][n2_offset]); + sfree_new(array + n1_offset); + } + +/* ---------------------------------------------------------------------- + create a 4d array +------------------------------------------------------------------------- */ + + template <typename TYPE> + TYPE ****create(TYPE ****&array, int n1, int n2, int n3, int n4, + const char *name) + { + bigint nbytes = sizeof(TYPE) * n1*n2*n3*n4; + TYPE *data = (double *) smalloc_new(nbytes,name); + nbytes = sizeof(TYPE *) * n1*n2*n3; + TYPE **cube = (double **) smalloc_new(nbytes,name); + nbytes = sizeof(TYPE **) * n1*n2; + TYPE ***plane = (double ***) smalloc_new(nbytes,name); + nbytes = sizeof(TYPE ***) * n1; + array = (double ****) smalloc_new(nbytes,name); + + int i,j,k; + int n = 0; + for (i = 0; i < n1; i++) { + array[i] = &plane[i*n2]; + for (j = 0; j < n2; j++) { + plane[i*n2+j] = &cube[i*n2*n3+j*n3]; + for (k = 0; k < n3; k++) { + cube[i*n2*n3+j*n3+k] = &data[n]; + n += n4; + } + } + } + return array; + } + +/* ---------------------------------------------------------------------- + destroy a 4d array +------------------------------------------------------------------------- */ + + template <typename TYPE> + void destroy(TYPE ****array) + { + if (array == NULL) return; + sfree_new(array[0][0][0]); + sfree_new(array[0][0]); + sfree_new(array[0]); + sfree_new(array); + } }; } diff --git a/src/neigh_bond.cpp b/src/neigh_bond.cpp index 2ef6b89507..b16598011e 100644 --- a/src/neigh_bond.cpp +++ b/src/neigh_bond.cpp @@ -51,8 +51,7 @@ void Neighbor::bond_all() if (newton_bond || i < atom1) { if (nbondlist == maxbond) { maxbond += BONDDELTA; - bondlist = memory->grow_2d_int_array(bondlist,maxbond,3, - "neighbor:bondlist"); + memory->grow(bondlist,maxbond,3,"neighbor:bondlist"); } bondlist[nbondlist][0] = i; bondlist[nbondlist][1] = atom1; @@ -91,8 +90,7 @@ void Neighbor::bond_partial() if (newton_bond || i < atom1) { if (nbondlist == maxbond) { maxbond += BONDDELTA; - bondlist = memory->grow_2d_int_array(bondlist,maxbond,3, - "neighbor:bondlist"); + memory->grow(bondlist,maxbond,3,"neighbor:bondlist"); } bondlist[nbondlist][0] = i; bondlist[nbondlist][1] = atom1; @@ -135,8 +133,7 @@ void Neighbor::angle_all() if (newton_bond || (i <= atom1 && i <= atom2 && i <= atom3)) { if (nanglelist == maxangle) { maxangle += BONDDELTA; - anglelist = memory->grow_2d_int_array(anglelist,maxangle,4, - "neighbor:anglelist"); + memory->grow(anglelist,maxangle,4,"neighbor:anglelist"); } anglelist[nanglelist][0] = atom1; anglelist[nanglelist][1] = atom2; @@ -181,8 +178,7 @@ void Neighbor::angle_partial() if (newton_bond || (i <= atom1 && i <= atom2 && i <= atom3)) { if (nanglelist == maxangle) { maxangle += BONDDELTA; - anglelist = memory->grow_2d_int_array(anglelist,maxangle,4, - "neighbor:anglelist"); + memory->grow(anglelist,maxangle,4,"neighbor:anglelist"); } anglelist[nanglelist][0] = atom1; anglelist[nanglelist][1] = atom2; @@ -230,9 +226,7 @@ void Neighbor::dihedral_all() (i <= atom1 && i <= atom2 && i <= atom3 && i <= atom4)) { if (ndihedrallist == maxdihedral) { maxdihedral += BONDDELTA; - dihedrallist = - memory->grow_2d_int_array(dihedrallist,maxdihedral,5, - "neighbor:dihedrallist"); + memory->grow(dihedrallist,maxdihedral,5,"neighbor:dihedrallist"); } dihedrallist[ndihedrallist][0] = atom1; dihedrallist[ndihedrallist][1] = atom2; @@ -282,9 +276,7 @@ void Neighbor::dihedral_partial() (i <= atom1 && i <= atom2 && i <= atom3 && i <= atom4)) { if (ndihedrallist == maxdihedral) { maxdihedral += BONDDELTA; - dihedrallist = - memory->grow_2d_int_array(dihedrallist,maxdihedral,5, - "neighbor:dihedrallist"); + memory->grow(dihedrallist,maxdihedral,5,"neighbor:dihedrallist"); } dihedrallist[ndihedrallist][0] = atom1; dihedrallist[ndihedrallist][1] = atom2; @@ -333,9 +325,7 @@ void Neighbor::improper_all() (i <= atom1 && i <= atom2 && i <= atom3 && i <= atom4)) { if (nimproperlist == maximproper) { maximproper += BONDDELTA; - improperlist = - memory->grow_2d_int_array(improperlist,maximproper,5, - "neighbor:improperlist"); + memory->grow(improperlist,maximproper,5,"neighbor:improperlist"); } improperlist[nimproperlist][0] = atom1; improperlist[nimproperlist][1] = atom2; @@ -385,9 +375,7 @@ void Neighbor::improper_partial() (i <= atom1 && i <= atom2 && i <= atom3 && i <= atom4)) { if (nimproperlist == maximproper) { maximproper += BONDDELTA; - improperlist = - memory->grow_2d_int_array(improperlist,maximproper,5, - "neighbor:improperlist"); + memory->grow(improperlist,maximproper,5,"neighbor:improperlist"); } improperlist[nimproperlist][0] = atom1; improperlist[nimproperlist][1] = atom2; diff --git a/src/neigh_list.cpp b/src/neigh_list.cpp index 9426c3df68..c5bd04b3f7 100644 --- a/src/neigh_list.cpp +++ b/src/neigh_list.cpp @@ -70,27 +70,27 @@ NeighList::NeighList(LAMMPS *lmp, int size) : Pointers(lmp) NeighList::~NeighList() { if (!listcopy) { - memory->sfree(ilist); - memory->sfree(numneigh); + memory->destroy(ilist); + memory->destroy(numneigh); memory->sfree(firstneigh); memory->sfree(firstdouble); - for (int i = 0; i < maxpage; i++) memory->sfree(pages[i]); + for (int i = 0; i < maxpage; i++) memory->destroy(pages[i]); memory->sfree(pages); if (dnum) { - for (int i = 0; i < maxpage; i++) memory->sfree(dpages[i]); + for (int i = 0; i < maxpage; i++) memory->destroy(dpages[i]); memory->sfree(dpages); } } delete [] iskip; - memory->destroy_2d_int_array(ijskip); + memory->destroy(ijskip); - if (maxstencil) memory->sfree(stencil); + if (maxstencil) memory->destroy(stencil); if (maxstencil_multi) { for (int i = 1; i <= atom->ntypes; i++) { - memory->sfree(stencil_multi[i]); - memory->sfree(distsq_multi[i]); + memory->destroy(stencil_multi[i]); + memory->destroy(distsq_multi[i]); } delete [] nstencil_multi; delete [] stencil_multi; @@ -110,13 +110,11 @@ void NeighList::grow(int nmax) if (nmax <= maxlocal) return; maxlocal = nmax; - memory->sfree(ilist); - memory->sfree(numneigh); + memory->destroy(ilist); + memory->destroy(numneigh); memory->sfree(firstneigh); - ilist = (int *) - memory->smalloc(maxlocal*sizeof(int),"neighlist:ilist"); - numneigh = (int *) - memory->smalloc(maxlocal*sizeof(int),"neighlist:numneigh"); + memory->create(ilist,maxlocal,"neighlist:ilist"); + memory->create(numneigh,maxlocal,"neighlist:numneigh"); firstneigh = (int **) memory->smalloc(maxlocal*sizeof(int *),"neighlist:firstneigh"); @@ -137,8 +135,8 @@ void NeighList::stencil_allocate(int smax, int style) if (style == BIN) { if (smax > maxstencil) { maxstencil = smax; - memory->sfree(stencil); - stencil = (int *) memory->smalloc(smax*sizeof(int),"neighlist:stencil"); + memory->destroy(stencil); + memory->create(stencil,smax,"neighlist:stencil"); } } else { @@ -156,12 +154,10 @@ void NeighList::stencil_allocate(int smax, int style) if (smax > maxstencil_multi) { maxstencil_multi = smax; for (i = 1; i <= n; i++) { - memory->sfree(stencil_multi[i]); - memory->sfree(distsq_multi[i]); - stencil_multi[i] = (int *) - memory->smalloc(smax*sizeof(int),"neighlist:stencil_multi"); - distsq_multi[i] = (double *) memory->smalloc(smax*sizeof(double), - "neighlist:distsq_multi"); + memory->destroy(stencil_multi[i]); + memory->destroy(distsq_multi[i]); + memory->create(stencil_multi[i],smax,"neighlist:stencil_multi"); + memory->create(distsq_multi[i],smax,"neighlist:distsq_multi"); } } } @@ -179,15 +175,13 @@ int **NeighList::add_pages() pages = (int **) memory->srealloc(pages,maxpage*sizeof(int *),"neighlist:pages"); for (int i = npage; i < maxpage; i++) - pages[i] = (int *) memory->smalloc(pgsize*sizeof(int), - "neighlist:pages[i]"); + memory->create(pages[i],pgsize,"neighlist:pages[i]"); if (dnum) { dpages = (double **) memory->srealloc(dpages,maxpage*sizeof(double *),"neighlist:dpages"); for (int i = npage; i < maxpage; i++) - dpages[i] = (double *) memory->smalloc(dnum*pgsize*sizeof(double), - "neighlist:dpages[i]"); + memory->create(dpages[i],dnum*pgsize,"neighlist:dpages[i]"); } return pages; @@ -201,8 +195,7 @@ void NeighList::copy_skip_info(int *rq_iskip, int **rq_ijskip) { int ntypes = atom->ntypes; iskip = new int[ntypes+1]; - ijskip = memory->create_2d_int_array(ntypes+1,ntypes+1, - "neigh_list:ijskip"); + memory->create(ijskip,ntypes+1,ntypes+1,"neigh_list:ijskip"); int i,j; for (i = 1; i <= ntypes; i++) iskip[i] = rq_iskip[i]; for (i = 1; i <= ntypes; i++) diff --git a/src/neigh_request.cpp b/src/neigh_request.cpp index 4eb2a73a56..bd55b6e79f 100644 --- a/src/neigh_request.cpp +++ b/src/neigh_request.cpp @@ -64,7 +64,7 @@ NeighRequest::NeighRequest(LAMMPS *lmp) : Pointers(lmp) NeighRequest::~NeighRequest() { delete [] iskip; - memory->destroy_2d_int_array(ijskip); + memory->destroy(ijskip); } /* ---------------------------------------------------------------------- diff --git a/src/neigh_stencil.cpp b/src/neigh_stencil.cpp index 7f2170a022..8c41021782 100644 --- a/src/neigh_stencil.cpp +++ b/src/neigh_stencil.cpp @@ -14,7 +14,6 @@ #include "neighbor.h" #include "neigh_list.h" #include "atom.h" -#include "memory.h" using namespace LAMMPS_NS; diff --git a/src/neighbor.cpp b/src/neighbor.cpp index bddea6484b..76ec425b72 100644 --- a/src/neighbor.cpp +++ b/src/neighbor.cpp @@ -138,26 +138,26 @@ Neighbor::Neighbor(LAMMPS *lmp) : Pointers(lmp) Neighbor::~Neighbor() { - memory->destroy_2d_double_array(cutneighsq); + memory->destroy(cutneighsq); delete [] cuttype; delete [] cuttypesq; delete [] fixchecklist; - memory->destroy_2d_double_array(xhold); + memory->destroy(xhold); - memory->sfree(binhead); - memory->sfree(bins); + memory->destroy(binhead); + memory->destroy(bins); - memory->sfree(ex1_type); - memory->sfree(ex2_type); - memory->destroy_2d_int_array(ex_type); + memory->destroy(ex1_type); + memory->destroy(ex2_type); + memory->destroy(ex_type); - memory->sfree(ex1_group); - memory->sfree(ex2_group); + memory->destroy(ex1_group); + memory->destroy(ex2_group); delete [] ex1_bit; delete [] ex2_bit; - memory->sfree(ex_mol_group); + memory->destroy(ex_mol_group); delete [] ex_mol_bit; for (int i = 0; i < nlist; i++) delete lists[i]; @@ -173,10 +173,10 @@ Neighbor::~Neighbor() for (int i = 0; i < old_nrequest; i++) delete old_requests[i]; memory->sfree(old_requests); - memory->destroy_2d_int_array(bondlist); - memory->destroy_2d_int_array(anglelist); - memory->destroy_2d_int_array(dihedrallist); - memory->destroy_2d_int_array(improperlist); + memory->destroy(bondlist); + memory->destroy(anglelist); + memory->destroy(dihedrallist); + memory->destroy(improperlist); } /* ---------------------------------------------------------------------- */ @@ -225,7 +225,7 @@ void Neighbor::init() n = atom->ntypes; if (cutneighsq == NULL) { - cutneighsq = memory->create_2d_double_array(n+1,n+1,"neigh:cutneighsq"); + memory->create(cutneighsq,n+1,n+1,"neigh:cutneighsq"); cuttype = new double[n+1]; cuttypesq = new double[n+1]; } @@ -326,14 +326,14 @@ void Neighbor::init() // free xhold and bins if not needed for this run if (dist_check == 0) { - memory->destroy_2d_double_array(xhold); + memory->destroy(xhold); maxhold = 0; xhold = NULL; } if (style == NSQ) { - memory->sfree(bins); - memory->sfree(binhead); + memory->destroy(bins); + memory->destroy(binhead); maxbin = maxhead = 0; binhead = NULL; bins = NULL; @@ -344,14 +344,14 @@ void Neighbor::init() if (dist_check) { if (maxhold == 0) { maxhold = atom->nmax; - xhold = memory->create_2d_double_array(maxhold,3,"neigh:xhold"); + memory->create(xhold,maxhold,3,"neigh:xhold"); } } if (style != NSQ) { if (maxbin == 0) { maxbin = atom->nmax; - bins = (int *) memory->smalloc(maxbin*sizeof(int),"bins"); + memory->create(bins,maxbin,"bins"); } } @@ -363,8 +363,8 @@ void Neighbor::init() else exclude = 1; if (nex_type) { - memory->destroy_2d_int_array(ex_type); - ex_type = (int **) memory->create_2d_int_array(n+1,n+1,"neigh:ex_type"); + memory->destroy(ex_type); + memory->create(ex_type,n+1,n+1,"neigh:ex_type"); for (i = 1; i <= n; i++) for (j = 1; j <= n; j++) @@ -647,7 +647,7 @@ void Neighbor::init() // copy current requests and style to old for next run for (i = 0; i < old_nrequest; i++) delete old_requests[i]; - memory->sfree(old_requests); + memory->destroy(old_requests); old_nrequest = nrequest; old_requests = requests; nrequest = maxrequest = 0; @@ -663,29 +663,27 @@ void Neighbor::init() if (atom->molecular && atom->nbonds && maxbond == 0) { if (nprocs == 1) maxbond = atom->nbonds; else maxbond = static_cast<int> (LB_FACTOR * atom->nbonds / nprocs); - bondlist = memory->create_2d_int_array(maxbond,3,"neigh:bondlist"); + memory->create(bondlist,maxbond,3,"neigh:bondlist"); } if (atom->molecular && atom->nangles && maxangle == 0) { if (nprocs == 1) maxangle = atom->nangles; else maxangle = static_cast<int> (LB_FACTOR * atom->nangles / nprocs); - anglelist = memory->create_2d_int_array(maxangle,4,"neigh:anglelist"); + memory->create(anglelist,maxangle,4,"neigh:anglelist"); } if (atom->molecular && atom->ndihedrals && maxdihedral == 0) { if (nprocs == 1) maxdihedral = atom->ndihedrals; else maxdihedral = static_cast<int> (LB_FACTOR * atom->ndihedrals / nprocs); - dihedrallist = - memory->create_2d_int_array(maxdihedral,5,"neigh:dihedrallist"); + memory->create(dihedrallist,maxdihedral,5,"neigh:dihedrallist"); } if (atom->molecular && atom->nimpropers && maximproper == 0) { if (nprocs == 1) maximproper = atom->nimpropers; else maximproper = static_cast<int> (LB_FACTOR * atom->nimpropers / nprocs); - improperlist = - memory->create_2d_int_array(maximproper,5,"neigh:improperlist"); + memory->create(improperlist,maximproper,5,"neigh:improperlist"); } // set flags that determine which topology neighboring routines to use @@ -1093,8 +1091,8 @@ void Neighbor::build() if (includegroup) nlocal = atom->nfirst; if (nlocal > maxhold) { maxhold = atom->nmax; - memory->destroy_2d_double_array(xhold); - xhold = memory->create_2d_double_array(maxhold,3,"neigh:xhold"); + memory->destroy(xhold); + memory->create(xhold,maxhold,3,"neigh:xhold"); } for (i = 0; i < nlocal; i++) { xhold[i][0] = x[i][0]; @@ -1133,8 +1131,8 @@ void Neighbor::build() if (style != NSQ && atom->nmax > maxbin) { maxbin = atom->nmax; - memory->sfree(bins); - bins = (int *) memory->smalloc(maxbin*sizeof(int),"bins"); + memory->destroy(bins); + memory->create(bins,maxbin,"bins"); } // check that pairwise lists with special bond weighting will not overflow @@ -1179,8 +1177,8 @@ void Neighbor::build_one(int i) if (style != NSQ && atom->nmax > maxbin) { maxbin = atom->nmax; - memory->sfree(bins); - bins = (int *) memory->smalloc(maxbin*sizeof(int),"bins"); + memory->destroy(bins); + memory->create(bins,maxbin,"bins"); } // this condition can cause LAMMPS to crash @@ -1354,8 +1352,8 @@ void Neighbor::setup_bins() mbins = bbin; if (mbins > maxhead) { maxhead = mbins; - memory->sfree(binhead); - binhead = (int *) memory->smalloc(maxhead*sizeof(int),"neigh:binhead"); + memory->destroy(binhead); + memory->create(binhead,maxhead,"neigh:binhead"); } // create stencil of bins to search over in neighbor list construction @@ -1481,10 +1479,8 @@ void Neighbor::modify_params(int narg, char **arg) if (iarg+4 > narg) error->all("Illegal neigh_modify command"); if (nex_type == maxex_type) { maxex_type += EXDELTA; - ex1_type = (int *) memory->srealloc(ex1_type,maxex_type*sizeof(int), - "neigh:ex1_type"); - ex2_type = (int *) memory->srealloc(ex2_type,maxex_type*sizeof(int), - "neigh:ex2_type"); + memory->grow(ex1_type,maxex_type,"neigh:ex1_type"); + memory->grow(ex2_type,maxex_type,"neigh:ex2_type"); } ex1_type[nex_type] = atoi(arg[iarg+2]); ex2_type[nex_type] = atoi(arg[iarg+3]); @@ -1495,12 +1491,8 @@ void Neighbor::modify_params(int narg, char **arg) if (iarg+4 > narg) error->all("Illegal neigh_modify command"); if (nex_group == maxex_group) { maxex_group += EXDELTA; - ex1_group = - (int *) memory->srealloc(ex1_group,maxex_group*sizeof(int), - "neigh:ex1_group"); - ex2_group = - (int *) memory->srealloc(ex2_group,maxex_group*sizeof(int), - "neigh:ex2_group"); + memory->grow(ex1_group,maxex_group,"neigh:ex1_group"); + memory->grow(ex2_group,maxex_group,"neigh:ex2_group"); } ex1_group[nex_group] = group->find(arg[iarg+2]); ex2_group[nex_group] = group->find(arg[iarg+3]); @@ -1518,9 +1510,7 @@ void Neighbor::modify_params(int narg, char **arg) } if (nex_mol == maxex_mol) { maxex_mol += EXDELTA; - ex_mol_group = - (int *) memory->srealloc(ex_mol_group,maxex_mol*sizeof(int), - "neigh:ex_mol_group"); + memory->grow(ex_mol_group,maxex_mol,"neigh:ex_mol_group"); } ex_mol_group[nex_mol] = group->find(arg[iarg+2]); if (ex_mol_group[nex_mol] == -1) -- GitLab