Using Parfor for solving ODE via numerical methods (Euler)

2 vues (au cours des 30 derniers jours)
Logan Becker
Logan Becker le 27 Fév 2022
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 commentaires
Torsten
Torsten le 27 Fév 2022
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 le 27 Fév 2022
Ah, I thought that would be an issue! Thank you.

Connectez-vous pour commenter.

Réponses (1)

Mike Croucher
Mike Croucher le 28 Fév 2022
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.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by