Using Parfor for solving ODE via numerical methods (Euler)

2 visualizaciones (últimos 30 días)
Logan Becker
Logan Becker el 27 de Feb. de 2022
Respondida: Mike Croucher el 28 de Feb. de 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 comentarios
Torsten
Torsten el 27 de Feb. de 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 el 27 de Feb. de 2022
Ah, I thought that would be an issue! Thank you.

Iniciar sesión para comentar.

Respuestas (1)

Mike Croucher
Mike Croucher el 28 de Feb. de 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.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by