Running long simulations in MATLAB on a UNIX system
This procedure describes a method for running long simulations in MATLAB on a UNIX system. This method allows you to start your simulation code at a given time and lower the CPU priority of your simulation in order to play nicely with users. Since the simulation is run in the background, one can login and logout in order to periodically monitor the simulation status. The following example is contained here.
In your matlab directory create a text file called ‘startup.x’ that contains the following lines:
where ‘program’ is the name of the .m file containing your simulation code. If you have additional simulation codes to run, list them all before the ‘quit’.
In your matlab directory create a text file (shell script) named ‘job’ that contains the following lines:
mv startup.x startup.m
nice matlab > out.txt 2>&1
mv startup.m startup.x
Explanation: We begin by renaming the startup.x file to startup.m. When MATLAB launches, it automatically looks for a file called startup.m and immediately executes it. This script dumps anything that normally goes to the screen to the file called ‘out.txt’. Periodic messaging in your program allows you to trace execution by simply examining ‘out.txt’ with the command ‘tail -f out.txt’. The UNIX nice command assigns you a lower CPU priority (if there are no other users, nice will have no impact). Finally, we rename startup.m to startup.x. The whole point of startup.x is so that when launch MATLAB on another occasion, we don’t start your simulation over!
To get this going simply type at the UNIX command prompt:
at now job
Then logoff. You can verify/monitor CPU time from any terminal with the UNIX command ‘top’. Hint: if you type
at 0200 myjob
your job will be put in the crontab and will execute starting at 2am.