 # Iterative process running out of sync

Hi,

i am currently doing my bachelors in chemistry and i am trying to simulate a reaction with a cellular automaton. It works fine, but is too slow. So i introduced ray.

I now have the issue, that my computation runs out of sync. Its an iterative process, so all processes need to wait for each other to finish in order to start over. All processes are dependent on the result of the calculation of the other processes of the previous step. I am only using numpy arrays for the calculation.

This is the main iteration-loop:

`````` for i in range(1, n):

# these are the two processes calculating the concentration of x and y for half of the cell each
temp_L_x, temp_L_y = Proc_L.remote()
temp_R_x, temp_R_y = Proc_R.remote()

#i tought that this ensures, that the total concentration of the whole automaton Cges_x and Cges_y of this iterationstep is calculated after both processes have finished:
Cges_x, Cges_y = End_Iter_Konz.remote(temp_L_x, temp_L_y, temp_R_x, temp_R_y)

Cx[:, :] = ray.get(Cges_x)
Cy[:, :] = ray.get(Cges_y)

#loop to print the concentration with matplotlib
if i % 5 == 0:
draw_figure.remote(i, h, Cx)
draw_figure.remote(i, h, Cy)
h += 1 # numbering of the images
``````

This is one example of the calculation process:

``````@ray.remote(num_returns=2)
def Proc_R():

Cx_diff_gesamt[:, slice:] = XXXXXXXX
Cy_diff_gesamt[:, slice:] = XXXXXXX
Cx[:, slice:] = XXXXXXX + Cx_diff_gesamt[:, slice:] * dt
Cy[:, slice:] = XXXXXXXXX + Cy_diff_gesamt[:, slice:] * dt

return Cx[:, slice:], Cy[:, slice:]
``````

The issue i am now having is, that the output (the matplotlib picture) fails to stay in sync. The longer the iterationprocess goes on, the worse it gets. Here is an example how it looks:

I am relatively new to python especially to parallelisation. Help would be very appreciated!

Thanks for your help!

Can you elaborate what it means by “not in sync”?

Sure,
somehow the output of the matplotlib-generated plots (example above) of the two sides dont match up when splitting the whole cell into two separate processes which each calculate one half of the cell. The image on the right is what one frame looks like in this case, whereas is should look like the frame on the left (hogenous). The Frame on the right looks like one process is further down the iterative process than the other.
I rendered a short video of the resulting cell where it might be better understandable what i mean by “out of sync”:
This is without ray and how it should look like: https://youtu.be/8EY-nyMiOUk
This is with ray, you can see the two halfes were i divided the cell into two parts, each for one process: https://youtu.be/Md6k995qnl8

Thanks!