Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: How to adapt code so it runs in parfor
Replies: 2   Last Post: Jun 19, 2012 8:55 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Paddy Carter

Posts: 8
Registered: 10/21/10
How to adapt code so it runs in parfor
Posted: Jun 18, 2012 11:59 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Apologies if what follows is poorly expressed, I am a novice.

Preamble:

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 am using a "relaxation algorithm" that somebody else has written to solve the equations and compute the paths of the relevant variables: http://ideas.repec.org/p/eth/wpswif/04-35.html

In this algorithm, parameters in the equations are global variables.

The parameters which I wish to sweep over different combinations of, are global variables (these are my additions, but I think they also need to be globals).

When I try to use parfor, I get transparency violation errors, I think because I am trying to declare global variables within the loop.

I know that parfor can be used to run multiple simulations, sweeping over parameter values, but all the examples I have seen use Simulink, for example:

http://blogs.mathworks.com/seth/2010/10/17/parallel-computing-with-simulink-running-thousands-of-simulations/

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



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.