share data between workers while retrieving data from handle class within parpool

1 回表示 (過去 30 日間)
Marc Laub
Marc Laub 2020 年 6 月 14 日
回答済み: Edric Ellis 2020 年 6 月 16 日
Hey guys,
following problem.
I have a handle class which is linked to different handle class objects of its own class and of other classes.
So like i have 3 points and each points knows its position and to which points its is connected by an edge, called neighbour vertex in my case.
I now need to refine the edges connecting the points and I want to do this in parralel because there are many of these points and edges. At the same tome I have to relink the new edges and nes points to its neighbour points.
So in this example A,B,C are the old points and D and E are the new points. Additionaly I have to change the edges AB to AD and create a new edge DB, same goes for BC to BE and creating EC.
When doing this in parralel there is the problem the when the points as handle classes are a broacast variable that changes from another worker do not affect them. When worker 1 changes the connection from BC to BE and another worker changes the connection from BA to BD, they dont know from each other. It would results in two different B's with 2 different sets af neighbour points on each worker.
So how is this done in Matlab, especially with handle classes, since I even have problems to link vertices to each other in parrallel (without creating new ones), since somehow the chages are not reflected after parfor correctly to the editor even though I used all of the advices here:
They advise direct indexing, but I dont know which way would be more direct than:
parfor i=1:length(edges)
So this code does not work in aprfor, I dont get an error but I just get vertices back with 0 neighbours...
Maybe somebody culd help me eith this or give me a hint
Many thanks in advance
Best regards


Edric Ellis
Edric Ellis 2020 年 6 月 16 日
To get data out of a parfor loop, you must have either a "sliced output" or a "reduction output". Your code example above has neither of these - v1 and v2 will be analysed as "temporary variables" because you assign a whole new value to them in each iteration of the loop.
I spotted your other question about handle classes in parfor. It's not clear to me which part of your algorithm is the time-consuming piece that you are hoping to speed up with parfor. But in general, you cannot modify instances of handle classes on the worker and have the changes show up back at the client (nor on other workers). So, in general, modifying a graph structure in this way is really not amenable to parallelism.
My general advice would be: use the MATLAB profiler on your code running in serial, and work out where the real time is being spent. See if you can arrange things so that this is divided up into independent pieces of work. That is the simplest way to being able to run stuff in parallel.

その他の回答 (0 件)


Help Center および File ExchangeParallel Computing Fundamentals についてさらに検索




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by