KMP-MPI/src/sequential.c

41 lines
961 B
C
Raw Normal View History

2021-03-26 16:32:20 +00:00
#include "util.h"
#include "kmp.h"
#include <stdio.h>
2021-03-26 17:07:43 +00:00
#include <malloc.h>
2021-03-26 16:32:20 +00:00
2021-03-27 11:32:38 +00:00
#ifdef TIME
#include <papi.h>
#endif
int main(int argc, char **argv) {
char *text_file_path = get_text_file(argc, argv);
2021-03-26 16:32:20 +00:00
int text_len, pattern_len;
2021-03-27 11:32:38 +00:00
#ifdef TIME
2021-03-26 16:53:23 +00:00
long_long start_time = PAPI_get_real_usec();
2021-03-27 11:32:38 +00:00
#endif
char *text = read_file(text_file_path, &text_len);
2021-03-26 16:32:20 +00:00
char *pattern = read_file("data/pattern.txt", &pattern_len);
int lps[pattern_len];
create_lps(pattern, pattern_len, lps);
int match_number = 0;
int residue = 0;
2021-03-27 11:32:38 +00:00
#ifdef TIME
2021-03-26 16:53:23 +00:00
long_long start_search = PAPI_get_real_usec();
2021-03-27 11:32:38 +00:00
#endif
2021-03-26 16:32:20 +00:00
int *matches = search_pattern(text, pattern, lps, &match_number, &residue);
2021-03-26 17:07:43 +00:00
free(text);
2021-03-27 11:32:38 +00:00
#ifdef TIME
2021-03-26 16:32:20 +00:00
long_long end_time = PAPI_get_real_usec();
2021-03-27 11:32:38 +00:00
#endif
2021-03-26 16:32:20 +00:00
printf("found %d matches\n", match_number);
2021-03-27 11:32:38 +00:00
#ifdef TIME
2021-03-26 16:53:23 +00:00
printf("total elapsed: %d\n", end_time - start_time);
printf("search elapsed: %d\n", end_time - start_search);
2021-03-27 11:32:38 +00:00
#endif
2021-03-26 16:32:20 +00:00
}