3 int main(int argc
, char *argv
[])
12 printf("Please provide pattern, text and loop sizes!\n");
18 times
= atoi(argv
[3]);
21 MPI_Init( &argc
, &argv
);
25 /* Allocate text and pattern */
26 char **text
= ( char ** )malloc( n
* sizeof( char * ));
29 printf("Failed to allocate array!\n");
33 for( i
= 0; i
< n
; i
++ ) {
34 text
[i
] = ( char * )malloc( n
* sizeof( char ));
36 if( text
[i
] == NULL
) {
37 printf("Failed to allocate array!\n");
42 char **pattern
= ( char ** )malloc( m
* sizeof( char * ));
44 if( pattern
== NULL
) {
45 printf("Failed to allocate array!\n");
49 for( i
= 0; i
< m
; i
++ ) {
50 pattern
[i
] = ( char * )malloc( m
* sizeof( char ));
52 if( pattern
[i
] == NULL
) {
53 printf("Failed to allocate array!\n");
58 printf("Executing all algorithms %i times for m = %i and n = %i\n",times
, m
, n
);
60 for (i
= 0; i
< times
; i
++) {
61 create_files( m
, n
, ALPHABET_SIZE
);
62 load_files( text
, pattern
, m
, n
);
64 naive( text
, pattern
, m
, n
);
69 printf("Average elapsed time for naive: %f\n", t3
/times
);
73 for (i
= 0; i
< times
; i
++) {
74 create_files( m
, n
, ALPHABET_SIZE
);
75 load_files( text
, pattern
, m
, n
);
77 karp( text
, pattern
, m
, n
);
82 printf("Average elapsed time for karp: %f\n", t3
/times
);
86 for (i
= 0; i
< times
; i
++) {
87 create_files( m
, n
, ALPHABET_SIZE
);
88 load_files( text
, pattern
, m
, n
);
90 zhu( text
, pattern
, m
, n
, 1 );
95 printf("Average elapsed time for zhu1: %f\n", t3
/times
);
99 for (i
= 0; i
< times
; i
++) {
100 create_files( m
, n
, ALPHABET_SIZE
);
101 load_files( text
, pattern
, m
, n
);
103 zhu( text
, pattern
, m
, n
, 2 );
108 printf("Average elapsed time for zhu2: %f\n", t3
/times
);
112 for (i
= 0; i
< times
; i
++) {
113 create_files( m
, n
, ALPHABET_SIZE
);
114 load_files( text
, pattern
, m
, n
);
116 bird( text
, pattern
, m
, n
);
121 printf("Average elapsed time for bird1: %f\n", t3
/times
);
125 for (i
= 0; i
< times
; i
++) {
126 create_files( m
, n
, ALPHABET_SIZE
);
127 load_files( text
, pattern
, m
, n
);
129 bird2( text
, pattern
, m
, n
);
134 printf("Average elapsed time for bird2: %f\n", t3
/times
);
138 for (i
= 0; i
< times
; i
++) {
139 create_files( m
, n
, ALPHABET_SIZE
);
140 load_files( text
, pattern
, m
, n
);
142 baeza( text
, pattern
, m
, n
);
147 printf("Average elapsed time for baeza1: %f\n", t3
/times
);
151 for (i
= 0; i
< times
; i
++) {
152 create_files( m
, n
, ALPHABET_SIZE
);
153 load_files( text
, pattern
, m
, n
);
155 baeza2( text
, pattern
, m
, n
);
160 printf("Average elapsed time for baeza2: %f\n", t3
/times
);
166 //Deallocate text and pattern
167 for( i
= 0; i
< n
; i
++)
172 for( i
= 0; i
< m
; i
++)