00001 #include "charm.h"
00002 #include "ck.h"
00003 #include "ckobjid.h"
00004
00010 void* CkObjID::getObject(){
00011
00012 switch(type){
00013 case TypeChare:
00014 return CkLocalChare(&data.chare.id);
00015 case TypeMainChare:
00016 return CkLocalChare(&data.chare.id);
00017 case TypeGroup:
00018
00019 CkAssert(data.group.onPE == CkMyPe());
00020 return CkLocalBranch(data.group.id);
00021 case TypeNodeGroup:
00022 CkAssert(data.group.onPE == CkMyNode());
00023
00024 {
00025 CmiImmediateLock(CksvAccess(_nodeGroupTableImmLock));
00026 void *retval = CksvAccess(_nodeGroupTable)->find(data.group.id).getObj();
00027 CmiImmediateUnlock(CksvAccess(_nodeGroupTableImmLock));
00028
00029 return retval;
00030 }
00031 case TypeArray:
00032 {
00033
00034
00035 CkArrayID aid(data.array.id);
00036
00037 if(aid.ckLocalBranch() == NULL){ return NULL;}
00038
00039 CProxyElement_ArrayBase aProxy(aid,data.array.idx.asChild());
00040
00041 return aProxy.ckLocal();
00042 }
00043 default:
00044 CkAbort("Object lookup by ID failed with invalid object type!");
00045 return NULL;
00046 }
00047 }
00048
00049
00050 int CkObjID::guessPE(){
00051 switch(type){
00052 case TypeChare:
00053 case TypeMainChare:
00054 return data.chare.id.onPE;
00055 case TypeGroup:
00056 case TypeNodeGroup:
00057 return data.group.onPE;
00058 case TypeArray:
00059 {
00060 CkArrayID aid(data.array.id);
00061 if(aid.ckLocalBranch() == NULL){
00062 return -1;
00063 }
00064 return aid.ckLocalBranch()->lastKnown(data.array.idx.asChild());
00065 }
00066 default:
00067 CkAbort("PE lookup by object ID failed with invalid object type!");
00068 return -1;
00069 }
00070 }
00071
00072 char *CkObjID::toString(char *buf) const {
00073
00074 switch(type){
00075 case TypeChare:
00076 sprintf(buf,"Chare %p PE %d ",data.chare.id.objPtr,data.chare.id.onPE);
00077 break;
00078 case TypeMainChare:
00079 sprintf(buf,"Chare %p PE %d ",data.chare.id.objPtr,data.chare.id.onPE);
00080 break;
00081 case TypeGroup:
00082 sprintf(buf,"Group %d PE %d ",data.group.id.idx,data.group.onPE);
00083 break;
00084 case TypeNodeGroup:
00085 sprintf(buf,"NodeGroup %d Node %d ",data.group.id.idx,data.group.onPE);
00086 break;
00087 case TypeArray:
00088 {
00089 const CkArrayIndexMax &idx = data.array.idx.asChild();
00090 const int *indexData = idx.data();
00091 sprintf(buf,"Array |%d %d %d| id %d ",indexData[0],indexData[1],indexData[2],data.array.id.idx);
00092 break;
00093 }
00094 default:
00095 CkAssert(0);
00096 }
00097
00098 return buf;
00099 }
00100
00101 void CkObjID::updatePosition(int PE){
00102 if(guessPE() == PE){
00103 return;
00104 }
00105 switch(type){
00106 case TypeChare:
00107 case TypeMainChare:
00108 CkAssert(data.chare.id.onPE == PE);
00109 break;
00110 case TypeGroup:
00111 case TypeNodeGroup:
00112 CkAssert(data.group.onPE == PE);
00113 break;
00114 default:
00115 CkAssert(0);
00116 }
00117 }
00118
00119