Question: Example#pragma omp parallelint id = omp _ get _ thread _ num ( ) ;Alid ] = big _ call ( id ) ; /

Example#pragma omp parallelint id = omp_get_ thread_num () ;Alid]= big_call (id); //some large function#pragma omp barrier //Tells all threads to wait at this pointBlid]= big_calc2(id, A)//barrier is used so that A is finished//updating before using.In the case of mutual exclusion, a section of code is defined such that only one thread can access it at a time. This section of code is called a critical section. If a thread reaches the critical section but a 2nd thread is still executing it, the first thread has to wait to execute the critical section. The following statement is used to define that block of code:#pragma omp criticalExample:float res;#pragma omp parallelfloat B; int i, id, nthrds;B = big_job (i);#pragma omp critical //critical sectionres += consume (B); //only one thread will add to res at a timeAlternatively, #pragma omp atomic may be used instead of #pragma omp critical. Atomic works the same as critical but uses hardware that may speed up specific operations. This should only be used to do quick updates in memory (e.g. x++,--x). When in doubt, use critical because is the more general version.ExerciseMake copies and modify your parallelized "pi.c" program 3 times. First use omp barrier and record the processing time for 1,2,3, and 4 threads. Repeat this for omp critical and omp atomic. Compare their processing times. Which is the best method to use?Hint: When using critical and atomic update sum without array to avoid false sharingDashboard68CalendarOTo Do

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!