Clear Filters
Clear Filters

Parallel computing problem

1 view (last 30 days)
Sampath reddy
Sampath reddy on 22 Mar 2012
I have 3 programs to run in parallel, each on one core on my quad core processor. For this i'm using jobs and tasks method. After every iteration of the loop in the 3 functions, i have to use data from each program( that are running parallel on the cores individually) and calculate a variable and then use this updated variable for the next iteration in the programs. I thought to use global variable for the common data but i'm unable to make it work. Any help anyone?

Answers (1)

Edric Ellis
Edric Ellis on 22 Mar 2012
GLOBAL data is never shared between your desktop MATLAB session and the workers running jobs and tasks. However, you might find it somewhat easier to open a MATLABPOOL and then use PARFOR to get your job done. Perhaps something a bit like this:
matlabpool open local 3
done = false;
myFcns = {@myFcn1, @myFcn2, @myFcn3};
overallState = 0;
while ~done
parfor ii = 1:3
result(ii) = feval(myFcns{ii});
end
overallState = overallState + sum(result);
done = (overallState > 42);
end
In other words, you could put your three functions into a cell array of function handles. The PARFOR loop runs these in parallel, and collects the results into 'result', and you can operate on that in your MATLAB session, and then do some more stuff in parallel.
  1 Comment
Sampath reddy
Sampath reddy on 24 Mar 2012
Does parfor function support global variables?

Sign in to comment.

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!