While loop in Julia's collection

General OpenMP discussion
Forum rules
The OpenMP Forums are now closed to new posts. Please visit Stack Overflow if you are in need of help: https://stackoverflow.com/questions/tagged/openmp
Locked
MagicznyMaciej
Posts: 1
Joined: Wed Jan 13, 2021 3:48 pm

While loop in Julia's collection

Post by MagicznyMaciej »

Hi Everyone,
I have a little question, I wrote a program to do the Julia sets problem with openMP and paralleled the main for loop, and wondering if I should also parallelize while loop. Is it profitable, and if so, I would ask for tips on how to do it. Code below, if i can do something better tell me ;) thank you for the answers

CODE:

N=5000;
WIDTH=600;
HEIGHT=600;

#pragma omp parallel for default(none) schedule(dynamic)\
num_threads(6) shared(Xmax,Xmin,Ymax,Ymin,ratioX,ratioY,N,WIDTH, HEIGHT,table,c)\
private(n,i,x,y,z,temp,z1) reduction(+ : pointsCounter)
for (i = 0; i < (WIDTH ) * (HEIGHT ); i++)
{
x = i % WIDTH;
y = i / WIDTH;
complex<double> p((ratioX * x + Xmin), (ratioY * y + Ymin));
temp = 255;
z = p;
n=1;
z1 = z * z + c;


while(abs(z1) < 2.0 && n < N)
{
z1 = z * z + c;
z=z1;
n++;
}
if(n < N)
{
pointsCounter++;
temp=0;
}
table[y * WIDTH + x] = temp;
}

MarkB
Posts: 808
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh

Re: While loop in Julia's collection

Post by MarkB »

You can't parallelise the while loop - there is a dependency between iterations on the value of z. I don't think you can do much better than this, except perhaps to experiment with other loop scheduling options/chunksizes.

Locked