NAMD
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Friends | List of all members
PatchMap Class Reference

#include <PatchMap.h>

Public Types

enum  { MaxTwoAway = 5*5*5 - 3*3*3 }
 
enum  { MaxOneAway = 3*3*3 - 1 }
 
enum  { MaxOneOrTwoAway = MaxOneAway + MaxTwoAway }
 

Public Member Functions

int sizeGrid (ScaledPosition xmin, ScaledPosition xmax, const Lattice &lattice, BigReal patchSize, double maxNumPatches, int staticAtomAssignment, int asplit, int bsplit, int csplit)
 
void makePatches (ScaledPosition xmin, ScaledPosition xmax, const Lattice &lattice, BigReal patchSize, double maxNumPatches, int staticAtomAssignment, int replicaUniformPatchGrids, int lcpo, int asplit, int bsplit, int csplit)
 
void checkMap ()
 
 ~PatchMap (void)
 
HomePatchListhomePatchList ()
 
void homePatchIDList (PatchIDList &)
 
void basePatchIDList (int pe, PatchIDList &)
 
int numHomePatches (void)
 
int numPatches (void) const
 
int numPatchesOnNode (int node)
 
int numNodesWithPatches (void)
 
int gridsize_a (void) const
 
int gridsize_b (void) const
 
int gridsize_c (void) const
 
int numaway_a (void) const
 
int numaway_b (void) const
 
int numaway_c (void) const
 
int periodic_a (void) const
 
int periodic_b (void) const
 
int periodic_c (void) const
 
ScaledPosition origin (void) const
 
int pid (int aIndex, int bIndex, int cIndex)
 
int index_a (int pid) const
 
int index_b (int pid) const
 
int index_c (int pid) const
 
BigReal min_a (int pid) const
 
BigReal max_a (int pid) const
 
BigReal min_b (int pid) const
 
BigReal max_b (int pid) const
 
BigReal min_c (int pid) const
 
BigReal max_c (int pid) const
 
ScaledPosition center (int pid) const
 
PatchID assignToPatch (Position p, const Lattice &l)
 
int downstream (int pid1, int pid2)
 
int node (int pid) const
 
int basenode (int pid) const
 
int numCids (int pid) const
 
int cid (int pid, int i) const
 
void assignNode (PatchID, NodeID)
 
void assignBaseNode (PatchID, NodeID)
 
void assignBaseNode (PatchID)
 
void newCid (int pid, int cid)
 
int oneAwayNeighbors (int pid, PatchID *neighbor_ids=0)
 
int oneOrTwoAwayNeighbors (int pid, PatchID *neighbor_ids, PatchID *downstream_ids=0, int *transform_ids=0)
 
int getPatchesInOctet (int pid, PatchID *pids, int *transform_ids=0)
 
int upstreamNeighbors (int pid, PatchID *neighbor_ids)
 
int downstreamNeighbors (int pid, PatchID *neighbor_ids)
 
void printPatchMap (void)
 
Patchpatch (PatchID pid)
 
HomePatchhomePatch (PatchID pid)
 
void registerPatch (PatchID pid, HomePatch *pptr)
 
void unregisterPatch (PatchID pid, HomePatch *pptr)
 
void registerPatch (PatchID pid, Patch *pptr)
 
void unregisterPatch (PatchID pid, Patch *pptr)
 
void initTmpPatchAtomsList ()
 
void delTmpPatchAtomsList ()
 
std::vector< int > * getTmpPatchAtomsList ()
 

Static Public Member Functions

static PatchMapInstance ()
 
static PatchMapObject ()
 
static PatchMapObjectOnPe (int pe)
 
static void registerPatchMgr (PatchMgr *pmgr)
 

Protected Member Functions

int packSize (void)
 
void pack (char *buf, int size)
 
void unpack (char *buf)
 
 PatchMap (void)
 

Friends

class WorkDistrib
 

Detailed Description

Definition at line 23 of file PatchMap.h.

Member Enumeration Documentation

anonymous enum
Enumerator
MaxTwoAway 

Definition at line 45 of file PatchMap.h.

45 { MaxTwoAway = 5*5*5 - 3*3*3 };
anonymous enum
Enumerator
MaxOneAway 

Definition at line 46 of file PatchMap.h.

46 { MaxOneAway = 3*3*3 - 1 };
anonymous enum
Enumerator
MaxOneOrTwoAway 

Definition at line 47 of file PatchMap.h.

Constructor & Destructor Documentation

PatchMap::~PatchMap ( void  )

Definition at line 291 of file PatchMap.C.

292 {
293  if ( ! CkMyRank() ) {
294  if (patchData && ! computeIdArena ) {
295  for (int i=0; i<nPatches; i++) {
296  delete [] patchData[i].cids;
297  }
298  }
299  delete [] patchData;
300  delete [] nPatchesOnNode;
301  delete computeIdArena;
302  }
303  delete [] patchBounds_a;
304  delete [] patchBounds_b;
305  delete [] patchBounds_c;
306  delete [] myPatch;
307  delete [] myHomePatch;
308 }
PatchMap::PatchMap ( void  )
protected

Definition at line 39 of file PatchMap.C.

Referenced by Instance().

40 {
41  nPatches = 0;
42  nNodesWithPatches = 0;
43  int npes = CkNumPes();
44  if ( ! CkMyRank() ) {
45  nPatchesOnNode = new int[npes];
46  memset(nPatchesOnNode,0,npes*sizeof(int));
47  patchData = NULL;
48  computeIdArena = NULL;
49  }
50  patchBounds_a = 0;
51  patchBounds_b = 0;
52  patchBounds_c = 0;
53  myPatch = 0;
54  myHomePatch = 0;
55 
56  aDim = bDim = cDim = 0;
57  aAway = bAway = cAway = 1;
58  aPeriodic = bPeriodic = cPeriodic = 0;
59  aMaxIndex = bMaxIndex = cMaxIndex = 0;
60 }

Member Function Documentation

void PatchMap::assignBaseNode ( PatchID  pid,
NodeID  node 
)

Definition at line 472 of file PatchMap.C.

References node(), and pid().

472  {
473  patchData[pid].basenode=node;
474 }
int node(int pid) const
Definition: PatchMap.h:114
int pid(int aIndex, int bIndex, int cIndex)
Definition: PatchMap.inl:27
void PatchMap::assignBaseNode ( PatchID  pid)

Definition at line 476 of file PatchMap.C.

References basenode(), node(), and pid().

476  {
477 
478  int i = 1;
479 
480  NodeID node = patchData[pid].node;
481 
482  if ( CkNumPes() > 2*nPatches+1 ) {
483 
484  int newnode = ( CkNumPes() + node - 1 ) % CkNumPes();
485  bool success = 0;
486 
487  while ( i < CkNumPes() && !success) {
488  if ( nPatchesOnNode[newnode] == 0 )
489  success = 1;
490 
491  //we know till pid, we have assigned all base nodes
492  for (int count = 0; count < pid; count ++)
493  if (patchData[count].basenode > 0 && patchData[count].basenode == newnode) {
494  success = 0;
495  break;
496  }
497 
498  //no patch or a patche's base node on this newnode. this is a good node
499  if (success) break;
500 
501  newnode = ( CkNumPes() + node - i - 1 ) % CkNumPes();
502  i ++;
503  }
504  patchData[pid].basenode = newnode;
505 
506  } else {
507  patchData[pid].basenode=node;
508  }
509 }
int basenode(int pid) const
Definition: PatchMap.h:117
int node(int pid) const
Definition: PatchMap.h:114
int pid(int aIndex, int bIndex, int cIndex)
Definition: PatchMap.inl:27
int NodeID
Definition: NamdTypes.h:184
void PatchMap::assignNode ( PatchID  pid,
NodeID  node 
)

Definition at line 465 of file PatchMap.C.

References node(), and pid().

465  {
466  patchData[pid].node=node;
467  if ( nPatchesOnNode[node] == 0 ) nNodesWithPatches += 1;
468  nPatchesOnNode[node] += 1;
469 }
int node(int pid) const
Definition: PatchMap.h:114
int pid(int aIndex, int bIndex, int cIndex)
Definition: PatchMap.inl:27
PatchID PatchMap::assignToPatch ( Position  p,
const Lattice l 
)
inline

