Using Parfor for solving ODE via numerical methods (Euler)

조회 수: 3 (최근 30일)
Logan Becker
Logan Becker 2022년 2월 27일
답변: Mike Croucher 2022년 2월 28일
Hello,
I am trying to optimize a project I am working on and I am considering parralizing my computations. My calculations consist of solving and ODE via euler over a large number of trials at the same time. When trying to use it I run into the error of "The parfor loops can not run due to the way variable 'x' is used". I tried looking for solutions but do not necessarily understand the reccomendations. Below is a simple example of the type of problem I am trying to solve. I appreciate any feedback. Thank you.
t = 0:0.1:10;
nT = 1000;
x = zeros(length(t),nT);
parfor i = 2:length(t)
x(i,:) = x(i-1,:) - dt*x(i-1,:)
end
  댓글 수: 2
Torsten
Torsten 2022년 2월 27일
You cannot parallelize a loop if the variable x(i) you want to compute depends on x(i-1).
Only independent calculations can be parallelized.
Logan Becker
Logan Becker 2022년 2월 27일
Ah, I thought that would be an issue! Thank you.

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

답변 (1개)

Mike Croucher
Mike Croucher 2022년 2월 28일
As others have said, you cannot parallelise this loop. However, what you can do is parallelise independent runs of this loop.
You say you have a 'large number of trials.' Does that mean you want to run the above code many times with different parameters? If so, you can probably parallelise at that level.

카테고리

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