You create an OpenMP application by using Microsoft Visual C++. You write the following code segment. (Line numbers are included for reference only.)
01 #pragma omp parallel for
02 for(int i=0;i<50000;i++)
03 {
04 doWorkA(i);
05 doWorkB(i);
06 }
The doWorkA and doWorkB methods are independent method calls. You need to optimize performance while protecting the method calls against multiple thread access.Which code segment should you use to replace lines 04 and 05?
A.
#pragma omp critical
{
doWorkA(i);
}
#pragma omp critical
{
doWorkB(i);}
B.
#pragma omp critical (WorkA)
{
doWorkA(i);
}
#pragma omp critical (WorkB)
{
doWorkB(i);
}
C.
#pragma omp critical
{
doWorkA(i);
}
#pragma omp flush(i)
#pragma omp critical
{
doWorkB(i);
}
D.
#pragma omp critical (work)
{
#pragma omp critical
{
doWorkA(i);
}
#pragma omp critical
{
doWorkB(i);
}
}