00001
00002 #include "pose.h"
00003
00005 void pvtObjectNode::sanitize()
00006 {
00007 if (present) {
00008 CmiAssert(ovt >= -1);
00009 CmiAssert(index >= 0);
00010 CmiAssert((sync == OPTIMISTIC) || (sync == CONSERVATIVE));
00011 CmiAssert((localObjPtr != NULL) && (localObjPtr->IsActive() < 2));
00012 }
00013 }
00014
00016 pvtObjects::pvtObjects()
00017 {
00018 int i;
00019 numObjs = numSpaces = firstEmpty = stratIterCount = 0;
00020 size = 100;
00021 if (!(objs = (pvtObjectNode *)malloc(100 * sizeof(pvtObjectNode)))) {
00022 CkPrintf("ERROR: pvtObjects::pvtObjects: OUT OF MEMORY!\n");
00023 CkExit();
00024 }
00025 for (i=0; i<size; i++) objs[i].set(POSE_UnsetTS, POSE_UnsetTS, false, 0, NULL);
00026 }
00027
00029 int pvtObjects::Insert(int index, POSE_TimeType ovt, int sync, sim *myPtr)
00030 {
00031 int idx;
00032 int i;
00033 if (numObjs < size) {
00034 idx = firstEmpty;
00035 if (firstEmpty == numSpaces)
00036 numSpaces++;
00037 objs[idx].set(ovt, index, true, sync, myPtr);
00038 numObjs++;
00039 for (i=firstEmpty+1; i<size; i++)
00040 if (!objs[i].isPresent()) {
00041 firstEmpty = i;
00042 break;
00043 }
00044 }
00045 else {
00046 firstEmpty = size;
00047 size += 50;
00048 if (!(objs =
00049 (pvtObjectNode *)realloc(objs, size * sizeof(pvtObjectNode)))) {
00050 CkPrintf("ERROR: pvtObjects::Insert: OUT OF MEMORY!\n");
00051 CkExit();
00052 }
00053 for (i=firstEmpty; i<size; i++)
00054 objs[i].set(POSE_UnsetTS, POSE_UnsetTS, false, 0, NULL);
00055 idx = firstEmpty;
00056 objs[idx].set(ovt, index, true, sync, myPtr);
00057 numObjs++;
00058 numSpaces++;
00059 firstEmpty++;
00060 }
00061 return idx;
00062 }
00063
00064 void pvtObjects::callAtSync() {
00065 int i;
00066 for (i=0; i<numSpaces; i++)
00067 if (objs[i].isPresent()) {
00068 (objs[i].localObjPtr)->AtSync();
00069 }
00070 }
00072 void pvtObjects::Wake() {
00073 int i;
00074 for (i=0; i<numSpaces; i++)
00075 if (objs[i].isPresent()) (objs[i].localObjPtr)->Status();
00076 }
00078 void pvtObjects::Commit() {
00079 int i;
00080 for (i=0; i<numSpaces; i++)
00081 if (objs[i].isPresent()) (objs[i].localObjPtr)->Commit();
00082 }
00084 void pvtObjects::CheckpointCommit() {
00085 int i;
00086 for (i=0; i<numSpaces; i++)
00087 if (objs[i].isPresent()) (objs[i].localObjPtr)->CheckpointCommit();
00088 }
00090 void pvtObjects::StratCalcs() {
00091
00092 if (stratIterCount >= PVT_STRAT_CALC_PERIOD) {
00093
00094
00095
00096 long long totalRBs = 0LL;
00097 int poserCount = 0;
00098 for (int i = 0; i < numSpaces; i++) {
00099 if (objs[i].isPresent()) {
00100 totalRBs += (objs[i].localObjPtr)->basicStats[1];
00101 poserCount++;
00102 }
00103 }
00104 if (poserCount > 0) {
00105 GVT *localGVT = (GVT *)CkLocalBranch(TheGVT);
00106
00107
00108
00109
00110 int gvtIterCount = localGVT->getGVTIterationCount() * CkNumPes() + CkMyPe();
00111 int avgRBsPerGVTIter = (int)((totalRBs * (long long)totalNumPosers) / ((long long)gvtIterCount * (long long)poserCount));
00112 for (int i = 0; i < numSpaces; i++) {
00113
00114 if (objs[i].isPresent() && (objs[i].localObjPtr->myStrat->STRAT_T == ADAPT5_T)) {
00115 ((adapt5 *)((objs[i].localObjPtr)->myStrat))->setAvgRBsPerGVTIter(avgRBsPerGVTIter);
00116 }
00117 }
00118 }
00119 stratIterCount = 0;
00120 } else {
00121 stratIterCount++;
00122 }
00123 }
00124
00126 void pvtObjects::dump()
00127 {
00128 int i;
00129 CkPrintf("numObjs=%d numSpaces=%d firstEmpty=%d size=%d\n",
00130 numObjs, numSpaces, firstEmpty, size);
00131 for (i=0; i<numSpaces; i++) {
00132 CkPrintf("[%d] ", i);
00133 objs[i].dump();
00134 CkPrintf("\n");
00135 }
00136 }
00137
00139 void pvtObjects::sanitize()
00140 {
00141 int i;
00142 CmiAssert(numObjs >= 0);
00143 CmiAssert(numSpaces >= 0);
00144 CmiAssert(size >= 0);
00145 CmiAssert(firstEmpty >= 0);
00146 CmiAssert(numObjs <= numSpaces);
00147 CmiAssert(numSpaces <= size);
00148 CmiAssert(firstEmpty < numSpaces);
00149 for (int i=0; i<numSpaces; i++) objs[i].sanitize();
00150 }