MATLAB Tips for Simulation Parinya Sanguansat. Version Selection  X86  Faster  Smaller  X64  Slower  Bigger.

Slides:



Advertisements
Similar presentations
Introduction to Matlab
Advertisements

Introduction to Matlab Workshop Matthew Johnson, Economics October 17, /13/20151.
MATLAB – What is it? Computing environment / programming language Tool for manipulating matrices Many applications, you just need to get some numbers in.
Maths for Computer Graphics
Stanford University CS243 Winter 2006 Wei Li 1 Loop Transformations and Locality.
Introduction to Matlab By: Dr. Maher O. EL-Ghossain.
1 Systems of Linear Equations Iterative Methods. 2 B. Iterative Methods 1.Jacobi method and Gauss Seidel 2.Relaxation method for iterative methods.
Lecture 7 Sept 17 Goals: Complete Chapter 4 Chapters 5 and 6.
1 11/27/06CS150 Introduction to Computer Science 1 Searching Arrays.
Array HTML version. Declaration in Main Program 2 ways to declare a real array A of rank N : DIMENSION A( start_index1 : end_index1, …, start_indexN :
Computer Science 1620 Multi-Dimensional Arrays. we used arrays to store a set of data of the same type e.g. store the assignment grades for a particular.
Science Advisory Committee Meeting - 20 September 3, 2010 Stanford University 1 04_Parallel Processing Parallel Processing Majid AlMeshari John W. Conklin.
Matlab Intro. Outline Matlab introduction Matlab elements Types Variables Matrices.
A Presentation on the Implementation of Decision Trees in Matlab
18.337: Image Median Filter Rafael Palacios Aeronautics and Astronautics department. Visiting professor (IIT-Institute for Research in Technology, University.
MATLAB Programming Session
5.3 Machine-Independent Compiler Features
1 © 2012 The MathWorks, Inc. Speeding up MATLAB Applications.
CIS 601 MATLAB First Impressions. MATLAB This introduction will give Some basic ideas Main advantages and drawbacks compared to other languages.
General Computer Science for Engineers CISC 106 Lecture 07 James Atlas Computer and Information Sciences 06/29/2009.
Multi-Dimensional Arrays
REVIEW 2 Exam History of Computers 1. CPU stands for _______________________. a. Counter productive units b. Central processing unit c. Copper.
1 Tips for solving Project 1 Reactor SO 3 SO 2 +O 2.
ELG 3120 Signal and System Analysis 1 Introduction to MATLAB TAs Wei Zhang Ozgur Ekici (Section A)(Section B) ELG 3120 Lab Tutorial 1.
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
Section 3.6 – Solving Systems Using Matrices
IT253: Computer Organization Lecture 3: Memory and Bit Operations Tonga Institute of Higher Education.
Matlab tutorial course Lesson 6: Programming tips
Lecture 28: Mathematical Insight and Engineering.
Introduction to MATLAB Session 3 Simopekka Vänskä, THL Department of Mathematics and Statistics University of Helsinki 2011.
ARRAYS 1 Week 2. Data Structures  Data structure  A particular way of storing and organising data in a computer so that it can be used efficiently 
1 Chapter 3 Arrays (2) 1. Array Referencing 2. Common Operations 1. Slicing 2. Diminution 3. Augmentation 3. List of Commonly Used Built-in Functions 1.
Arrays 1 Multiple values per variable. Why arrays? Can you collect one value from the user? How about two? Twenty? Two hundred? How about… I need to collect.
Matlab Programming for Engineers Dr. Bashir NOURI Introduction to Matlab Matlab Basics Branching Statements Loops User Defined Functions Additional Data.
CIS162AD - C# Arrays – part 1 12_arrays_loading.ppt.
Chapter 11. Multidimensional Arrays and Vectors Multidimensional Arrays Vectors Computer Programming with JAVA.
Matlab The language of Technical computing Mr. D. Suresh Assistant Professor, Dept. of CSE, PSNA CET, Dindigul.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
Zeinab EidAlgorithm Analysis1 Chapter 4 Analysis Tools.
ITC Research Computing Support Using Matlab Effectively By: Ed Hall Research Computing Support Center Phone: Φ Fax:
Performance Optimization Getting your programs to run faster.
Introduction to Matlab. What is Matlab? A software environment for interactive numerical computations Examples:  Matrix computations and linear algebra.
Section 5 - Arrays. Problem solving often requires information be viewed as a “list” List may be one-dimensional or multidimensional List is implemented.
Lecture 26: Reusable Methods: Enviable Sloth. Creating Function M-files User defined functions are stored as M- files To use them, they must be in the.
3.6 Solving Systems Using Matrices You can use a matrix to represent and solve a system of equations without writing the variables. A matrix is a rectangular.
FORTRAN History. FORTRAN - Interesting Facts n FORTRAN is the oldest Language actively in use today. n FORTRAN is still used for new software development.
ElVis Improvements Summer 2008 Eric Zatz PPPL Summer Intern Mentor – Eliot Feibush August 11, 2008.
Basics Copyright © Software Carpentry 2011 This work is licensed under the Creative Commons Attribution License See
Chapter 11Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 11 l Multidimensional Arrays l Vectors Multidimensional Arrays.
Image Processing A Study in Pixel Averaging Building a Resolution Pyramid With Parallel Computing Denise Runnels and Farnaz Zand.
CSE 455 : Computer Vision MATLAB 101 Getting Started with MATLAB.
Improving Matlab Performance CS1114
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
Finishing up Chapter 5. Will this code enter the if statement? G=[30,55,10] if G
CIS 595 MATLAB First Impressions. MATLAB This introduction will give Some basic ideas Main advantages and drawbacks compared to other languages.
1 ENERGY 211 / CME 211 Lecture 4 September 29, 2008.
1 Introduction to Matlab. 2 What is Matlab? Matlab is basically a high level language which has many specialized toolboxes for making things easier for.
Arrays An array is a sequence of objects all of which have the same type. The objects are called the elements of the array and are numbered consecutively.
Is RRTMGP suited for GPU?
Prof. Zhang Gang School of Computer Sci. & Tech.
Introduction To Matlab Class 1
Matlab review Matlab is a numerical analysis system
Matlab Fundamentals: working with data.
Matlab tutorial course
funCTIONs and Data Import/Export
Matlab Intro.
14.1 Vectors in Two Dimensions
RDFinancial in PowerPoint
Matlab Intro.
ME 123 Computer Applications I Lecture 5: Input and Output 3/17/03
Presentation transcript:

MATLAB Tips for Simulation Parinya Sanguansat

Version Selection  X86  Faster  Smaller  X64  Slower  Bigger

Section  Syntax: % section  Run Section  Run without save

Save the results  Long time processing  Power failure  Computer freeze and crash  TIP  Save and continue next time  Don't save all variables  Too many saves, slow down your work  Display progress (Text / GUI)  Redundant save file

Example work for i=1:100 result(i) = i end

Save and continue next time if exist('savedata','file') load savedata end if ~exist('startindex','var') startindex = 1; end for i=startindex:100 result(i) = i; startindex = i; save savedata end

Don't save all variables if exist('savedata','file') load savedata end if ~exist('startindex','var') startindex = 1; end for i=startindex:100 result(i) = i; startindex = i; save('savedata','startindex','result'); end

Too many saves, slow down your work if exist('savedata','file') load savedata end if ~exist('startindex','var') startindex = 1; end for i=startindex:100 result(i) = i; if mod(i,10) == 0 startindex = i; save('savedata','startindex','result'); end

Display progress if exist('savedata','file') load savedata end if ~exist('startindex','var') startindex = 1; end endindex = 100; fprintf('\n\n%6.2f%', 0); for i=startindex:endindex result(i) = i; fprintf('\b\b\b\b\b\b\b%6.2f%', i/endindex * 100); pause(1) if mod(i,10) == 0 startindex = i; save('savedata','startindex','result'); end

Display progress with GUI if exist('savedata','file') load savedata end if ~exist('startindex','var') startindex = 1; end endindex = 100; waitbar(startindex/endindex,'Processing...'); fprintf('\n\n%6.2f%', 0); for i=startindex:endindex result(i) = i; waitbar(i/endindex); fprintf('\b\b\b\b\b\b\b%6.2f%', i/endindex * 100); pause(1) if mod(i,10) == 0 startindex = i; save('savedata','startindex','result'); end

Redundant save file if exist('savedata','file') load savedata end if ~exist('startindex','var') startindex = 1; end endindex = 100; waitbar(startindex/endindex,'Processing...'); fprintf('\n\n%6.2f%', 0); for i=startindex:endindex result(i) = i; waitbar(i/endindex); fprintf('\b\b\b\b\b\b\b%6.2f%', i/endindex * 100); pause(1) if mod(i,10) == 0 startindex = i; save('savedata','startindex','result'); save('savedata2','startindex','result'); % redundant save data end

Speed up your work  Long time processing  Using huge memory  TIP  Display too much information will slow down your work  Allocate memory  Use small data type first  Access row (the first dimension) first  Eliminate nested loop  Array processing with GPU

Display % display too much information will slow down your work for i=1:100 result(i) = i; if mod(i,10) == 0 result(i) end

Allocation memory memsize = 100; result = zeros(1,memsize); for i=1:memsize result(i) = i; end

Use small data type first memsize = 100; result = zeros(1,memsize,'uint8'); for i=1:memsize result(i) = i; end

Access row (the first index) first A = rand(1000); for j=1:size(A,1) for i=1:size(A,2) A(i,j) = 1; end

Eliminate nested loop A = rand(1000); for i=1:numel(A) A(i) = 1; % row index = mod(i-1,size(A,1))+1 % column index = ceil(i/size(A,1)); end Vectorization Linear indexing

Array processing with GPU X = rand(1000); G = gpuArray(X); % Send data to GPU G2 = G.* G; % Performed on GPU W = gather(G); % Return data to client