Thanks for reply!
ftinetti wrote:The compiler is right, a is not scalar so it cannot be a reduction variable. Also, it does not make sense being a reduction variable, since there is not reduction on a.
So I have changed the whole reduction to shared.
ftinetti wrote:1) variable j should be declared private, since it is shared by default, which is a problem
OK, I have changed code to private(j) so I understand that only i (and those parts of a that have corresponding i) is used for parallel processing and each thread has only j with different value for each thread.
ftinetti wrote:2) Processing 5x5 matrices in parallel would not provide any speedup, since there is almost no work to do (neither sequentially, nor in parallel)
I think it can be done in parallel in such a way that one row is calculated in one thread, the other row in the other thread and so on.
ftinetti wrote:3) Maybe schedule(static,1) would only add overhead on this kind of processing, I would use the default schedule (i.e. no schedule clause)
I have changed the whole reduction to shared.
Now the whole code looks like this:
- Code: Select all
#define N 5
void main ()
int maxThreads = omp_get_max_threads();
int i, j;
//#pragma omp parallel for reduction(+:a)
#pragma omp parallel for shared(a) private(j)
for (i = 0; i < N; i++)
for (j = 0; j < N; j++)
a[i][j] = i + j;
Is it good approach?
In fact this is theoretical exercise from book about parallel processing. I assume that solving this task may help me to understand basics of OpenMP better.