I am coding a Mandelbrot set generator and I have parallelized it with 4 subprocesses, each one calculate a different region of Mandelbrot set.
The parallelizing code is the following:
def run_threads(self): # Parallelize calcs with 4 subprocesses
with Pool(processes=4) as pool:
p1 = pool.apply_async(self.run, (0, int(self.width / 2), 0, int(self.width / 2)))
p2 = pool.apply_async(self.run, (0, int(self.width / 2), int(self.width / 2), self.width))
p3 = pool.apply_async(self.run, (int(self.width / 2), self.width, 0, int(self.width / 2)))
p4 = pool.apply_async(self.run, (int(self.width / 2), self.width, int(self.width / 2), self.width))
r1 = (p1.get(timeout=10))
r2 = (p2.get(timeout=10))
r3 = (p3.get(timeout=10))
r4 = (p4.get(timeout=10))
#r2 = self.run(0, int(self.width / 2), int(self.width / 2), self.width)
for i in range(0, int(self.width / 2)):
for j in range(0, int(self.width / 2)):
self.values[i, j] = r1[i,j]
for i in range(0, int(self.width / 2)):
for j in range(int(self.width / 2), self.width):
self.values[i, j] = r2[i,j]
for i in range(int(self.width / 2), self.width):
for j in range(0, int(self.width / 2)):
self.values[i, j] = r3[i,j]
for i in range(int(self.width / 2), self.width):
for j in range(int(self.width / 2), self.width):
self.values[i, j] = r4[i,j]
but the output is this
The two correctly represented regions correspond to r1 and r4, so r2 and r3 arent working properly. If I run the commented code for r2, the output is now correct, so I dont know what I am doing wrong.
PS: self.values and values are the color of each pixel.
Thank you