Is it possible to build a parfor loop where workers share and edit (only) one variable array?
Show older comments
Good day!
I am building a ray tracer to solve for thermal radiation within a solid.
Ray tracers are usually considered an exemplary algorithm for parallel computing, as you can "launch" rays on parallel workers. All the worker's computations are entirely independent, and by the end, you can sum up the results of the workers.
Nevertheless, I need to modify this slightly and make the computation of each worker dependent on a variable that needs to be accessible and editable by the other workers. In other words, most of the calculation is still independent but, in some intermediate steps, I need to check a "bookkeeping" or a "counter" (defined for the solid), and depending on the value stored there, the worker decides what to do. Each worker would also need to edit or update this counter after checking its value.
Is there a way to do this?
If not, I see a way of building a parfor inside a while loop, where only the independent calculation would be done in parallel workers. Nevertheless, given the number of iterations, I feel this method would most likely be slower than just a for loop.
Looking for your comments, and thank you very much!
Sebastian.
Accepted Answer
More Answers (0)
Categories
Find more on Parallel Computing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!