So, I am developing a work to do the comparison of a sequential and parallel execution of a Pattern Matching method. My input is a .txt of dozens of lines, which I go through and store inside a buffer:
...
fread(buffer, sizeof(char), numero_bytes, aux);
Once this is done, I run it 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);
Execution ends.
My idea was to do sequential execution the same way. For each line, a thread would be allocated to perform the check, but I guess it does not work just like that.
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 question: Do I have to declare in a different way? Something's missing? If anyone can give me a light, I would be very grateful!
Still, if anyone knows: why does a single thread work? I guess it does not run sequentially, even with a single thread, because the execution time is less than that of the sequential ..