OpenMP: local variables automatically closed?

#pragma omp parallel { int x; // private to each thread ? } #pragma omp parallel for for (int i = 0; i < 1000; ++i) { int x; // private to each thread ? } 

Thank!

PS If local variables are automatically closed, why use a private offer?

+43
c ++ c parallel-processing openmp
Jun 15 '11 at 13:25
source share
3 answers

PS If local variables are automatically closed, why use a private offer?

It is assumed that in earlier versions of C you had to declare all variables at the beginning of the function, and this is still the prevailing style.

That is, the code is:

 #pragma omp parallel { int x; } 

is the preferred method in C ++. But in some versions of C you cannot use this code, you need to use the private clause.

+26
Jun 15 2018-11-11T00:
source share

The reason for the private offer is that you do not need to change the code .

The only way to parallelize the following code without a personal reason

 int i,j; #pragma omp parallel for private(j) for(i = 0; i < n; i++) { for(j = 0; j < n; j++) { //do something } } 

- change the code. For example, for example:

 int i #pragma omp parallel for for(i = 0; i < n; i++) { int j; for(j = 0; j < n; j++) { //do something } } 

This code is completely correct C89 / C90, but one of the goals of OpenMP is not to change your code, except to add pragma statements that can be turned on or off at compile time.

+33
May 04 '15 at 9:09
source share

Data in the parallel region is private for each stream.

Please refer to http://en.wikipedia.org/wiki/OpenMP#Data_sharing_attribute_clauses [Data Sharing Attribute Classes]

+5
Jun 15 2018-11-15T00:
source share



All Articles