add calculate_absolute_indices function
This commit is contained in:
parent
4f62118a78
commit
59053ba109
31
main.c
31
main.c
@ -22,6 +22,8 @@ void distribute_pattern();
|
|||||||
|
|
||||||
void search_for_splitted_pattern(int *residue, int *match_number, int **matches);
|
void search_for_splitted_pattern(int *residue, int *match_number, int **matches);
|
||||||
|
|
||||||
|
void calculate_absolute_indices(int match_number, int *matches);
|
||||||
|
|
||||||
void collect_results(int *match_number, int *matches);
|
void collect_results(int *match_number, int *matches);
|
||||||
|
|
||||||
int rank, size;
|
int rank, size;
|
||||||
@ -58,29 +60,19 @@ int main() {
|
|||||||
int lps[pattern_len];
|
int lps[pattern_len];
|
||||||
create_lps(pattern, pattern_len, lps);
|
create_lps(pattern, pattern_len, lps);
|
||||||
|
|
||||||
|
// search for matches
|
||||||
int match_number = 0;
|
int match_number = 0;
|
||||||
int residue;
|
int residue;
|
||||||
|
|
||||||
// search for matches
|
|
||||||
int *matches = search_pattern(private_text, pattern, lps, &match_number, &residue);
|
int *matches = search_pattern(private_text, pattern, lps, &match_number, &residue);
|
||||||
|
|
||||||
search_for_splitted_pattern(&residue, &match_number, &matches);
|
search_for_splitted_pattern(&residue, &match_number, &matches);
|
||||||
|
|
||||||
// sending the remain to the last process
|
calculate_absolute_indices(match_number, matches);
|
||||||
// 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.
|
|
||||||
int shift = rank * (private_text_len - remain); // the rest is zero for all but the last process
|
|
||||||
apply_shift(shift, matches, match_number);
|
|
||||||
|
|
||||||
printf("%d -> result number: %d\n", rank, match_number);
|
printf("%d -> result number: %d\n", rank, match_number);
|
||||||
|
|
||||||
collect_results(&match_number, matches);
|
collect_results(&match_number, matches);
|
||||||
|
|
||||||
MPI_Finalize();
|
MPI_Finalize();
|
||||||
|
|
||||||
if (rank == MASTER) {
|
if (rank == MASTER) {
|
||||||
@ -191,6 +183,19 @@ void search_for_splitted_pattern(int *residue, int *match_number, int **matches)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void calculate_absolute_indices(int match_number, int *matches) {
|
||||||
|
// 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.
|
||||||
|
int shift = rank * (private_text_len - remain); // the rest is zero for all but the last process
|
||||||
|
apply_shift(shift, matches, match_number);
|
||||||
|
}
|
||||||
|
|
||||||
void collect_results(int *match_number, int *matches) {
|
void collect_results(int *match_number, int *matches) {
|
||||||
if (rank == MASTER) {
|
if (rank == MASTER) {
|
||||||
// allocation for the array containing the number of matches of each process
|
// allocation for the array containing the number of matches of each process
|
||||||
|
Loading…
Reference in New Issue
Block a user