Using Parfor for solving ODE via numerical methods (Euler)

4 views (last 30 days)
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,:)

Sign in to comment.

Answers (1)

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

Community Treasure Hunt

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

Start Hunting!