MATLAB is a high-level language and interactive environment for numerical computation, visualization, and programming. Using MATLAB, you can analyze data, develop algorithms, and create models and applications. The language, tools, and built-in math functions enable you to explore multiple approaches and reach a solution faster than with spreadsheets or traditional programming languages, such as C/C++ or Java™.
Before using Matlab, you should check if required environment variables are properly set. If they are not, set them following these steps:
test@login01:~$ salloc salloc: Granted job allocation 391632 test@node10:~$ test@node010:~# module load MATLAB/2017a test@node010:~# module list Currently Loaded Modules: 1) Java/1.8.0_121 2) MATLAB/2017a
Fig 1. Matlab runtime modifiers
| -help | Help | Shows Matlab help |
| -e | Display environment variables |
Display ALL environment variables. If the status return is not 0, some corrective actions may be needed. Matlab is not run. |
| -n | Display diagnostics |
Display environment variables, libraries, arguments and other diagnostic information to the standard output. Matlab is not run |
| -arch | Architecture request | Start Matlab assuming processor architecture arch. |
| -nodisplay | Disable X | Do not display any X command. Matlab's JVM is started |
| -nojvm | Disable Matlab JVM | Do not start Matlab's JAva virtual machine. Any Matlab extension depending on JVM will not run |
| -r <file.m> | Run file inmediately | Start Matlab and run file.m inmediately after |
| -logfile file.log | Send output to file | Make a copy of all output to file.log. This include crash reports. |
To send Matlab jobs in the background, a combination of Matlab modifiers and SGE options will be used. In the next steps we'll cover how to send a Matlab job to a SGE queue:
1. Write your matlab source in a file with .m extension, the next is named as 'example.m'
x = [1 2 3 4];
fprintf('Example number = %i\n', x)
2. Write a submit job script named as 'matlab-job.sh'. Place it wherever on your home directory, and specify here the desired options.
#!/bin/bash #SBATCH -J prova_uname10 #SBATCH -p short #SBATCH -N 1 #SBATCH -n 32 #SBATCH --chdir=/home/test/Matlab #SBATCH --time=2:00 #SBATCH -o slurm.%N.%J.%u.out # STDOUT #SBATCH -e slurm.%N.%J.%u.err # STDERR module load MATLAB/2017a matlab -nojvm -nodisplay -r "example;quit;"
|
–workdir |
Change error and output to the working directory |
The output file and the error file will be placed in the directory from which 'sbatch' is called. |
|
-e <path>/<filename> |
Redirect error file |
The system will create the given file on the path specified and will redirect the job's error file here. If name is not specified, default name will apply. |
|
-o <path>/<filename> |
Redirect output file |
The system will create the given file on the path specified and will redirect the job's output file here. If name is not specified, default name will apply. |
| -r | Run inmediately | Start Matlab and run file.m inmediately after |
|
-nojvm |
JVM disabled |
Does not start the JVM software and uses current window. Graphics will not work without the JVM. |
|
-nodisplay |
Display disabled |
Also starts the JVM and does not start the desktop in addition it also ignores Commands and the DISPLAY environment variable in LINUX. |
3. Submit your matlab job:
test@login01:~/Matlab$ sbatch matlab.sh Submitted batch job 1100
4. Monitor the job status:
test@login01:~/Matlab$ squeue
JOBID PARTITION NAME USER ST TIME NODES NODELIST(REASON)
1101 short matlab_t test R 0:03 1 node001
5. When the job is finished, the output files are created in your Current Working Directory:
0 -rw-r--r-- 1 test info_users 0 Jan 18 20:54 slurm.node001.1101.test.err 1 -rw-r--r-- 1 test info_users 405 Jan 18 20:54 slurm.node001.1101.test.out
6. The standard output results of Matlab, file with stderr is empty(job without errors):
test@login01:~/Matlab$ tail -f slurm.node001.1101.test.out
March 27, 2017
For online documentation, see http://www.mathworks.com/support
For product information, visit www.mathworks.com.
Example number = 1
Example number = 2
Example number = 3
Example number = 4