1 / 12

MATLAB

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

talisa
Download Presentation

MATLAB

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. MATLAB Center for Integrated Research Computing http://info.circ.rochester.edu/Summer_School_Workshops/Matlab.html

  2. 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

  3. Running Matlab interactively from the command line module load matlab srun -t 60 --ptymatlab –nodesktop

  4. 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

  5. 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

  6. 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

  7. 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

  8. 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

  9. 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.

  10. 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

  11. 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');

  12. 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.

More Related