-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprintresult.cpp
61 lines (45 loc) · 1.38 KB
/
printresult.cpp
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
void computeResult(int j, int id){
int i = N_LENGTH; //LAST POSITION - ASSUMING THIS VARIABLES ARE UPDATED FOR EACH PROCESS!
string result;
string tmp;
string final_result;
while(i != 0){
if(N[i] == M[j]){ //MATCH
result.insert(0, N[i]); //insert into the first pos of string, the letter
i--;
j--;
}
else if(TABLE[i][j-1] => TABLE [i-1][j]) // GO LEFT
j--;
else
i--;
}
if (id != 0){
int size = result.size();
MPI_Send(&size, 1, MPI_INT, 0, 5, MPI_COMM_WORLD); // REVIEW A TAG
MPI_Send(result, size, MPI_CHAR, 0, 6, MPI_COMM_WORLD ); // STRINGS DON'T NEED /0!; REVIEW TAG
MPI_Send($j, 1, MPI_INT, id-1, 7, MPI_COMM_WORLD); //REVIEW TAG;
}
else{
for(int k = p; i > 0; i++){
MPI_Recv($length, 1, MPI_INT, p, 5, MPI_COMM_WORLD, &status ); //RECV STRLEN FROM 3 PROCESSORS
MPI_Recv(tmp, lenght, MPI_CHAR, p, 6, MPI_COMM_WORLD, &status); //RECV STR FROM 3 PROCESSORS
final_result.insert(0, tmp); //JOIN ALL STR;
}
final_result.insert(0, result);
cout << final_result.size() << endl;
cout << final_result << endl;
}
}
void printResult(int id, int p){
int i = N_LENGTH;
int j = M_LENGTH; //LAST POSITION
int length;
if(id == p){ //starts with the last processor!
computeResult(j, id);
}
else {
MPI_Recv(&j, 1, MPI_INT, id-1, 7, MPI_COMM_WORLD, $status);//RECEIVE COLUMN
computeResult(j, id);//PERFORM ALGORITHM.
}
}