Согласно документации:
default(shared|none);
Controls the default data-sharing attributes of
variables that are referenced in a parallel or task
construct.
shared(list);
Declares one or more list items to be shared by tasks
generated by a parallel or task construct.
private(list);
Declares one or more list items to be private to a task.
Вот пример рабочего кода: Однако, это, вероятно, может быть сделано намного лучше.
int main()
{
int npoints = 2000;
int sum = 0;
double rand_no_x;
double rand_no_y;
int num_threads;
int sample_points_per_thread;
srand((unsigned int)time(0));
#pragma omp parallel default(none) private(rand_no_x, rand_no_y, num_threads, sample_points_per_thread) shared(npoints) reduction(+: sum) num_threads(8)
{
num_threads = omp_get_num_threads();
sample_points_per_thread = npoints / num_threads;
sum = 0;
for (int i = 0; i < sample_points_per_thread; i++) {
rand_no_x = (double)rand() / (double)RAND_MAX;
rand_no_y = (double)rand() / (double)RAND_MAX;
if (((rand_no_x - 0.5) * (rand_no_x - 0.5) + (rand_no_y - 0.5) * (rand_no_y - 0.5)) < 0.25) {
sum = sum + 1;
}
}
}
printf("%f\n", (4.0 * (double)sum) / (double)npoints);
}