Skip to content
Extraits de code Groupes Projets
Valider 4ea5ab9d rédigé par Nicolas MARIE's avatar Nicolas MARIE
Parcourir les fichiers

fixe omp version coalessant memory allocations

parent 7b5e2944
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -204,7 +204,7 @@ main(int argc, char **argv) ...@@ -204,7 +204,7 @@ main(int argc, char **argv)
return 1; return 1;
} }
for (j = 0; j < n_bytes; j++) for (j = 0; j < n_bytes - size_pattern; j++)
{ {
int distance = 0; int distance = 0;
#if APM_DEBUG #if APM_DEBUG
...@@ -217,13 +217,6 @@ main(int argc, char **argv) ...@@ -217,13 +217,6 @@ main(int argc, char **argv)
#endif #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); distance = levenshtein(pattern[i], &buf[j], size_pattern, column);
if (distance <= approx_factor) if (distance <= approx_factor)
......
...@@ -119,7 +119,6 @@ main(int argc, char **argv) ...@@ -119,7 +119,6 @@ main(int argc, char **argv)
double duration; double duration;
size_t n_bytes; size_t n_bytes;
size_t *n_matches; size_t *n_matches;
int num_threads;
/* Check number of arguments */ /* Check number of arguments */
if (argc < 4) if (argc < 4)
...@@ -185,11 +184,6 @@ main(int argc, char **argv) ...@@ -185,11 +184,6 @@ main(int argc, char **argv)
return 1; return 1;
} }
#pragma omp parallel
{
num_threads = omp_get_num_threads();
}
#if APM_DEBUG #if APM_DEBUG
printf("Number of threads: %d\n", num_threads); printf("Number of threads: %d\n", num_threads);
#endif #endif
...@@ -203,24 +197,28 @@ main(int argc, char **argv) ...@@ -203,24 +197,28 @@ main(int argc, char **argv)
for (i = 0; i < nb_patterns; i++) for (i = 0; i < nb_patterns; i++)
{ {
size_t size_pattern = strlen(pattern[i]); size_t size_pattern = strlen(pattern[i]);
unsigned int *column;
n_matches[i] = 0; n_matches[i] = 0;
column = malloc((size_pattern + 1) * num_threads * sizeof(unsigned int));
int matches = 0;
#pragma omp parallel reduction(+:matches)
{
unsigned int *column;
column = malloc((size_pattern + 1) * sizeof(unsigned int));
if (column == NULL) if (column == NULL)
{ {
fprintf(stderr, fprintf(stderr,
"Error: unable to allocate memory for column (%ldB)\n", "Error: unable to allocate memory for column (%ldB)\n",
(size_pattern + 1) * sizeof(unsigned int) * num_threads); (size_pattern + 1) * sizeof(unsigned int));
return 1; exit(EXIT_FAILURE);
} }
int matches = 0; #pragma omp for schedule(dynamic, 40960)
#pragma omp parallel for reduction(+:matches)
for (j = 0; j < n_bytes; j++) for (j = 0; j < n_bytes - size_pattern; j++)
{ {
int distance = 0; int distance = 0;
#if APM_DEBUG #if APM_DEBUG
if (j % (n_bytes / 100) == 0) if (j % (n_bytes / 100) == 0)
...@@ -231,16 +229,8 @@ main(int argc, char **argv) ...@@ -231,16 +229,8 @@ main(int argc, char **argv)
#endif #endif
if (n_bytes - j < size_pattern) distance = levenshtein(pattern[i], &buf[j],
{ size_pattern, column);
//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 + (omp_get_thread_num() * (size_pattern + 1))
);
if (distance <= approx_factor) if (distance <= approx_factor)
{ {
...@@ -248,9 +238,10 @@ main(int argc, char **argv) ...@@ -248,9 +238,10 @@ main(int argc, char **argv)
} }
} }
n_matches[i] = matches;
free(column); free(column);
} }
n_matches[i] = matches;
}
/* Timer stop */ /* Timer stop */
gettimeofday(&t2, NULL); gettimeofday(&t2, NULL);
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter