:
-, :
# pragma omp parallel for
for (int bb=0; bb<10000; bb++)
{
for (int i=0; i<20000; i++)
{
#pragma omp critical
{
int a = uniform_distribution(0,20000);
}
}
}
, :
# pragma omp parallel
{
boost::random::mt19937 eng(omp_get_thread_num());
#pragma omp for
for (int bb=0; bb<10000; bb++)
{
for (int i=0; i<20000; i++)
{
int a = uniform_distribution(0,20000, eng);
}
}
}
, (, , ), . , . , , , , , ( , ). ( ).
- , .
EDIT. To be clear, mutual exclusion solutions make sense if random number generation is not a major part of the work of threads (that is // presumably some more code..., the example exists and doesn't take a trivial amount of time to complete). The critical section should cover only access to the shared variable, but changing your architecture a bit will allow you to more precisely control this (and in the case of local thread storage, it can also allow you to bypass the link eng))
jerry source
share