Uses gather
This commit is contained in:
parent
451d04cccf
commit
cc30d00aec
13
main.c
13
main.c
@ -17,6 +17,7 @@ int sum_array(int *, int);
|
|||||||
int main() {
|
int main() {
|
||||||
int rank, size, private_text_len, text_len, pattern_len;
|
int rank, size, private_text_len, text_len, pattern_len;
|
||||||
int *text_piece;
|
int *text_piece;
|
||||||
|
int *match_numbers;
|
||||||
int *displacements;
|
int *displacements;
|
||||||
int remain;
|
int remain;
|
||||||
char *pattern, *text;
|
char *pattern, *text;
|
||||||
@ -90,15 +91,12 @@ int main() {
|
|||||||
printf("%d -> result number: %d\n", rank, match_number);
|
printf("%d -> result number: %d\n", rank, match_number);
|
||||||
|
|
||||||
if (rank == MASTER) {
|
if (rank == MASTER) {
|
||||||
int match_numbers[size];
|
match_numbers = (int *) malloc(sizeof(int) * size);
|
||||||
match_numbers[MASTER] = match_number;
|
}
|
||||||
|
|
||||||
for (int i = 0; i < size; ++i) {
|
MPI_Gather(&match_number, 1, MPI_INT, match_numbers, 1, MPI_INT, MASTER, MPI_COMM_WORLD);
|
||||||
if (i == MASTER) continue;
|
|
||||||
|
|
||||||
MPI_Recv(match_numbers + i, 1, MPI_INT, i, DEFAULT_TAG, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (rank == MASTER) {
|
||||||
match_number = sum_array(match_numbers, size);
|
match_number = sum_array(match_numbers, size);
|
||||||
matches = (int *) realloc(matches, sizeof(int) * match_number);
|
matches = (int *) realloc(matches, sizeof(int) * match_number);
|
||||||
|
|
||||||
@ -113,7 +111,6 @@ int main() {
|
|||||||
offset += match_numbers[i];
|
offset += match_numbers[i];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
MPI_Send(&match_number, 1, MPI_INT, MASTER, DEFAULT_TAG, MPI_COMM_WORLD);
|
|
||||||
MPI_Send(matches, match_number, MPI_INT, MASTER, DEFAULT_TAG, MPI_COMM_WORLD);
|
MPI_Send(matches, match_number, MPI_INT, MASTER, DEFAULT_TAG, MPI_COMM_WORLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user