25 #define ALIGN_8(x) (((unsigned long)x + 7) & (~7))
27 #define PACKMSG_CHECKSUM(X)
33 template<
class T>
inline T*
new_array(T*,
int n) {
return new T[n]; }
35 #define PACK_MSG(MSGTYPE,MSGDATA) \
36 void *MSGTYPE::pack(MSGTYPE *packmsg_msg) { \
37 PACKMSG_CHECKSUM(unsigned int packmsg_checksum = 0;) \
38 int packmsg_size = 0; \
39 char *packmsg_cur = 0; \
41 const int packmsg_pass = 0; \
43 packmsg_size += sizeof(packmsg_checksum); \
44 PACK_MEMORY(&packmsg_size,sizeof(packmsg_size)); \
48 void *packmsg_buf = CkAllocBuffer(packmsg_msg,packmsg_size); \
49 packmsg_cur = (char *)packmsg_buf; \
51 const int packmsg_pass = 1; \
53 packmsg_cur += sizeof(packmsg_checksum); \
54 PACK_MEMORY(&packmsg_size,sizeof(packmsg_size)); \
59 packmsg_cur = (char *)packmsg_buf; \
60 for ( int i=sizeof(packmsg_checksum); i < packmsg_size; i++ ) { \
61 packmsg_checksum += (unsigned char) packmsg_cur[i]; \
63 CmiMemcpy(packmsg_buf,(void *)&packmsg_checksum,sizeof(packmsg_checksum)); \
69 MSGTYPE *MSGTYPE::unpack(void *packmsg_buf) { \
71 unsigned int packmsg_checksum = 0; \
72 unsigned int packmsg_checksum_orig = 0; \
74 int packmsg_size = 0; \
75 void *packmsg_msg_ = CkAllocBuffer(packmsg_buf,sizeof(MSGTYPE)); \
76 MSGTYPE *packmsg_msg = new (packmsg_msg_) MSGTYPE; \
77 char *packmsg_cur = (char *)packmsg_buf; \
79 const int packmsg_pass = 2; \
81 CmiMemcpy((void *)&packmsg_checksum_orig,(void *)packmsg_cur, \
82 sizeof(packmsg_checksum)); \
83 packmsg_cur += sizeof(packmsg_checksum); \
84 PACK_MEMORY(&packmsg_size,sizeof(packmsg_size)); \
85 char *packmsg_cur2 = (char *)packmsg_buf; \
86 for ( int i=sizeof(packmsg_checksum); i < packmsg_size; i++ ) { \
87 packmsg_checksum += (unsigned char) packmsg_cur2[i]; \
89 if ( packmsg_checksum != packmsg_checksum_orig ) { \
91 sprintf(errmsg,"PACKMSG checksums do not agree! %s(%d): %d vs %d", \
92 __FILE__, __LINE__, packmsg_checksum, packmsg_checksum_orig); \
98 CkFreeMsg(packmsg_buf); \
102 #define PACK_MEMORY(BUF,SIZE) { \
103 int ASIZE = ALIGN_8(SIZE); \
104 switch ( packmsg_pass ) { \
106 packmsg_size += (ASIZE); \
109 CmiMemcpy((void *)packmsg_cur,(void *)(BUF),(SIZE)); \
110 packmsg_cur += (ASIZE); \
113 CmiMemcpy((void *)(BUF),(void *)packmsg_cur,(SIZE)); \
114 packmsg_cur += (ASIZE); \
121 #define PACK_THIS PACK_MEMORY(packmsg_msg,sizeof(*packmsg_msg));
123 #define PACK(DATA) PACK_MEMORY(&(packmsg_msg->DATA),sizeof(packmsg_msg->DATA))
125 #define PACK_RESIZE(DATA) { \
126 int packmsg_array_len = packmsg_msg->DATA.size(); \
127 PACK_MEMORY(&packmsg_array_len,sizeof(packmsg_array_len)); \
128 if ( packmsg_pass == 2 ) packmsg_msg->DATA.resize(packmsg_array_len); \
129 int packmsg_array_size = \
130 packmsg_array_len * sizeof_element(packmsg_msg->DATA); \
131 PACK_MEMORY(packmsg_msg->DATA.begin(),packmsg_array_size); \
134 #define PACK_ARRAY(DATA,LEN) { \
136 PACK_MEMORY(packmsg_msg->DATA,packmsg_msg->LEN*sizeof(*(packmsg_msg->DATA))); \
139 #define PACK_AND_NEW_ARRAY(DATA,LEN) { \
141 if ( packmsg_pass == 2 ) { \
142 packmsg_msg->DATA = new_array(packmsg_msg->DATA,packmsg_msg->LEN); \
144 PACK_MEMORY(packmsg_msg->DATA,packmsg_msg->LEN*sizeof(*(packmsg_msg->DATA))); \
T * new_array(T *, int n)
size_t sizeof_element(ResizeArray< T > &)