Parallel Code
조회 수: 4 (최근 30일)
이전 댓글 표시
Hi
Can I run this code in parallel?
A1=F(A1,B1)
A2=F(A2,B2)
F is a function, A1 B1 are unrelated to A2 B2
How can I do this ? ( now it runs one after the other)
Thanks
Shani
댓글 수: 0
답변 (1개)
Edric Ellis
2012년 4월 17일
If you have Parallel Computing Toolbox, you could do this:
% first start up 2 local workers
matlabpool open local 2
% Make cell arrays of inputs
Ain = {A1, A2}; Bin = {B1, B2};
parfor ii=1:2
% Return outputs as a cell array
Aout{ii} = F(Ain{ii}, Bin{ii});
end
댓글 수: 5
Edric Ellis
2014년 9월 15일
You should not open and close the pool each time - you should open the pool once and leave it open. Each time the pool opens, you are creating new workers with a fresh random number generator state.
참고 항목
카테고리
Help Center 및 File Exchange에서 Parallel Computing Fundamentals에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!