Commit fcc387f2 authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

change ring communication API to no longer require a static variable pointing...

change ring communication API to no longer require a static variable pointing to 'this' of the caller
parent 286d4f27
Loading
Loading
Loading
Loading
+9 −13
Original line number Diff line number Diff line
@@ -41,10 +41,6 @@ using namespace LAMMPS_NS;
using namespace FixConst;
using namespace MathConst;

// allocate space for static class variable

FixRigidSmall *FixRigidSmall::frsptr;

#define MAXLINE 1024
#define CHUNK 1024
#define ATTRIBUTE_PERBODY 20
@@ -1499,8 +1495,7 @@ void FixRigidSmall::create_bodies()
  // func = update bbox with atom coords from every proc
  // when done, have full bbox for every rigid body my atoms are part of

  frsptr = this;
  comm->ring(m,sizeof(double),buf,1,ring_bbox,NULL);
  comm->ring(m,sizeof(double),buf,1,ring_bbox,NULL,(void *)this);

  // check if any bbox is size 0.0, meaning rigid body is a single particle

@@ -1549,8 +1544,7 @@ void FixRigidSmall::create_bodies()
  // func = update idclose,rsqclose with atom IDs from every proc
  // when done, have idclose for every rigid body my atoms are part of

  frsptr = this;
  comm->ring(m,sizeof(double),buf,2,ring_nearest,NULL);
  comm->ring(m,sizeof(double),buf,2,ring_nearest,NULL,(void *)this);

  // set bodytag of all owned atoms, based on idclose
  // find max value of rsqclose across all procs
@@ -1581,8 +1575,7 @@ void FixRigidSmall::create_bodies()
  // when done, have rsqfar for all atoms in bodies I own

  rsqfar = 0.0;
  frsptr = this;
  comm->ring(m,sizeof(double),buf,3,ring_farthest,NULL);
  comm->ring(m,sizeof(double),buf,3,ring_farthest,NULL,(void *)this);

  // find maxextent of rsqfar across all procs
  // if defined, include molecule->maxextent
@@ -1609,8 +1602,9 @@ void FixRigidSmall::create_bodies()
   update bounding box for rigid bodies my atoms are part of
------------------------------------------------------------------------- */

