Presentation is loading. Please wait.

Presentation is loading. Please wait.

C ENTER FOR I NTEGRATED R ESEARCH C OMPUTING MATLAB

Similar presentations


Presentation on theme: "C ENTER FOR I NTEGRATED R ESEARCH C OMPUTING MATLAB"— Presentation transcript:

1 C ENTER FOR I NTEGRATED R ESEARCH C OMPUTING MATLAB http://info.circ.rochester.edu/Summer_School_Workshops/Matlab.html

2 Outline Part I – Interacting with Matlab Running Matlab interactively from the command line Submitting batch jobs to Matlab Matlab scripts, functions, paths. Accessing the GUI environment Part II – Speeding up Matlab Computations 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 --pty matlab –nodesktop

4 Submitting Batch Jobs sbatch matlab.slurm nprimes=0; primes=[]; for i=2:100 if (all(mod(i,primes(1:nprimes)) ~= 0)) nprimes=nprimes+1; primes(nprimes)=i; end primes example1.m #!/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 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; \ 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 BlueHive custer. 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 --pty matlab -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.


Download ppt "C ENTER FOR I NTEGRATED R ESEARCH C OMPUTING MATLAB"

Similar presentations


Ads by Google