120 likes | 350 Views
MATLAB. C enter for I ntegrated R esearch C omputing. http: // info.circ.rochester.edu / Summer_School_Workshops / Matlab.html. Outline. Part I – Interacting with Matlab Running Matlab interactively from the command line Submitting batch jobs to Matlab
E N D
MATLAB Center for Integrated Research Computing http://info.circ.rochester.edu/Summer_School_Workshops/Matlab.html
Outline Part I – Interacting with Matlab Running Matlabinteractively from the command line Submitting batch jobs to Matlab Matlabscripts, functions, paths. Accessing the GUI environment Part II – Speeding up MatlabComputations Using the Code Profiler and the Code Analyzer Symmetric Multi-Processing with Matlab Accelerating Matlab computations with GPUs Running Matlab in distributed memory environments Part III – Mixing Matlab and Fortran/C code Compiling MEX code from C/Fortran Turning Matlab routines into C code
Running Matlab interactively from the command line module load matlab srun -t 60 --ptymatlab –nodesktop
Submitting Batch Jobs sbatchmatlab.slurm example1.m nprimes=0; primes=[]; for i=2:100 if (all(mod(i,primes(1:nprimes)) ~= 0)) nprimes=nprimes+1; primes(nprimes)=i; end end primes #!/bin/bash #SBATCH -t 60 module load matlab matlab -r "example1" matlab.slurm
Submitting Batch Jobs • sbatch matlab2.slurm • Can also use 'here files' to pass commands to matlab via standard in #!/bin/bash #SBATCH -t 60 module load matlab matlab<<EOF nprimes=0; primes=[]; for i=2:100 if (all(mod(i,primes(1:nprimes)) ~= 0)) nprimes=nprimes+1; primes(nprimes)=i; end end primes EOF matlab2.slurm
Submitting Batch Jobs • sbatch matlab3.slurm • Or you can put the entire program in quotes. • Use commas to separate lines that you want the results from • We are using the back slash \ as a line continuation character for bash. #!/bin/bash #SBATCH -t 60 module load matlab matlab -r " \ nprimes=0; \ primes=[]; \ for i=2:100; \ if (all(mod(i,primes(1:nprimes)) ~= 0)); \ nprimes=nprimes+1; \ primes(nprimes)=i; \ end; \ end; \ primes \ " matlab3.slurm
Calling Functions or Scripts not in your cwd You can use the addpath command before calling scripts or functions. #!/bin/bash #SBATCH -t 60 module load matlab matlab -r "addpath('/public/jcarrol5/matlab'); example1" /home/jcarrol5/matlab5.slurm
Exercise 1 Run the following matlab program on bluehive to approximate the value of pi. (or one of your own programs) N=1e6 x=rand(N,1) y=rand(N,1) pi_approx=sum(x.^2+y.^2 < 1)/N*4.0
Accessing the GUI features • To use Matlab's GUI you must connect through suitable environment • Both MobaXterm(Windows) and Terminal (Mac/Linux) support X11 forwarding necessary for accessing the Matlab GUI. • X2go provides a remote desktop session within the BlueHivecuster. • Why X2go? • Faster than using X11 forwarding (compresses data) • Has clients for all major operating systems • Saves your session when you are disconnected • You don’t have to restart Matlab if your network connection drops.
Running interactive jobs with X11 forwarding • Before we ran the following to launch an interactive matlab session (without the Matlab GUI) • srun -t 60 --ptymatlab -nodesktop • To use the GUI we have to use the interactive script • interactive -t 60 • matlab • There is also a 'JobLauncher' utility which you can access through the Gnome Menu Bar
Using the terminal but with GUI support • You can connect with X11 forwarding and still start matlab without a desktop • matlab -nodesktop • Figure windows will still pop up etc... • You can also make plots without a GUI using imagesc(rand(100))); print('-dpdf','-r300','fig1-batch.pdf');
Matlab Code Analyzer and Profiler Matlab has sophisticated tools for analyzing and profiling code. It will often offer suggestions on how to speed up your code.