Parallel computing problem
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Edric Ellis
2012-3-22
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Parallel for-Loops (parfor) 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!