# Loop multiprocessing and shared memory using ray

**URL:** https://discuss.ray.io/t/loop-multiprocessing-and-shared-memory-using-ray/1197
**Category:** Ray Core
**Created:** [March 10, 2021, 11:39am UTC](https://discuss.ray.io/t/loop-multiprocessing-and-shared-memory-using-ray/1197 "2021-03-10T11:39:29Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![RaphINSA7](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/raphinsa7/32/600_2.png) [@RaphINSA7](https://discuss.ray.io/u/RaphINSA7)
#### Post date: [March 10, 2021, 11:39am UTC](https://discuss.ray.io/t/loop-multiprocessing-and-shared-memory-using-ray/1197/1 "2021-03-10T11:39:30Z")

</div>

I am currently trying to measure the photo-consistency between two images thanks to the planesweep algorithm [Collins, 1995], therefore I have set up a variable called “ **score-map** ” of size **H x W x L** ( **H** and **W** are the size of the processed images and **L** is the depth range). This process needs to be achieved very quickly, that’s why I am trying to exploit the 8 cores of my CPU in an optimal way.

I tried to parallel the processes since each increment i of depths is independent of the others. However, at the moment I am encountering some difficulties, the returning error is the following:

_RayTaskError(ValueError): ray::iteration\_planesweep() (pid=2320, ip=192.168.1.97) File “python\ray\_raylet.pyx”, line 480, in ray.\_raylet.execute\_task File “”, line 78, in iteration\_planesweep ValueError: assignment destination is read-only_

I am aware that the problem may comes from the variable that needs to be shared across all the processes, but I cannot translate this need into a concrete form. Because in the ray package, ray.put() is supposed to allow a variable to be shared across the different independent processes.  
I have a solution which consist of saving a file for each processing loop but it is also time-consuming …

Another problem is to adapt the multiprocessing with the complexity of my algorithm, I tried to build two separate functions to make the adaptation to ray easier, also by exporting part of the processing outside the main class or the actor. But I can’t get a concrete result, either it returns an incomprehensible error, or the program runs without producing anything.

This is a link to a file containing my algorithm : [https://we.tl/t-VaQk8yPaPv](https://we.tl/t-VaQk8yPaPv)

I would be very thankful if someone could help me solve this problem.

Thank you in advance for your time and consideration.

Raphaël HAENEL

---

<div class="post-metadata">

### Author: ![Ameer\_Haj\_Ali](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/ameer_haj_ali/32/279_2.png) [@Ameer\_Haj\_Ali](https://discuss.ray.io/u/Ameer_Haj_Ali)
#### Post date: [March 10, 2021, 9:28pm UTC](https://discuss.ray.io/t/loop-multiprocessing-and-shared-memory-using-ray/1197/2 "2021-03-10T21:28:09Z")

</div>

Thanks @RaphINSA7. Please tag me if you do not get a response for a while.  
CC @sangcho