Definition at line 14 of file PatchMap.inl.

References pid(), Lattice::scale(), Vector::x, Vector::y, and Vector::z.

Referenced by ParallelIOMgr::calcAtomsInEachPatch(), and WorkDistrib::createAtomLists().

15 {
16  int ai, bi, ci;
17  ScaledPosition s = l.scale(p);
18  ai = (int)floor(((BigReal)aDim)*((s.x-aOrigin)/aLength));
19  bi = (int)floor(((BigReal)bDim)*((s.y-bOrigin)/bLength));
20  ci = (int)floor(((BigReal)cDim)*((s.z-cOrigin)/cLength));
21  return pid(ai,bi,ci);
22 }
Definition: Vector.h:64
BigReal z
Definition: Vector.h:66
BigReal x
Definition: Vector.h:66
int pid(int aIndex, int bIndex, int cIndex)
Definition: PatchMap.inl:27
BigReal y
Definition: Vector.h:66
ScaledPosition scale(Position p) const
Definition: Lattice.h:83
double BigReal
Definition: common.h:112
int PatchMap::basenode ( int  pid) const
inline

Definition at line 117 of file PatchMap.h.

References pid().

Referenced by assignBaseNode(), basePatchIDList(), and LdbCoordinator::requiredProxies().

117 { return patchData[pid].basenode; }
int pid(int aIndex, int bIndex, int cIndex)
Definition: PatchMap.inl:27
void PatchMap::basePatchIDList ( int  pe,
PatchIDList pids 
)

Definition at line 454 of file PatchMap.C.

References ResizeArray< T >::add(), basenode(), and ResizeArray< T >::resize().

Referenced by CudaComputeNonbonded::assignPatches(), and ProxyMgr::createProxies().

454  {
455  pids.resize(0);
456  int i;
457  for ( i=0; i<nPatches; ++i ) {
458  if ( patchData[i].basenode == pe ) {
459  pids.add(i);
460  }
461  }
462 }
int basenode(int pid) const
Definition: PatchMap.h:117
int add(const Elem &elem)
Definition: ResizeArray.h:97
void resize(int i)
Definition: ResizeArray.h:84
ScaledPosition PatchMap::center ( int  pid) const
inline

Definition at line 99 of file PatchMap.h.

References pid().

Referenced by ComputeNonbondedPair::doForce(), ComputeNonbondedCUDA::doWork(), register_cuda_compute_pair(), CudaComputeNonbonded::registerComputePair(), and WorkDistrib::sortPmePes().

99  {
100  const PatchData &pd = patchData[pid];
101  return ScaledPosition(patchBounds_a[pd.aIndex*2+1],
102  patchBounds_b[pd.bIndex*2+1],
103  patchBounds_c[pd.cIndex*2+1]);
104  }
Vector ScaledPosition
Definition: Lattice.h:15
int pid(int aIndex, int bIndex, int cIndex)
Definition: PatchMap.inl:27
void PatchMap::checkMap ( void  )

Definition at line 274 of file PatchMap.C.

References DebugM.

Referenced by ComputeMgr::updateLocalComputes5().

275 {
276  int patchCount=0;
277  for (int i=0; i<nPatches; i++) {
278  if (myPatch[i]) {
279  patchCount++;
280  if ( myPatch[i]->getPatchID() != i) {
281  DebugM(4, "patchID("<<myPatch[i]->getPatchID()
282  <<") != patchID("
283  <<i<<")\n");
284  }
285  }
286  }
287  DebugM(4, "Patch Count = " <<patchCount<<"\n");
288 }
#define DebugM(x, y)
Definition: Debug.h:59
int PatchMap::cid ( int  pid,
int  i 
) const
inline

Definition at line 123 of file PatchMap.h.

References pid().

Referenced by newCid().

123 { return patchData[pid].cids[i]; }
int pid(int aIndex, int bIndex, int cIndex)
Definition: PatchMap.inl:27
void PatchMap::delTmpPatchAtomsList ( )
inline

Definition at line 219 of file PatchMap.h.

Referenced by ParallelIOMgr::sendAtomsToHomePatchProcs().

219  {
220  for(int i=0; i<nPatches; i++){
221  tmpPatchAtomsList[i].clear();
222  }
223  delete [] tmpPatchAtomsList;
224  tmpPatchAtomsList = NULL;
225  }
int PatchMap::downstream ( int  pid1,
int  pid2 
)
inline

Definition at line 51 of file PatchMap.inl.

References notUsed.

Referenced by ComputeHomeTuples< TholeElem, Thole, TholeValue >::loadTuples().

52 {
53  register int ds;
54 
55  if ( pid1 == pid2 ) { ds = pid1; }
56 
57  else if ( pid1 == notUsed || pid2 == notUsed ) { ds = notUsed; }
58 
59  else {
60  register PatchData *pdat1 = &(patchData[pid1]);
61  register PatchData *pdat2 = &(patchData[pid2]);
62 
63  // c
64  register int k = pdat1->cIndex;
65  register int k2 = pdat2->cIndex;
66  if ( ( k ? k : cMaxIndex ) == k2 + 1 ) k = k2;
67 
68  // b
69  register int j = pdat1->bIndex;
70  register int j2 = pdat2->bIndex;
71  if ( ( j ? j : bMaxIndex ) == j2 + 1 ) j = j2;
72 
73  // a
74  register int i = pdat1->aIndex;
75  register int i2 = pdat2->aIndex;
76  if ( ( i ? i : aMaxIndex ) == i2 + 1 ) i = i2;
77 
78  ds = ((k*bDim)+j)*aDim + i;
79  }
80 
81  return ds;
82 }
int PatchMap::downstreamNeighbors ( int  pid,
PatchID neighbor_ids 
)

Definition at line 714 of file PatchMap.C.

References DebugM, Lattice::index(), and pid().

Referenced by LdbCoordinator::requiredProxies().

715 {
716  int xi, yi, zi;
717  int xinc, yinc, zinc;
718  int n=0;
719 
720  for(zinc=-1;zinc<=0;zinc++)
721  {
722  zi = patchData[pid].cIndex + zinc;
723  if ((zi < 0) || (zi >= cDim))
724  if ( ! cPeriodic ) continue;
725  for(yinc=-1;yinc<=0;yinc++)
726  {
727  yi = patchData[pid].bIndex + yinc;
728  if ((yi < 0) || (yi >= bDim))
729  if ( ! bPeriodic ) continue;
730  for(xinc=-1;xinc<=0;xinc++)
731  {
732  if ((xinc==0) && (yinc==0) && (zinc==0))
733  continue;
734 
735  xi = patchData[pid].aIndex + xinc;
736  if ((xi < 0) || (xi >= aDim))
737  if ( ! aPeriodic ) continue;
738 
739  if (neighbor_ids)
740  neighbor_ids[n]=this->pid(xi,yi,zi);
741 #if 0
742  if ( transform_ids )
743  {
744  int xt = 0; if ( xi < 0 ) xt = -1; if ( xi >= aDim ) xt = 1;
745  int yt = 0; if ( yi < 0 ) yt = -1; if ( yi >= bDim ) yt = 1;
746  int zt = 0; if ( zi < 0 ) zt = -1; if ( zi >= cDim ) zt = 1;
747  transform_ids[n] = Lattice::index(xt,yt,zt);
748  }
749 #endif
750  n++;
751  }
752  }
753  }
754  DebugM(3,"Patch " << pid << " has " << n << " upstream neighbors.\n");
755  return n;
756 }
static int index(int i=0, int j=0, int k=0)
Definition: Lattice.h:25
#define DebugM(x, y)
Definition: Debug.h:59
int pid(int aIndex, int bIndex, int cIndex)
Definition: PatchMap.inl:27
int PatchMap::getPatchesInOctet ( int  pid,
PatchID pids,
int *  transform_ids = 0 
)

Definition at line 634 of file PatchMap.C.

References DebugM, Lattice::index(), MODULO, and pid().

