Trying to understand private and shared openmp data clauses.
Hello everyone. I have the code like this:
const int numRows = 4;
const int numColumns = 100;
int array2D[numRows][numColumns];
omp_set_num_threads(numRows);
const int numThreadsAvailableInParallelRegion = omp_get_max_threads();
int threadId;
#pragma omp parallel default(none) private(threadId) shared(array2D)
{
threadId = omp_get_thread_num();
for (int i = 0; i < numColumns; ++i)
{
array2D[threadId][i] = threadId + i + 1;
}
}
It works fine.
The questions:
Why MVS compiler doesn't complain about numColumns variable that is not explicitly specified neither in private clause nor in shared clause.
What exactly default(none) directive tells us? Does it indicate that all variables defined before the parallel region are private, or that all variables defined before the parallel region have an undefined status (neither private nor shared)? And that I have to explicitly specify what is private and what is shared?
Are these two are equivalent?
#pragma omp parallel
and
#pragma omp parallel dafault(shared)
If yes, why might I need the second one?
I think MVS compiler only supports openmp 2.0. I have
Microsoft Visual Studio Professional 2019 Version 16.9.4
In OpenMP 2.0, constants do not have to be listed in sharing clauses in the case of default(none)
. If listed, they have to be either shared
or firstprivate
(they are probably shared
by default, but it's not really said, maybe the choice is left to the implementation).
And yes, default(shared)
is the default default()
:). You may just want to specify it for code clarity (personally I don't)