MATLAB Building and Running Faster Matlab UNIVERSITY OF SHEFFIELD CiCS DEPARTMENT Deniz Savas & Mike Griffiths JULY.2008.

Slides:



Advertisements
Similar presentations
17 Copyright © 2005, Oracle. All rights reserved. Deploying Applications by Using Java Web Start.
Advertisements

Profiling your application with Intel VTune at NERSC
Intel® performance analyze tools Nikita Panov Idrisov Renat.
Introduction To Java Objectives For Today â Introduction To Java â The Java Platform & The (JVM) Java Virtual Machine â Core Java (API) Application Programming.
LINUX-WINDOWS INTERACTION. One software allowing interaction between Linux and Windows is WINE. Wine allows Linux users to load Windows programs while.
Lecture Roger Sutton CO331 Visual programming 15: Debugging 1.
Phones OFF Please Operating System Introduction Parminder Singh Kang Home:
Introduction to MATLAB Northeastern University: College of Computer and Information Science Co-op Preparation University (CPU) 10/22/2003.
Robert’s Rules of Matlab. Disclaimer: My usual processing flow is to use c or fortran codes linked together via tcsh scripts. I find Matlab to be really.
Chapter 10 Application Development. Chapter Goals Describe the application development process and the role of methodologies, models and tools Compare.
Installing and running COMSOL on a Windows HPCS2008(R2) cluster
COP4020 Programming Languages
Session-02. Objective In this session you will learn : What is Class Loader ? What is Byte Code Verifier? JIT & JAVA API Features of Java Java Environment.
Systems Software Operating Systems.
1 Introduction to Tool chains. 2 Tool chain for the Sitara Family (but it is true for other ARM based devices as well) A tool chain is a collection of.
Hands-On Microsoft Windows Server 2008 Chapter 1 Introduction to Windows Server 2008.
Lesson 4 Computer Software
1 ENG236: ENG236: C++ Programming Environment (2) Rocky K. C. Chang THE HONG KONG POLYTECHNIC UNIVERSITY.
Chapter 2 Build Your First Project A Step-by-Step Approach 2 Exploring Microsoft Visual Basic 6.0 Copyright © 1999 Prentice-Hall, Inc. By Carlotta Eaton.
1 Integrated Development Environment Building Your First Project (A Step-By-Step Approach)
CS413: Java Programming language Applications Applets
© 2008, Renesas Technology America, Inc., All Rights Reserved 1 Introduction Purpose  This training course provides an overview of the installation and.
Slide 1 System Software Software The term that we use for all the programs and data that we use with a computer system. Two types of software: Program.
Systems Software & Operating systems
Basics of Web Databases With the advent of Web database technology, Web pages are no longer static, but dynamic with connection to a back-end database.
Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.
1 Computing Software. Programming Style Programs that are not documented internally, while they may do what is requested, can be difficult to understand.
OS provide a user-friendly environment and manage resources of the computer system. Operating systems manage: –Processes –Memory –Storage –I/O subsystem.
Most modern operating systems incorporate these five components.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 1 Introduction to Computers and Programming.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
Tutorial 111 The Visual Studio.NET Environment The major differences between Visual Basic 6.0 and Visual Basic.NET are the latter’s support for true object-oriented.
Chapter 34 Java Technology for Active Web Documents methods used to provide continuous Web updates to browser – Server push – Active documents.
Compiled Matlab on Condor: a recipe 30 th October 2007 Clare Giacomantonio.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
Parallel Computing with Matlab CBI Lab Parallel Computing Toolbox TM An Introduction Oct. 27, 2011 By: CBI Development Team.
1 Computer Programming (ECGD2102 ) Using MATLAB Instructor: Eng. Eman Al.Swaity Lecture (1): Introduction.
Just as there are many human languages, there are many computer programming languages that can be used to develop software. Some are named after people,
Invitation to Computer Science 5 th Edition Chapter 6 An Introduction to System Software and Virtual Machine s.
Systems Software Operating Systems. What is software? Software is the term that we use for all the programs and data that we use with a computer system.
Active-HDL Interfaces Debugging C Code Course 10.
MATRIX MULTIPLY WITH DRYAD B649 Course Project Introduction.
9/2/ CS171 -Math & Computer Science Department at Emory University.
Tool Integration with Data and Computation Grid GWE - “Grid Wizard Enterprise”
Advanced Topics- Functions Introduction to MATLAB 7 Engineering 161.
Issues Autonomic operation (fault tolerance) Minimize interference to applications Hardware support for new operating systems Resource management (global.
ITC Research Computing Support Using Matlab Effectively By: Ed Hall Research Computing Support Center Phone: Φ Fax:
LOGO Development of the distributed computing system for the MPD at the NICA collider, analytical estimations Mathematical Modeling and Computational Physics.
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
1 Software. 2 What is software ► Software is the term that we use for all the programs and data on a computer system. ► Two types of software ► Program.
Matlab for Engineers Gari Clifford © Centre for Doctoral Training in Healthcare Innovation Institute of Biomedical Engineering Department of.
Copyright © 2010, SAS Institute Inc. All rights reserved. SAS ® Using the SAS Grid.
INFSO-RI Enabling Grids for E-sciencE Using of GANGA interface for Athena applications A. Zalite / PNPI.
Microsoft Office 2008 for Mac – Illustrated Unit D: Getting Started with Safari.
“Moh’d Sami” AshhabSummer 2008University of Jordan MATLAB By (Mohammed Sami) Ashhab University of Jordan Summer 2008.
Cliff Addison University of Liverpool NW-GRID Training Event 26 th January 2007 SCore MPI Taking full advantage of GigE.
Active-HDL Server Farm Course 11. All materials updated on: September 30, 2004 Outline 1.Introduction 2.Advantages 3.Requirements 4.Installation 5.Architecture.
CITA 171 Section 1 DOS/Windows Introduction. DOS Disk operating system (DOS) –Term most often associated with MS-DOS –Single-tasking operating system.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
Wednesday NI Vision Sessions
Chapter 2 Build Your First Project A Step-by-Step Approach 2 Exploring Microsoft Visual Basic 6.0 Copyright © 1999 Prentice-Hall, Inc. By Carlotta Eaton.
Using ROSSMANN to Run GOSET Studies Omar Laldin ( using materials from Jonathan Crider, Harish Suryanarayana ) Feb. 3, 2014.
Advanced Computing Facility Introduction
Spark Presentation.
Introduction to Operating System (OS)
Electronics II Physics 3620 / 6620
SPL – PS1 Introduction to C++.
Presentation transcript:

MATLAB Building and Running Faster Matlab UNIVERSITY OF SHEFFIELD CiCS DEPARTMENT Deniz Savas & Mike Griffiths JULY.2008

PART 3TOPICS Improving Performance and The Profiler Running Matlab on Iceberg Matlab Compiler

Making Matlab Use More Compute Resource Compute Cluster e.g. Iceberg Uses a scheduler e.g. Sun Grid Engine Break a matlab job in to many independent tasks –E.g. cycle of a for loop might run independently Array of matlab tasks running on compute cluster Can run 1000’s of tasks Good for –parametric sampling –Genetic algorithms –Model ensembles

Submitting a matlab job to Sun Grid Engine on Iceberg qsub mymatlabjob.sh Where mymatlabjob.sh is: #!/bin/sh #$ -cwd #$ -l h_rt=hh:mm:ss #$ -l mem=1G /usr/local/bin/matlab -nojvm -nosplash -nodisplay outputfile

Access to More Compute Resources Grids –White Rose Grid/N8 Benefits –Access to data –More compute resources –Share applications with collaboration partners Example lensless microscopy project at Sheffield

Final Remarks Task arrays are a powerful method utilising large pools of compute resources e.g. clusters Mainly use batch submission mode not interactive use of matlab Challenging to utilise compute resource outside adminstrative domain –Difficulty alleviated using geodise toolkit Parallel computing toolbox enables researchers to develop interactive matlab applications able to exploit a pool of compute resources

Practice session 9 Open the folder iceberg_sgearray Submit the beats job as an SGE task array Open an interactive session using qsh and use the command –qsub beats.sh

Improving Performance of Matlab Using profiler – to check for bottlenecks Built in functions Vectorisation Pre loading Multi core

Built In Functions Some matlab routines are *.m files, others are compiled into matlab (built-in) and are much faster. Try to use built-ins where possible. Use type functionname to see if a function is a built-in.

Vectorisation Matlab scripts can be written using fortran/C-style "for" loops, but to make the most of matlab's abilities you should try whenever possible to treat matrices as a single entity rather than a bundle of elements. Vectorisation functions ▬ arrayfun ▬ repmat ▬ bsxfun (Binary Singleton eXpansion FUNction)

Vectorisation Example 1: for i = 1:100 for j = 1:100 r(i,j) = sqrt(i^2+j^2); end [i,j]=meshgrid(1:100,1:100); r = sqrt(i.^2+j.^2); Vectorised this becomes

Vectorisation Example 2: Vectorise the following, where elements depend on previous ones n=1000; x(1)=1; for j=1:n-1, x(j+1) = x(j) + n - j; end n=1000; x(1)=1; j=1:n-1; x(j+1) = n - j; cumsum(x); Vectorised this becomes

Monitoring Memory Usage with Matlab Matlab has the ability to increase the size of a matrix on demand. If you know the maximum size of a matrix beforehand, it's worth creating the matrix with this size initially rather than making the matrix grow incrementally. Using cell and zeros function Speed-up factors of 500 are possible using this method. Common problems include deframgementation of matlab memory Use pack reorganises memory so minimal space used Try different memory managers ▬ cache (default), compact, fast and debug ( ▬ Specify using –memmgr switch on matlab command line ▬ E.g. matlab –memmgr debug ▬ matlab –memmgr fast Monitor memory utilisation within matlab by using ▬ feature memstats When submitting task to iceberg specify memory requirements e.g. ▬ qsh –l mem=2G etc… ▬ qsub –l mem=2G etc… (or make sure #$ -l mem=2G is at the head of the script file) pload function in parallel matlab loads data onto nodes

Using Multicore Can yield improved performance Select File Preferences From preferences menu select ▬ General->Multithreading Tick enable multithreaded computation Use maxNumCompThreads to setthe number of threads ▬ N = maxNumCompThreads returns the current maximum number of computational threads N. ▬ LASTN = maxNumCompThreads(N) sets the maximum number of computational threads to N, and returns the previous maximum number of computational threads, LASTN.

The profiler This facility is enhanced recently at version 6.x, which enables the user to investigate the time take taken to run a matlab task or a script. The profiling reports help us to improve the efficiency of the code by pin-pointing the parts of the code that takes most of the time. Type profiler to start the profiler up and In the run this code field enter the name of your script file, or keep that field clear and just click on Start profiling followed by running your task as usual from the Matlab Command Window and when finish click on the stop profiling icon. Clicking on the profiling summary icon will display a profile summary which can be expanded by clicking on the routine names on the list.

Practice Session 9 Profiling ▬ In the folder vectorize run the scripts genar.m and genarray.m. Compare the performance and compare the scripts. ▬ See the file named findrt.m in the examples directory - sub directory: root ▬ Study this script and run it under the control of Matlab debugger. ▬ Run the scripts animpeaks1.m and animpeaks2.m and compare using the profiler

Using MEX to Build Faster Applications Motivation ▬ Matlab excellent for prototyping ▬ For raw speed not as good Set up MEX ▬ mex -setup Compile c routines using mex ▬ Simple examples Basics of Mex programming ▬ Need to be a C programmer

Example - timestwo Example to multiply a scalar by 2, timestwo.c Compile the mex file ▬ mex timestwo.c Run the mex file takes as input one scalar ▬ timestwo(3)

Example xtimesy Example multiply a matrix by a scalar Compile ▬ mex xtimesy.c Run the example the matlab function takes as input a scalar and a matrix ▬ v1=rand(2,2) ▬ v2=xtimesy(5.0,v1)

Example demo.cpp Take as input two matrices ▬ Add a scalar fixed scalar to one (not input) ▬ Take the square of the second matrix ▬ Display each of the elements of the first matrix Compile ▬ mex demo.cpp Run the demo ▬ v1=rand(2,2) ▬ v2=rand(3,3) ▬ [vo1,vo2]=demo(v1,v2)

What does Matlab Compiler do ? Compiles ‘builds’ a Matlab application into a stand alone software. It can be used to ; ▬ Package Matlab applications as a stand-alone executable (.exe) or dynamic link library (.dll or.so ) ▬ Distribute these applications as independent ( free to use) software that does not require installing Matlab at the destination computer. ▬ Incorporate Matlab developed code into programs written in other languages. ▬ Internally, Matlab Compiler makes use of the MEX ‘external-interface’ features of Matlab that are used for linking external Fortran and C programs with Matlab.

How do I use the Matlab Compiler ? COMMAND LINE: Matlab compiler can be accessed by using the mcc ( Matlab Compiler Command ) from the Matlab command line. GUI : It can also be used in a GUI environment by using the deployment tool. Via Desktop  Deployment Tool or by typing deploytool at the command line. GUI method is recommended as it is intuitive and easier to use. The GUI method, invokes the mcc command-line methods in the background as and when it is needed.

Compiler Deployment Terminology: Matlab Compiler (mcc) : Matlab utility that automatically converts a Matlab script (.m file ) into a C/C++ source file (.c /.c++ /.cpp ) Compiler : A platform dependent C/C++ compiler compatible with Matlab, such as Lahey, g++, Intel or Microsoft compilers. Building an Application: The act of generating a stand-alone (.exe) or Dynamic Link Library (.dll or.so ) from one or more.m or.c or.c++ source files. Deployment : Running the built application on another machine that uses the same platform ( ie. Windows/Linux/Mac 64bit/32bit ) MCR : Matlab Compiler Runtime. Software components needed to run mcc generated software. This is independent of your own software but dependent on platform.

Overview Your Matlab Script (.m) The Matlab Compiler Stand Alone executable (.exe) Shared Library (.dll or.so )

How does the Matlab Compiler Work

Tasks performed internally by the Matlab Compiler Parse the command line Performs dependency analysis to create a CTF ( Component Technology File Archive ) Check to ensure all dependencies are satisfied Auto generates C/C++ code by translating the users Matlab script file(s). Auto generates target specific wrapper code files Passes all files that needs to be compiled ‘including any MEX files that are provided’ to the native compiler. Generates the required software item ( i.e..exe,.dll,.so,.jar file ) Note that most of the internal Matlab functions are not translated but simply referenced from the Matlab Compiler Runtime Library (MCR) (in the form of.DLL or.so). That is why MCR is needed.

Practice – using the matlab compiler Using mex compile and run the example c programs ▬ xtimesy.c ▬ demo.cpp ▬ timestwo.c The examples are in the mex folder of the matlab_examples Adapt the program timestwo.c so that it adds two scalar values