635 {
636  int xi, yi, zi;
637  int xinc, yinc, zinc;
638  int n=0;
639  const int xs = patchData[pid].aIndex;
640  const int ys = patchData[pid].bIndex;
641  const int zs = patchData[pid].cIndex;
642 
643  for(zinc=0; zinc<2; zinc++) {
644  zi = zs + zinc;
645  for(yinc=0; yinc<2; yinc++) {
646  yi = ys + yinc;
647  for(xinc=0; xinc<2; xinc++) {
648  xi = xs + xinc;
649  int aIndex = MODULO(xi,aDim);
650  int bIndex = MODULO(yi,bDim);
651  int cIndex = MODULO(zi,cDim);
652  pids[n] = ((cIndex*bDim)+bIndex)*aDim + aIndex;
653  if ( transform_ids ) {
654  int xt = 0; if ( xi < 0 ) xt = -1; if ( xi >= aDim ) xt = 1;
655  int yt = 0; if ( yi < 0 ) yt = -1; if ( yi >= bDim ) yt = 1;
656  int zt = 0; if ( zi < 0 ) zt = -1; if ( zi >= cDim ) zt = 1;
657  transform_ids[n] = Lattice::index(xt,yt,zt);
658  }
659  n++;
660  } // for x
661  } // for y
662  } // for z
663  DebugM(3,"Patch " << pid << " has " << n << " second neighbors.\n");
664  return n;
665 }
static int index(int i=0, int j=0, int k=0)
Definition: Lattice.h:25
#define DebugM(x, y)
Definition: Debug.h:59
int pid(int aIndex, int bIndex, int cIndex)
Definition: PatchMap.inl:27
#define MODULO(I, J)
Definition: PatchMap.inl:25
std::vector<int>* PatchMap::getTmpPatchAtomsList ( )
inline

Definition at line 226 of file PatchMap.h.

Referenced by ParallelIOMgr::calcAtomsInEachPatch(), and ParallelIOMgr::sendAtomsToHomePatchProcs().

226  {
227  return tmpPatchAtomsList;
228  }
int PatchMap::gridsize_a ( void  ) const
inline
int PatchMap::gridsize_b ( void  ) const
inline
int PatchMap::gridsize_c ( void  ) const
inline
HomePatch * PatchMap::homePatch ( PatchID  pid)
inline
void PatchMap::homePatchIDList ( PatchIDList pids)

Definition at line 443 of file PatchMap.C.

References ResizeArray< T >::add(), node(), and ResizeArray< T >::resize().

Referenced by ProxyMgr::buildProxySpanningTree(), and ProxyMgr::buildProxySpanningTree2().

443  {
444  pids.resize(0);
445  int i;
446  for ( i=0; i<nPatches; ++i ) {
447  if ( patchData[i].node == CkMyPe() ) {
448  pids.add(i);
449  }
450  }
451 }
int add(const Elem &elem)
Definition: ResizeArray.h:97
void resize(int i)
Definition: ResizeArray.h:84
int node(int pid) const
Definition: PatchMap.h:114
HomePatchList * PatchMap::homePatchList ( )

Definition at line 438 of file PatchMap.C.

Referenced by ProxyMgr::buildProxySpanningTree2(), ComputeHomePatches::initialize(), and Node::run().

438  {
439  return &(CkpvAccess(PatchMap_patchMgr)->homePatches);
440 }
int PatchMap::index_a ( int  pid) const
inline
int PatchMap::index_b ( int  pid) const
inline
int PatchMap::index_c ( int  pid) const
inline
void PatchMap::initTmpPatchAtomsList ( )
inline

Definition at line 216 of file PatchMap.h.

Referenced by ParallelIOMgr::calcAtomsInEachPatch().

216  {
217  tmpPatchAtomsList = new std::vector<int>[nPatches];
218  }
PatchMap * PatchMap::Instance ( )
static

Definition at line 32 of file PatchMap.C.

References PatchMap().

Referenced by Node::Node(), and PatchMgr::PatchMgr().

32  {
33  if (CkpvAccess(PatchMap_instance) == 0) {
34  CkpvAccess(PatchMap_instance) = new PatchMap;
35  }
36  return(CkpvAccess(PatchMap_instance));
37 }
PatchMap(void)
Definition: PatchMap.C:39
void PatchMap::makePatches ( ScaledPosition  xmin,
ScaledPosition  xmax,
const Lattice lattice,
BigReal  patchSize,
double  maxNumPatches,
int  staticAtomAssignment,
int  replicaUniformPatchGrids,
int  lcpo,
int  asplit,
int  bsplit,
int  csplit 
)

Definition at line 171 of file PatchMap.C.

References endi(), iINFO(), index_a(), index_b(), index_c(), iout, NAMD_bug(), replica_min_double(), sizeGrid(), Vector::x, Vector::y, and Vector::z.

Referenced by WorkDistrib::patchMapInit().

176 {
177  sizeGrid(xmin,xmax,lattice,patchSize,maxNumPatches,staticAtomAssignment,asplit,bsplit,csplit);
178 
179  if ( replicaUniformPatchGrids ) {
180  int oldpcount = aDim * bDim * cDim;
181  double dims[3];
182  dims[0] = aDim;
183  dims[1] = bDim;
184  dims[2] = cDim;
185  replica_min_double(dims,3);
186  aDim = dims[0];
187  bDim = dims[1];
188  cDim = dims[2];
189  int newpcount = aDim * bDim * cDim;
190  if ( newpcount > oldpcount ) {
191  NAMD_bug("replicaUniformPatchGrids increased patch count");
192  }
193  if ( newpcount < oldpcount ) {
194  iout << iINFO << "PATCH GRID REDUCED TO BE UNIFORM ACROSS REPLICAS\n";
195  }
196  }
197 
198  iout << iINFO << "PATCH GRID IS ";
199  iout << aDim;
200  if ( aPeriodic ) iout << " (PERIODIC)";
201  iout << " BY ";
202  iout << bDim;
203  if ( bPeriodic ) iout << " (PERIODIC)";
204  iout << " BY ";
205  iout << cDim;
206  if ( cPeriodic ) iout << " (PERIODIC)";
207  iout << "\n";
208  iout << iINFO << "PATCH GRID IS ";
209  iout << aAway << "-AWAY BY ";
210  iout << bAway << "-AWAY BY ";
211  iout << cAway << "-AWAY\n";
212  iout << endi;
213 
214  aMaxIndex = ( ! aPeriodic || aDim == 2 ) ? 10000 : aDim;
215  bMaxIndex = ( ! bPeriodic || bDim == 2 ) ? 10000 : bDim;
216  cMaxIndex = ( ! cPeriodic || cDim == 2 ) ? 10000 : cDim;
217 
218  aLength = aPeriodic ? 1.0 :
219  ( lcpo || aDim > aAway + 1 ? aDim * (patchSize / aAway) : xmax.x - xmin.x );
220  bLength = bPeriodic ? 1.0 :
221  ( lcpo || bDim > bAway + 1 ? bDim * (patchSize / bAway) : xmax.y - xmin.y );
222  cLength = cPeriodic ? 1.0 :
223  ( lcpo || cDim > cAway + 1 ? cDim * (patchSize / cAway) : xmax.z - xmin.z );
224 
225  aOrigin = aPeriodic ? -0.5 : 0.5 * (xmin.x + xmax.x - aLength);
226  bOrigin = bPeriodic ? -0.5 : 0.5 * (xmin.y + xmax.y - bLength);
227  cOrigin = cPeriodic ? -0.5 : 0.5 * (xmin.z + xmax.z - cLength);
228 
229  nPatches=aDim*bDim*cDim;
230  patchData = new PatchData[nPatches];
231 
232  patchBounds_a = new BigReal[2*aDim+1];
233  patchBounds_b = new BigReal[2*bDim+1];
234  patchBounds_c = new BigReal[2*cDim+1];
235  for ( int i=0; i<(2*aDim+1); ++i ) {
236  patchBounds_a[i] = ((0.5*(double)i)/(double)aDim) * aLength + aOrigin;
237  }
238  for ( int i=0; i<(2*bDim+1); ++i ) {
239  patchBounds_b[i] = ((0.5*(double)i)/(double)bDim) * bLength + bOrigin;
240  }
241  for ( int i=0; i<(2*cDim+1); ++i ) {
242  patchBounds_c[i] = ((0.5*(double)i)/(double)cDim) * cLength + cOrigin;
243  }
244 
245  for(int i=0; i<nPatches; ++i)
246  {
247  PatchData &p = patchData[i];
248  p.basenode = -1;
249  p.numCids = 0;
250  p.aIndex = index_a(i);
251  p.bIndex = index_b(i);
252  p.cIndex = index_c(i);
253 #ifdef MEM_OPT_VERSION
254  p.numAtoms = 0;
255  p.numFixedAtoms = 0;
256 #endif
257  p.numCids = 0;
258  int max_computes = 30;
259  p.cids = new int[max_computes];
260  for ( int j = 0; j < max_computes; ++j ) p.cids[j] = -1;
261  p.numCidsAllocated = max_computes;
262  }
263 
264  if ( ! myPatch ) {
265  myPatch = new Patch*[nPatches];
266  }
267  memset(myPatch,0,nPatches*sizeof(Patch*));
268  if ( ! myHomePatch ) {
269  myHomePatch = new HomePatch*[nPatches];
270  }
271  memset(myHomePatch,0,nPatches*sizeof(HomePatch*));
272 }
std::ostream & iINFO(std::ostream &s)
Definition: InfoStream.C:107
int index_a(int pid) const
Definition: PatchMap.h:86
BigReal z
Definition: Vector.h:66
#define iout
Definition: InfoStream.h:87
int sizeGrid(ScaledPosition xmin, ScaledPosition xmax, const Lattice &lattice, BigReal patchSize, double maxNumPatches, int staticAtomAssignment, int asplit, int bsplit, int csplit)
Definition: PatchMap.C:62
Definition: Patch.h:35
void NAMD_bug(const char *err_msg)
Definition: common.C:123
int index_b(int pid) const
Definition: PatchMap.h:87
BigReal x
Definition: Vector.h:66
int index_c(int pid) const
Definition: PatchMap.h:88
void replica_min_double(double *dat, int count)
BigReal y
Definition: Vector.h:66
infostream & endi(infostream &s)
Definition: InfoStream.C:38
double BigReal
Definition: common.h:112
BigReal PatchMap::max_a ( int  pid) const
inline

