00001
00002
00003
00004
00005
00006 #include "pose.h"
00007
00008
00009 lbObjects::lbObjects()
00010 {
00011 numObjs = numSpaces = firstEmpty = 0;
00012 size = 100;
00013 if (!(objs = (lbObjectNode *)malloc(100 * sizeof(lbObjectNode)))) {
00014 CkPrintf("ERROR: lbObjects::lbObjects: OUT OF MEMORY!\n");
00015 CkExit();
00016 }
00017 for (int i=0; i<size; i++) {
00018 objs[i].present = 0;
00019 objs[i].eet = objs[i].ne = objs[i].execPrio = 0;
00020 objs[i].rbOh = 0.0;
00021 objs[i].comm = (int *)malloc(CkNumPes()*sizeof(int));
00022 for (int j=0; j<CkNumPes(); j++) objs[i].comm[j] = 0;
00023 objs[i].totalComm = objs[i].localComm = objs[i].remoteComm =
00024 objs[i].maxComm = 0;
00025 objs[i].maxCommPE = -1;
00026 }
00027 }
00028
00029
00030
00031 int lbObjects::Insert(int sync, int index, sim *myPtr)
00032 {
00033 int idx, i;
00034 if (numObjs < size) {
00035 idx = firstEmpty;
00036 if (firstEmpty == numSpaces)
00037 numSpaces++;
00038 objs[idx].index = index;
00039 objs[idx].present = 1;
00040 objs[idx].sync = sync;
00041 objs[idx].localObjPtr = myPtr;
00042 numObjs++;
00043 for (i=firstEmpty+1; i<size; i++)
00044 if (objs[i].present == 0) {
00045 firstEmpty = i;
00046 break;
00047 }
00048 }
00049 else {
00050 firstEmpty = size;
00051 size += 50;
00052 if (!(objs =
00053 (lbObjectNode *)realloc(objs, size * sizeof(lbObjectNode)))) {
00054 CkPrintf("ERROR: lbObjects::Insert: OUT OF MEMORY!\n");
00055 CkExit();
00056 }
00057 for (i=firstEmpty; i<size; i++) {
00058 objs[i].present = 0;
00059 objs[i].eet = objs[i].ne = objs[i].execPrio = 0;
00060 objs[i].rbOh = 0.0;
00061 objs[i].comm = (int *)malloc(CkNumPes()*sizeof(int));
00062 for (int j=0; j<CkNumPes(); j++) objs[i].comm[j] = 0;
00063 objs[i].totalComm = objs[i].localComm = objs[i].remoteComm =
00064 objs[i].maxComm = 0;
00065 objs[i].maxCommPE = -1;
00066 }
00067
00068 idx = firstEmpty;
00069 objs[idx].index = index;
00070 objs[idx].present = 1;
00071 objs[idx].sync = sync;
00072 objs[idx].localObjPtr = myPtr;
00073 numObjs++;
00074 numSpaces++;
00075 firstEmpty++;
00076 }
00077 return idx;
00078 }
00079
00080
00081 void lbObjects::Delete(int idx)
00082 {
00083 objs[idx].present = 0;
00084 objs[idx].localObjPtr = NULL;
00085 numObjs--;
00086 if (idx < firstEmpty)
00087 firstEmpty = idx;
00088 }
00089
00090 void lbObjects::UpdateEntry(int idx, POSE_TimeType ovt, POSE_TimeType eet, int ne, double rbOh,
00091 int *srVec)
00092 {
00093 if (objs[idx].present) {
00094 objs[idx].ovt = ovt;
00095 objs[idx].eet = eet;
00096 objs[idx].ne = ne;
00097 objs[idx].rbOh = rbOh;
00098 for (int i=0; i<CkNumPes(); i++)
00099 AddComm(idx, i, srVec[i]);
00100 }
00101 else CkPrintf("ERROR: lbObjects::UpdateEntry: No such object exists.\n");
00102 }
00103
00104
00105 void lbObjects::AddComm(int idx, int pe, int sr)
00106 {
00107 if (objs[idx].present) {
00108 objs[idx].comm[pe] += sr;
00109 objs[idx].totalComm += sr;
00110 if (pe == CkMyPe())
00111 objs[idx].localComm += sr;
00112 else objs[idx].remoteComm += sr;
00113 }
00114 else CkPrintf("ERROR: lbObjects::AddComm: No such object exists.\n");
00115 }
00116
00117
00118 void lbObjects::ResetComm()
00119 {
00120 for (int i=0; i<numSpaces; i++)
00121 if (objs[i].present) {
00122 for (int j=0; j<CkNumPes(); j++)
00123 objs[i].comm[j] = 0;
00124 objs[i].totalComm = objs[i].localComm = objs[i].remoteComm =
00125 objs[i].maxComm = 0;
00126 objs[i].maxCommPE = -1;
00127 }
00128 }
00129
00130 void lbObjects::RequestReport()
00131 {
00132 for (int i=0; i<numSpaces; i++)
00133 if (objs[i].present)
00134 (objs[i].localObjPtr)->ReportLBdata();
00135 }
00136
00137
00138 void lbObjects::dump()
00139 {
00140 CkPrintf("numObjs=%d numSpaces=%d firstEmpty=%d size=%d\n",
00141 numObjs, numSpaces, firstEmpty, size);
00142 for (int i=0; i<numSpaces; i++) {
00143 CkPrintf("[%d] ", i);
00144 objs[i].dump();
00145 CkPrintf("\n");
00146 }
00147 }