Non-traditional High-Level Languages for HPC Applications

:

GNU Octave
Juan Carlos Chaves, Ph.D. SIP On-site at ARL MSRC Ohio Supercomputer Center
Users Group Conference (UGC2006) 26 Jun 2006

Distribution Statement A: Cleared for Public Release. Distribution is unlimited.

1

Purpose of This Tutorial
• Provide an introduction to the Octave system • Teach how to obtain and configure Octave for your own PC • Teach how to configure, build and install Octave at the HPCMP HPC platforms • Teach how to exploit Octave HPC technology at the HPCMP Centers • Be a concise guide to relevant Octave info on the Web

Distribution Statement A: Cleared for Public Release. Distribution is unlimited.

2

What is Octave?
• High-level language, primarily intended for numerical computations initiated and maintained by John W. Eaton (University of Wisconsin) • A stated goal of Octave is to be compatible with MATLAB • Provides a convenient command line interactive interface for solving scientific and technical problems numerically • Has built-in a large collection of mathematical algorithms and convenience functions
Distribution Statement A: Cleared for Public Release. Distribution is unlimited. 3

Typical uses of Octave
• Prototyping: an interactive Octave session becomes a system-prototyping environment rivaling systems such as the well-known MATLAB

• Programming language: a powerful but easy to use programming language, mostly compatible with MATLAB, for use in developing sophisticated programs and algorithms

• Batch-oriented HPC applications: Octave and its parallel extensions may also be run under a batch system such as LSF, the mandate queuing system at the DoD HPCMP Centers
Distribution Statement A: Cleared for Public Release. Distribution is unlimited. 4

Linux and Mac OS X including architectures unsupported by MATLAB • MATLAB clone: syntax is very similar to MATLAB.code development proceeds incrementally. Excellent development and rapid prototyping environment Distribution Statement A: Cleared for Public Release.Octave Advantages • Free program available under the GNU General Public License (GNU GPL) and runs on Windows. Careful programming will allow a script to run on both Octave and MATLAB • Open source community: large and very active support community all over the world • High productivity system: interactive . 5 . Distribution is unlimited.

