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)
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)
......
......@@ -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,24 +197,28 @@ 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));
int matches = 0;
#pragma omp parallel reduction(+:matches)
{
unsigned int *column;
column = malloc((size_pattern + 1) * 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;
(size_pattern + 1) * sizeof(unsigned int));
exit(EXIT_FAILURE);
}
int matches = 0;
#pragma omp parallel for reduction(+:matches)
#pragma omp for schedule(dynamic, 40960)
for (j = 0; j < n_bytes; j++)
for (j = 0; j < n_bytes - size_pattern; j++)
{
int distance = 0;
#if APM_DEBUG
if (j % (n_bytes / 100) == 0)
......@@ -231,16 +229,8 @@ 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 + (omp_get_thread_num() * (size_pattern + 1))
);
distance = levenshtein(pattern[i], &buf[j],
size_pattern, column);
if (distance <= approx_factor)
{
......@@ -248,9 +238,10 @@ main(int argc, char **argv)
}
}
n_matches[i] = matches;
free(column);
}
n_matches[i] = matches;
}
/* Timer stop */
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