[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Condor-users] Possible solution: running M-files on Windows Condor Pool



Thanks for posting this.
-Ian

Smith, Ian wrote:
As promised some findings on how to run M-files using Matlab under Condor
on Windows.
The most obvious way would seem to be to get Condor to run something like
this:

%MATLABEXE% -logfile output.log -nodesktop -nosplash -nojvm  < myscript.m

(where %MATLABEXE% is the location of the main Matlab executable). This
seems to work under UNIX  but when using it under Windows the interpreter
seems to wait for ever and never seems to execute any of the commands
in the script (you can see that the interpreter does actually start by looking
at the FlexLM log where you can see that a license is checked out by the
account used to run Condor jobs). The way around this is to use
%MATLABEXE% -logfile output.log -nodesktop -nosplash -nojvm  -r myscript

Note the lack of a ".m" extension on the M-file - this seems to be assumed by
Matlab and this will fail if you use myscript.m
This despite all of the command line arguments this >still< pops up a cmd.exe
window. There has been some discussion over whether this causes a fatal
error when run under Condor but I can only say that under Condor 7.0.2 it
does not - it works fine. So problem solved ??? Not by a long way. When this is run under Condor, the job finishes straight away without the M-file seemingly being executed.
The reason for this is - which is certainly not obvious - is that the Matlab
interpreter *does not block*. In other works the cmd.exe window runs
concurrently with whatever kicked it off. You can think of this as similar
to a fork/exec in UNIX. Since Condor does not wait around for Matlab
to complete it will terminate the process straight away so that the job
never runs for any appreciable amount of time.
The key to getting things to work is to start the Matlab interpreter from
a .bat file and have the .bat file wait until the interpreter has finished.
There are a number of ways of doing this e.g.

a/  Have the .bat file sleep for a while so hopefully the interpreter has
     finished (not exactly bullet proof).

b/ Wait for a file created by the M-file to signal completion (bit messy -
    also users have to remember to put this in their code).

c/ Loop around waiting until the MATLAB process has gone away.

The last one is the one is probably the most elegant and the one I went
for. A sample .bat file is given below:


---------------------- sample .bat file ----------------------------------------------------------
set SCRIPT=%1
set MATLABEXE=c:\matlab2009\bin\matlab
set MATLAB=c:\matlab2009

rem
rem make sure the Condor execute dir is used for temporary files
rem

set TMP=%CD%
set TEMP=%CD%
set USERPROFILE=%CD%

rem
rem set PATH so that MATLAB can locate cmd.exe
rem

set PATH=c:\winnt\system32

rem
rem run the script  - CONCURRENTLY !
rem
%MATLABEXE% -logfile output.log -nodesktop -nosplash -nojvm -r %SCRIPT%

rem
rem loop (possibly infinitely !!!) until the MATLAB process disappears
rem

:lookagain
  rem possible race hazard it we don't sleep for a bit first
sleep 1 rem rem check for the existence of the MATLAB process using pslist
  rem (pslist implicity sets errorlevel, 1 indicates process absent)
  rem

  pslist MATLAB
  if NOT ERRORLEVEL 1 goto lookagain

---------------------- end sample .bat file ----------------------------------------------------------

Note that the M-file >must< contain a quit; statement at the end or this
will loop forever (or more likely until the job gets evicted).
There are a few other subtleties. Matlab will try to write files under c:\documents and settings\....
which isn't writeable by the account Condor jobs run under (if it is then that's a big
security hole !). This will cause a fatal error. Setting the environment
variables:

set TMP=%CD%
set TEMP=%CD%
set USERPROFILE=%CD%

will make Matlab use the scratch Condor execute directory for temporary
files. Any writable directory would of course do but by using the execute
dir, Condor will delete the files on completetion and you won't need to rely on
condor_preen to clean up the left overs.

Things should now work but of course if you have only a limited
number of Matlab licenses then you may need to ensure that enough
free licenses are available to run the job(s).

One of the main reasons I've looked at this is as a way of allowing
users to create standalone executables by building them on
the pool. This way they don't have the hassle of building them
on their own desktop and uploading them each time (of course
they don't actually need Windows on their desktop either which
is a bonus to many).
The easiest way of doing this one would think would just be to
create a M-file with the compiler command in it e.g.

mcc -mv userscript.m;
quit;



If you try using this you will probably find that the job never reaches completion. The reason is that Matlab will prompt for which compiler to use and therefore
in batch mode it wait forever.

To get around this ensure that a file containing the compiler settings gets
sent as an input file with the job. It's easy to create this file as Matlab
does it for you. Run a Matlab job on the desktop and look in

Application Data\Mathworks\MATLAB\R2009a

under the current working dir. The file compopts.bat contains the compiler
options. You will probably need to set %MATLAB% as I've done in
the .bat file above. This .bat file is run by Matlab so you don't need to run
it from your own .bat file.

Hope this helps - any comments appreciated.

regards,

-ian.

DISCLAIMER: this works for me using Condor 7.0.2, Win XP SP3 and Matlab R2009a
but I can't guarantee it works on other setups.









_______________________________________________
Condor-users mailing list
To unsubscribe, send a message to condor-users-request@xxxxxxxxxxx with a
subject: Unsubscribe
You can also unsubscribe by visiting
https://lists.cs.wisc.edu/mailman/listinfo/condor-users

The archives can be found at:
https://lists.cs.wisc.edu/archive/condor-users/

--
Ian Cottam
Information Systems Manager
Manchester Interdisciplinary Biocentre &
School of Materials &
School of Chemical Engineering and Analytical Science (Room C24)
The John Garside Building (Room G.002)
The University of Manchester
e: ian.cottam@xxxxxxxxxxxxxxxx
t: 0161 306 5198
m: 07856 849831
http://personalpages.manchester.ac.uk/staff/Ian.Cottam
[Giving a talk in MIB? Upload it: http://ic.mib.man.ac.uk/mibtheatre.php]