ODE Event Detection in Parfor loop
9 次查看(过去 30 天)
显示 更早的评论
I have an ODE45 function that uses an event detection function, and normally it works great! But, I'm trying to parallelize the process and putting the ode45 call inside the parfor loop fails to record the events. My basic code is below. When I use parfor rather than a simple for loop, the .te, .ye, and .ie fields of my struct are all blank (but are correctly populated with "for"), while the .y, and .t fields are fine.
State(1:100) = struct;
parfor i = 1:length(State)
tspan = 1:1000;
Opt = odeset('RelTol',1e-10,'AbsTol',1e-10,'Events',@myEvent);
[t,y,te,ye,ie] = ode45(@myOde, tspan, Y0, Opt);
State(i).t = t;
State(i).y = y;
State(i).te = te;
State(i).ye = ye;
State(i).ie = ie;
end
Is there a way to use Event Detection in a parfor loop? Am I just initializing something wrong, or do I need to try something other than parfor?
1 个评论
Edric Ellis
2019-8-29
Your example is not executable, so I can't work out why this isn't working - please could you set this up as a "Minimal, Reproducible Example".
回答(1 个)
James Penrod
2019-8-29
1 个评论
Edric Ellis
2019-8-30
Glad you got it sorted (ah, the value of the "Minimal, Reproducible Example"!). As you have found out, global variables are not synchronized from client to workers, or across workers.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Parallel and Cloud 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!