Abort if pattern is to long
This commit is contained in:
parent
13f6786a13
commit
fa007ceef0
12
main.c
12
main.c
@ -30,8 +30,11 @@ int main() {
|
|||||||
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
|
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
|
||||||
|
|
||||||
if (rank == MASTER) {
|
if (rank == MASTER) {
|
||||||
text = read_file("data/text.txt", &text_len);
|
text = "text";//read_file("data/text.txt", &text_len);
|
||||||
pattern = read_file("data/pattern.txt", &pattern_len);
|
pattern = "pattern";//read_file("data/pattern.txt", &pattern_len);
|
||||||
|
|
||||||
|
text_len = strlen(text);
|
||||||
|
pattern_len = strlen(pattern);
|
||||||
|
|
||||||
printf("text: %s\n", text);
|
printf("text: %s\n", text);
|
||||||
printf("pattern: %s\n", pattern);
|
printf("pattern: %s\n", pattern);
|
||||||
@ -39,6 +42,9 @@ int main() {
|
|||||||
private_text_len = text_len / size;
|
private_text_len = text_len / size;
|
||||||
remain = text_len % size;
|
remain = text_len % size;
|
||||||
|
|
||||||
|
if (pattern_len > private_text_len)
|
||||||
|
MPI_Abort(MPI_COMM_WORLD, 1);
|
||||||
|
|
||||||
text_piece = (int *) malloc(sizeof(int) * size);
|
text_piece = (int *) malloc(sizeof(int) * size);
|
||||||
displacements = (int *) malloc(sizeof(int) * size);
|
displacements = (int *) malloc(sizeof(int) * size);
|
||||||
|
|
||||||
@ -93,7 +99,7 @@ int main() {
|
|||||||
find_end(residue, pattern, private_text, &matches, &match_number);
|
find_end(residue, pattern, private_text, &matches, &match_number);
|
||||||
}
|
}
|
||||||
|
|
||||||
print_array(matches, match_number);
|
//print_array(matches, match_number);
|
||||||
|
|
||||||
int shift = rank * (private_text_len - remain);
|
int shift = rank * (private_text_len - remain);
|
||||||
apply_shift(shift, matches, match_number);
|
apply_shift(shift, matches, match_number);
|
||||||
|
Loading…
Reference in New Issue
Block a user