As far as I know, this program should get a speedup of 2 or more when run with 2 threads. Instead of that I get pretty much the same as serially.
static void proc_paralelo (int n, char *vprimos, int nthr) {
omp_set_num_threads(nthr);
int i, j, prim, posiciones;
int raiz_n = sqrt(n);
for (i=1;i < raiz_n; i++)
{
if (vprimos[i]==0)
{
prim=i+1;
posiciones=ceil((float)(n-(i+prim))/(float)prim);
#pragma omp parallel for private(j) schedule (static, posiciones/omp_get_num_threads())
for (j=0; j<posiciones; j++){
vprimos[i+prim+(j*prim)]=1;}
}
}
}
The number of threads I use is 2 (my processor's cores) and the size of n
is 20000000.
The times I get are:
- serially: 650000000 ns
- in parallel: 630000000 ns