calcoloscientifico:userguide:matlab:serial
MATLAB serial job
This approach has to be used if you do not need any interactivity and you do use MATLAB on the HPC cluster. In this case MATLAB does not need to be installed on your local computer.
Example of execution of a MATLAB serial program
cp -p /hpc/share/samples/matlab/pi_greco.m .
Script pi_greco.m
:
- pi_greco.m
tic N_int=100; N_int_0=1e2; N_int_f=1e7; passo=ceil((N_int_f-N_int_0)/N_int); res=zeros(N_int,1); i=1; for N=N_int_0:passo:N_int_f Z=rand(2,N); res(i)=sum((Z(1,:)-0.5).^2+(Z(2,:)-0.5).^2<0.5^2)/(N*0.5^2); i=i+1; end disp(res(end)) toc
Once you have written your MATLAB code you need to supply a shell script (that is a file with extension .sh
) where you specify the resources you need to run your MATLAB code on the HPC servers.
See this small introduction on resource management
See the example below:
Script my_matlab_script.sh
:
- my_matlab_script.sh
#!/bin/sh #SBATCH --job-name=matlab #SBATCH --output=%x.o%j #SBATCH --error=%x.e%j #SBATCH --nodes=1 #SBATCH --ntasks-per-node=1 #SBATCH --partition=vrt #SBATCH --mem=8G #SBATCH --time=00:30:00 #SBATCH --account=<account> module load matlab/R2022a matlab -nodisplay -r pi_greco
To submit the shell script my_matlab_script.sh
and start the computation, type:
sbatch my_matlab_script.sh
add a section for retrieving and display the output
calcoloscientifico/userguide/matlab/serial.txt · Ultima modifica: 30/06/2022 12:53 da fabio.spataro