diff --git a/src/parallel-v2.c b/src/parallel-v2.c index 376426c..9286db9 100644 --- a/src/parallel-v2.c +++ b/src/parallel-v2.c @@ -16,13 +16,10 @@ int find_end(int residue, char *pattern, char *text, int shift); int main(int argc, char **argv) { int rank, size; - int text_len; // length of all text int private_text_len; // length of private text int pattern_len; //length of the pattern - char *text; char *pattern; int remain = 0; - int *text_piece; int *displacements; char *private_text; int *match_numbers; @@ -119,15 +116,16 @@ int main(int argc, char **argv) { if (rank != 0) { MPI_Status myStatus; MPI_Wait(&rec_rq, &myStatus); + int splitted_match = -1; if (residue != 0) { - int splitted_match = find_end(other_residue, pattern, private_text, shift); - MPI_Send(&splitted_match, 1, MPI_INT, MASTER, DEFAULT_TAG, MPI_COMM_WORLD); + splitted_match = find_end(other_residue, pattern, private_text, shift); } + MPI_Send(&splitted_match, 1, MPI_INT, MASTER, DEFAULT_TAG, MPI_COMM_WORLD); } if (rank == MASTER) { int splitted_match; - for (int i = 0; i < size - 1; i++) { + for (int i = 1; i < size; i++) { MPI_Recv(&splitted_match, 1, MPI_INT, MPI_ANY_SOURCE, DEFAULT_TAG, MPI_COMM_WORLD, MPI_STATUS_IGNORE); if (splitted_match > 0) { total_matches[total_match_number] = splitted_match;