Question: Implicit Threading [Bahremand] Consider the following fragment of code that uses OpenMP: #include #include int main() { int i = 256; #pragma omp parallel {

Implicit Threading

[Bahremand] Consider the following fragment of code that uses OpenMP:

#include #include int main() { int i = 256; #pragma omp parallel { int x, y; x = omp_get_num_threads(); y = omp_get_thread_num(); printf("x = %d, y = %d, i = %d ",x,y,i); } }

GNU documentation: omp_get_num_threads: Returns the number of threads in the current team. In a sequential section of the program omp_get_num_threads returns 1. At runtime, the size of the current team may be set either by the NUM_THREADS clause or by omp_set_num_threads. omp_get_thread_num: "Returns a unique thread identification number within the current team. In parallel regions the return value varies from 0 to omp_get_num_threads-1 inclusive."

Trace this fragment and provide the expected output. Assume NUM_THREADS is set to 3. Will the output always be the same? Explain.

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!