you’re taking this tutorial!) • Unlike MATLAB. • Unlike MATLAB. Distribution is unlimited. Inc. 6 . limiting the application of Octave in scientific and engineering graphics. including the creation of GUIs. • Unlike MATLAB.Octave Disadvantages • Relatively complex installation procedure (But fortunately. lacks support from a multi-million dollar company such as the MathWorks. fewer toolboxes are available Distribution Statement A: Cleared for Public Release. it does not support object-oriented programming • Unlike MATLAB supports only basic graphic capabilities.

7 .44 • Semicolons suppress output: octave:5> product = 16*16.99.34 product = 261.Octave – basic features • No declarations needed: octave:1> 14 + 28 ans = 42 • Mixed types: octave:2> product = 16*16. octave:6> product product = 271. Distribution is unlimited.84 Distribution Statement A: Cleared for Public Release.

Distribution is unlimited. 8 . 34 ] a= 1 1 2 3 5 8 13 21 34 • Row vectors and the colon operator : octave:8> row_vector = 1:5 row_vector = 1 2 3 4 5 Distribution Statement A: Cleared for Public Release. 5. 21. 13. 3. 8. 1.Octave – Matrix notation • Working with matrices: octave:7> a = [ 1. 2.

3) ans = 0.00000 0. octave:14> b(3.27638 1.55636 0. b(3. octave:16> b b= 0. Distribution is unlimited.2).53600 0.1).36208 Distribution Statement A: Cleared for Public Release. b(3.31457 0.Octave – Matrix Subscripting • Working with subscripts: octave:13> b = rand (3.2) = 1.94927 ans = 0. 3).22555 0.46079 0.36208 octave:15> b(3. 9 .27638 ans = 0.11940 0.

:.79753 1.53750 -0.:.21434 2. 10 .724684 0.20065 ans(:.1) = -1.84360 0.:.4) = -1.94572 -0.01204 0.568425 -0.16023 0.31952 -0.72208 0.094533 0.64897 ans(:.043409 Distribution Statement A: Cleared for Public Release.59228 0.09797 ans(:.3) = -1.80322 0.:.537532 -1. Distribution is unlimited.62063 1.786163 -0.48319 0.3.Octave – Multidimensional Arrays • Example of a 3D random array filled with normal data: octave:20> r = randn(2.42084 1.2) = -0.4) r= ans(:.05765 -0.

14286 octave:30> H_inv = inv(H) H_inv = 16.000 octave:31> H*H_inv ans = 1.0000e+00 11 Distribution Statement A: Cleared for Public Release.20000 0.Octave – Matrix Operations • Example of a Hilbert matrix and its inverse: octave:29> H = hilb(4) H= 1.000 -140.2737e-13 1.6209e-14 1.1369e-13 -1.25000 0.000 -4200.25000 0.33333 0.000 -120. .0000e+00 1.000 -4200.000 240.4139e-15 9.16667 0.000 -140.000 240.3137e-14 3.000 -2700. Distribution is unlimited.0947e-14 -1.0000e+00 3.000 -120.25000 0.6032e-13 1.16667 0.25000 0.000 1200.9165e-14 -2.20000 0.4477e-13 1.50000 0.000 1680.7387e-15 1.000 6480.000 -2700.6843e-14 1.50000 0.0000e+00 5.000 2800.20000 0.000 1680.33333 0.1285e-13 1.00000 0.33333 0.

25000 0.20000 0.16667 0.20000 0.16667 0.50000 0.00000 0.*H_inv ans = 16 -60 80 -35 -60 400 -675 336 80 -675 1296 -700 -35 336 -700 400 Distribution Statement A: Cleared for Public Release.33333 0.33333 0.14286 octave:33> H_inv = invhilb(4) H_inv = 16 -120 240 -140 -120 1200 -2700 1680 240 -2700 6480 -4200 -140 1680 -4200 2800 octave:34> H.25000 0. Distribution is unlimited.50000 0. 12 .25000 0.20000 0.33333 0.Octave – Dot Operator • Another example of a Hilbert matrix and its inverse: H= 1.25000 0.

transposition. subtraction. division. multiplication (matrix and component-wise). 13 . etc.Octave – Matrix manipulation • Is at the heart of Octave including addition. Distribution is unlimited. • Has a number of functions for generating common matrices including: octave:35> eye(3) ans = 1 0 0 0 1 0 0 0 1 octave:36> ones(3) ans = 1 1 1 1 1 1 1 1 1 octave:37> zeros(3) ans = 0 0 0 0 0 0 0 0 0 Distribution Statement A: Cleared for Public Release.

Distribution is unlimited.linear algebra.Octave – Groups of Specialized Functions • Including: . . .input and output. .sets. . Distribution Statement A: Cleared for Public Release. .optimization.differential equations. . .statistics.plotting. . 14 .polynomial manipulations.matrix manipulation. .non-linear equations. .signal processing and image processing.control theory. .financial functions. .

For example. • Another useful command is help -i <topic>. 15 . Distribution Statement A: Cleared for Public Release. For example: octave:6> help svd – Will provide extensive help for the Singular Value Decomposition Octave routine.Octave – Getting help • Getting help from Octave is very easy. Distribution is unlimited. including relevant examples. octave:7> help -i svd – Will search for svd in the function index. which will search the Octave manual index.

Octave – Useful Web Links • 375 page manual available on-line at Octave's home site at: http://www.org/ • Octave Forge: GNU Octave Repository is a central location for the collaborative development of toolboxes for GNU Octave: http://octave.octave.octave. Distribution is unlimited.html • The Octave Wiki: user-contributed advice. tips and tricks at: http://wiki.net/ Distribution Statement A: Cleared for Public Release.org/doc/index. examples. 16 .sourceforge.

html • The Octave Script Archive at: http://wiki.Octave – Useful Web Links (2) • The Octave-forge toolboxes: http://octave. Distribution is unlimited.octave.jsp Distribution Statement A: Cleared for Public Release.org/math/math_calculator.online-utility.net/index/index. 17 .pl?CategoryScriptArchive • On-line access to Octave (up to 4 minutes of run time allowed) : http://www.sourceforge.org/wiki.

18 . .A Linux API emulation layer (cygwin1. Distribution is unlimited.Getting and Configuring Octave for the PC • 1) The Octave under Cygwin Solution Download Octave + the Octave-forge extensions (toolboxes) under Cygwin. which provide Linux look and feel. .Available at: http://www.dll DLL) for Linux API functionality.cygwin. a Linux-like environment for Windows which consists of two parts: .com/ Distribution Statement A: Cleared for Public Release.A collection of tools.

19 . Distribution is unlimited.Point and Click PC Octave Installation Distribution Statement A: Cleared for Public Release.

Distribution is unlimited. 20 .Point and Click PC Octave Installation Distribution Statement A: Cleared for Public Release.

Distribution is unlimited. 21 .Octave on the Windows PC Linux like environment Octave-forge toolboxes include Distribution Statement A: Cleared for Public Release.

octave-epstk. • Quantian is tailored to numerical and quantitative analysis.Getting and Configuring Octave for the PC 2) The Octave under Quantian Solution • Quantian is a remastering of Knoppix. matwrap and Inline-Octave. • http://dirk.html • Contains ready to use Octave. 22 . Distribution Statement A: Cleared for Public Release. octave-sp. a self-configuring and directly bootable CD/DVD that turns any pc or laptop (provided it can boot from cdrom/dvd) into a fullfeatured Linux workstation. with add-on packages octave-forge. Distribution is unlimited.eddelbuettel.com/quantian.

