The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM 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.


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:

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:

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
simOut = sim('ForcedDampedPendulum','StopTime','100');
y = simOut.get('yout');

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
** run algorithm **
** compute reward **

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]

© The Math Forum at NCTM 1994-2017. All Rights Reserved.