NAMD
AtomMap.h
Go to the documentation of this file.
1 
14 #ifndef ATOMMAP_H
15 #define ATOMMAP_H
16 
17 #include "NamdTypes.h"
18 #include "ProcessorPrivate.h"
19 
20 #ifdef MEM_OPT_VERSION
21 
22 struct AtomMapEntry {
23  AtomMapEntry *next;
24  int pid;
25  short index;
26  short aid_upper;
27 };
28 
29 #endif
30 
31 enum { notUsed = -1 };
32 
33 class AtomMap
34 {
35 public:
36  static AtomMap *Instance();
37  inline static AtomMap *Object() { return CkpvAccess(AtomMap_instance); }
38  inline static AtomMap *ObjectOnPe(int pe) {
39  return CkpvAccessOther(AtomMap_instance, CmiRankOf(pe));
40  }
41  ~AtomMap(void);
42  void checkMap();
43 
44  void allocateMap(int nAtomIDs);
45 
47 
48  friend class AtomMapper;
49 #if defined(NAMD_CUDA) || defined(NAMD_HIP)
50 #ifdef BONDED_CUDA
51  friend class ComputeBondedCUDA;
52 #endif
53 #endif
54 
55 protected:
56  AtomMap(void);
57 
58 private:
59  int registerIDsCompAtomExt(PatchID pid, const CompAtomExt *begin, const CompAtomExt *end);
60  int registerIDsFullAtom(PatchID pid, const FullAtom *begin, const FullAtom *end);
61  int unregisterIDsCompAtomExt(PatchID pid, const CompAtomExt *begin, const CompAtomExt *end);
62  int unregisterIDsFullAtom(PatchID pid, const FullAtom *begin, const FullAtom *end);
63 
64 #ifdef MEM_OPT_VERSION
65  AtomMapEntry **entries;
66  bool onlyUseTbl;
67 #endif
68 
69  LocalID *localIDTable;
70  int tableSz;
71 
72 };
73 
74 #ifndef MEM_OPT_VERSION
75 //----------------------------------------------------------------------
76 // LocalID contains patch pid and local patch atom index
77 // for a given global atom number
79 {
80  return localIDTable[id];
81 }
82 #endif
83 
84 
85 class AtomMapper {
86 public:
87  AtomMapper(PatchID _pid) : pid(_pid), mapped(0), map(AtomMap::Object()) {}
88 #if defined(NAMD_CUDA) || defined(NAMD_HIP)
89 #ifdef BONDED_CUDA
90  AtomMapper(PatchID _pid, AtomMap *_map) : pid(_pid), mapped(0), map(_map) {}
91 #endif
92 #endif
94  if ( mapped ) NAMD_bug("deleted AtomMapper with atoms still mapped");
95  }
96  void registerIDsCompAtomExt(const CompAtomExt *begin, const CompAtomExt *end);
97  void registerIDsFullAtom(const FullAtom *begin, const FullAtom *end);
98  void unregisterIDsCompAtomExt(const CompAtomExt *begin, const CompAtomExt *end);
99  void unregisterIDsFullAtom(const FullAtom *begin, const FullAtom *end);
100 
101 private:
102  const PatchID pid;
103  int mapped;
104  AtomMap *map;
105 #ifdef MEM_OPT_VERSION
107 #endif
108 };
109 
110 
111 #endif /* ATOMMAP_H */
112 
void allocateMap(int nAtomIDs)
Definition: AtomMap.C:161
void checkMap()
Definition: AtomMap.C:145
void registerIDsFullAtom(const FullAtom *begin, const FullAtom *end)
Definition: AtomMap.C:50
static AtomMap * Instance()
Definition: AtomMap.C:125
~AtomMap(void)
Definition: AtomMap.C:150
void registerIDsCompAtomExt(const CompAtomExt *begin, const CompAtomExt *end)
Definition: AtomMap.C:24
static Units next(Units u)
Definition: ParseOptions.C:48
static AtomMap * ObjectOnPe(int pe)
Definition: AtomMap.h:38
void NAMD_bug(const char *err_msg)
Definition: common.C:195
LocalID localID(AtomID id)
Definition: AtomMap.h:78
~AtomMapper()
Definition: AtomMap.h:93
AtomMap(void)
Definition: AtomMap.C:133
static AtomMap * Object()
Definition: AtomMap.h:37
AtomMapper(PatchID _pid)
Definition: AtomMap.h:87
int32 AtomID
Definition: NamdTypes.h:35
void unregisterIDsFullAtom(const FullAtom *begin, const FullAtom *end)
Definition: AtomMap.C:100
int32 PatchID
Definition: NamdTypes.h:277
void unregisterIDsCompAtomExt(const CompAtomExt *begin, const CompAtomExt *end)
Definition: AtomMap.C:76