Definition at line 92 of file PatchMap.h.

References pid().

Referenced by WorkDistrib::createAtomLists(), ComputeLCPO::initialize(), ComputePmeMgr::initialize(), and ComputePmeMgr::initialize_pencils().

92 { return patchBounds_a[patchData[pid].aIndex*2+2]; }
int pid(int aIndex, int bIndex, int cIndex)
Definition: PatchMap.inl:27
BigReal PatchMap::max_b ( int  pid) const
inline

Definition at line 94 of file PatchMap.h.

References pid().

Referenced by WorkDistrib::createAtomLists(), ComputePmeCUDAMgr::getHomePencil(), ComputeLCPO::initialize(), and ComputePmeMgr::initialize_pencils().

94 { return patchBounds_b[patchData[pid].bIndex*2+2]; }
int pid(int aIndex, int bIndex, int cIndex)
Definition: PatchMap.inl:27
BigReal PatchMap::max_c ( int  pid) const
inline

Definition at line 96 of file PatchMap.h.

References pid().

Referenced by WorkDistrib::createAtomLists(), ComputePmeCUDAMgr::getHomePencil(), and ComputeLCPO::initialize().

96 { return patchBounds_c[patchData[pid].cIndex*2+2]; }
int pid(int aIndex, int bIndex, int cIndex)
Definition: PatchMap.inl:27
BigReal PatchMap::min_a ( int  pid) const
inline

Definition at line 91 of file PatchMap.h.

References pid().

Referenced by WorkDistrib::createAtomLists(), ComputeLCPO::initialize(), ComputePmeMgr::initialize(), and ComputePmeMgr::initialize_pencils().

91 { return patchBounds_a[patchData[pid].aIndex*2]; }
int pid(int aIndex, int bIndex, int cIndex)
Definition: PatchMap.inl:27
BigReal PatchMap::min_b ( int  pid) const
inline

Definition at line 93 of file PatchMap.h.

References pid().

Referenced by WorkDistrib::createAtomLists(), ComputePmeCUDAMgr::getHomePencil(), ComputeLCPO::initialize(), and ComputePmeMgr::initialize_pencils().

93 { return patchBounds_b[patchData[pid].bIndex*2]; }
int pid(int aIndex, int bIndex, int cIndex)
Definition: PatchMap.inl:27
BigReal PatchMap::min_c ( int  pid) const
inline

Definition at line 95 of file PatchMap.h.

References pid().

Referenced by WorkDistrib::createAtomLists(), ComputePmeCUDAMgr::getHomePencil(), and ComputeLCPO::initialize().

95 { return patchBounds_c[patchData[pid].cIndex*2]; }
int pid(int aIndex, int bIndex, int cIndex)
Definition: PatchMap.inl:27
void PatchMap::newCid ( int  pid,
int  cid 
)

Definition at line 512 of file PatchMap.C.

References cid(), numCids(), and pid().

513 {
514  if (patchData[pid].numCids >= patchData[pid].numCidsAllocated)
515  { // allocate more
516 // NAMD_die("PatchMap::newCid - not enough compute ID's allocated.");
517  ComputeID *old = patchData[pid].cids;
518  patchData[pid].numCidsAllocated += 10;
519  patchData[pid].cids = new int[patchData[pid].numCidsAllocated];
520  int i;
521  for (i=0; i<patchData[pid].numCids; i++)
522  patchData[pid].cids[i] = old[i];
523  for (i=patchData[pid].numCids; i<patchData[pid].numCidsAllocated; i++)
524  patchData[pid].cids[i] = -1;
525  delete [] old;
526  }
527  patchData[pid].cids[patchData[pid].numCids]=cid;
528  patchData[pid].numCids++;
529 }
int ComputeID
Definition: NamdTypes.h:183
int numCids(int pid) const
Definition: PatchMap.h:120
int cid(int pid, int i) const
Definition: PatchMap.h:123
int pid(int aIndex, int bIndex, int cIndex)
Definition: PatchMap.inl:27
int PatchMap::node ( int  pid) const
inline
int PatchMap::numaway_a ( void  ) const
inline

Definition at line 68 of file PatchMap.h.

68 { return aAway; }
int PatchMap::numaway_b ( void  ) const
inline

Definition at line 69 of file PatchMap.h.

69 { return bAway; }
int PatchMap::numaway_c ( void  ) const
inline

Definition at line 70 of file PatchMap.h.

70 { return cAway; }
int PatchMap::numCids ( int  pid) const
inline

Definition at line 120 of file PatchMap.h.

References pid().

Referenced by newCid(), pack(), printPatchMap(), and unpack().

120 { return patchData[pid].numCids; }
int pid(int aIndex, int bIndex, int cIndex)
Definition: PatchMap.inl:27
int PatchMap::numHomePatches ( void  )

Definition at line 432 of file PatchMap.C.

Referenced by LdbCoordinator::initialize(), CollectionMgr::CollectVectorInstance::reset(), and PatchMgr::sendMigrationMsgs().

433 {
434  return CkpvAccess(PatchMap_patchMgr)->homePatches.size();
435 }
int PatchMap::numNodesWithPatches ( void  )
inline

Definition at line 61 of file PatchMap.h.

Referenced by HomePatch::buildSpanningTree(), ComputePmeMgr::initialize(), and HomePatch::positionsReady().

61 { return nNodesWithPatches; }
int PatchMap::numPatches ( void  ) const
inline
int PatchMap::numPatchesOnNode ( int  node)
inline
static PatchMap* PatchMap::Object ( )
inlinestatic

Definition at line 27 of file PatchMap.h.

