33#define STRASSEN_STRASSENSUB_H
44#include " ValueMsg.h"
55#include < vector>
6+ #define VERBOSE2 0
67class strassenSub : public CBase_strassenSub {
78public:
89 strassenSub (CkMigrateMessage *m) {};
@@ -19,47 +20,26 @@ class strassenSub: public CBase_strassenSub{
1920 int size, char partition){
2021 std::vector<std::vector<int >> temp1 (size,std::vector<int >(size));
2122 std::vector<std::vector<int >> temp2 (size,std::vector<int >(size));
22- // CkPrintf("SUB: Work done by processor %d\n",CkMyPe());
23-
24- // if(VERBOSE)//CkPrintf("Work done by processor %d\n",CkMyPe());
25-
23+ if (VERBOSE2)CkPrintf (" Chare StrassenSub (size = %d, partition = %c) done by processor %d\n " ,size,partition,CkMyPe ());
24+
2625 // do the addition/substraction, and wait for for the result then call on it the bigger strassen chare
2726 // if needed a big multiplication
2827 // inside the bigger strassen chare it will decide whether to use the naive or strassen algo
2928 if (partition == ' 1' ){
30- // if(VERBOSE)//CkPrintf("here stressen SUB run 1:\n");
31- // CkPrintf("SUB1: Work done by processor %d\n",CkMyPe());
29+
3230
3331 /* first partition M1 = (A11+A22)(B11+B22)*/
3432 CkFuture p1add1 = CkCreateFuture (); // A11+A22
3533 CkFuture p1add2 = CkCreateFuture (); // B11+B22
36- // i could spawn all the additions needed here
37- // if(VERBOSE)//CkPrintf("here stressen SUB run 2:\n");
38-
39- CProxy_addition::ckNew (p1add1,A,B,size);// param not matching yet just a pseudo code
40- CProxy_addition::ckNew (p1add2,C,D,size);// param not matching yet just a pseudo code
41- // if(VERBOSE)//CkPrintf("here stressen SUB run 3:\n");
4234
43- // ValueMsg *m1 = new ValueMsg( size);
44- // ValueMsg *m2 = new ValueMsg( size);
35+ CProxy_addition::ckNew (p1add1,A,B, size);
36+ CProxy_addition::ckNew (p1add2,C,D, size);
4537
4638 ValueMsg * m1 = (ValueMsg *) CkWaitFuture (p1add1);
4739 ValueMsg * m2 = (ValueMsg *) CkWaitFuture (p1add2);
4840
49- /* if(VERBOSE)//CkPrintf("value of a11+a22:\n");
50-
51- for(int i=0; i<newSize;i++){
52- for (int j = 0; j < newSize; ++j)
53- {
54- if(VERBOSE)//CkPrintf("%d ",a11->v[i][j]);
55- }
56- if(VERBOSE)//CkPrintf("\n");
57- }*/
58-
59-
6041 CkFuture p1 = CkCreateFuture ();
6142
62-
6343 for (int i = 0 ; i < size; ++i)
6444 for (int j = 0 ; j < size; ++j)
6545
@@ -68,39 +48,24 @@ class strassenSub: public CBase_strassenSub{
6848 temp2[i][j] = m2->v [i][j];
6949 }
7050
71- CProxy_strassen::ckNew (p1,temp1,temp2,size); // to do (A11+A22)*(B11+B22) by giving m1->v and m2->v
72- // if(VERBOSE)//CkPrintf("here stressen SUB run 6:\n");
73-
74- // i could free m1 and m2 at this point
75- // if(VERBOSE)//CkPrintf("here stressen SUB run 7:\n");
76-
77- // ValueMsg *m3 = new ValueMsg(size);
51+ CProxy_strassen::ckNew (p1,temp1,temp2,size);
7852
7953 ValueMsg * m3 = (ValueMsg *) CkWaitFuture (p1);
80- // if(VERBOSE)//CkPrintf("here stressen SUB run 8:\n");
8154
8255 CkSendToFuture (f, m3);
8356 delete m1;
8457 delete m2;
85-
86- // p1 = m3->v; //returned product of the two summation
87- // i can free m3 at this point
88- // thinking of using CkProbeFuture on (p1,p2,p3...) instead of wait to not block the next products
89- // or should I use a block instead? UPDATES: I guess by now that I am using strassenSub It will be ok
9058 }
9159
9260 else if (partition == ' 6' || partition == ' 7' ){
93- // CkPrintf("SUB6-7: Work done by processor %d\n",CkMyPe());
94-
9561 /* partition M6 = (A21-A11)(B11+B12)*/
9662 /* OR partition M7 = (A12-A22)(B21+B22)*/
9763 CkFuture psub1 = CkCreateFuture ();
9864 CkFuture padd2 = CkCreateFuture ();
99- // i could spawn all the additions needed here
100- CProxy_substraction::ckNew (psub1,A,B,size);// param not matching yet just a pseudo code
101- CProxy_addition::ckNew (padd2,C,D,size);// param not matching yet just a pseudo code
102- // ValueMsg *m1 = new ValueMsg(size);
103- // ValueMsg *m2 = new ValueMsg(size);
65+
66+ CProxy_substraction::ckNew (psub1,A,B,size);
67+ CProxy_addition::ckNew (padd2,C,D,size);
68+
10469 ValueMsg * m1 = (ValueMsg *) CkWaitFuture (psub1);
10570 ValueMsg * m2 = (ValueMsg *) CkWaitFuture (padd2);
10671 CkFuture p = CkCreateFuture ();
@@ -111,17 +76,13 @@ class strassenSub: public CBase_strassenSub{
11176 temp1[i][j] = m1->v [i][j];
11277 temp2[i][j] = m2->v [i][j];
11378 }
114- CProxy_strassen::ckNew (p,temp1,temp2, size); // to do (A11+A22)*(B11+B22) by giving m1->v and m2->v
115- // i could free m1 and m2 at this point
116- // ValueMsg *m3 = new ValueMsg(size);
79+ CProxy_strassen::ckNew (p,temp1,temp2, size);
80+
11781 ValueMsg * m3 = (ValueMsg *) CkWaitFuture (p);
11882 delete m1;
11983 delete m2;
12084 CkSendToFuture (f, m3);
121- // p1 = m3->v; //returned product of the two summation
122- // i can free m3 at this point
123- // thinking of using CkProbeFuture on (p1,p2,p3...) instead of wait to not block the next products
124- // or should I use a block instead? UPDATES: I guess by now that I am using strassenSub It will be ok
85+
12586 }
12687
12788
@@ -138,61 +99,49 @@ class strassenSub: public CBase_strassenSub{
13899 const std::vector<std::vector<int >>& B, const std::vector<std::vector<int >>& C,
139100 int size,char partition){
140101 std::vector<std::vector<int >> temp1 (size,std::vector<int >(size));
102+ if (VERBOSE2)CkPrintf (" Chare StrassenSub (size = %d, partition = %c) done by processor %d\n " ,size,partition,CkMyPe ());
141103
142- // do the addition/substraction, and wait for for the result then call on it the bigger strassen chare
143- // if needed a big multiplication
144- // inside the bigger strassen chare it will decide whether to use the naive or strassen algo
145104 if (partition == ' 2' || partition == ' 5' ){
146- // CkPrintf("SUB2-5: Work done by processor %d\n",CkMyPe());
147105
148106 /* partition M2 =(A21+A22)B11*/
149107 /* OR partition M5 =(A11+A12)B22*/
150108 CkFuture padd1 = CkCreateFuture ();
151- // i could spawn all the additions needed here
152- CProxy_addition::ckNew (padd1,A,B,size);// param not matching yet just a pseudo code
153- // ValueMsg *m1 = new ValueMsg(size);
109+
110+ CProxy_addition::ckNew (padd1,A,B,size);
111+
154112 ValueMsg * m1 = (ValueMsg *) CkWaitFuture (padd1);
155113 CkFuture p = CkCreateFuture ();
156114 for (int i = 0 ; i < size; ++i)
157115 for (int j = 0 ; j < size; ++j)
158116 temp1[i][j] = m1->v [i][j];
159117
160118 CProxy_strassen::ckNew (p,temp1,C, size);
161- // i could free m1 and m2 at this point
162- // ValueMsg *m3 = new ValueMsg(size);
119+
163120 ValueMsg * m3 = (ValueMsg *) CkWaitFuture (p);
164121 delete m1;
165122 CkSendToFuture (f, m3);
166- // p1 = m3->v; //returned product of the two summation
167- // i can free m3 at this point
168- // thinking of using CkProbeFuture on (p1,p2,p3...) instead of wait to not block the next products
169- // or should I use a block instead? UPDATES: I guess by now that I am using strassenSub It will be ok
123+
170124 }
171125 else if (partition == ' 3' || partition == ' 4' ){
172- // CkPrintf("SUB3-4: Work done by processor %d\n",CkMyPe());
173126
174127 /* partition M3 = A11(B12-B22)*/
175128 /* OR partition M4 =A22(B21-B11)*/
176129 CkFuture psub1 = CkCreateFuture ();
177- // i could spawn all the additions needed here
178- CProxy_substraction::ckNew (psub1,B,C,size);// param not matching yet just a pseudo code
179- // ValueMsg *m1 = new ValueMsg(size);
130+
131+ CProxy_substraction::ckNew (psub1,B,C,size);
132+
180133 ValueMsg * m1 = (ValueMsg *) CkWaitFuture (psub1);
181134 CkFuture p = CkCreateFuture ();
182135 for (int i = 0 ; i < size; ++i)
183136 for (int j = 0 ; j < size; ++j)
184137 temp1[i][j] = m1->v [i][j];
185138
186139 CProxy_strassen::ckNew (p,A,temp1, size);
187- // i could free m1 and m2 at this point
188- // ValueMsg *m3 = new ValueMsg(size);
140+
189141 ValueMsg * m3 = (ValueMsg *) CkWaitFuture (p);
190142 delete m1;
191143 CkSendToFuture (f, m3);
192- // p1 = m3->v; //returned product of the two summation
193- // i can free m3 at this point
194- // thinking of using CkProbeFuture on (p1,p2,p3...) instead of wait to not block the next products
195- // or should I use a block instead? UPDATES: I guess by now that I am using strassenSub It will be ok
144+
196145 }
197146
198147
0 commit comments