Recall that all blocks modified by an unnamed critical directive…

Question Answered step-by-step Recall that all blocks modified by an unnamed critical directive… Recall that all blocks modified by an unnamed critical directive form a single critical section in OpenMP. What happens if we have a number of atomic directives in which different variables are being modified? Are they all treated as a single critical section? To test this, you can use a code similar to the below. The idea is to have all the threads simultaneously execute something like the following code:#pragma omp parallel num threads( thread_count){int i;double sum = 0.0;for ( i = 0; i < n; i ++){#pragma omp atomicsum += sin( i);}Note that since sum and i are declared in the parallel block, each thread has its own private copy. Now if we time this code for large n when thread_count = 1 and we also time it when thread_count > 1, then as long as thread_count is less than the number of available cores, the run-time for the single-threaded run should be roughly the same as the time for the multithreaded run if the different threads’ executions of sum += sin(i) are treated as different critical sections. On the other hand, if the different executions of sum += sin(i) are all treated as a single critical section, the multithreaded run should be much slower than the single-threaded run. Write  an OpenMP program that implements this test (you can extend the given code above). Does your implementation of OpenMP allow simultaneous execution of updates to different variables when the updates are protected by atomic directives? Engineering & Technology Computer Science Share QuestionEmailCopy link Comments (0)