![]() | ||
|
Matlab
General
Manual
Essentials
Resource specifics
Matlab on Neolith Note: In order to access Matlab you must belong the Unix group "liu" on Neolith. We are only allowed to grant access to Matlab for users at Linköping University. You can check the group memberships using the command "groups" on Neolith. If you are not in the "liu" group even though you are a Linköping University user, send an email to support@nsc.liu.se and ask to be added to the LiU group to run Matlab.
First example Step 1: Create a submit script. In this example we use a script named submit.sh with the following content: #!/bin/bash #SBATCH -N 1 #SBATCH -t 00:10:00 # This is the working directory that Matlab will use. # We run matlab in the directory /scratch/local and copy the # outputfile to the submit directory afterwards. We do so in order for # any large temporary files to be kept on the node local file system. TMPDIR=/scratch/local # The name of the Matlab script (without .m) job=xxxx # Save location of job directory (the batch job normally starts in the # same directory where you ran the submit script). JOBDIR=$(pwd) # Use $TMPDIR as working directory cd $TMPDIR cp $JOBDIR/$job.m . # Start Matlab and run the job file (which will produce a $job.out file in # the current working directory) matlab -r "$job;exit" # Move result file to the directory where the Matlab script is located. mv $job.out $JOBDIR/. # # End of script # Step 2: Create a simple Matlab script; create the file xxxx.m with the following content:
%
% Sum average of N random numbers
%
format long
N = 1e7;
R = rand([N,1]);
S = sum(R)/N;
fid=fopen('xxxx.out','w');
fprintf(fid,'A small Matlab example\n');
fprintf(fid,'Sum average = %16.12f\n',S);
fclose(fid);
%
% End
%
Step 3: Submit the job: module add matlab sbatch submit.shWhen the job has completed (use e.g "squeue -u $USER" to check status of job), there should be a file xxxx.out in the same directory as the Matlab script. Example output: % cat xxxx.out A small Matlab example Sum average = 0.500000294109
Second example Step 1: Create a submit script. In this example we use a script named parallel_submit.sh and assume that no large temporary files are created by the job and therefore run in the submit directory. The submit script have the following content:
#!/bin/bash
#
# Use 2 nodes, i.e. 16 cores.
#SBATCH -N 2
#
# 10 minutes time limit
#SBATCH -t 00:10:00
# Suitable options to Matlab is "-nodesktop" to avaoid the javadesktop,
# "-nospalsh" to avoid the startup splash screen and "-singleCompThread"
# to stop Matlab from multi threading.
# The last option is important when running more than one instance of
# Matlab on a node. Performance is severely decreased otherwise.
MATLAB='matlab -nodesktop -nodisplay -singleCompThread'
# The name of the Matlab script (without .m)
job=pppp
# Start Matlab and run the job file which will produce a $job_*.out
# and $job_*.log file for each of the 16 independent runs.
# Note the explicit "exit" to exit Matlab.
for i in $(seq 1 16);do
srun -N1 -n1 --exclusive ${MATLAB} -r "${job}(${i});exit" > ${job}_${i}.log &
done
wait
#
# End of script
#
Step 2: Create a simple Matlab function; create the file pppp.m with the following content:
function S = pppp(x)
%
% Sum average of N random numbers
%
format long
s = RandStream.create('mt19937ar','seed',x);
N = 1e7;
R = rand(s, N, 1);
S = sum(R)/N;
filename = ['pppp_', num2str(x), '.out'];
fid=fopen(filename,'w');
fprintf(fid,'A small Matlab example\n');
fprintf(fid,'Run with the input: %s\n', num2str(x));
fprintf(fid,'Sum average = %16.12f\n',S);
fclose(fid);
%
% End
%
Step 3: Submit the job: module add matlab sbatch parallel_submit.shWhen the job has completed (use e.g "squeue -u $USER" to check status of job), there should be 16 files pppp_*.out and 16 files pppp_*.log in the same directory as the Matlab script. Example output: % cat pppp_13.out A small Matlab example Run with the input: 13 Sum average = 0.499994051713and
% cat pppp_13.log
Warning: No window system found. Java option 'MWT' ignored
< M A T L A B (R) >
Copyright 1984-2009 The MathWorks, Inc.
Version 7.9.0.529 (R2009b) 64-bit (glnxa64)
August 12, 2009
To get started, type one of these: helpwin, helpdesk, or demo.
For product information, visit www.mathworks.com.
|