Skip to content

Commit 72507aa

Browse files
author
alielabridi
committed
staging vectors in pack/unpack
1 parent bc767cc commit 72507aa

File tree

5 files changed

+285
-44
lines changed

5 files changed

+285
-44
lines changed

AddSubMat.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,34 @@
55
class addition :public CBase_addition{
66
public:
77
addition(CkMigrateMessage *m) {};
8-
addition(CkFuture f,std::vector<std::vector<int>> A, std::vector<std::vector<int>> B, int size){
8+
addition(CkFuture f,const std::vector<std::vector<int>>& A, const std::vector<std::vector<int>>& B, int size){
99
thisProxy.run(f,A,B,size);
1010
}
11-
void run(CkFuture f,std::vector<std::vector<int>> A, std::vector<std::vector<int>> B, int size){
11+
void run(CkFuture f,const std::vector<std::vector<int>>& A, const std::vector<std::vector<int>>& B, int size){
1212
//if(VERBOSE)CkPrintf("addition run 1:\n");
1313
/*wrap the resulting addition in a message of size and send it back to future*/
1414

1515
//if(VERBOSE)CkPrintf("Work done by processor %d\n",CkMyPe());
16+
CkPrintf("ADD: Work done by processor %d\n",CkMyPe());
1617

1718

1819
ValueMsg *m = new ValueMsg(size);
1920

2021

2122

2223
//if(VERBOSE)CkPrintf("addition run 1-1:\n");
24+
/* CkPrintf("the result of the addition\n");
2325
2426
for (int i = 0; i < size; ++i)
2527
{
2628
for (int j = 0; j < size; ++j)
2729
{
2830
m->v[i][j] = A[i][j] + B[i][j];
31+
CkPrintf("%d ", m->v[i][j] );
2932
}
30-
}
33+
CkPrintf("\n");
34+
35+
}*/
3136
//if(VERBOSE)CkPrintf("addition run 2:\n");
3237

3338

@@ -43,13 +48,14 @@ class addition :public CBase_addition{
4348
class substraction :public CBase_substraction{
4449
public:
4550
substraction(CkMigrateMessage *m) {};
46-
substraction(CkFuture f,std::vector<std::vector<int>> A, std::vector<std::vector<int>> B, int size){
51+
substraction(CkFuture f,const std::vector<std::vector<int>>& A, const std::vector<std::vector<int>>& B, int size){
4752
thisProxy.run(f,A,B,size);
4853
}
49-
void run(CkFuture f,std::vector<std::vector<int>> A, std::vector<std::vector<int>> B, int size){
54+
void run(CkFuture f,const std::vector<std::vector<int>>& A, const std::vector<std::vector<int>>& B, int size){
5055
//std::vector<std::vector<int>> C;
5156

5257
//if(VERBOSE)CkPrintf("Work done by processor %d\n",CkMyPe());
58+
CkPrintf("substraction: Work done by processor %d\n",CkMyPe());
5359

5460
ValueMsg *m = new ValueMsg(size);
5561

StrassenSub.h

Lines changed: 86 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,24 @@
22
#ifndef STRASSEN_STRASSENSUB_H
33
#define STRASSEN_STRASSENSUB_H
44
#include "ValueMsg.h"
5-
5+
#include <vector>
66
class strassenSub: public CBase_strassenSub{
77
public:
88
strassenSub(CkMigrateMessage *m) {};
99
//overload the function to take three matrices or four
1010
//how should I adapt the class to implement for substraction
1111
/*four additions*/
12-
strassenSub(CkFuture f,std::vector<std::vector<int>> A,
13-
std::vector<std::vector<int>> B, std::vector<std::vector<int>> C, std::vector<std::vector<int>> D,
12+
strassenSub(CkFuture f,const std::vector<std::vector<int>>& A,
13+
const std::vector<std::vector<int>>& B, const std::vector<std::vector<int>>& C, const std::vector<std::vector<int>>& D,
1414
int size, char partition){ thisProxy.run(f,A,B,C,D,size,partition); }
1515

1616

17-
void run(CkFuture f,std::vector<std::vector<int>> A,
18-
std::vector<std::vector<int>> B, std::vector<std::vector<int>> C, std::vector<std::vector<int>> D,
17+
void run(CkFuture f,const std::vector<std::vector<int>>& A,
18+
const std::vector<std::vector<int>>& B, const std::vector<std::vector<int>>& C, const std::vector<std::vector<int>>& D,
1919
int size, char partition){
20+
std::vector<std::vector<int>> temp1(size,std::vector<int>(size));
21+
std::vector<std::vector<int>> temp2(size,std::vector<int>(size));
22+
CkPrintf("SUB: Work done by processor %d\n",CkMyPe());
2023

2124
//if(VERBOSE)CkPrintf("Work done by processor %d\n",CkMyPe());
2225

@@ -25,6 +28,7 @@ class strassenSub: public CBase_strassenSub{
2528
//inside the bigger strassen chare it will decide whether to use the naive or strassen algo
2629
if(partition == '1'){
2730
//if(VERBOSE)CkPrintf("here stressen SUB run 1:\n");
31+
CkPrintf("SUB1: Work done by processor %d\n",CkMyPe());
2832

2933
/*first partition M1 = (A11+A22)(B11+B22)*/
3034
CkFuture p1add1 = CkCreateFuture(); //A11+A22
@@ -38,8 +42,11 @@ class strassenSub: public CBase_strassenSub{
3842

3943
//ValueMsg *m1 = new ValueMsg(size);
4044
//ValueMsg *m2 = new ValueMsg(size);
45+
CkPrintf("SUB1 - END0: Work done by processor %d\n",CkMyPe());
46+
4147
ValueMsg * m1 = (ValueMsg *) CkWaitFuture(p1add1);
4248
ValueMsg * m2 = (ValueMsg *) CkWaitFuture(p1add2);
49+
CkPrintf("SUB1 - END0: Work done by processor %d\n",CkMyPe());
4350

4451
/* if(VERBOSE)CkPrintf("value of a11+a22:\n");
4552
@@ -51,30 +58,70 @@ class strassenSub: public CBase_strassenSub{
5158
if(VERBOSE)CkPrintf("\n");
5259
}*/
5360
//if(VERBOSE)CkPrintf("here stressen SUB run 4:\n");
61+
CkPrintf("SUB1 - END0: Work done by processor %d\n",CkMyPe());
5462

5563
CkFuture p1 = CkCreateFuture();
5664
//if(VERBOSE)CkPrintf("here stressen SUB run 5:\n");
57-
58-
CProxy_strassen::ckNew(p1,m1->v,m2->v,size); //to do (A11+A22)*(B11+B22) by giving m1->v and m2->v
65+
CkPrintf("SUB1 - END0: Work done by processor %d\n",CkMyPe());
66+
67+
CkPrintf("SUB1 - END5: Work done by processor %d\n",CkMyPe());
68+
CkPrintf("the result of m2 in partition %c\n",partition);
69+
for (int i = 0; i < size; ++i)
70+
{
71+
for (int j = 0; j < size; ++j)
72+
{
73+
CkPrintf("%d ",m2->v[i][j]);
74+
}
75+
CkPrintf("\n");
76+
77+
}
78+
CkPrintf("the result of m1 in partition %c\n",partition);
79+
80+
for (int i = 0; i < size; ++i)
81+
{
82+
for (int j = 0; j < size; ++j)
83+
{
84+
CkPrintf("%d ",m1->v[i][j]);
85+
}
86+
CkPrintf("\n");
87+
88+
}
89+
90+
for (int i = 0; i < size; ++i)
91+
for (int j = 0; j < size; ++j)
92+
93+
{
94+
temp1[i][j] = m1->v[i][j];
95+
temp2[i][j] = m2->v[i][j];
96+
}
97+
CkPrintf("SUB1 - END6: Work done by processor %d\n",CkMyPe());
98+
99+
CProxy_strassen::ckNew(p1,temp1,temp2,size); //to do (A11+A22)*(B11+B22) by giving m1->v and m2->v
59100
//if(VERBOSE)CkPrintf("here stressen SUB run 6:\n");
60101

61102
//i could free m1 and m2 at this point
62103
//if(VERBOSE)CkPrintf("here stressen SUB run 7:\n");
63104

64105
//ValueMsg *m3 = new ValueMsg(size);
65-
delete m1;
66-
delete m2;
106+
CkPrintf("SUB1 - END0: Work done by processor %d\n",CkMyPe());
107+
67108
ValueMsg * m3 = (ValueMsg *) CkWaitFuture(p1);
68109
//if(VERBOSE)CkPrintf("here stressen SUB run 8:\n");
110+
CkPrintf("SUB1 - END: Work done by processor %d\n",CkMyPe());
69111

70112
CkSendToFuture(f, m3);
113+
delete m1;
114+
delete m2;
115+
71116
//p1 = m3->v; //returned product of the two summation
72117
//i can free m3 at this point
73118
// thinking of using CkProbeFuture on (p1,p2,p3...) instead of wait to not block the next products
74119
//or should I use a block instead? UPDATES: I guess by now that I am using strassenSub It will be ok
75120
}
76121

77122
else if(partition == '6' || partition == '7'){
123+
CkPrintf("SUB6-7: Work done by processor %d\n",CkMyPe());
124+
78125
/*partition M6 = (A21-A11)(B11+B12)*/
79126
/*OR partition M7 = (A12-A22)(B21+B22)*/
80127
CkFuture psub1 = CkCreateFuture();
@@ -87,12 +134,19 @@ class strassenSub: public CBase_strassenSub{
87134
ValueMsg * m1 = (ValueMsg *) CkWaitFuture(psub1);
88135
ValueMsg * m2 = (ValueMsg *) CkWaitFuture(padd2);
89136
CkFuture p = CkCreateFuture();
90-
CProxy_strassen::ckNew(p,m1->v,m2->v, size); //to do (A11+A22)*(B11+B22) by giving m1->v and m2->v
137+
for (int i = 0; i < size; ++i)
138+
for (int j = 0; j < size; ++j)
139+
140+
{
141+
temp1[i][j] = m1->v[i][j];
142+
temp2[i][j] = m2->v[i][j];
143+
}
144+
CProxy_strassen::ckNew(p,temp1,temp2, size); //to do (A11+A22)*(B11+B22) by giving m1->v and m2->v
91145
//i could free m1 and m2 at this point
92-
delete m1;
93-
delete m2;
94146
//ValueMsg *m3 = new ValueMsg(size);
95147
ValueMsg * m3 = (ValueMsg *) CkWaitFuture(p);
148+
delete m1;
149+
delete m2;
96150
CkSendToFuture(f, m3);
97151
//p1 = m3->v; //returned product of the two summation
98152
//i can free m3 at this point
@@ -105,19 +159,22 @@ class strassenSub: public CBase_strassenSub{
105159

106160

107161
/*three addition*/
108-
strassenSub(CkFuture f,std::vector<std::vector<int>> A,
109-
std::vector<std::vector<int>> B, std::vector<std::vector<int>> C,
162+
strassenSub(CkFuture f,const std::vector<std::vector<int>>& A,
163+
const std::vector<std::vector<int>>& B, const std::vector<std::vector<int>>& C,
110164
int size, char partition){ thisProxy.run(f,A,B,C,size,partition); }
111165

112166

113-
void run(CkFuture f,std::vector<std::vector<int>> A,
114-
std::vector<std::vector<int>> B, std::vector<std::vector<int>> C,
167+
void run(CkFuture f,const std::vector<std::vector<int>>& A,
168+
const std::vector<std::vector<int>>& B, const std::vector<std::vector<int>>& C,
115169
int size,char partition){
170+
std::vector<std::vector<int>> temp1(size,std::vector<int>(size));
116171

117172
//do the addition/substraction, and wait for for the result then call on it the bigger strassen chare
118173
//if needed a big multiplication
119174
//inside the bigger strassen chare it will decide whether to use the naive or strassen algo
120175
if(partition == '2' || partition == '5'){
176+
CkPrintf("SUB2-5: Work done by processor %d\n",CkMyPe());
177+
121178
/*partition M2 =(A21+A22)B11*/
122179
/*OR partition M5 =(A11+A12)B22*/
123180
CkFuture padd1 = CkCreateFuture();
@@ -126,19 +183,24 @@ class strassenSub: public CBase_strassenSub{
126183
//ValueMsg *m1 = new ValueMsg(size);
127184
ValueMsg * m1 = (ValueMsg *) CkWaitFuture(padd1);
128185
CkFuture p = CkCreateFuture();
186+
for (int i = 0; i < size; ++i)
187+
for (int j = 0; j < size; ++j)
188+
temp1[i][j] = m1->v[i][j];
129189

130-
CProxy_strassen::ckNew(p,m1->v,C, size);
190+
CProxy_strassen::ckNew(p,temp1,C, size);
131191
//i could free m1 and m2 at this point
132-
delete m1;
133192
//ValueMsg *m3 = new ValueMsg(size);
134193
ValueMsg * m3 = (ValueMsg *) CkWaitFuture(p);
194+
delete m1;
135195
CkSendToFuture(f, m3);
136196
//p1 = m3->v; //returned product of the two summation
137197
//i can free m3 at this point
138198
// thinking of using CkProbeFuture on (p1,p2,p3...) instead of wait to not block the next products
139199
//or should I use a block instead? UPDATES: I guess by now that I am using strassenSub It will be ok
140200
}
141201
else if(partition == '3' || partition == '4'){
202+
CkPrintf("SUB3-4: Work done by processor %d\n",CkMyPe());
203+
142204
/*partition M3 = A11(B12-B22)*/
143205
/*OR partition M4 =A22(B21-B11)*/
144206
CkFuture psub1 = CkCreateFuture();
@@ -147,11 +209,15 @@ class strassenSub: public CBase_strassenSub{
147209
//ValueMsg *m1 = new ValueMsg(size);
148210
ValueMsg * m1 = (ValueMsg *) CkWaitFuture(psub1);
149211
CkFuture p = CkCreateFuture();
150-
CProxy_strassen::ckNew(p,A,m1->v, size);
212+
for (int i = 0; i < size; ++i)
213+
for (int j = 0; j < size; ++j)
214+
temp1[i][j] = m1->v[i][j];
215+
216+
CProxy_strassen::ckNew(p,A,temp1, size);
151217
//i could free m1 and m2 at this point
152-
delete m1;
153218
//ValueMsg *m3 = new ValueMsg(size);
154219
ValueMsg * m3 = (ValueMsg *) CkWaitFuture(p);
220+
delete m1;
155221
CkSendToFuture(f, m3);
156222
//p1 = m3->v; //returned product of the two summation
157223
//i can free m3 at this point

0 commit comments

Comments
 (0)