Quantcast
Viewing all articles
Browse latest Browse all 22145

OpenMP C Program Clarification

If you want to access the thread-local values of a privatized variable from outside of the parallel scope, you can write them back to a globally declared auxiliary array. This is the way it was described in an OpenMP book

(2017 - Bertil Schmidt, Jorge Gonzalez-Dominguez, Christian Hundt, Moritz Schlarb - Parallel Programming_ Concepts and Practice-Morgan Kaufmann)

Authors came up with this program --

int main () {     // maximum number of threads and auxiliary memory      int num = omp_get_max_threads();     int * aux = new int[num];     int i = 1; // we pass this via copy by value     #pragma omp parallel firstprivate(i) num_threads(num) {         // get the thread identifier j         int j = omp_get_thread_num();         i += j;         aux[j] = i;     }     for(k=0; k<num; k++)         printf("%d \n", aux[k]); } 

Tried this in Mac -->

Image may be NSFW.
Clik here to view.
Error message

What is the problem here?


Viewing all articles
Browse latest Browse all 22145

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>