1
So I’m developing a work to perform the comparison of a sequential and parallel execution of a Pattern Matching method. My input is a. txt of dozens of lines, which I traverse and store inside a buffer:
...
fread(buffer, sizeof(char), numero_bytes, aux);
Once done, I run once sequentially:
/* quebro a string em varias linhas*/
char * string_sequencial = strtok(strdup(buffer), str);
/*Enquanto existir linhas a serem verificadas: */
while(string_sequencial != NULL) {
if(match(padrao, string_sequencial)) // Método Pattern Matching
{
cont_padroes_sequencial++;
}
/*vai para a proxima linha*/
string_sequencial = strtok(NULL, str);
/*Conta o numero de linhas para o for da execução paralela*/
n_linha++;
}
So far so good, my problem is that when I use more than one thread in:
omp_set_num_threads(1);
The execution ends.
My idea was to make it equal to sequential execution. For each line, a thread would be allocated to perform the check, but I guess it doesn’t just work that way.
The stretch of parallelization:
char * string_paralelo = strtok(strdup(buffer), str);
// <<<
#pragma omp parallel
{
omp_set_num_threads(1);
#pragma omp for
for(int i = 0; i < n_linha; i++)
{
if(match(padrao, string_paralelo))
{
cont_padroes_paralelo++;
}
string_paralelo = strtok(NULL, str);
}
}
My doubt: Do I need to state something differently? Is something missing? If someone can give me a light, I would be very grateful!
Still, if anyone knows: why does a single thread work? I imagine it doesn’t run sequentially, even with a single thread, because the running time is shorter than the sequential one..
the clause
reduction
makes a reducing, that is, it combines the values ofcont_padroes_paralelo
obtained by all threads by the type of reduction specified, in which case the+
: sum all values– 648trindade