00001
00018 #ifndef PETABLE_H
00019 #define PETABLE_H
00020
00021 #include "router.h"
00022
00023 #ifndef NULL
00024 #define NULL 0
00025 #endif
00026
00027 #define CMK_COMLIB_USE_VECTORIZE 0
00028
00029 #define MSGQLEN 32
00030
00031 typedef struct ptinfo {
00032 int refCount;
00033 int magic;
00034 int offset;
00035
00036 int msgsize;
00037 void *msg;
00038 struct ptinfo * next;
00039 } PTinfo;
00040
00041 typedef struct ptvectorlist {
00042 int count;
00043 int *sizes;
00044 char **msgs;
00045 }* PTvectorlist;
00046
00047
00048
00049
00050
00051
00052 #define PTALLOC(ktmp) {\
00053 if (PTFreeList) {\
00054 ktmp=PTFreeList;\
00055 PTFreeList=ktmp->next;\
00056 }\
00057 else {\
00058 ktmp=(PTinfo *)CmiAlloc(21*sizeof(PTinfo)+sizeof(PTinfo *));\
00059 for (int ii=1; ii<20; ++ii) {\
00060 ktmp[ii].next = &(ktmp[ii+1]);\
00061 }\
00062 ktmp[20].next = NULL;\
00063 PTFreeList=&(ktmp[1]);\
00064 *((PTinfo**)(&ktmp[21]))=PTFreeChunks;\
00065 PTFreeChunks=ktmp;\
00066 }\
00067 }
00068
00069 #define PTFREE(ktmp) {\
00070 ktmp->next=PTFreeList;\
00071 PTFreeList=ktmp;\
00072 }
00073
00074 #define PTNEXTCHUNK(ktmp) (*((PTinfo**)(&ktmp[21])));
00075
00076 #define REALLOC(ktmp, ksize) {\
00077 PTinfo **junkptr=(PTinfo **)CmiAlloc(2*ksize*sizeof(void *));\
00078 for (int ki=0; ki<ksize;ki++) junkptr[ki]=ktmp[ki];\
00079 CmiFree(ktmp);\
00080 ktmp=junkptr;\
00081 }
00082
00083 class PeTable {
00084 private:
00085 PTinfo ***PeList;
00086 CkVec<PTinfo *> ptrvec;
00087
00088 PTinfo *PTFreeList;
00089 PTinfo *PTFreeChunks;
00090
00091 int *msgnum, *MaxSize;
00092 int NumPes;
00093 int magic;
00094
00095
00096 inline int TotalMsgSize(int npe, int *pelist, int *nm, int *nd) {
00097 register int totsize=0;
00098 magic++;
00099 *nm=0;
00100 *nd=0;
00101
00102 for (int i=0;i<npe;i++) {
00103 int index = pelist[i];
00104 *nm += msgnum[index];
00105
00106 ComlibPrintf("%d: NUM MSGS %d, %d\n", CkMyPe(), index,
00107 msgnum[index]);
00108
00109 for (int j=0;j<msgnum[index];j++) {
00110 if (PeList[index][j]->magic != magic) {
00111 int tmp_size = PeList[index][j]->msgsize;
00112 tmp_size = ALIGN8(tmp_size);
00113 totsize += tmp_size;
00114 totsize += sizeof(int)+sizeof(int);
00115 PeList[index][j]->magic=magic;
00116 (*nd)++;
00117 }
00118 }
00119 }
00120 return(totsize);
00121 }
00122
00123 public:
00124
00125 PeTable(int n);
00126 ~PeTable();
00127
00128 inline void InsertMsgs(int npe, int *pelist, int size, void *msg) {
00129 PTinfo *tmp;
00130 PTALLOC(tmp);
00131 tmp->refCount=0;
00132 tmp->magic=0;
00133 tmp->offset=0;
00134
00135 tmp->msgsize=size;
00136 tmp->msg=msg;
00137
00138 for (int j=0;j<npe;j++) {
00139 tmp->refCount++;
00140 int index=pelist[j];
00141
00142 ComlibPrintf("[%d] Inserting %d %d %d\n", CkMyPe(),
00143 msgnum[index], index, size);
00144
00145 if (msgnum[index] >= MaxSize[index]) {
00146 REALLOC(PeList[index], MaxSize[index]);
00147 MaxSize[index] *= 2;
00148 }
00149 PeList[index][msgnum[index]]=tmp;
00150 msgnum[index]++;
00151 }
00152 }
00153
00154 inline void InsertMsgs(int npe, int *pelist, int nmsgs, void **msglist){
00155 msgstruct **m=(msgstruct **)msglist;
00156 for (int i=0;i<nmsgs;i++)
00157 InsertMsgs(npe, pelist, m[i]->msgsize, m[i]->msg);
00158 }
00159
00160 void ExtractAndDeliverLocalMsgs(int pe, Strategy *myStrat);
00161
00162 int UnpackAndInsert(void *in);
00163 int UnpackAndInsertAll(void *in, int npes, int *pelist);
00164
00165 char * ExtractAndPack(comID, int, int, int *pelist, int *length);
00166 char * ExtractAndPackAll(comID id, int ufield, int *length);
00167
00168 struct ptvectorlist * ExtractAndVectorize(comID, int, int, int *pelist);
00169 struct ptvectorlist * ExtractAndVectorizeAll(comID id, int ufield);
00170
00171 void GarbageCollect();
00172 void Purge();
00173 };
00174
00175 #endif
00176