Octave under The Quantian Scientific Computing Environment Get the latest ISO image and burn it to a blank DVD: http://quantian.fhcrc.org/Quantian_0.iso Distribution Statement A: Cleared for Public Release. Distribution is unlimited.2.9. 23 .7.

2.gz 4) Download the jpeg library (version 6b) if not present: http://www.72.tar.gz 2) Download Octave-Forge extensions that go with Octave 2. Distribution is unlimited.6-7.1.gz Distribution Statement A: Cleared for Public Release.org/files/jpegsrc.net/project/showfiles.imagemagick.tar.Installing Octave at the HPCMP systems • Prerequisites: 1) Download Octave (version 2.octave.ijg. 24 .1.72 http://sourceforge.tar.org/pub/octave/bleeding-edge/octave2.v6b.72) ftp://ftp.org/pub/ImageMagick/ImageMagick6.1.php?group_id=2888 3) Download ImageMagick ftp://ftp.

tar.1.1.1.72 install: > gzip -dc octave-2. 25 . > make > make install • Octave building takes a long time. So grab a cup of coffee and relax! Distribution Statement A: Cleared for Public Release./configure” script for the Octave-Forge extensions to work.72.72 > /configure --prefix=$HOME/octave --enable-dld --enableshared • Note that the “--enable-shared” option must be activated in the “.Octave – Installation • Step # 1: Octave 2. Distribution is unlimited.gz | tar -xvf > cd octave-2.

26 . Distribution is unlimited.Install the Octave-forge toolboxes Distribution Statement A: Cleared for Public Release.

gz | tar –xvf – > cd octave-forge-2006./configure --with-path=$HOME/octave-forge -prefix=$HOME > make -k > make check > make icheck > make install Distribution Statement A: Cleared for Public Release.03.72 > setenv PATH $HOME/octave/bin:$PATH > gzip -dc octave-forge-2006.17.1. 27 . Distribution is unlimited.17 > .Octave-Forge – Installation • Installing Octave-Forge extensions that go with Octave 2.tar.03.

LOADPATH ]. Distribution Statement A: Cleared for Public Release. Distribution is unlimited.72/m/startup/octaverc and include the following lines: LOADPATH = [ getenv("HOME"). 28 . "/octave-forge//:". "/octave-forge/bin:". EXEC_PATH ]. EXEC_PATH = [ getenv("HOME").1.Octave-Forge – Configuration • Configuring Octave-Forge extensions: Edit the file: $HOME/octave/share/octave/2.

Octave-Forge – Required Libraries • The Octave-Forge function “$HOME/octaveforge/image/imwrite.6 > . 29 .m” requires the ImageMagick "convert" utility: > gzip -dc ImageMagick-6.v6b. Distribution is unlimited.org/files/jpegsrc. If this library is not installed on your system then install the jpeg library (version 6b): http://www.ijg.6 | tar –xvf – > cd ImageMagick-6.gz Distribution Statement A: Cleared for Public Release.2.tar./configure --prefix=$HOME/ImageMagick > make > make install > setenv PATH $HOME/ImageMagick/bin:$PATH • Note: ImageMagick needs the jpeg library.2.

Distribution is unlimited. This customization of MatlabMPI is sometimes called OctaveMPI • Use bcMPI a full MPI interface for Octave to create complex parallel programs (coming soon from OSC!) Distribution Statement A: Cleared for Public Release.Running Octave at the HPCMP systems • 1) Running executable Octave scripts to solve cheerfully parallel programs • 2) Use MatlabMPI with Octave. 30 .

