Parallel computing problem
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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?
0 Kommentare
Antworten (1)
Edric Ellis
am 22 Mär. 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.
Siehe auch
Kategorien
Mehr zu Parallel for-Loops (parfor) finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!