Using Parfor for solving ODE via numerical methods (Euler)

2 次查看(过去 30 天)
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.

请先登录,再进行评论。

回答(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