Referenced by WorkDistrib::assignNodeToPatch(), CudaComputeNonbonded::assignPatches(), CudaComputeNonbonded::assignPatchesOnPe(), ProxyMgr::buildProxySpanningTree(), ProxyMgr::buildProxySpanningTree2(), HomePatch::buildSpanningTree(), ProxyMgr::buildSpanningTree0(), ParallelIOMgr::calcAtomsInEachPatch(), ComputeEwald::ComputeEwald(), ComputeGlobal::ComputeGlobal(), ComputeHomePatches::ComputeHomePatches(), ComputeHomeTuples< TholeElem, Thole, TholeValue >::ComputeHomeTuples(), ComputeNonbondedCUDA::ComputeNonbondedCUDA(), Controller::Controller(), WorkDistrib::createAtomLists(), ComputeMgr::createComputes(), WorkDistrib::createHomePatches(), ParallelIOMgr::createHomePatches(), ProxyMgr::createProxies(), ProxyMgr::createProxy(), Rebalancer::createSpanningTree(), MigrateAtomsCombinedMsg::distribute(), WorkDistrib::distributeHomePatches(), ComputeNonbondedPair::doForce(), ComputeFullDirect::doWork(), dumpbench(), findRecipEvirPe(), Patch::forceBoxClosed(), ComputePmeCUDAMgr::getHomePencil(), Sync::holdComputes(), ComputePmeCUDA::initialize(), ComputePatch::initialize(), ComputePatchPair::initialize(), ComputeHomePatch::initialize(), ComputePme::initialize(), ComputeLCPO::initialize(), ComputePmeMgr::initialize(), ComputeSelfTuples< TholeElem, Thole, TholeValue >::initialize(), ComputeMsmMgr::initialize(), ComputePmeMgr::initialize_computes(), ComputePmeMgr::initialize_pencils(), WorkDistrib::mapComputes(), Sync::openSync(), Node::outputPatchComputeMaps(), WorkDistrib::patchMapInit(), Patch::positionsReady(), HomePatch::positionsReady(), ProxyPatch::ProxyPatch(), recursive_bisect_with_curve(), ParallelIOMgr::recvAtomsCntPerPatch(), ComputeMgr::recvComputeDPMEData(), ComputeMgr::recvComputeDPMEResults(), ComputeMgr::recvComputeEwaldResults(), ComputeMgr::recvComputeGlobalResults(), ComputeExtMgr::recvCoord(), ComputeMsmSerialMgr::recvCoord(), ComputeFmmSerialMgr::recvCoord(), ComputeGBISserMgr::recvCoord(), GlobalMasterServer::recvData(), ProxyMgr::recvData(), ProxyMgr::recvImmediateProxyAll(), ProxyMgr::recvImmediateProxyData(), ProxyMgr::recvImmediateResults(), ProxyMgr::recvNodeAwareSpanningTree(), ProxyMgr::recvNodeAwareSpanningTreeOnHomePatch(), ProxyMgr::recvNodeAwareSTParent(), ComputeQMMgr::recvPartQM(), ProxyMgr::recvPatchProxyInfo(), ProxyMgr::recvProxies(), ProxyMgr::recvProxyAll(), ProxyMgr::recvProxyData(), ProxyMgr::recvRegisterProxy(), ProxyMgr::recvResult(), ProxyMgr::recvResults(), ProxyMgr::recvSpanningTree(), ProxyMgr::recvSpanningTreeOnHomePatch(), ProxyMgr::recvUnregisterProxy(), CudaComputeNonbonded::registerComputePair(), ProxyMgr::registerProxy(), registerUserEventsForAllComputeObjs(), WorkDistrib::reinitAtoms(), ProxyMgr::removeProxy(), CollectionMgr::CollectVectorInstance::reset(), CollectionMaster::CollectVectorInstance::reset(), LdbCoordinator::resume(), Node::run(), WorkDistrib::savePatchMap(), ParallelIOMgr::sendAtomsToHomePatchProcs(), ComputeMgr::sendComputeDPMEData(), ComputeMgr::sendComputeEwaldData(), ProxyMgr::sendNodeAwareSpanningTreeToHomePatch(), MsmBlock::sendPatch(), MsmC1HermiteBlock::sendPatch(), WorkDistrib::sendPatchMap(), ProxyMgr::sendResult(), ProxyMgr::sendResults(), ProxyMgr::sendSpanningTrees(), ProxyMgr::sendSpanningTreeToHomePatch(), Sequencer::Sequencer(), WorkDistrib::sortPmePes(), Node::startup(), NamdCentLB::Strategy(), ProxyMgr::unregisterProxy(), ComputeMgr::updateLocalComputes5(), ComputeHomePatch::~ComputeHomePatch(), ComputeLCPO::~ComputeLCPO(), ComputePatch::~ComputePatch(), ComputePatchPair::~ComputePatchPair(), and ComputePmeCUDA::~ComputePmeCUDA().

27 { return CkpvAccess(PatchMap_instance); }
static PatchMap* PatchMap::ObjectOnPe ( int  pe)
inlinestatic

Definition at line 28 of file PatchMap.h.

Referenced by ComputeNonbondedCUDA::assignPatches(), CudaComputeNonbonded::assignPatches(), and findProxyPatchPes().

28  {
29  return CkpvAccessOther(PatchMap_instance, CmiRankOf(pe));
30  }
int PatchMap::oneAwayNeighbors ( int  pid,
PatchID neighbor_ids = 0 
)

Definition at line 532 of file PatchMap.C.

References DebugM, Lattice::index(), and pid().

533 {
534  int xi, yi, zi;
535  int xinc, yinc, zinc;
536  int n=0;
537 
538  for(zinc=-1;zinc<=1;zinc++)
539  {
540  zi = patchData[pid].cIndex + zinc;
541  if ((zi < 0) || (zi >= cDim))
542  if ( ! cPeriodic ) continue;
543  for(yinc=-1;yinc<=1;yinc++)
544  {
545  yi = patchData[pid].bIndex + yinc;
546  if ((yi < 0) || (yi >= bDim))
547  if ( ! bPeriodic ) continue;
548  for(xinc=-1;xinc<=1;xinc++)
549  {
550  if ((xinc==0) && (yinc==0) && (zinc==0))
551  continue;
552 
553  xi = patchData[pid].aIndex + xinc;
554  if ((xi < 0) || (xi >= aDim))
555  if ( ! aPeriodic ) continue;
556 
557  if (neighbor_ids)
558  neighbor_ids[n]=this->pid(xi,yi,zi);
559 #if 0
560  if ( transform_ids )
561  {
562  int xt = 0; if ( xi < 0 ) xt = -1; if ( xi >= aDim ) xt = 1;
563  int yt = 0; if ( yi < 0 ) yt = -1; if ( yi >= bDim ) yt = 1;
564  int zt = 0; if ( zi < 0 ) zt = -1; if ( zi >= cDim ) zt = 1;
565  transform_ids[n] = Lattice::index(xt,yt,zt);
566  }
567 #endif
568  n++;
569  }
570  }
571  }
572  DebugM(3,"Patch " << pid << " has " << n << " first neighbors.\n");
573  return n;
574 }
static int index(int i=0, int j=0, int k=0)
Definition: Lattice.h:25
#define DebugM(x, y)
Definition: Debug.h:59
int pid(int aIndex, int bIndex, int cIndex)
Definition: PatchMap.inl:27
int PatchMap::oneOrTwoAwayNeighbors ( int  pid,
PatchID neighbor_ids,
PatchID downstream_ids = 0,
int *  transform_ids = 0 
)

Definition at line 579 of file PatchMap.C.

References DebugM, Lattice::index(), and pid().

