diff --git a/Projet/CODE/apm/src/apm.c b/Projet/CODE/apm/src/apm.c index e029b0ffb36fbd13d064beb8a8372fdc275f1296..8de453a7eae3e1bdc928a2b36ff04d087da8d813 100644 --- a/Projet/CODE/apm/src/apm.c +++ b/Projet/CODE/apm/src/apm.c @@ -204,7 +204,7 @@ main(int argc, char **argv) return 1; } - for (j = 0; j < n_bytes; j++) + for (j = 0; j < n_bytes - size_pattern; j++) { int distance = 0; #if APM_DEBUG @@ -217,13 +217,6 @@ main(int argc, char **argv) #endif - if (n_bytes - j < size_pattern) - { - //size = n_bytes - j; - //NO ! we do not want to match substring of our input, wth - continue; - } - distance = levenshtein(pattern[i], &buf[j], size_pattern, column); if (distance <= approx_factor) diff --git a/Projet/CODE/apm/src/apm_omp.c b/Projet/CODE/apm/src/apm_omp.c index 739ec7b1deb5448438a114ab688cc4b70a4609aa..9ee23ed2a9825a2c211fa41e05ea666d8dc9a047 100644 --- a/Projet/CODE/apm/src/apm_omp.c +++ b/Projet/CODE/apm/src/apm_omp.c @@ -119,7 +119,6 @@ main(int argc, char **argv) double duration; size_t n_bytes; size_t *n_matches; - int num_threads; /* Check number of arguments */ if (argc < 4) @@ -185,11 +184,6 @@ main(int argc, char **argv) return 1; } - #pragma omp parallel - { - num_threads = omp_get_num_threads(); - } - #if APM_DEBUG printf("Number of threads: %d\n", num_threads); #endif @@ -203,53 +197,50 @@ main(int argc, char **argv) for (i = 0; i < nb_patterns; i++) { size_t size_pattern = strlen(pattern[i]); - unsigned int *column; n_matches[i] = 0; - column = malloc((size_pattern + 1) * num_threads * sizeof(unsigned int)); - - if (column == NULL) - { - fprintf(stderr, - "Error: unable to allocate memory for column (%ldB)\n", - (size_pattern + 1) * sizeof(unsigned int) * num_threads); - return 1; - } int matches = 0; - #pragma omp parallel for reduction(+:matches) - - for (j = 0; j < n_bytes; j++) + #pragma omp parallel reduction(+:matches) { - int distance = 0; -#if APM_DEBUG + unsigned int *column; + column = malloc((size_pattern + 1) * sizeof(unsigned int)); - if (j % (n_bytes / 100) == 0) + if (column == NULL) { - printf("Procesing byte %ld (out of %ld)(%ld%%)\n", - j, n_bytes, j / (n_bytes / 100)); + fprintf(stderr, + "Error: unable to allocate memory for column (%ldB)\n", + (size_pattern + 1) * sizeof(unsigned int)); + exit(EXIT_FAILURE); } -#endif + #pragma omp for schedule(dynamic, 40960) - if (n_bytes - j < size_pattern) + for (j = 0; j < n_bytes - size_pattern; j++) { - //size = n_bytes - j; - //NO ! we do not want to match substring of our input, wth - continue; - } + int distance = 0; - distance = levenshtein(pattern[i], &buf[j], size_pattern, - column + (omp_get_thread_num() * (size_pattern + 1)) - ); +#if APM_DEBUG - if (distance <= approx_factor) - { - matches++; + if (j % (n_bytes / 100) == 0) + { + printf("Procesing byte %ld (out of %ld)(%ld%%)\n", + j, n_bytes, j / (n_bytes / 100)); + } + +#endif + + distance = levenshtein(pattern[i], &buf[j], + size_pattern, column); + + if (distance <= approx_factor) + { + matches++; + } } - } + free(column); + } n_matches[i] = matches; - free(column); } /* Timer stop */