MATLAB Answers

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

조회 수: 1(최근 30일)
Marc Laub
Marc Laub 14 Jun 2020
답변: Edric Ellis 16 Jun 2020
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

  댓글 수: 0

댓글을 달려면 로그인하십시오.


Edric Ellis
Edric Ellis 16 Jun 2020
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

댓글을 달려면 로그인하십시오.




Community Treasure Hunt

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

Start Hunting!

Translated by