580 {
581  int xi, yi, zi;
582  int xinc, yinc, zinc;
583  int n=0;
584  const int xs = patchData[pid].aIndex;
585  const int ys = patchData[pid].bIndex;
586  const int zs = patchData[pid].cIndex;
587 
588  for(zinc=0;zinc<=cAway;zinc++)
589  {
590  zi = zs + zinc;
591  if ((zi < 0) || (zi >= cDim))
592  if ( ! cPeriodic ) continue;
593  for(yinc=(zinc>0 ? -bAway : 0);yinc<=bAway;yinc++)
594  {
595  yi = ys + yinc;
596  if ((yi < 0) || (yi >= bDim))
597  if ( ! bPeriodic ) continue;
598  for(xinc=((zinc>0 || yinc>0) ? -aAway : 0);xinc<=aAway;xinc++)
599  {
600  if ((xinc==0) && (yinc==0) && (zinc==0))
601  continue;
602 
603  xi = xs + xinc;
604  if ((xi < 0) || (xi >= aDim))
605  if ( ! aPeriodic ) continue;
606 
607  neighbor_ids[n] = this->pid(xi,yi,zi);
608  if ( transform_ids )
609  {
610  int xt = 0; if ( xi < 0 ) xt = -1; if ( xi >= aDim ) xt = 1;
611  int yt = 0; if ( yi < 0 ) yt = -1; if ( yi >= bDim ) yt = 1;
612  int zt = 0; if ( zi < 0 ) zt = -1; if ( zi >= cDim ) zt = 1;
613  transform_ids[n] = Lattice::index(xt,yt,zt);
614  }
615  if ( downstream_ids )
616  {
617  int xd = ( xi < xs ? xi : xs );
618  int yd = ( yi < ys ? yi : ys );
619  int zd = ( zi < zs ? zi : zs );
620  downstream_ids[n] = this->pid(xd,yd,zd);
621  }
622  n++;
623  }
624  }
625  }
626  DebugM(3,"Patch " << pid << " has " << n << " second neighbors.\n");
627  return n;
628 }
static int index(int i=0, int j=0, int k=0)
Definition: Lattice.h:25
#define DebugM(x, y)
Definition: Debug.h:59
int pid(int aIndex, int bIndex, int cIndex)
Definition: PatchMap.inl:27
ScaledPosition PatchMap::origin ( void  ) const
inline

Definition at line 78 of file PatchMap.h.

78  {
79  return ScaledPosition(aOrigin,bOrigin,cOrigin);
80  }
Vector ScaledPosition
Definition: Lattice.h:15
void PatchMap::pack ( char *  buf,
int  size 
)
protected

Definition at line 328 of file PatchMap.C.

References DebugM, NAMD_bug(), node(), numCids(), PACK, and PACKN.

Referenced by WorkDistrib::sendPatchMap().

329 {
330  DebugM(4,"Packing PatchMap on node " << CkMyPe() << std::endl);
331  int i,j;
332 
333  // fill in the data
334  char *b = buffer;
335  PACK(int,nPatches);
336  DebugM(3,"nPatches = " << nPatches << std::endl);
337  PACK(int,aDim); PACK(int,bDim); PACK(int,cDim);
338  PACK(int,aAway); PACK(int,bAway); PACK(int,cAway);
339  PACK(int,aPeriodic); PACK(int,bPeriodic); PACK(int,cPeriodic);
340  PACK(int,aMaxIndex); PACK(int,bMaxIndex); PACK(int,cMaxIndex);
341  PACK(BigReal,aOrigin); PACK(BigReal,bOrigin); PACK(BigReal,cOrigin);
342  PACK(BigReal,aLength); PACK(BigReal,bLength); PACK(BigReal,cLength);
343  PACK(int,nNodesWithPatches);
344  PACKN(BigReal,patchBounds_a,2*aDim+1);
345  PACKN(BigReal,patchBounds_b,2*bDim+1);
346  PACKN(BigReal,patchBounds_c,2*cDim+1);
347  PACKN(int,nPatchesOnNode,CkNumPes());
348  PACKN(PatchData,patchData,nPatches);
349  for(i=0;i<nPatches;++i) {
350  DebugM(3,"Packing Patch " << i << " is on node " << patchData[i].node <<
351  " with " << patchData[i].numCids << " cids.\n");
352  PACKN(ComputeID,patchData[i].cids,patchData[i].numCids);
353  }
354  if ( buffer + size != b ) {
355  NAMD_bug("PatchMap::pack does not match PatchMap::packSize");
356  }
357  //DebugM(3,buffer + size - b << " == 0 ?" << std::endl);
358 }
int ComputeID
Definition: NamdTypes.h:183
#define DebugM(x, y)
Definition: Debug.h:59
int numCids(int pid) const
Definition: PatchMap.h:120
void NAMD_bug(const char *err_msg)
Definition: common.C:123
int node(int pid) const
Definition: PatchMap.h:114
#define PACK(type, data)
Definition: PatchMap.C:311
#define PACKN(type, data, cnt)
Definition: PatchMap.C:312
double BigReal
Definition: common.h:112
int PatchMap::packSize ( void  )
protected

Definition at line 314 of file PatchMap.C.

Referenced by WorkDistrib::sendPatchMap().

315 {
316  int i, size = 0;
317  size += 14 * sizeof(int) + 6 * sizeof(BigReal);
318  size += (2*(aDim+bDim+cDim)+3) * sizeof(BigReal);
319  size += CkNumPes() * sizeof(int);
320  for(i=0;i<nPatches;++i)
321  {
322  size += sizeof(PatchData);
323  size += patchData[i].numCids * sizeof(ComputeID);
324  }
325  return size;
326 }
int ComputeID
Definition: NamdTypes.h:183
double BigReal
Definition: common.h:112
Patch * PatchMap::patch ( PatchID  pid)
inline
int PatchMap::periodic_a ( void  ) const
inline

Definition at line 73 of file PatchMap.h.

73 { return aPeriodic; }
int PatchMap::periodic_b ( void  ) const
inline

Definition at line 74 of file PatchMap.h.

74 { return bPeriodic; }
int PatchMap::periodic_c ( void  ) const
inline

Definition at line 75 of file PatchMap.h.

75 { return cPeriodic; }
int PatchMap::pid ( int  aIndex,
int  bIndex,
int  cIndex 
)
inline

Definition at line 27 of file PatchMap.inl.

References MODULO.

Referenced by assignBaseNode(), assignNode(), assignToPatch(), basenode(), center(), cid(), downstreamNeighbors(), getPatchesInOctet(), homePatch(), max_a(), max_b(), max_c(), min_a(), min_b(), min_c(), newCid(), node(), numCids(), oneAwayNeighbors(), oneOrTwoAwayNeighbors(), patch(), registerPatch(), unregisterPatch(), and upstreamNeighbors().

28 {
29  if ( aPeriodic ) aIndex = MODULO(aIndex,aDim);
30  else
31  {
32  if ( aIndex < 0 ) aIndex = 0;
33  if ( aIndex >= aDim ) aIndex = aDim - 1;
34  }
35  if ( bPeriodic ) bIndex = MODULO(bIndex,bDim);
36  else
37  {
38  if ( bIndex < 0 ) bIndex = 0;
39  if ( bIndex >= bDim ) bIndex = bDim - 1;
40  }
41  if ( cPeriodic ) cIndex = MODULO(cIndex,cDim);
42  else
43  {
44  if ( cIndex < 0 ) cIndex = 0;
45  if ( cIndex >= cDim ) cIndex = cDim - 1;
46  }
47  return ((cIndex*bDim)+bIndex)*aDim + aIndex;
48 }
#define MODULO(I, J)
Definition: PatchMap.inl:25
void PatchMap::printPatchMap ( void  )

Definition at line 759 of file PatchMap.C.

References node(), and numCids().

760 {
761  CkPrintf("---------------------------------------");
762  CkPrintf("---------------------------------------\n");
763 
764  CkPrintf("nPatches = %d\n",nPatches);
765  for(int i=0;i<nPatches;i++)
766  {
767  CkPrintf("Patch %d:\n",i);
768  CkPrintf(" node = %d\n",patchData[i].node);
769  CkPrintf(" xi,yi,zi = %d, %d, %d\n",
770  patchData[i].aIndex,patchData[i].bIndex,patchData[i].cIndex);
771  CkPrintf(" numCids = %d\n",patchData[i].numCids);
772  CkPrintf(" numCidsAllocated = %d\n",patchData[i].numCidsAllocated);
773  for(int j=0; j < patchData[i].numCids; j++)
774  {
775  CkPrintf(" %10d ",patchData[i].cids[j]);
776  if (!((j+1) % 6))
777  CkPrintf("\n");
778  }
779  CkPrintf("\n---------------------------------------");
780  CkPrintf("---------------------------------------\n");
781  }
782 
783 }
int numCids(int pid) const
Definition: PatchMap.h:120
int node(int pid) const
Definition: PatchMap.h:114
void PatchMap::registerPatch ( PatchID  pid,
HomePatch pptr 
)

