Move sending of remain

This commit is contained in:
Raffaele Mignone 2021-03-21 14:09:04 +01:00
parent f19c43bb67
commit 5cdbeea5db
Signed by: norangebit
GPG Key ID: F5255658CB220573

14
main.c
View File

@ -44,13 +44,6 @@ int main() {
distribute_text(); distribute_text();
// sending the remain to the last trial
// this is necessary for the calculation of the offset
if (rank == MASTER)
MPI_Send(&remain, 1, MPI_INT, size - 1, DEFAULT_TAG, MPI_COMM_WORLD);
else if (rank == size - 1)
MPI_Recv(&remain, 1, MPI_INT, MASTER, DEFAULT_TAG, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
printf("%d -> input: %s\n", rank, private_text); printf("%d -> input: %s\n", rank, private_text);
printf("%d -> text len: %d\n", rank, private_text_len); printf("%d -> text len: %d\n", rank, private_text_len);
@ -87,6 +80,13 @@ int main() {
find_end(residue, pattern, private_text, &matches, &match_number); find_end(residue, pattern, private_text, &matches, &match_number);
} }
// sending the remain to the last process
// this is necessary for the calculation of shift amount
if (rank == MASTER)
MPI_Send(&remain, 1, MPI_INT, size - 1, DEFAULT_TAG, MPI_COMM_WORLD);
else if (rank == size - 1)
MPI_Recv(&remain, 1, MPI_INT, MASTER, DEFAULT_TAG, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
// transformation of match indices from relative to absolute position. // transformation of match indices from relative to absolute position.
int shift = rank * (private_text_len - remain); // the rest is zero for all but the last process int shift = rank * (private_text_len - remain); // the rest is zero for all but the last process
apply_shift(shift, matches, match_number); apply_shift(shift, matches, match_number);