00001 #ifndef OBJID_H
00002 #define OBJID_H
00003
00004 #include "charm.h"
00005 #include "converse.h"
00006 #include "pup.h"
00007
00008
00009
00010
00011 #ifndef CMK_OBJID_COLLECTION_BITS
00012 #define CMK_OBJID_COLLECTION_BITS 21
00013 #endif
00014
00015 #define CMK_OBJID_TYPE_TAG_BITS 3
00016 #define CMK_OBJID_ELEMENT_BITS (64 - CMK_OBJID_COLLECTION_BITS - CMK_OBJID_TYPE_TAG_BITS)
00017
00018
00019 static_assert(CMK_OBJID_COLLECTION_BITS > 0,
00020 "CMK_OBJID_COLLECTION_BITS must be greater than 0!");
00021 static_assert(CMK_OBJID_COLLECTION_BITS < (64 - CMK_OBJID_TYPE_TAG_BITS),
00022 "CMK_OBJID_COLLECTION_BITS must be less than (64 - CMK_OBJID_TYPE_TAG_BITS)!");
00023 static_assert((CMK_OBJID_COLLECTION_BITS + CMK_OBJID_ELEMENT_BITS + CMK_OBJID_TYPE_TAG_BITS) == 64,
00024 "The total number of collection + element + type tag bits must be 64!");
00025
00026 namespace ck {
00027
00031 class ObjID {
00033 public:
00034 ObjID(): id(0) {}
00036 ObjID(const CmiUInt8 id_) : id(id_) { }
00037 ObjID(const CkGroupID gid, const CmiUInt8 eid)
00038 : id( ((CmiUInt8)gid.idx << ELEMENT_BITS) | eid)
00039 {
00040 if ( (CmiUInt8)gid.idx > (COLLECTION_MASK >> ELEMENT_BITS) ) {
00041 CmiPrintf("\nError> ObjID ran out of collection bits, please try re-building "
00042 "Charm++ with a higher number of collection bits using "
00043 "-DCMK_OBJID_COLLECTION_BITS=N, such that %d<N<30\n",
00044 COLLECTION_BITS);
00045
00046
00047 CmiAbort("Attempting to create too many chare collections!");
00048 }
00049 if ( eid > ELEMENT_MASK ) {
00050 CmiPrintf("\nError> ObjID ran out of element bits, please try re-building "
00051 "Charm++ with a lower number of collection bits using "
00052 "-DCMK_OBJID_COLLECTION_BITS=N, such that 3<N<%d\n",
00053 COLLECTION_BITS);
00054
00055 CmiAbort("Attempting to create too many chare elements!");
00056 }
00057 }
00058
00059
00060
00061 inline CkGroupID getCollectionID() const {
00062 CkGroupID gid;
00063 gid.idx = (id & COLLECTION_MASK) >> ELEMENT_BITS;
00064 return gid;
00065 }
00067 inline CmiUInt8 getElementID() const { return id & ELEMENT_MASK; }
00068 inline CmiUInt8 getID() const { return id & (COLLECTION_MASK | ELEMENT_MASK); }
00069
00070 enum bits {
00071 ELEMENT_BITS = CMK_OBJID_ELEMENT_BITS,
00072 COLLECTION_BITS = CMK_OBJID_COLLECTION_BITS,
00073 TYPE_TAG_BITS = CMK_OBJID_TYPE_TAG_BITS
00074 };
00075 enum masks : CmiUInt8 {
00076 ELEMENT_MASK = ((1ULL << ELEMENT_BITS) - 1),
00077 COLLECTION_MASK = (((1ULL << COLLECTION_BITS) - 1) << ELEMENT_BITS),
00078 TYPE_TAG_MASK = (((1ULL << TYPE_TAG_BITS) - 1) << (ELEMENT_BITS + COLLECTION_BITS))
00079 };
00080
00081 private:
00082
00084 CmiUInt8 id;
00085 };
00086
00087 inline bool operator==(ObjID lhs, ObjID rhs) {
00088 return lhs.getID() == rhs.getID();
00089 }
00090 inline bool operator!=(ObjID lhs, ObjID rhs) {
00091 return !(lhs == rhs);
00092 }
00093
00094 }
00095
00096 PUPbytes(ck::ObjID)
00097 #endif // OBJID_H
00098