My Matlab3

Embed Size (px)

Citation preview

  • 8/2/2019 My Matlab3

    1/33

    1

    Introduction to Matlab

    High Performance Computing (HPC) team

    W.K. Kwan ([email protected])

    Asst. IT Director

    Phone: 2857 8631

    Lilian Y.L. Chan ([email protected])

    IT Manager

    Phone: 2859 2485

    Tony W.K. Cheung ([email protected])

    IT Officer

    Phone: 2241 5185

    mailto:[email protected]:[email protected]:[email protected]:[email protected]:[email protected]:[email protected]
  • 8/2/2019 My Matlab3

    2/33

    2

    HPC computers

    hpcpower (32-bit cluster) (128-node dual PIV 2.8 GHz RHL cluster)

    +

    ( 50-node dual PIV 3.06 GHz from Physics)

    Will be obsolete

    hpcpower2 (64-bit cluster)

    smpserve

    Machines running in parallel operating environment Your program has been parallelized?? Need special account and requires application

  • 8/2/2019 My Matlab3

    3/33

    3

    Agenda

    1. Introduction

    2. What is Matlab

    3. Where and how to access Matlab inHKU CC

    4. Elementary operations in Matlab

    5. More matrix manipulations in Matlab

  • 8/2/2019 My Matlab3

    4/33

    4

    Agenda(cont.)

    1. Polynomials operations

    2. Graph plotting

    3. What is Matlab programming

    4. What is m files

    5. More beyond

    Compiled to binary code

    Massively executed in hpcpower2 Massively executed in lab. PCs via CONDOR

  • 8/2/2019 My Matlab3

    5/33

    5

    Matlab in CC

    Installation of Matlab license server

    20+ license + some toolkits

    SMPSERVE System Every smpserve account holder can run

    matlab in the system, but required accountapplication (but we dont have PC versionof matlab)

    HPCPOWER2 Can also run Matlab, but you need special

    account on HPCPOWER2

  • 8/2/2019 My Matlab3

    6/33

    6

    Other sources of Matlab

    Matlab in your dept. laboratory

    Can be PC / linux based

    Toolkits ??

  • 8/2/2019 My Matlab3

    7/33

    7

    History

    A high-level language and a problem-

    solving environment for mathematical

    and scientific calculation

    Originated in later 1970s by Cleve

    Moler

    Aimed at to provide interactive access

    to the Fortran linear algebra packages

    EISPACK and LINPACK

  • 8/2/2019 My Matlab3

    8/33

    8

    History (cont.)

    Programming language environment

    developed, many m-files circulating

    around

    More graphical commands and tool-

    boxes offered

    Go commercial, with the company

    MathWorks Inc. formed in 1984 by

    Moler and John Little

  • 8/2/2019 My Matlab3

    9/33

    9

    Matlab

    Text mode operation, very fast

    Graphics mode

    Require X-Windows facilities

    Very slow !!!

  • 8/2/2019 My Matlab3

    10/33

    10

    Mechanism for X-display

    Local X windows Display

    (UNIX workstation

    PC Linux

    MS-Wins, with emulator s/w)

    HOST

    Computer

    (smpserve)xhost +

    setenv DISPLAY

  • 8/2/2019 My Matlab3

    11/33

    11

    Steps in running smpserveMatlab under eXcursion X-

    Windows emulation

    environment

  • 8/2/2019 My Matlab3

    12/33

    12

    Excursion setup (PC side)

    When power on your DELL PC, boot

    from WINME partition

    (eXcursion not available in XP, sorry!)

    Open a command prompt window

    (run->command)

    Check the IP address of your current

    session (ipconfig)

    Call up eXcursion by clicking the

    eXcursion icon in Programs

  • 8/2/2019 My Matlab3

    13/33

    13

    eXcursion setup (host side)

    Click Simpterm icon, telnet and logon hkusua

    Type echo $DISPLAY to see where your displaygoes

    Type setenv DISPLAY 147.8.xxx.xxx:0.0

    Check echo $DISPLAY again to confirm yourmatlab display indeed goes to your PC terminal

    To switch back to text-only Matlab (much faster) exit from Matlab

    type setenv DISPLAY Check echo $DISPLAY again

    Restart Matlab

  • 8/2/2019 My Matlab3

    14/33

    14

    Seminar material

    HKUCC slide on Matlab

    UD200 - Using Matlab 6.5 in the Unix Environ

    (http://www.hku.hk/cc/home/documentations/userdoc.htm)

    Selected reprint from other Univs.

    http://www.hku.hk/local/cc/training/matlab2001.ppthttp://www.hku.hk/local/cc/training/matlab2001.ppt
  • 8/2/2019 My Matlab3

    15/33

    15

    Course Materials

    Too too many over the Internet

    http://www.hku.hk/cc/home/documentatio(hkuccs version)

    http://www.math.utah.edu/lab/ms/matlab/m(very good short introductory)

    http://www.indiana.edu/~statmath/math/m

    (comprehensive yet easy to read)

    http://www.hku.hk/cc/home/documentations/training.htmhttp://www.math.utah.edu/lab/ms/matlab/matlab.htmlhttp://www.indiana.edu/~statmath/math/matlab/gettingstarted/index.htmlhttp://www.indiana.edu/~statmath/math/matlab/gettingstarted/index.htmlhttp://www.math.utah.edu/lab/ms/matlab/matlab.htmlhttp://www.hku.hk/cc/home/documentations/training.htm
  • 8/2/2019 My Matlab3

    16/33

    16

    Links (cont.)

    http://www.math.mtu.edu/~msgocken/intro

    (comprehensive and advanced)

    http://ist.uwaterloo.ca/ec/scientific/Matlab/

    (some very useful tips, easy read)

    http://math.ucsd.edu/~driver/21d-s99/matl

    (most classical matlab tutorial, updated

    version only available in book)

    http://www.math.mtu.edu/~msgocken/intro/intro.htmlhttp://ist.uwaterloo.ca/ec/scientific/Matlab/matlab.htmhttp://math.ucsd.edu/~driver/21d-s99/matlab-primer.htmlhttp://math.ucsd.edu/~driver/21d-s99/matlab-primer.htmlhttp://ist.uwaterloo.ca/ec/scientific/Matlab/matlab.htmhttp://www.math.mtu.edu/~msgocken/intro/intro.html
  • 8/2/2019 My Matlab3

    17/33

    17

    Links (cont.)

    Others http://www.engin.umich.edu/group/ctm/basic/ba(handling of polynomials)

    http://www-personal.engin.umich.edu/~tilbury/tutorials/ma(Mech. Engin.: automatic control)

    http://users.ece.gatech.edu/~bonnie/book/TUTO(Transfer function response)

    http://www.mathworks.com/products/education/(collection of Matlab tutorial web-pages

    http://www.engin.umich.edu/group/ctm/basic/basic.htmlhttp://www-personal.engin.umich.edu/~tilbury/tutorials/matlab_tutorial.htmlhttp://users.ece.gatech.edu/~bonnie/book/TUTORIAL/tutorial.htmlhttp://www.mathworks.com/products/education/basics.shtmlhttp://www.mathworks.com/products/education/basics.shtmlhttp://users.ece.gatech.edu/~bonnie/book/TUTORIAL/tutorial.htmlhttp://www-personal.engin.umich.edu/~tilbury/tutorials/matlab_tutorial.htmlhttp://www.engin.umich.edu/group/ctm/basic/basic.html
  • 8/2/2019 My Matlab3

    18/33

    For Interactive users

    18

  • 8/2/2019 My Matlab3

    19/33

    19

    Get familiar with the basic operation on

    matlab, in particular related to your

    discipline

    Find resources over Internet

    Study M-files examples(/sua_d1/matlab7/toolbox)

    Programming keeps to the minimum

    Ask

  • 8/2/2019 My Matlab3

    20/33

    For HEAVY numbercrunching users

    20

  • 8/2/2019 My Matlab3

    21/33

    21

    Interfacing with C/Fortran

    programs Working in Matlab but calling C/Fortran

    modules to handle the complicatednumerical calculation Main advantage: to take advantage of the graphics

    plotting and build-in matrix operation facilities inMatlab

    C/Fortran routines (sayprog1.exe) compiled asindependent executable programs

    Matlab results wrote to disk files Execute C/Fortran programs by specifying !

    prog1.exe (i.e. treatingprog1.exe as a standardUNIX command like ls or cd )

  • 8/2/2019 My Matlab3

    22/33

    22

    Working in C/Fortran but calling Matlab to

    handle the matrix operation Main advantage: build-in matrix operation facilities

    in Matlab

    C/Fortran results wrote to disk files

    Prepare the Matlab instructions and storing in am-file (say ml-bat1.m)

    Execute Matlab in batch mode, within the mainprogram by specifying

    call system ( matlab < ml-bat1.m > ml-bat1.out, ierr) !

    Fortranierr = system (matlab < ml-bat1.m > ml-bat1.out) ! C

    where the Matlab output will be captured in file ml-bat1.outfor further processing in the Fortran/Cprogram

  • 8/2/2019 My Matlab3

    23/33

    23

    Compiled Matlab M-files

    Program(s) will be linked and convertedinto a single executable file

    Executable program much compact in size

    When actual running, Matlab system (theinterpreter) will not longer be required Much faster running

    Much memory available for program use NO License count problem

  • 8/2/2019 My Matlab3

    24/33

    24

    Compiled Matlab M-files (cont.)

    Better program security (executable programcant be viewed)

    Need extra software license, Matlab compiler Different licenses required for Linux and

    Microsoft Windows versions (BUT, both notavailable yet in HKUCC)

    During actual program execution, many run-timevendor-provided libraries have to be pre-

    installed (shared libraries under Linux dlls (Dynamic-link libraries) under MSFT Windows

    environment )

  • 8/2/2019 My Matlab3

    25/33

    Direct running of Matlab

    matlab < myprog.m >

    Slow, as the instructions in myprog.m will

    have to be interpreted at statement by

    statement (take care of your loops!)

    matlab software itself will eat your big

    chunk of memory

    We have only 20 licenses

    25

  • 8/2/2019 My Matlab3

    26/33

    Matlab compiler (mcr)

    Matlab M-files compiled and stored in

    exe files

    For program security and faster operation

    Dont need matlab when in actual running

    No license count concern

    (Of course the matlab compiler needs

    independent license)

    26

  • 8/2/2019 My Matlab3

    27/33

    mcr procedure

    1. Create a separate directory and place all your relatedm files there

    (a sample: mysquare.m)

    function magicsquare(n)%MAGICSQUARE generates a magic square matrix of the

    size

    % specified by the input parameter n.

    % Copyright 2003 The MathWorks, Inc.

    if (ischar(n))

    n=str2num(n);

    end

    magic(n)

    27

  • 8/2/2019 My Matlab3

    28/33

    mcr procedure (cont.)

    2. Test run your m file(s) within matlabmatlab>> pwd

    >> ls>> magicsquare(3)

    ans =

    8 1 63 5 74 9 2

    28

  • 8/2/2019 My Matlab3

    29/33

    mcr procedure (cont.)

    3. Compile your file(s) within matlab

    >> mcc m magicsquare.m

    >> ls

    (many files include the executable magicsquare will be produced)

    4. Open a new windows,

    run this magicsquare OUTSIDE matlab

    ./magicsquare 3

    ans =8 1 6

    3 5 7

    4 9 2

    29

  • 8/2/2019 My Matlab3

    30/33

    30

    Running Matlab in aparallel computing

    environment

  • 8/2/2019 My Matlab3

    31/33

    31

    MultiMatlab

    Parallelized Matlab, still academic R&Dprojects with little real general-purposeproducts available, very expensive

    Not all mathematical algorithms can beparallelized

    For one single task, trying to split theintense calculation for using multiple

    CPUs/cores (But if you have many independent

    tasks .)

  • 8/2/2019 My Matlab3

    32/33

    32

    Running Matlab in parallel computing

    environment

    Analysis your program flow

    split the serial execution into separate independenttasks that can be executed asynchronously byspecifying 1 (or 2) parameters

    Write a mpi driving program (Fortran/C) to call uprequired no. of CPUs (available)

    Drive different CPUs/cores to work on differentserial tasks

    Consolidate the result, either through disk files orMatlab memory files

  • 8/2/2019 My Matlab3

    33/33

    33

    Other Scientific computing software

    packages in CC

    Mathematica

    2 licenses on smpserve platform only

    Symbolic math. software

    PV-WAVE Visual data analysis development environment

    Very powerful, file I/O, 2D, 3D analysis, animated

    show, programming interface

    Many licenses on PCs platform, and HPCPOWER