Quindi ho una regione parallela esterna con due regioni parallele interne. È possibile inserire 2 fili in parallelo esterno e 4 fili in ciascun interno? Ho fatto qualcosa di simile, ma sembra non funzionare come lo voglio. Eventuali suggerimenti?Parallelismo aperto a Mp aperto
start_r = omp_get_wtime();
omp_set_nested(1);
omp_set_num_threads(2);
#pragma omp parallel
{
printf("Thread %d executes the outer parallel region\n",omp_get_thread_num());
omp_set_num_threads(4);
#pragma omp parellel for private(i,j,color)schedule(guided, chunk) default(shared)
{
// Blur
for (int i = 1; i < x-1; i++)
for (int j = 1; j < y-1; j++)
for (int k = 0; k < 3; k++)
{
wynik = 0;
wynik = ((color[(i-1)][((j - 1))][k] +
color[(i-1)][j][k] +
color[(i-1)][(j + 1)][k] +
color[i][(j - 1)][k] +
color[i][j][k] +
color[i][(j + 1)][k] +
color[(i+1)][(j - 1)][k] +
color[(i+1)][j][k] +
color[(i+1)][(j + 1)][k])/9);
if (wynik>255)wynik = 255;
if (wynik<0)wynik = 0;
color2[i][j][k] = wynik;
}
stop_r = omp_get_wtime();
cout << "Wyostrzenie zejelo : " << (stop_r-start_r) <<" sekund"<< endl;
cout<<omp_get_nested()<<endl;
cout<<"Ilość wątków dla rozmycia : "<<omp_get_num_threads()<<endl;
printf("Thread %d executes the inner parallel region\n",omp_get_thread_num());
}
omp_set_num_threads(4);
#pragma omp parellel for schedule(guided, chunk) privat(i,j,color) default(shared)
{
// Sharp
for (int i = 1; i < x - 1; i++)
for (int j = 1; j < y - 1; j++)
for (int k = 0; k < 3; k++)
{
wynik = 0;
wynik = (color[(i-1)][(j - 1)][k] * (0) +
color[(i-1)][j][k] * (-1) +
color[(i-1)][(j + 1)][k] * (0) +
color[i][(j - 1)][k] * (-1) +
color[i][j][k] * 20 +
color[i][(j + 1)][k] * (-1) +
color[(i+1)][(j - 1)][k] * (0) +
color[(i+1)][j][k] * (-1) +
color[(i+1)][(j + 1)][k] * (0))/16;
wynik = wynik % 255;
color3[i][j][k] = wynik;
}
cout<<omp_get_nested()<<endl;
cout<<"Ilość wątków dla wyostrzenia : "<<omp_get_num_threads()<<endl;
printf("Thread %d executes the inner parallel region\n",omp_get_thread_num());
}
}
for (int j = 0; j < y; j++)
for (int i = 0; i < x; i++)
{
fwrite(color2[i][j], 1, 3, fp2);
fwrite(color3[i][j], 1, 3, fp3);
}
fclose(fp);
fclose(fp2);
fclose(fp3);
system("PAUSE");
return 0;
}
}
vi suggerisco di codificare questo anche con OpenMP –