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
27 #define CMK_COMLIB_USE_VECTORIZE 0
31 typedef struct ptinfo
{
35 /*int freelistindex;*/
41 typedef struct 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) {\
55 PTFreeList=ktmp->next;\
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;\
69 #define PTFREE(ktmp) {\
70 ktmp->next=PTFreeList;\
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];\
86 CkVec
<PTinfo
*> ptrvec
;
91 int *msgnum
, *MaxSize
;
96 inline int TotalMsgSize(int npe
, int *pelist
, int *nm
, int *nd
) {
97 register int totsize
=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
,
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
);
114 totsize
+= sizeof(int)+sizeof(int);
115 PeList
[index
][j
]->magic
=magic
;
128 inline void InsertMsgs(int npe
, int *pelist
, int size
, void *msg
) {
134 /*tmp->freelistindex=-1;*/
138 for (int j
=0;j
<npe
;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
]);
149 PeList
[index
][msgnum
[index
]]=tmp
;
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();