31 .72/bin/octave/octave qf Distribution Statement A: Cleared for Public Release.sh by adding a single line to the beginning of the Octave m-file #! /usr/bin/octave –qf • For example at the ARL MSRC JVN Cluster: #! /usr/cta/unsupported/octave/2.Cheerfully Parallel Programs • Executable Octave script files (like executable shell scripts) • Excellent feature of Octave very useful for large cheerfully parallel problems or where a mixture of programs. Distribution is unlimited.1.Octave . tools or applications may be needed to solve the problem • A Octave code my_code.m can be easily converted to an executable Octave program my_executable_script.

it is possible to use LSF queuing system at the HPCMP Centers to schedule large batch jobs.sh • Then. 32 .sh jvn-l1> ./my_executable_script. Distribution is unlimited.Cheerfully Parallel Programs • To make the script executable and run it at JVN input: jvn-l1> chmod u+x my_executable_script. • The SIP team has advanced tools to facilitate this process: The SIP Productivity Enhancement Tool Distribution Statement A: Cleared for Public Release.Octave .

OctaveMPI: MatlabMPI under Octave • OctaveMPI is the name usually given to customization (port?) of MatlabMPI to Octave • For example.cs. this straightforward tailoring has been done by our collaborators at Indiana University (Professor Arun Chauhan): www. Distribution is unlimited.indiana.edu/~achauhan/publications/ScriptingLangs/IU-TR2006-631. 33 .pdf • We have run OctaveMPI programs at the Seafarer Linux Cluster (SSC – San Diego) • This tutorial will teach you how to do it! Distribution Statement A: Cleared for Public Release.

Distribution is unlimited. MatlabMPI.edu/~acha uhan/publications/ScriptingLang s/abs-iu-tr2006-631.cs.5 GHz) • Interconnect: Gigabit Ethernet • NFS optimized for MatlabMPI • Ref: http://www.html Distribution Statement A: Cleared for Public Release.indiana. 34 .OctaveMPI Performance Comparing OctaveMPI. MPI-TB for MATLAB and C/MPI • Experiments performed under controlled conditions using a 8 node Linux cluster at Indiana University (Intel Xeon 2.

%matlab_location = ' matlab '. Distribution is unlimited.] matlab_location = ' octave '.MatlabMPI Configuration for Octave • Customize MatMPI_Comm_settings.matlab_command = [matlab_location '-display null -nojvm -nosplash']. % Build unix matlab launch command based. % [OK TO CHANGE. Distribution Statement A: Cleared for Public Release. [DON'T CHANGE] %machine_db_settings. % [OK TO CHANGE.matlab_command = [matlab_location ' --no-history --no-line-editing '].] % Hard code location of matlab on remote unix systems. matlab_location = ' /usr/bin/octave'.m at /MatlabMPI/src/ % Set location of matlab on unix systems. % Generic location. machine_db_settings. 35 .

Explanation: in Octave the backslash character ‘\’ starts the escape sequence character: MATLAB: > backslash = ‘\’ Octave: > backslash = ‘\\’ • Disable (comment out) the pc/unix translation of “pwd” implemented at MatMPI_dir_map. For example at file MPI_Bcast.bat']. Distribution is unlimited.bat'].m: link_script = ['MatMPI\Link_Commands_t' num2str(tag) '.MatlabMPI Configuration for Octave (2) • Fix the Octave special character “\” string problem. 36 .m Distribution Statement A: Cleared for Public Release. Octave line must read: link_script = ['MatMPI\\Link_Commands_t' num2str(tag) '.

37 . Distribution is unlimited.diff between MatlabMPI and OctaveMPI Distribution Statement A: Cleared for Public Release.

change the open mode to binary: temp_fid = fopen(lock_file.MatlabMPI Configuration for Octave (3) • To avoid Octave warnings.'r').'rb'). For example: addpath('/mnt/sda1/OctaveMPI/src') Distribution Statement A: Cleared for Public Release.octaverc” containing the location of OctaveMPI source directory. 38 . Distribution is unlimited. For Octave change to: temp_fid = fopen(lock_file. for example at MPI_Recv. • In each directory where you run OctaveMPI code include the dot file “.m.

39 . Distribution is unlimited.OctaveMPI Live Demo • A live demo of the Octave/OctaveMPI parallel capabilities using the Quantian Scientific Computing Environment (live bootable Linux DVD) running a image processing application! Distribution Statement A: Cleared for Public Release.

Distribution is unlimited. GS04T01BFC0060. 40 .Acknowledgement “This publication was made possible through support provided by DoD HPCMP PET activities through Mississippi State University under contract No.” Distribution Statement A: Cleared for Public Release. The opinions expressed herein are those of the author(s) and do not necessarily reflect the views of the DoD or Mississippi State University.

Sign up to vote on this title
UsefulNot useful