Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Modifying Matlab files during the execution of batch jobs

Subject: Modifying Matlab files during the execution of batch jobs

From: PLH

Date: 4 Feb, 2011 09:22:03

Message: 1 of 6

Hello all,

Lately, I've had Matlab crash quite a few times during some background jobs I've been running, and I'm trying to find the problem (if, indeed, it is a Matlab problem and not some other process). One thing I wanted to check is the following:

When Matlab executes a batch command like

job = batch('myscript','matlabpool',2)

does it copy myscript, and all the user-created scripts called within myscript, into memory and run from THOSE copies? Should I expect errors if I later alter myscript, or anyone of the scripts called within it, whilst the batch job is still running?

I know Matlab code isn't compiled at runtime, and I'm unsure as what the interpreter actually does, and what files are safe to modify...

Any help is, as always, greatly appreciated,

PLH

Subject: Modifying Matlab files during the execution of batch jobs

From: Rune Allnor

Date: 4 Feb, 2011 09:45:04

Message: 2 of 6

On Feb 4, 10:22 am, "PLH " <paulhalky...@googlemail.com> wrote:
> Hello all,
>
> Lately, I've had Matlab crash quite a few times during some background jobs I've been running, and I'm trying to find the problem (if, indeed, it is a Matlab problem and not some other process).  One thing I wanted to check is the following:
>
> When Matlab executes a batch command like
>
> job = batch('myscript','matlabpool',2)
>
> does it copy myscript, and all the user-created scripts called within myscript, into memory and run from THOSE copies?  Should I expect errors if I later alter myscript, or anyone of the scripts called within it, whilst the batch job is still running?
>
> I know Matlab code isn't compiled at runtime, and I'm unsure as what the interpreter actually does, and what files are safe to modify...

To be totally safe - don't modify files used by the script
while the script is running. There are a number of cases to
consider

1) You modify the file MyFile.m while matlab executes MyFile.

In this case one might assume that the interpreter loads and
parses the file once at the start, and then is oblivious to
any changes of MyFile.m until the function has completed.

2) MyFile.m calls SomeFunction.m, and you change SomeFunction

This one is tricky. Does the intrepreter check for time stamps
on SomeFunction each time it calls it? It may or it may not.
If it does, it might find that the file has changed, and load
the new version of the file in the middle of the MyFunction run.

3) Change something during a parallel run of MyFunction.m.

If matlab spawns several processes, you might find that the
interpreter checks or loads the files at the start of the
new process. If that's the case, it will load whatever is
stored on the disk at the time the process is spawned. In
which case you are in trouble.

So to make *sure* this is not the problem: Don't modify
any files during a run.

Rune

Subject: Modifying Matlab files during the execution of batch jobs

From: Edric M Ellis

Date: 7 Feb, 2011 08:16:38

Message: 3 of 6

"PLH " <paulhalkyard@googlemail.com> writes:

> Lately, I've had Matlab crash quite a few times during some background
> jobs I've been running, and I'm trying to find the problem (if,
> indeed, it is a Matlab problem and not some other process). One thing
> I wanted to check is the following:
>
> When Matlab executes a batch command like
>
> job = batch('myscript','matlabpool',2)
>
> does it copy myscript, and all the user-created scripts called within
> myscript, into memory and run from THOSE copies?

This is roughly what I would expect the behaviour to appear to be;
however I wouldn't like to rely on it. To rule this out, you could add
"myscript" and dependencies as FileDependencies to your batch job, see

http://www.mathworks.com/help/toolbox/distcomp/batch.html

Note that if you specify a directory, that is recursively added to the
job. These files are copied for the workers to use.

Cheers,

Edric.

Subject: Modifying Matlab files during the execution of batch jobs

From: PLH

Date: 7 Feb, 2011 09:06:03

Message: 4 of 6

I now copy my batch scripts to a different location when I run them, so I can't inadvertently tinker with them during execution; this seems to have fixed the problem I was having.

I will also have a play with the filedependencies to make my implementation less sloppy.

Many thanks to both of you for your help,

PLH.

Subject: Modifying Matlab files during the execution of batch jobs

From: Michiel

Date: 28 Jul, 2012 13:20:14

Message: 5 of 6

"PLH" wrote in message <iioclr$s9n$1@fred.mathworks.com>...
> I now copy my batch scripts to a different location when I run them, so I can't inadvertently tinker with them during execution; this seems to have fixed the problem I was having.
>
> I will also have a play with the filedependencies to make my implementation less sloppy.
>
> Many thanks to both of you for your help,
>
> PLH.

If this is of any help:

I have run several times multiple sessions of Matlab, using the same files for each session in order to obtain more results in less time. This is how I proceed:

1) I set the input data in my input file and start the calculus in the first session.

2) I change the input data in the input file and start a second calculus in the second session, and so on.

Since the file containing the inputdata is the same for each session, I modify it everytime. That is, the final version of the file corresponds to the one of the last session. However, the first session does not take that values, but rather the values I set for the first session.

Conclusion: according to my experience, modifying a file during a calculus does not change the results, it takes the file as it was just before executing the file.

Best regards,

Michiel

Subject: Modifying Matlab files during the execution of batch jobs

From: Michiel

Date: 28 Jul, 2012 13:21:13

Message: 6 of 6

"PLH" wrote in message <iioclr$s9n$1@fred.mathworks.com>...
> I now copy my batch scripts to a different location when I run them, so I can't inadvertently tinker with them during execution; this seems to have fixed the problem I was having.
>
> I will also have a play with the filedependencies to make my implementation less sloppy.
>
> Many thanks to both of you for your help,
>
> PLH.

If this is of any help:

I have run several times multiple sessions of Matlab, using the same files for each session in order to obtain more results in less time. This is how I proceed:

1) I set the input data in my input file and start the calculus in the first session.

2) I change the input data in the input file and start a second calculus in the second session, and so on.

Since the file containing the inputdata is the same for each session, I modify it everytime. That is, the final version of the file corresponds to the one of the last session. However, the first session does not take that values, but rather the values I set for the first session.

Conclusion: according to my experience, modifying a file during a calculus does not change the results, it takes the file as it was just before executing the file.

Best regards,

Michiel

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us