14 #define MIN_DEBUG_LEVEL 4
18 #ifdef MEM_OPT_VERSION
20 #define MAXNUMATOMS (1<<MAXBITS)
27 #ifdef MEM_OPT_VERSION
28 if ( ! map->onlyUseTbl ) {
31 AtomMapEntry *e = entries.begin();
32 for (
int i=0; i<n; ++i, ++e ) {
36 short aid_upper = aid >> MAXBITS;
37 e->aid_upper = aid_upper;
38 int aid_hash = aid & (MAXNUMATOMS-1);
39 AtomMapEntry **me = map->entries + aid_hash;
40 while ( *me && (*me)->aid_upper < aid_upper ) me = &((*me)->next);
46 if ( map->registerIDsCompAtomExt(pid, begin, end) )
NAMD_bug(
"atom map failed");
53 #ifdef MEM_OPT_VERSION
54 if ( ! map->onlyUseTbl ) {
57 AtomMapEntry *e = entries.begin();
58 for (
int i=0; i<n; ++i, ++e ) {
62 short aid_upper = aid >> MAXBITS;
63 e->aid_upper = aid_upper;
64 int aid_hash = aid & (MAXNUMATOMS-1);
65 AtomMapEntry **me = map->entries + aid_hash;
66 while ( *me && (*me)->aid_upper < aid_upper ) me = &((*me)->next);
72 if ( map->registerIDsFullAtom(pid, begin, end) )
NAMD_bug(
"atom map failed");
77 if ( ! mapped )
return;
79 #ifdef MEM_OPT_VERSION
80 if ( ! map->onlyUseTbl ) {
82 if ( entries.size() != n ) {
83 CkPrintf(
"AtomMapper entries.size() %d != %d\n", entries.size(), n);
84 NAMD_bug(
"AtomMapper::unregisterIDsCompAtomExt size mismatch");
86 AtomMapEntry *e = entries.begin();
87 for (
int i=0; i<n; ++i, ++e ) {
89 int aid_hash = aid & (MAXNUMATOMS-1);
90 AtomMapEntry **me = map->entries + aid_hash;
91 while ( *me != e ) me = &((*me)->next);
96 if ( map->unregisterIDsCompAtomExt(pid, begin, end) )
NAMD_bug(
"atom map failed");
101 if ( ! mapped )
return;
103 #ifdef MEM_OPT_VERSION
104 if ( ! map->onlyUseTbl ) {
106 if ( entries.size() != n ) {
107 CkPrintf(
"AtomMapper entries.size() %d != %d\n", entries.size(), n);
108 NAMD_bug(
"AtomMapper::unregisterIDsFullAtom size mismatch");
110 AtomMapEntry *e = entries.begin();
111 for (
int i=0; i<n; ++i, ++e ) {
113 int aid_hash = aid & (MAXNUMATOMS-1);
114 AtomMapEntry **me = map->entries + aid_hash;
115 while ( *me != e ) me = &((*me)->next);
120 if ( map->unregisterIDsFullAtom(pid, begin, end) )
NAMD_bug(
"atom map failed");
126 if (CkpvAccess(AtomMap_instance) == 0) {
127 CkpvAccess(AtomMap_instance) =
new AtomMap;
129 return CkpvAccess(AtomMap_instance);
138 #ifdef MEM_OPT_VERSION
152 delete [] localIDTable;
154 #ifdef MEM_OPT_VERSION
163 #ifdef MEM_OPT_VERSION
164 if ( nAtomIds > MAXNUMATOMS ) {
165 entries =
new AtomMapEntry*[MAXNUMATOMS];
166 memset(entries,0,MAXNUMATOMS*
sizeof(AtomMapEntry*));
171 if ( nAtomIds <= tableSz )
return;
172 LocalID *oldTable = localIDTable;
173 localIDTable =
new LocalID[nAtomIds];
174 for(
int i=0; i < tableSz; i++)
175 localIDTable[i] = oldTable[i];
176 for(
int i=tableSz; i < nAtomIds; i++)
177 localIDTable[i].pid = localIDTable[i].index =
notUsed;
185 if (localIDTable == NULL)
191 unsigned int ali = a->id;
192 if (localIDTable[ali].pid == pid) {
204 if (localIDTable == NULL)
208 for(
const FullAtom *a = begin; a != end; ++a)
210 unsigned int ali = a->id;
211 if (localIDTable[ali].pid == pid) {
226 if (localIDTable == NULL)
232 unsigned int ali = a->id;
233 localIDTable[ali].
pid = pid;
234 localIDTable[ali].
index = a - begin;
243 if (localIDTable == NULL)
247 for(
const FullAtom *a = begin; a != end; ++a)
249 unsigned int ali = a->id;
250 localIDTable[ali].
pid = pid;
251 localIDTable[ali].
index = a - begin;
258 #ifdef MEM_OPT_VERSION
262 return localIDTable[id];
265 short aid_upper =
id >> MAXBITS;
266 int aid_hash =
id & (MAXNUMATOMS-1);
267 AtomMapEntry *me = entries[aid_hash];
268 while ( me && me->aid_upper < aid_upper ) me = me->next;
270 if ( me && me->aid_upper == aid_upper ) {
272 rval.
index = me->index;
void allocateMap(int nAtomIDs)
void registerIDsFullAtom(const FullAtom *begin, const FullAtom *end)
static AtomMap * Instance()
void registerIDsCompAtomExt(const CompAtomExt *begin, const CompAtomExt *end)
void NAMD_bug(const char *err_msg)
LocalID localID(AtomID id)
void unregisterIDsFullAtom(const FullAtom *begin, const FullAtom *end)
void unregisterIDsCompAtomExt(const CompAtomExt *begin, const CompAtomExt *end)