-
Notifications
You must be signed in to change notification settings - Fork 6
/
ValueMsg.h
100 lines (70 loc) · 2.08 KB
/
ValueMsg.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#ifndef STRASSEN_VALUEMSG_H
#define STRASSEN_VALUEMSG_H
#include "pup_stl.h"
class ValueMsg : public CMessage_ValueMsg {
public:
/*std::vector<std::vector<int> > v;
*/
int size;
int **v;
//i found a solution to allocate a non fixed sized without segment fault
ValueMsg(int size){
this->size = size;
v = new int*[size];
for (int i = 0; i < size; ++i)
v[i] = new int[size];
}
//for the time being i am going to stick to array as vectors produce segment fault
static ValueMsg* unpack(void *buf)
{
// CkPrintf("M::unpack called\n");
char *bufChar = (char *) buf;
int size;
memcpy(&size,bufChar,sizeof(int));
ValueMsg* pmsg = (ValueMsg*)CkAllocBuffer(buf, sizeof(ValueMsg));
pmsg = new ((void*)pmsg) ValueMsg(size);
for (int i = 0; i < size; ++i)
memcpy(&(pmsg->v[i][0]),bufChar+sizeof(int)+i*sizeof(int)*size, sizeof(int)*size);
/*testing display*/
/* int* bufInt = (int *) buf;
for (int i = 0; i < size*size + 1; ++i)
CkPrintf("the element %d in buffer(unpack) : %d\n", i,*(bufInt+i));
//CkExit();
CkPrintf("the result of unpacking \n");
for (int i = 0; i < size; ++i)
{
for (int j = 0; j < size; ++j)
CkPrintf("%d|",pmsg->v[i][j]);
CkPrintf("\n");
}*/
CkFreeMsg(buf);
return pmsg;
}
static void* pack(ValueMsg* inmsg)
{
// CkPrintf("M::pack called\n");
int size = inmsg->size;
int totalsize = sizeof(int) + (size* sizeof(int) * size);
char* buf = (char*) CkAllocBuffer(inmsg,totalsize);
memcpy(buf,&(size),sizeof(int));
for (int i = 0; i < size; ++i)
memcpy(buf+sizeof(int)+i*sizeof(int)*size, &(inmsg->v[i][0]), sizeof(int)*size);
/*testing display*/
/*for (int i = 0; i < size; ++i)
{
for (int j = 0; j < size; ++j)
{
CkPrintf("%d|",inmsg->v[i][j]);
}
CkPrintf("\n");
}
int* bufInt = (int *) buf;
for (int i = 0; i < size*size + 1; ++i)
CkPrintf("the element %d in buffer(pack) : %d\n", i,*(bufInt+i));
*/
delete inmsg;
return (void*) buf;
}
};
// allocate memory for varmessage so charm can keep track of memory
#endif