-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_mpi.c
81 lines (66 loc) · 1.98 KB
/
main_mpi.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "lab4_io.h"
#include "lab4_mpi.h"
#include <stdlib.h>
#include "mpi.h"
/*
Arguments:
arg: input filename (consist text, pattern_set)
*/
int main(int argc, char *argv[])
{
if (argc < 2){
printf("\nLess Arguments\n");
return 0;
}
if (argc > 2){
printf("\nTOO many Arguments\n");
return 0;
}
//---------------------------------------------------------------------
int n; // length of text (input)
char* text; // text (input)
int num_patterns; // #patterns to be searched in the text (input)
int* m_set; // lengths of patterns in pattern_set (input)
int* p_set; // periods of patterns in pattern_set (input)
char** pattern_set; // set of patterns to be searched (input)
int* match_counts; // #match of pattern_i in text (to be computed)
int* matches; // set of all match of each pattern_i in text (to be computed)
//---------------------------------------------------------------------
double start_time, computation_time, total_time;
int id;
/*
-- Pre-defined function --
reads input text and patterns from input file and creats array text, m_set, p_set and pattern_set
see lab4_io.h for details
*/
read_data (argv[1], &n, &text, &num_patterns, &m_set, &p_set, &pattern_set);
MPI_Init(&argc, &argv);
start_time = MPI_Wtime();
// /*
// *****************************************************
// TODO -- You must implement this two function
// *****************************************************
// */
periodic_pattern_matching (
n,
text,
num_patterns,
m_set,
p_set,
pattern_set,
&match_counts,
&matches);
computation_time = MPI_Wtime() - start_time;
MPI_Reduce(&computation_time, &total_time, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD);
MPI_Comm_rank(MPI_COMM_WORLD, &id);
if (id == 0) {
/*
--Pre-defined function --
checks for correctness of results computed by periodic_pattern_matching
and outputs the results
*/
write_result(match_counts, matches, total_time);
}
MPI_Finalize();
return 0;
}