Skip to content

Commit 4fbdd5b

Browse files
author
alielabridi
committed
polishing
1 parent b0adf0a commit 4fbdd5b

File tree

6 files changed

+532
-157
lines changed

6 files changed

+532
-157
lines changed

AddSubMat.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef STRASSEN_ADDSUBMAT_H
22
#define STRASSEN_ADDSUBMAT_H
33
#include "ValueMsg.h"
4+
#define VERBOSE2 0
45

56
class addition :public CBase_addition{
67
public:
@@ -9,6 +10,7 @@ class addition :public CBase_addition{
910
thisProxy.run(f,A,B,size);
1011
}
1112
void run(CkFuture f,const std::vector<std::vector<int>>& A, const std::vector<std::vector<int>>& B, int size){
13+
if(VERBOSE2)CkPrintf("Chare addition (size = %d) done by processor %d\n",size,CkMyPe());
1214
/*wrap the resulting addition in a message of size and send it back to future*/
1315
ValueMsg *m = new ValueMsg(size);
1416
for (int i = 0; i < size; ++i)
@@ -25,7 +27,7 @@ class substraction :public CBase_substraction{
2527
thisProxy.run(f,A,B,size);
2628
}
2729
void run(CkFuture f,const std::vector<std::vector<int>>& A, const std::vector<std::vector<int>>& B, int size){
28-
//CkPrintf("substraction: Work done by processor %d\n",CkMyPe());
30+
if(VERBOSE2)CkPrintf("Chare substraction (size = %d) done by processor %d\n",size,CkMyPe());
2931
/*wrap the resulting addition in a message of size and send it back to future*/
3032
ValueMsg *m = new ValueMsg(size);
3133
for (int i = 0; i < size; ++i)

OpenMP-Strassen.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,15 @@ omp_set_dynamic(0); // Explicitly disable dynamic teams
275275
omp_set_num_threads(proc);
276276

277277
start = omp_get_wtime();
278+
clock_t begin = clock();
279+
278280
matmultS(size, size, size, A, B, C);
281+
clock_t endclock = clock();
282+
279283
end = omp_get_wtime();
280284

281285
double elapsed_secs = end - start;
286+
double elapsed_secsclock = double(end - begin) / CLOCKS_PER_SEC;
282287

283288
/*checking result if correct*/
284289

@@ -290,12 +295,12 @@ start = omp_get_wtime();
290295
for (int j = 0; j < size; ++j)
291296
if(C[i][j] != A[i][j]) correctness = false;
292297
if(correctness){
293-
printf("OpenMP - Correct: matrix size = %d, Threshold = %d,# of proc = %d, Exec time = %lf sec \n", size, THRESHOLD,omp_get_max_threads(),elapsed_secs );
294-
myfile<<"OpenMP - Correct: matrix size = " <<size<<", Threshold = "<< THRESHOLD<<",# of proc = "<<omp_get_max_threads()<<" , Exec time = " << elapsed_secs << "\n";
298+
printf("OpenMP - Correct: matrix size = %d, Threshold = %d,# of proc = %d, Exec time = %lf sec \n", size, THRESHOLD,omp_get_max_threads(),elapsed_secsclock );
299+
myfile<<"OpenMP - Correct: matrix size = " <<size<<", Threshold = "<< THRESHOLD<<",# of proc = "<<omp_get_max_threads()<<" , Exec time = " << elapsed_secsclock << "\n";
295300
}
296301
else{
297-
printf("OpenMP - Incorrect: matrix size = %d, Threshold = %d,# of proc = %d, Exec time = %lf sec \n", size, THRESHOLD,omp_get_max_threads(),elapsed_secs );
298-
myfile<<"OpenMP - Incorrect: matrix size = " <<size<<", Threshold = "<< THRESHOLD<<",# of proc = "<<omp_get_max_threads()<<" , Exec time = " << elapsed_secs << "\n";
302+
printf("OpenMP - Incorrect: matrix size = %d, Threshold = %d,# of proc = %d, Exec time = %lf sec \n", size, THRESHOLD,omp_get_max_threads(),elapsed_secsclock );
303+
myfile<<"OpenMP - Incorrect: matrix size = " <<size<<", Threshold = "<< THRESHOLD<<",# of proc = "<<omp_get_max_threads()<<" , Exec time = " << elapsed_secsclock << "\n";
299304
}
300305
myfile.close();
301306

StrassenSub.h

Lines changed: 25 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#define STRASSEN_STRASSENSUB_H
44
#include "ValueMsg.h"
55
#include <vector>
6+
#define VERBOSE2 0
67
class strassenSub: public CBase_strassenSub{
78
public:
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

Comments
 (0)