Apologies if what follows is poorly expressed, I am a novice.
I have loop that takes weeks to run that I want to convert to parfor so that I can run it on our computing cluster to save time.
This loops sweeps over combinations of parameters, and each iteration solves a bunch of differential equations and computes a scalar reward function. I am looking for the parameters that maximize this reward, via a brute-force search. The iterations are independent.
I do not think the relaxation algorithm I am using could be converted into a Simulink routine (at least, not by me - I know nothing about Simulink), so my question is, does anybody know how I should go about what I am trying to do, running multiple simulations with different paramterizations, without running into trouble with trying to change global variables each iteration?
from the example above:
parfor i = 1:n^2 assignin('base','thetaX0',thetaMat(i)); assignin('base','thetadotX0',thetadotMat(i)); simOut = sim('ForcedDampedPendulum','StopTime','100'); y = simOut.get('yout'); map(i)=y(end); end
I think "ForcedDampedPendulum" is the Simulink routine that the author has written which is being run for each i, and the "assignin" lines are where the parameters are changes for each i ... can I use this approach without using a Simulink routine per se?
I don't think it's worthwhile replicating chunks of my code, but the basic logic is that besides setting a large set of global variables that do not change outside the loop, inside the loop each iteration includes these lines:
parfor index=1:N beta=betarange(index); gamma=gammrange(index); tau=taurange(index) ** run algorithm ** ** compute reward ** end
these parameters are part of the equations that the algorithm solves, so if I understand correctly need to be global so that the various functions can access them (?)
help much appreciated - and please remember I will need spoon feeding - also please let me know if I have omitted important information