How to use parallel computing

조회 수: 1 (최근 30일)
Stéphane
Stéphane 2014년 9월 24일
댓글: Stéphane 2014년 9월 25일
Hello,
I'm very new in parallel computing and I can't find what I want in the matlab help (even if it's probably in there...).
I have a code that computes things on two different (big) matrices and then use both of them to compute something else :
for i = 1:N
M1 = computeMatrix1(M1);
M2 = computeMatrix2(M2);
X = doSomething(M1,M2).
end
computeMatrix1() and computeMatrix2() can be processed independently.
My question is then : is there a way to ask matlab to process these two functions on different processors, and then process doSomething() when the previous functions are done ? Or is my question silly because I'm so ignorant in parallel processing...
Thanks
  댓글 수: 2
Raymond Norris
Raymond Norris 2014년 9월 24일
Are computeMatrix1 and computeMatrix2 the same function called with different input arguments? Or are they completely different functions?
The for loop itself is then not independent since for example, M1 is dependent on the previous iteration, correct?
Stéphane
Stéphane 2014년 9월 25일
They are different functions at the moment, but I could probably find a way to merge them into one function.
And yes, the M1 is dependent on the previous iteration.
Thanks for your help

댓글을 달려면 로그인하십시오.

답변 (1개)

José-Luis
José-Luis 2014년 9월 24일
In order for Matlab to compute the functions on different cores (not the same as different processors), you could always:
a = cell(1,2),
a{1} = M1;
a{2} = M2;
parfor ii = 1:2
a{ii} = computeMatrix(a{ii});
end
X = doSomething(a{1},a{2}); %You would need to take this out of the loop
  댓글 수: 1
Stéphane
Stéphane 2014년 9월 25일
Thanks, I'll try and let you know.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by