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