void FixRigidSmall::ring_bbox(int n, char *cbuf)
void FixRigidSmall::ring_bbox(int n, char *cbuf, void *ptr)
{
  FixRigidSmall *frsptr = (FixRigidSmall *) ptr;
  std::map<tagint,int> *hash = frsptr->hash;
  double **bbox = frsptr->bbox;

@@ -1641,8 +1635,9 @@ void FixRigidSmall::ring_bbox(int n, char *cbuf)
   update nearest atom to body center for rigid bodies my atoms are part of
------------------------------------------------------------------------- */

void FixRigidSmall::ring_nearest(int n, char *cbuf)
void FixRigidSmall::ring_nearest(int n, char *cbuf, void *ptr)
{
  FixRigidSmall *frsptr = (FixRigidSmall *) ptr;
  std::map<tagint,int> *hash = frsptr->hash;
  double **ctr = frsptr->ctr;
  tagint *idclose = frsptr->idclose;
@@ -1681,8 +1676,9 @@ void FixRigidSmall::ring_nearest(int n, char *cbuf)
   update rsqfar = distance from owning atom to other atom
------------------------------------------------------------------------- */

void FixRigidSmall::ring_farthest(int n, char *cbuf)
void FixRigidSmall::ring_farthest(int n, char *cbuf, void *ptr)
{
  FixRigidSmall *frsptr = (FixRigidSmall *) ptr;
  double **x = frsptr->atom->x;
  imageint *image = frsptr->atom->image;
  int nlocal = frsptr->atom->nlocal;
+3 −7
Original line number Diff line number Diff line
@@ -31,10 +31,6 @@ class FixRigidSmall : public Fix {
  friend class ComputeRigidLocal;

 public:
  // static variable for ring communication callback to access class data

  static FixRigidSmall *frsptr;

  FixRigidSmall(class LAMMPS *, int, char **);
  virtual ~FixRigidSmall();
  virtual int setmask();
@@ -199,9 +195,9 @@ class FixRigidSmall : public Fix {

  // callback functions for ring communication

  static void ring_bbox(int, char *);
  static void ring_nearest(int, char *);
  static void ring_farthest(int, char *);
  static void ring_bbox(int, char *, void *);
  static void ring_nearest(int, char *, void *);
  static void ring_farthest(int, char *, void *);

  // debug

+9 −13
Original line number Diff line number Diff line
@@ -39,10 +39,6 @@ using namespace LAMMPS_NS;
using namespace FixConst;
using namespace MathConst;

// allocate space for static class variable

FixShake *FixShake::fsptr;

#define BIG 1.0e20
#define MASSDELTA 0.1

@@ -844,8 +840,7 @@ void FixShake::find_clusters()

  // cycle buffer around ring of procs back to self

  fsptr = this;
  comm->ring(size,sizeof(tagint),buf,1,ring_bonds,buf);
  comm->ring(size,sizeof(tagint),buf,1,ring_bonds,buf,(void *)this);

  // store partner info returned to me

@@ -970,8 +965,7 @@ void FixShake::find_clusters()

  // cycle buffer around ring of procs back to self

  fsptr = this;
  comm->ring(size,sizeof(tagint),buf,2,ring_nshake,buf);
  comm->ring(size,sizeof(tagint),buf,2,ring_nshake,buf,(void *)this);

  // store partner info returned to me
  
@@ -1123,8 +1117,7 @@ void FixShake::find_clusters()

  // cycle buffer around ring of procs back to self

  fsptr = this;
  comm->ring(size,sizeof(tagint),buf,3,ring_shake,NULL);
  comm->ring(size,sizeof(tagint),buf,3,ring_shake,NULL,(void *)this);

  memory->destroy(buf);

@@ -1211,8 +1204,9 @@ void FixShake::find_clusters()
     search for bond with 1st atom and fill in bondtype
------------------------------------------------------------------------- */

void FixShake::ring_bonds(int ndatum, char *cbuf)
void FixShake::ring_bonds(int ndatum, char *cbuf, void *ptr)
{
  FixShake *fsptr = (FixShake *)ptr;
  Atom *atom = fsptr->atom;
  double *rmass = atom->rmass;
  double *mass = atom->mass;
@@ -1248,8 +1242,9 @@ void FixShake::ring_bonds(int ndatum, char *cbuf)
   if I own partner, fill in nshake value
------------------------------------------------------------------------- */

void FixShake::ring_nshake(int ndatum, char *cbuf)
void FixShake::ring_nshake(int ndatum, char *cbuf, void *ptr)
{
  FixShake *fsptr = (FixShake *)ptr;
  Atom *atom = fsptr->atom;
  int nlocal = atom->nlocal;

@@ -1269,8 +1264,9 @@ void FixShake::ring_nshake(int ndatum, char *cbuf)
   if I own partner, fill in nshake value
------------------------------------------------------------------------- */

void FixShake::ring_shake(int ndatum, char *cbuf)
void FixShake::ring_shake(int ndatum, char *cbuf, void *ptr)
{
  FixShake *fsptr = (FixShake *)ptr;
  Atom *atom = fsptr->atom;
  int nlocal = atom->nlocal;

+3 −4
Original line number Diff line number Diff line
@@ -134,10 +134,9 @@ class FixShake : public Fix {
  // static variable for ring communication callback to access class data
  // callback functions for ring communication

  static FixShake *fsptr;
  static void ring_bonds(int, char *);
  static void ring_nshake(int, char *);
  static void ring_shake(int, char *);
  static void ring_bonds(int, char *, void *);
  static void ring_nshake(int, char *, void *);
  static void ring_shake(int, char *, void *);
};

}
+29 −27
Original line number Diff line number Diff line
@@ -28,8 +28,6 @@
using namespace LAMMPS_NS;
using namespace FixConst;

FixDrude *FixDrude::sptr = NULL;

/* ---------------------------------------------------------------------- */

FixDrude::FixDrude(LAMMPS *lmp, int narg, char **arg) :
@@ -111,7 +109,6 @@ void FixDrude::build_drudeid(){
  std::vector<tagint> core_drude_vec;
  partner_set = new std::set<tagint>[nlocal]; // Temporary sets of bond partner tags

  sptr = this;
  if (atom->molecular == 1)
  {
    // Build list of my atoms' bond partners
@@ -149,7 +146,7 @@ void FixDrude::build_drudeid(){
  // Loop on procs to fill my atoms' sets of bond partners
  comm->ring(core_drude_vec.size(), sizeof(tagint),
             (char *) core_drude_vec.data(),
             4, ring_build_partner, NULL, 1);
             4, ring_build_partner, NULL, (void *)this, 1);

  // Build the list of my Drudes' tags
  // The only bond partners of a Drude particle is its core,
@@ -165,7 +162,7 @@ void FixDrude::build_drudeid(){
  // so that each core finds its Drude.
  comm->ring(drude_vec.size(), sizeof(tagint),
             (char *) drude_vec.data(),
             3, ring_search_drudeid, NULL, 1);
             3, ring_search_drudeid, NULL, (void *)this, 1);
  delete [] partner_set;
}

@@ -174,14 +171,15 @@ void FixDrude::build_drudeid(){
 * Look in my cores' bond partner tags if there is a Drude tag.
 * If so fill this core's dureid.
------------------------------------------------------------------------- */
void FixDrude::ring_search_drudeid(int size, char *cbuf){
void FixDrude::ring_search_drudeid(int size, char *cbuf, void *ptr){
  // Search for the drude partner of my cores
  Atom *atom = sptr->atom;
  FixDrude *fdptr = (FixDrude *) ptr;
  Atom *atom = fdptr->atom;
  int nlocal = atom->nlocal;
  int *type = atom->type;
  std::set<tagint> *partner_set = sptr->partner_set;
  tagint *drudeid = sptr->drudeid;
  int *drudetype = sptr->drudetype;
  std::set<tagint> *partner_set = fdptr->partner_set;
  tagint *drudeid = fdptr->drudeid;
  int *drudetype = fdptr->drudetype;

  tagint *first = (tagint *) cbuf;
  tagint *last = first + size;
@@ -203,11 +201,12 @@ void FixDrude::ring_search_drudeid(int size, char *cbuf){
 * buffer contains bond partners. Look for my atoms and add their partner's
 * tag in its set of bond partners.
------------------------------------------------------------------------- */
void FixDrude::ring_build_partner(int size, char *cbuf){
void FixDrude::ring_build_partner(int size, char *cbuf, void *ptr){
  // Add partners from incoming list
  Atom *atom = sptr->atom;
  FixDrude *fdptr = (FixDrude *) ptr;
  Atom *atom = fdptr->atom;
  int nlocal = atom->nlocal;
  std::set<tagint> *partner_set = sptr->partner_set;
  std::set<tagint> *partner_set = fdptr->partner_set;
  tagint *it = (tagint *) cbuf;
  tagint *last = it + size;

@@ -338,11 +337,11 @@ void FixDrude::rebuild_special(){
  // Remove Drude particles from the special lists of each proc
  comm->ring(drude_vec.size(), sizeof(tagint),
             (char *) drude_vec.data(),
             9, ring_remove_drude, NULL, 1);
             9, ring_remove_drude, NULL, (void *)this, 1);
  // Add back Drude particles in the lists just after their core
  comm->ring(core_drude_vec.size(), sizeof(tagint),
             (char *) core_drude_vec.data(),
             10, ring_add_drude, NULL, 1);
             10, ring_add_drude, NULL, (void *)this, 1);

  // Check size of special list
  nspecmax_loc = 0;
@@ -373,16 +372,17 @@ void FixDrude::rebuild_special(){
  // Copy core's list into their drude list
  comm->ring(core_special_vec.size(), sizeof(tagint),
             (char *) core_special_vec.data(),
             11, ring_copy_drude, NULL, 1);
             11, ring_copy_drude, NULL, (void *)this, 1);
}

/* ----------------------------------------------------------------------
 * When receive buffer, build a set of drude tags, look into my atoms'
 * special list if some tags are drude particles. If so, remove it.
------------------------------------------------------------------------- */
void FixDrude::ring_remove_drude(int size, char *cbuf){
void FixDrude::ring_remove_drude(int size, char *cbuf, void *ptr){
  // Remove all drude particles from special list
  Atom *atom = sptr->atom;
  FixDrude *fdptr = (FixDrude *) ptr;
  Atom *atom = fdptr->atom;
  int nlocal = atom->nlocal;
  int **nspecial = atom->nspecial;
  tagint **special = atom->special;
@@ -390,7 +390,7 @@ void FixDrude::ring_remove_drude(int size, char *cbuf){
  tagint *first = (tagint *) cbuf;
  tagint *last = first + size;
  std::set<tagint> drude_set(first, last);
  int *drudetype = sptr->drudetype;
  int *drudetype = fdptr->drudetype;

  for (int i=0; i<nlocal; i++) {
    if (drudetype[type[i]] == DRUDE_TYPE) continue;
@@ -415,16 +415,17 @@ void FixDrude::ring_remove_drude(int size, char *cbuf){
 * Loop on my atoms' special list to find core tags. Insert their Drude
 * particle if they have one.
------------------------------------------------------------------------- */
void FixDrude::ring_add_drude(int size, char *cbuf){
void FixDrude::ring_add_drude(int size, char *cbuf, void *ptr){
  // Assume special array size is big enough
  // Add all particle just after their core in the special list
  Atom *atom = sptr->atom;
  FixDrude *fdptr = (FixDrude *) ptr;
  Atom *atom = fdptr->atom;
  int nlocal = atom->nlocal;
  int **nspecial = atom->nspecial;
  tagint **special = atom->special;
  int *type = atom->type;
  tagint *drudeid = sptr->drudeid;
  int *drudetype = sptr->drudetype;
  tagint *drudeid = fdptr->drudeid;
  int *drudetype = fdptr->drudetype;

  tagint *first = (tagint *) cbuf;
  tagint *last = first + size;
@@ -471,15 +472,16 @@ void FixDrude::ring_add_drude(int size, char *cbuf){
 * in the buffer. Loop on my Drude particles and copy their special
 * info from that of their core if the latter is found in the map.
------------------------------------------------------------------------- */
void FixDrude::ring_copy_drude(int size, char *cbuf){
void FixDrude::ring_copy_drude(int size, char *cbuf, void *ptr){
  // Copy special list of drude from its core (except itself)
  Atom *atom = sptr->atom;
  FixDrude *fdptr = (FixDrude *) ptr;
  Atom *atom = fdptr->atom;
  int nlocal = atom->nlocal;
  int **nspecial = atom->nspecial;
  tagint **special = atom->special;
  int *type = atom->type;
  tagint *drudeid = sptr->drudeid;
  int *drudetype = sptr->drudetype;
  tagint *drudeid = fdptr->drudeid;
  int *drudetype = fdptr->drudetype;

  tagint *first = (tagint *) cbuf;
  tagint *last = first + size;
Loading