Definition at line 786 of file PatchMap.C.

References endi(), iERRORF, iout, iPE(), and pid().

Referenced by PatchMgr::createHomePatch(), ProxyMgr::createProxies(), and ProxyMgr::createProxy().

786  {
787  registerPatch(pid,(Patch*)pptr);
788  if (myHomePatch[pid] != 0) {
789  iout << iPE << iERRORF
790  << "homePatchID("<<pid<<") is being re-registered!\n" << endi;
791  }
792  myHomePatch[pid] = pptr;
793 }
std::ostream & iPE(std::ostream &s)
Definition: InfoStream.C:40
#define iout
Definition: InfoStream.h:87
Definition: Patch.h:35
#define iERRORF
Definition: DataStream.h:62
int pid(int aIndex, int bIndex, int cIndex)
Definition: PatchMap.inl:27
infostream & endi(infostream &s)
Definition: InfoStream.C:38
void registerPatch(PatchID pid, HomePatch *pptr)
Definition: PatchMap.C:786
void PatchMap::registerPatch ( PatchID  pid,
Patch pptr 
)

Definition at line 805 of file PatchMap.C.

References endi(), iERRORF, iout, iPE(), and pid().

806 {
807  if (myPatch[pid] != 0) {
808  iout << iPE << iERRORF
809  << "patchID("<<pid<<") is being re-registered!\n" << endi;
810  }
811  myPatch[pid] = pptr;
812 }
std::ostream & iPE(std::ostream &s)
Definition: InfoStream.C:40
#define iout
Definition: InfoStream.h:87
#define iERRORF
Definition: DataStream.h:62
int pid(int aIndex, int bIndex, int cIndex)
Definition: PatchMap.inl:27
infostream & endi(infostream &s)
Definition: InfoStream.C:38
static void PatchMap::registerPatchMgr ( PatchMgr pmgr)
inlinestatic

Definition at line 49 of file PatchMap.h.

Referenced by PatchMgr::PatchMgr().

49  {
50  CkpvAccess(PatchMap_patchMgr) = pmgr;
51  }
int PatchMap::sizeGrid ( ScaledPosition  xmin,
ScaledPosition  xmax,
const Lattice lattice,
BigReal  patchSize,
double  maxNumPatches,
int  staticAtomAssignment,
int  asplit,
int  bsplit,
int  csplit 
)

Definition at line 62 of file PatchMap.C.

References Lattice::a(), Lattice::a_p(), Lattice::a_r(), Lattice::b(), Lattice::b_p(), Lattice::b_r(), Lattice::c(), Lattice::c_p(), Lattice::c_r(), NAMD_die(), Vector::unit(), Vector::x, Vector::y, and Vector::z.

Referenced by makePatches(), and WorkDistrib::patchMapInit().

66 {
67  aPeriodic = lattice.a_p();
68  bPeriodic = lattice.b_p();
69  cPeriodic = lattice.c_p();
70 
71  aAway = asplit;
72  bAway = bsplit;
73  cAway = csplit;
74 
75  int minNumPatches = 1;
76  if ( aPeriodic ) minNumPatches *= aAway;
77  if ( bPeriodic ) minNumPatches *= bAway;
78  if ( cPeriodic ) minNumPatches *= cAway;
79  if ( maxNumPatches < minNumPatches ) maxNumPatches = minNumPatches;
80 
81  if ( aPeriodic ) {
82  BigReal sysDim = lattice.a_r().unit() * lattice.a();
83  aDim = (int)(sysDim * aAway / patchSize);
84  } else {
85  BigReal sysDim = xmax.x - xmin.x;
86  aDim = (int)(sysDim * aAway / patchSize);
87  if ((aDim * patchSize) < (sysDim * aAway)) aDim++;
88  if ( aDim < aAway + 1 ) aDim = aAway + 1;
89  }
90 
91  if ( bPeriodic ) {
92  BigReal sysDim = lattice.b_r().unit() * lattice.b();
93  bDim = (int)(sysDim * bAway / patchSize);
94  } else {
95  BigReal sysDim = xmax.y - xmin.y;
96  bDim = (int)(sysDim * bAway / patchSize);
97  if ((bDim * patchSize) < (sysDim * bAway)) bDim++;
98  if ( bDim < bAway + 1 ) bDim = bAway + 1;
99  }
100 
101  if ( cPeriodic ) {
102  BigReal sysDim = lattice.c_r().unit() * lattice.c();
103  cDim = (int)(sysDim * cAway / patchSize);
104  } else {
105  BigReal sysDim = xmax.z - xmin.z;
106  cDim = (int)(sysDim * cAway / patchSize);
107  if ((cDim * patchSize) < (sysDim * cAway)) cDim++;
108  if ( cDim < cAway + 1 ) cDim = cAway + 1;
109  }
110 
111  if ( aDim < 0 || bDim < 0 || cDim < 0 ) {
112  NAMD_die("Bug in PatchMap::sizeGrid - negative grid dimension.");
113  }
114 
115  if ( staticAtomAssignment ) {
116  if ( aPeriodic || bPeriodic || cPeriodic )
117  NAMD_die("Static atom assignment is incompatible with periodic boundary conditions.");
118  aDim = aAway + 1;
119  bDim = bAway + 1;
120  cDim = cAway + 1;
121  }
122 
123  const int amin = (aPeriodic ? aAway : 1);
124  const int bmin = (bPeriodic ? bAway : 1);
125  const int cmin = (cPeriodic ? cAway : 1);
126 
127  // CkPrintf("searching %d-away %d-away %d-away max %d\n",aAway,bAway,cAway,(int)maxNumPatches);
128 
129  if ( aDim < amin ) aDim = amin;
130  if ( bDim < bmin ) bDim = bmin;
131  if ( cDim < cmin ) cDim = cmin;
132 
133  if ( maxNumPatches > (double)aDim*bDim*cDim ) {
134  maxNumPatches = (double)aDim*bDim*cDim;
135  }
136 
137  int abest = amin;
138  int bbest = bmin;
139  int cbest = cmin;
140  int cdim = maxNumPatches;
141  cdim /= aDim; cdim /= bDim;
142  if ( cdim < cmin ) cdim = cmin;
143  for ( ; cdim <= cDim; ++cdim ) {
144  int bdim = maxNumPatches;
145  bdim /= aDim; bdim /= cdim;
146  if ( bdim < bmin ) bdim = bmin;
147  for ( ; bdim <= bDim; ++bdim ) {
148  int adim = maxNumPatches;
149  adim /= bdim; adim /= cdim;
150  if ( adim < amin ) adim = amin;
151  for ( ; adim <= aDim; ++adim ) {
152  if ( adim*bdim*cdim > maxNumPatches ) break;
153  // CkPrintf("testing %d * %d * %d == %d\n",adim,bdim,cdim,adim*bdim*cdim);
154  if ( adim*bdim*cdim > abest*bbest*cbest ) {
155  abest = adim; bbest = bdim; cbest = cdim;
156  }
157  if ( abest*bbest*cbest == maxNumPatches ) break;
158  }
159  if ( abest*bbest*cbest == maxNumPatches ) break;
160  }
161  if ( abest*bbest*cbest == maxNumPatches ) break;
162  }
163  aDim = abest;
164  bDim = bbest;
165  cDim = cbest;
166 
167  // CkPrintf("found %d * %d * %d == %d\n",aDim,bDim,cDim,aDim*bDim*cDim);
168  return aDim*bDim*cDim;
169 }
Vector a_r() const
Definition: Lattice.h:268
Vector c_r() const
Definition: Lattice.h:270
BigReal z
Definition: Vector.h:66
Vector b_r() const
Definition: Lattice.h:269
BigReal x
Definition: Vector.h:66
void NAMD_die(const char *err_msg)
Definition: common.C:83
BigReal y
Definition: Vector.h:66
Vector b() const
Definition: Lattice.h:253
int b_p() const
Definition: Lattice.h:274
int a_p() const
Definition: Lattice.h:273
Vector a() const
Definition: Lattice.h:252
Vector unit(void) const
Definition: Vector.h:182
Vector c() const
Definition: Lattice.h:254
double BigReal
Definition: common.h:112
int c_p() const
Definition: Lattice.h:275
void PatchMap::unpack ( char *  buf)
protected

