Fix warnings and errors in ampi_noimpl.C
[charm.git] / src / util / pup_cmialloc.C
blob58891f4a06a8781a05347e2a2090a5c979997811
1 #include "pup_cmialloc.h"
3 void PUP_cmiAllocSizer::bytes(void *,size_t n,size_t itemSize,PUP::dataType) {
4     nBytes += n * itemSize;
7 void PUP_toCmiAllocMem::bytes(void *p, size_t n, size_t itemSize, 
8                               PUP::dataType t) {
10     n *= itemSize;
11     memcpy((void *)buf, p, n);    
12     buf += n;
15 void PUP_fromCmiAllocMem::bytes(void *p, size_t n, size_t itemSize, 
16                                 PUP::dataType t)
18     n*=itemSize;
19     memcpy(p,(const void *)buf,n);
20     
21     buf+= n;
24 void PUP_cmiAllocSizer::pupCmiAllocBuf(void **msg) {
25     CmiChunkHeader chnk_hdr = *(BLKSTART(*msg));
26     pupCmiAllocBuf(msg, chnk_hdr.size);
29 void PUP_cmiAllocSizer::pupCmiAllocBuf(void **msg, size_t msg_size) {
31     //The cmialloced buf can only start at an aligned memory location
32     //So nbytes has to be aligned
33     nBytes = ALIGN8(nBytes);
35     nBytes += sizeof(CmiChunkHeader);
36     //Here the user buffer pointer will start, hence everything has to
37     //be aligned till here
38     nBytes += msg_size;  //The actual size of the user message
42 void PUP_toCmiAllocMem::pupCmiAllocBuf(void **msg) {
43     pupCmiAllocBuf(msg, SIZEFIELD(msg));
46 void PUP_toCmiAllocMem::pupCmiAllocBuf(void **msg, size_t msg_size) {
48     CmiChunkHeader chnk_hdr;
50     buf = origBuf + ALIGN8_LONG(size());
52     chnk_hdr.size = msg_size;
53     chnk_hdr.setRef(origBuf - (buf + sizeof(CmiChunkHeader)));
54     
55     //Copy the Chunk header
56     memcpy(buf, &chnk_hdr, sizeof(CmiChunkHeader));
57     buf += sizeof(CmiChunkHeader);
59     //Now buf is a memory aligned pointer
60     //Copy the message
61     //While unpacking, this aligned pointer will be returned
62     memcpy(buf, *msg, msg_size);
63     buf += msg_size;
66 void PUP_fromCmiAllocMem::pupCmiAllocBuf(void **msg) {
67     //First align buf
68     buf = (PUP::myByte *)(intptr_t)ALIGN8_LONG((intptr_t)buf);
70     //Now get the chunk header
71     CmiChunkHeader chnk_hdr;    
72     //Get the Chunk header
73     memcpy(&chnk_hdr, buf, sizeof(CmiChunkHeader));
74     buf += sizeof(CmiChunkHeader);
76     //Now we are at the begining of the user buffer
77     *msg = buf;
79     //Move the local buf forward by size bytes
80     buf += chnk_hdr.size;
81     
82     //update the reference count of the original buf
83     REFFIELDINC(origBuf);
88 /***** END CmiAlloc'ed buffer management functions ***********/