How to divide each pixel calculation of Mandelbrot into different nodes?

戏子无情 提交于 2020-01-04 14:22:32

问题


My question here is what data structure should I use to distribute the work to each threads and get the calculated value from them. First thing in my mind is fill vector[0] .. vector[63999] (for 800x800 pixel) with struct that holds x,y and iterate_value. Pass those vector to each node -> then further divide the given vector to each core(Os-thread) -> then further divide the given vector to each thread. Is there any other possible way to send and received the values? and also if I do it in vector way should I pass the vector by pass by value or pass by reference, which one would be better in this case ?


回答1:


Different points of the mandelbrot set take varying amounts of time to compute (points near the edge are more expensive), so giving each worker an even number of pixels will have some of them finishing faster than others.

Break the image into small rectangles (tiles). Create a work list using a multithreaded queue, and fill it with the tiles. Each worker thread loops, picking a tile off the work list and submitting the results, until the work list is empty.




回答2:


Pixels are evenly spaced, so why send the coordinates for each one? Just tell each node the x and y coordinates of its lower left pixel, the spacing between pixels, and the number of pixels. This way, your work unit specification is a small constant size.

As far as the larger design goes, there is no point in having more worker threads than physical cores to run on. The context switches of multiple threads per core only reduces performance.



来源:https://stackoverflow.com/questions/16050254/how-to-divide-each-pixel-calculation-of-mandelbrot-into-different-nodes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!