Workaround for global structure within parfor

1 view (last 30 days)
Alex Wolff
Alex Wolff on 9 Jul 2015
Edited: Matt J on 9 Jul 2015
I have a global structure to which I store outputs of a block of code within a for loop.
I want to run this code in parallel using parfor which does not play well with the global structure.
I have tried passing the structure as an input to all of my subfunctions but that increased run time substantially and made it difficult to keep track of variables within the subfunctions.
Is there any better way to approach this?
Thanks,
-Alex

Answers (1)

Matt J
Matt J on 9 Jul 2015
Edited: Matt J on 9 Jul 2015
We need to see what the loop looks like and what exactly it is you are parallel-slicing. Basically, though, it sounds like you're better off writing the data to individual sliced variables in the loop. Then, after the loop, assign the finished result to fields of your global structure.
I have tried passing the structure as an input to all of my subfunctions but that increased run time substantially
There's no obvious reason it should have...

Categories

Find more on Parallel for-Loops (parfor) 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!