Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

AtomMap.C

Go to the documentation of this file.
00001 
00007 /*
00008    Tracks location of Atoms on node.  Singleton.
00009 */
00010 
00011 #include "ProcessorPrivate.h"
00012 #include "AtomMap.h"
00013 
00014 #define MIN_DEBUG_LEVEL 4
00015 // #define DEBUGM
00016 #include "Debug.h"
00017 
00018 
00019 // Singleton method
00020 AtomMap *AtomMap::Instance() {
00021   if (CkpvAccess(AtomMap_instance) == 0) {
00022     CkpvAccess(AtomMap_instance) = new AtomMap; // this is never deleted!
00023   }
00024   return CkpvAccess(AtomMap_instance);
00025 }
00026 
00027 //----------------------------------------------------------------------
00028 AtomMap::AtomMap(void)
00029 {
00030   localIDTable = NULL;
00031   cleared = false;
00032 }
00033 
00034 void
00035 AtomMap::checkMap(void)
00036 { }
00037   
00038 
00039 //----------------------------------------------------------------------
00040 AtomMap::~AtomMap(void)
00041 {
00042   delete [] localIDTable;  // Delete on a NULL pointer should be ok
00043 }
00044 
00045 //----------------------------------------------------------------------
00046 // Creates fixed size table
00047 void AtomMap::allocateMap(int nAtomIds)
00048 {
00049   localIDTable = new LocalID[nAtomIds];
00050   tableSz = nAtomIds;
00051   for(int i=0; i < nAtomIds; i++)
00052     localIDTable[i].pid = localIDTable[i].index = notUsed;
00053   cleared = true;
00054 }
00055 
00056 //
00057 int AtomMap::unregisterIDs(PatchID pid, const CompAtomExt *begin, const CompAtomExt *end)
00058 {
00059   if (localIDTable == NULL)
00060     return -1;
00061   else 
00062   {
00063     for(const CompAtomExt *a = begin; a != end; ++a)
00064     {
00065         unsigned int ali = a->id;
00066         if (localIDTable[ali].pid == pid) {
00067             localIDTable[ali].pid = notUsed;
00068             localIDTable[ali].index = notUsed;
00069         }
00070     }
00071     return 0;
00072   }
00073 }
00074 //----------------------------------------------------------------------
00075 int AtomMap::registerIDs(PatchID pid, const CompAtomExt *begin, const CompAtomExt *end)
00076 {
00077   if (localIDTable == NULL)
00078     return -1;
00079   else 
00080   {
00081     for(const CompAtomExt *a = begin; a != end; ++a)
00082     {
00083         unsigned int ali = a->id;
00084         localIDTable[ali].pid = pid;
00085         localIDTable[ali].index = a - begin;
00086     }
00087     cleared = false;
00088     return 0;
00089   }
00090 }
00091 
00092 //----------------------------------------------------------------------
00093 // resets map to notUsed condition
00094 void AtomMap::clearMap(void)
00095 {
00096   if (!cleared && localIDTable != NULL)
00097   {
00098     for(int i=0; i < tableSz; i++)
00099       localIDTable[i].pid = localIDTable[i].index = notUsed;
00100     cleared = true;
00101   }
00102 }
00103 
00104 void AtomMap::print()
00105 {
00106   for (int i=0; i<tableSz; i++) {
00107     CkPrintf("AtomMap on node %d\n", CkMyPe());
00108     CkPrintf("AtomID %d -> PatchID %d:Index %d\n", i, localIDTable[i].pid,
00109       localIDTable[i].index);
00110   }
00111 }
00112 
00113 

Generated on Mon Nov 23 04:59:18 2009 for NAMD by  doxygen 1.3.9.1