Definition at line 365 of file PatchMap.C.

References DebugM, ObjectArena< Type >::getNewArray(), node(), numCids(), ObjectArena< Type >::setBlockSize(), UNPACK, and UNPACKN.

Referenced by WorkDistrib::savePatchMap().

366 {
367  DebugM(4,"Unpacking PatchMap on node " << CkMyPe() << std::endl);
368 
369  int i,j;
370  char *b = (char*)ptr;
371  {
372  // defeat some over-zealous compilers
373  int nPatches_tmp;
374  UNPACK(int,nPatches_tmp);
375  nPatches = nPatches_tmp;
376  }
377  DebugM(3,"nPatches = " << nPatches << std::endl);
378 
379  if ( ! myPatch ) {
380  myPatch = new Patch*[nPatches];
381  }
382  memset(myPatch,0,nPatches*sizeof(Patch*));
383  if ( ! myHomePatch ) {
384  myHomePatch = new HomePatch*[nPatches];
385  }
386  memset(myHomePatch,0,nPatches*sizeof(HomePatch*));
387 
388  UNPACK(int,aDim); UNPACK(int,bDim); UNPACK(int,cDim);
389  UNPACK(int,aAway); UNPACK(int,bAway); UNPACK(int,cAway);
390  UNPACK(int,aPeriodic); UNPACK(int,bPeriodic); UNPACK(int,cPeriodic);
391  UNPACK(int,aMaxIndex); UNPACK(int,bMaxIndex); UNPACK(int,cMaxIndex);
392  UNPACK(BigReal,aOrigin); UNPACK(BigReal,bOrigin); UNPACK(BigReal,cOrigin);
393  UNPACK(BigReal,aLength); UNPACK(BigReal,bLength); UNPACK(BigReal,cLength);
394  UNPACK(int,nNodesWithPatches);
395 
396 
397 // CkPrintf("[%d] has bounds a %d b %d c %d npatches %d mem %d\n",CkMyPe(),aDim, bDim, cDim, nPatches, memusage_MB() );
398 
399  if ( ! patchBounds_a ) patchBounds_a = new BigReal[2*aDim+1];
400  if ( ! patchBounds_b ) patchBounds_b = new BigReal[2*bDim+1];
401  if ( ! patchBounds_c ) patchBounds_c = new BigReal[2*cDim+1];
402  UNPACKN(BigReal,patchBounds_a,2*aDim+1);
403  UNPACKN(BigReal,patchBounds_b,2*bDim+1);
404  UNPACKN(BigReal,patchBounds_c,2*cDim+1);
405 
406  if ( CkMyRank() ) return;
407 
408  UNPACKN(int,nPatchesOnNode,CkNumPes());
409 
410  if ( ! patchData ) patchData = new PatchData[nPatches];
411  else if ( ! computeIdArena ) {
412  for(i=0;i<nPatches;++i) {
413  delete [] patchData[i].cids;
414  }
415  }
416  UNPACKN(PatchData,patchData,nPatches);
417 
418  delete computeIdArena;
419  computeIdArena = new ObjectArena<ComputeID>;
420  computeIdArena->setBlockSize(1024);
421 
422  for(i=0;i<nPatches;++i) {
423  DebugM(3,"Unpacking Patch " << i << " is on node " << patchData[i].node <<
424  " with " << patchData[i].numCids << " cids.\n");
425  patchData[i].cids = computeIdArena->getNewArray(patchData[i].numCids);
426  patchData[i].numCidsAllocated = patchData[i].numCids;
427  UNPACKN(ComputeID,patchData[i].cids,patchData[i].numCids);
428  }
429 }
#define UNPACKN(type, data, cnt)
Definition: PatchMap.C:362
Type * getNewArray(int n)
Definition: ObjectArena.h:49
int ComputeID
Definition: NamdTypes.h:183
#define DebugM(x, y)
Definition: Debug.h:59
int numCids(int pid) const
Definition: PatchMap.h:120
Definition: Patch.h:35
void setBlockSize(int n)
Definition: ObjectArena.h:23
#define UNPACK(type, data)
Definition: PatchMap.C:361
int node(int pid) const
Definition: PatchMap.h:114
double BigReal
Definition: common.h:112
void PatchMap::unregisterPatch ( PatchID  pid,
HomePatch pptr 
)

Definition at line 796 of file PatchMap.C.

References DebugM, and pid().

Referenced by ProxyMgr::removeProxy(), PatchMgr::sendMovePatches(), and PatchMgr::sendOneHomePatch().

796  {
797  unregisterPatch(pid,(Patch*)pptr);
798  if (pptr == myHomePatch[pid]) {
799  DebugM(4, "UnregisterHomePatch("<<pid<<") at " << pptr << "\n");
800  myHomePatch[pid] = NULL;
801  }
802 }
#define DebugM(x, y)
Definition: Debug.h:59
Definition: Patch.h:35
void unregisterPatch(PatchID pid, HomePatch *pptr)
Definition: PatchMap.C:796
int pid(int aIndex, int bIndex, int cIndex)
Definition: PatchMap.inl:27
void PatchMap::unregisterPatch ( PatchID  pid,
Patch pptr 
)

Definition at line 815 of file PatchMap.C.

References DebugM, and pid().

816 {
817  if (pptr == myPatch[pid]) {
818  DebugM(4, "UnregisterPatch("<<pid<<") at " << pptr << "\n");
819  myPatch[pid] = NULL;
820  }
821 }
#define DebugM(x, y)
Definition: Debug.h:59
int pid(int aIndex, int bIndex, int cIndex)
Definition: PatchMap.inl:27
int PatchMap::upstreamNeighbors ( int  pid,
PatchID neighbor_ids 
)

Definition at line 669 of file PatchMap.C.

References DebugM, Lattice::index(), and pid().

Referenced by ProxyMgr::createProxies(), and ComputeHomeTuples< TholeElem, Thole, TholeValue >::initialize().

670 {
671  int xi, yi, zi;
672  int xinc, yinc, zinc;
673  int n=0;
674 
675  for(zinc=0;zinc<=1;zinc++)
676  {
677  zi = patchData[pid].cIndex + zinc;
678  if ((zi < 0) || (zi >= cDim))
679  if ( ! cPeriodic ) continue;
680  for(yinc=0;yinc<=1;yinc++)
681  {
682  yi = patchData[pid].bIndex + yinc;
683  if ((yi < 0) || (yi >= bDim))
684  if ( ! bPeriodic ) continue;
685  for(xinc=0;xinc<=1;xinc++)
686  {
687  if ((xinc==0) && (yinc==0) && (zinc==0))
688  continue;
689 
690  xi = patchData[pid].aIndex + xinc;
691  if ((xi < 0) || (xi >= aDim))
692  if ( ! aPeriodic ) continue;
693 
694  if (neighbor_ids)
695  neighbor_ids[n]=this->pid(xi,yi,zi);
696 #if 0
697  if ( transform_ids )
698  {
699  int xt = 0; if ( xi < 0 ) xt = -1; if ( xi >= aDim ) xt = 1;
700  int yt = 0; if ( yi < 0 ) yt = -1; if ( yi >= bDim ) yt = 1;
701  int zt = 0; if ( zi < 0 ) zt = -1; if ( zi >= cDim ) zt = 1;
702  transform_ids[n] = Lattice::index(xt,yt,zt);
703  }
704 #endif
705  n++;
706  }
707  }
708  }
709  DebugM(3,"Patch " << pid << " has " << n << " upstream neighbors.\n");
710  return n;
711 }
static int index(int i=0, int j=0, int k=0)
Definition: Lattice.h:25
#define DebugM(x, y)
Definition: Debug.h:59
int pid(int aIndex, int bIndex, int cIndex)
Definition: PatchMap.inl:27

Friends And Related Function Documentation

friend class WorkDistrib
friend

Definition at line 170 of file PatchMap.h.


The documentation for this class was generated from the following files: