LRTS Comm Thread Tracing in message recieve
[charm.git] / src / conv-com / petable.h
blobe94010df0c7af6bb2689145e3ff71687984df7de
1 /**
2 @addtogroup ConvComlib
3 @{
4 @file
5 @brief Stores lists of messages and sizes from multiple PEs
7 This header is meant for usage with ExtractAndVectorize and
8 ExtractAndVectorizeAll. It will contain a list of messages with its sizes.
9 The parent class will later call a CmiFree to sizes and msgs. This will
10 delete this two arrays, and also the containint ptvectorlist struct. This is
11 done (in the two functions) by allocating a single message containing both
12 the ptvectorlist struct, and the two arrays. Throught CmiReference
13 (incremented only once), when both the arrays are deleted, the struct will
14 also dirappear.
18 #ifndef PETABLE_H
19 #define PETABLE_H
21 #include "router.h"
23 #ifndef NULL
24 #define NULL 0
25 #endif
27 #define CMK_COMLIB_USE_VECTORIZE 0
29 #define MSGQLEN 32
31 typedef struct ptinfo {
32 int refCount;
33 int magic;
34 int offset;
35 /*int freelistindex;*/
36 int msgsize;
37 void *msg;
38 struct ptinfo * next;
39 } PTinfo;
41 typedef struct ptvectorlist {
42 int count;
43 int *sizes;
44 char **msgs;
45 }* PTvectorlist;
49 /* Reduce the no. of mallocs by allocating from
50 * a free list. By allocating 21 at a time, it allocates
51 * 512 contiguous bytes. */
52 #define PTALLOC(ktmp) {\
53 if (PTFreeList) {\
54 ktmp=PTFreeList;\
55 PTFreeList=ktmp->next;\
57 else {\
58 ktmp=(PTinfo *)CmiAlloc(21*sizeof(PTinfo)+sizeof(PTinfo *));\
59 for (int ii=1; ii<20; ++ii) {\
60 ktmp[ii].next = &(ktmp[ii+1]);\
62 ktmp[20].next = NULL;\
63 PTFreeList=&(ktmp[1]);\
64 *((PTinfo**)(&ktmp[21]))=PTFreeChunks;\
65 PTFreeChunks=ktmp;\
69 #define PTFREE(ktmp) {\
70 ktmp->next=PTFreeList;\
71 PTFreeList=ktmp;\
74 #define PTNEXTCHUNK(ktmp) (*((PTinfo**)(&ktmp[21])));
76 #define REALLOC(ktmp, ksize) {\
77 PTinfo **junkptr=(PTinfo **)CmiAlloc(2*ksize*sizeof(void *));\
78 for (int ki=0; ki<ksize;ki++) junkptr[ki]=ktmp[ki];\
79 CmiFree(ktmp);\
80 ktmp=junkptr;\
83 class PeTable {
84 private:
85 PTinfo ***PeList;
86 CkVec<PTinfo *> ptrvec;
88 PTinfo *PTFreeList;
89 PTinfo *PTFreeChunks;
90 // char * CombBuffer;
91 int *msgnum, *MaxSize;
92 int NumPes;
93 int magic;
94 //GList *FreeList;
96 inline int TotalMsgSize(int npe, int *pelist, int *nm, int *nd) {
97 register int totsize=0;
98 magic++;
99 *nm=0;
100 *nd=0;
102 for (int i=0;i<npe;i++) {
103 int index = pelist[i];
104 *nm += msgnum[index];
106 ComlibPrintf("%d: NUM MSGS %d, %d\n", CkMyPe(), index,
107 msgnum[index]);
109 for (int j=0;j<msgnum[index];j++) {
110 if (PeList[index][j]->magic != magic) {
111 int tmp_size = PeList[index][j]->msgsize;
112 tmp_size = ALIGN8(tmp_size);
113 totsize += tmp_size;
114 totsize += sizeof(int)+sizeof(int);
115 PeList[index][j]->magic=magic;
116 (*nd)++;
120 return(totsize);
123 public:
125 PeTable(int n);
126 ~PeTable();
128 inline void InsertMsgs(int npe, int *pelist, int size, void *msg) {
129 PTinfo *tmp;
130 PTALLOC(tmp);
131 tmp->refCount=0;
132 tmp->magic=0;
133 tmp->offset=0;
134 /*tmp->freelistindex=-1;*/
135 tmp->msgsize=size;
136 tmp->msg=msg;
138 for (int j=0;j<npe;j++) {
139 tmp->refCount++;
140 int index=pelist[j];
142 ComlibPrintf("[%d] Inserting %d %d %d\n", CkMyPe(),
143 msgnum[index], index, size);
145 if (msgnum[index] >= MaxSize[index]) {
146 REALLOC(PeList[index], MaxSize[index]);
147 MaxSize[index] *= 2;
149 PeList[index][msgnum[index]]=tmp;
150 msgnum[index]++;
154 inline void InsertMsgs(int npe, int *pelist, int nmsgs, void **msglist){
155 msgstruct **m=(msgstruct **)msglist;
156 for (int i=0;i<nmsgs;i++)
157 InsertMsgs(npe, pelist, m[i]->msgsize, m[i]->msg);
160 void ExtractAndDeliverLocalMsgs(int pe, Strategy *myStrat);
162 int UnpackAndInsert(void *in);
163 int UnpackAndInsertAll(void *in, int npes, int *pelist);
165 char * ExtractAndPack(comID, int, int, int *pelist, int *length);
166 char * ExtractAndPackAll(comID id, int ufield, int *length);
168 struct ptvectorlist * ExtractAndVectorize(comID, int, int, int *pelist);
169 struct ptvectorlist * ExtractAndVectorizeAll(comID id, int ufield);
171 void GarbageCollect();
172 void Purge();
175 #endif
177 /*@}*/