Running MATLAB Scripts in Octave Installation, porting, and advanced usage of Octave. Tom Holroyd NIMH MEG Core Facility April 19, 2007.

Slides:



Advertisements
Similar presentations
The Complete Technical Analysis and Development Environment An attractive alternative to MATLAB and GAUSS - Physics World.
Advertisements

Introduction to Linux Recap Installing programs Introduction to Video Editing with Linux.
PHP I.
Configuration management
Introduction to Programming using Matlab Session 2 P DuffourJan 2008.
Introduction to Matlab Workshop Matthew Johnson, Economics October 17, /13/20151.
Setting up of condor scheduler on computing cluster Raman Sehgal NPD-BARC.
Java.  Java is an object-oriented programming language.  Java is important to us because Android programming uses Java.  However, Java is much more.
Data Analytics and Dynamic Languages Lee E. Edlefsen, Ph.D. VP of Engineering 1.
MATLAB Extras Week 16 – 5/12/09 Kate Musgrave
Linux+ Guide to Linux Certification, Second Edition
SCRIPTING LANGUAGE. The first interactive shells were developed in the 1960s to enable remote operation of the first time-sharing systems, and these,
Programming Introduction November 9 Unit 7. What is Programming? Besides being a huge industry? Programming is the process used to write computer programs.
Low level CASE: Source Code Management. Source Code Management  Also known as Configuration Management  Source Code Managers are tools that: –Archive.
Guide To UNIX Using Linux Third Edition
Seven good reasons why everyone should be using R.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 2: Operating-System Structures Modified from the text book.
Chapter 3 Software Two major types of software
1 SEEM3460 Tutorial Unix Introduction. 2 Introduction What is Unix? An operation system (OS), similar to Windows, MacOS X Why learn Unix? Greatest Software.
Introduction to The Linaro Toolchain Embedded Processors Training Multicore Software Applications Literature Number: SPRPXXX 1.
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.
TrendReader Standard 2 This generation of TrendReader Standard software utilizes the more familiar Windows format (“tree”) views of functions and file.
What is R By: Wase Siddiqui. Introduction R is a programming language which is used for statistical computing and graphics. “R is a language and environment.
CHAPTER 4: INTRODUCTION TO COMPUTER ORGANIZATION AND PROGRAMMING DESIGN Lec. Ghader Kurdi.
Lab 8 – C# Programming Adding two numbers CSCI 6303 – Principles of I.T. Dr. Abraham Fall 2012.
Introducing Java.
Linux Operations and Administration
Introduction to Shell Script Programming
1 Chapter 2 & Chapter 4 §Browsers. 2 Terms §Software §Program §Application.
Trilinos 101: Getting Started with Trilinos November 7, :30-9:30 a.m. Mike Heroux Jim Willenbring.
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.
CHAPTER FOUR COMPUTER SOFTWARE.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
(1) A Beginner’s Quick Start to SIMICS. (2) Disclaimer This is a quick start document to help users get set up quickly Does not replace the user guide.
1 Computer Programming (ECGD2102 ) Using MATLAB Instructor: Eng. Eman Al.Swaity Lecture (1): Introduction.
Ch 1. A Python Q&A Session Spring Why do people use Python? Software quality Developer productivity Program portability Support libraries Component.
Linux Operations and Administration
How to configure, build and install Trilinos November 2, :30-9:30 a.m. Jim Willenbring Mike Phenow.
Guide to Programming with Python Chapter One Getting Started: The Game Over Program.
Robert Crawford, MBA West Middle School.  Explain how the binary system is used by computers.  Describe how software is written and translated  Summarize.
240-Current Research Easily Extensible Systems, Octave, Input Formats, SOA.
Samba – Good Just Keeps Getting Better The new and not so new features available in Samba, and how they benefit your organization. Copyright 2002 © Dustin.
Mantid Stakeholder Review Nick Draper 01/11/2007.
 Programming - the process of creating computer programs.
Getting Started with Trilinos October 14, :30-10:30 a.m. Jim Willenbring.
A. Aimar - EP/SFT LCG - Software Process & Infrastructure1 SPI Software Process & Infrastructure for LCG Project Overview LCG Application Area Internal.
More Unix Naomi Altman. Directories Directory = folder mkdir - makes a new directory rmdir - removes an empty directory cd mydirectory - moves you into.
JavaScript 101 Introduction to Programming. Topics What is programming? The common elements found in most programming languages Introduction to JavaScript.
Meeting Users Needs with Octave A survey of the use of Matlab™ and Octave at the NIH Tom Holroyd NIMH MEG Core Facility Presented at the Octave 2006 Workshop.
NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS ( NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS (PRACTICAL PART) Tutorial 2 : Matlab - Getting Started.
Installing Applications in FreeBSD lctseng. Computer Center, CS, NCTU 2 Before we start  Permission issue root: the super user Like administrator in.
Lab 9 Department of Computer Science and Information Engineering National Taiwan University Lab9 - Debugging I 2014/11/4/ 28 1.
How to configure, build and install Trilinos November 2, :30-9:30 a.m. Jim Willenbring.
Testing Infrastructure Wahid Bhimji Sam Skipsey Intro: what to test Existing testing frameworks A proposal.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
Parallel MATLAB jobs on Biowulf Dave Godlove, NIH February 17, 2016 While waiting for the class to begin, log onto Helix.
OCR A Level F453: The function and purpose of translators Translators a. describe the need for, and use of, translators to convert source code.
IST 210: PHP Basics IST 210: Organization of Data IST2101.
Programming Logic and Design Seventh Edition Chapter 1 An Overview of Computers and Programming.
Environment & Education & More Dan Bothell. Overview Data Teaching Materials Environment Other ACT-R 5.0 and RPM issues.
Development Environment
CST 1101 Problem Solving Using Computers
Introduction to Computer Science
Spark Presentation.
PYTHON: AN INTRODUCTION
The Linux Operating System
Introduction to Python
CSCI N317 Computation for Scientific Applications Unit 1 – 1 MATLAB
JavaScript is a scripting language designed for Web pages by Netscape.
Presentation transcript:

Running MATLAB Scripts in Octave Installation, porting, and advanced usage of Octave. Tom Holroyd NIMH MEG Core Facility April 19, 2007

Outline What is Octave? Issues for users Other tools Installation Prerequisites Octave Octave-forge (the toolboxes) Running Octave Initialization, paths, editing, script files, etc.

Outline (cont.) Porting Matlab.m files Octave is not “bug for bug” compatible No GUI, but 3 rd party packages exist Creating.oct files – Examples Stockwell transform Octave sockets Using the NIH Biowulf cluster Resources Very active developer community

What is Octave? Octave is an open source implementation of the MATLAB™ scripting language, available for Linux and Windows. It is distributed under the Gnu Public License (GPL). While many features are compatible, there are differences. This class is designed to familiarize Matlab users with the things they will need to do in order to run scripts in Octave.

Issues for Matlab Users Licensing – Octave is free Multi-processor and cluster 64-bit systems and large memory (> 2GB) Lack of GUI support Compatibility/portability issues with other analysis packages (e.g., R) Speed (we need to convert more.m files to C++) Support, e.g., bioinformatics experts

The License Hog This ran for a week. What the note doesn't say is that he was also using a license; nobody else could use Matlab for a week. I had a user who ran a long job which failed right at the end when it needed to do a t-test and the stats toolbox was busy.

Speed Octave is generally slower than Matlab, however C/C++ extensions can be written (.oct files) MEX file support – Octave can execute.mex files with some limitations No artificial limits on CPUs due to licensing

Other Tools Gnuplot – Octave uses gnuplot as a plotting engine matplotlib/pylab – Python extensions that have Matlab/Octave-like capability Open formats (e.g., HDF5) guarantee ease of use with other tools

Example – Contour Plots The time-frequency graph shown here was calculated using Octave with a C++ extension, then the data were exported to pylab for rendering in a manner similar to that used for Gnuplot. Stockwell Transform

Example – MEG Source Localization Power spectral estimates are used to generate maps of brain activity. Octave is used as a compute engine; we run hundreds of such datasets on the Biowulf cluster. The data are exported to AFNI for display.

Installation - Linux Prerequisites BLAS – may already be installed, e.g., $ rpm -q blas blas fc4 LAPACK $ rpm -q lapack lapack fc4 ATLAS – optional faster version of the above two FFTW $ rpm -q fftw fftw fc4

Installation (cont.) Prerequisites gperf – only required for building from CVS $ rpm -q gperf gperf gnuplot – most likely already installed

Installation (cont.) Get Octave Three versions listed: stable, testing, and development. Stable is ancient, testing lacks features. Get the development version (currently ). For the brave, get the latest CVS, but that changes daily. Note: some distributions, such as Fedora, have binaries available. Installation may be as simple as: $ yum install octave The Fedora binary is built with ATLAS, too.

Installation (cont.) Compile and Install Octave The usual: $ cd /usr/local/src $ tar -xjvf octave tar.bz2 $ cd octave $./configure $ make $ make install If you have an older compiler, this may help:./configure CXXFLAGS=-fpermissive

Installation - Windows A Windows build is available. From here you can download an installer that contains a complete Octave system for Windows that is very easy to use. It also includes the latest plotting tools.

Octave Forge Octave Forge is a set of packages Available at sourceforge.net: octave:1> pkg install statistics tar.gz octave:2> pkg list Package Name | Version | Installation directory geometry | | /home/tomh/octave/geometry parallel | | /home/tomh/octave/parallel signal | | /home/tomh/octave/signal statistics | | /home/tomh/octave/statistics Some toolboxes have prerequisites, e.g., the geometry toolbox requires qhull.

Octave Forge arpack audio civil combinatorics communications control econometrics engine fixed general geometry graceplot gsl ident image informationtheory integration io irsa java linear macosx mapping miscellaneous nan nnet octcdf odepkg optim optiminterp parallel db physicalconstants plot polynomial pt_br signal specfun special splines statistics strings struct symband symbolic tcl time tsa vrml windows xraylib zenity

Running Octave $ octave GNU Octave, version (i686-pc-linux-gnu). Copyright (C) 2007 John W. Eaton. This is free software; see the source code for copying conditions. There is ABSOLUTELY NO WARRANTY; not even for MERCHANTIBILITY or FITNESS FOR A PARTICULAR PURPOSE. For details, type `warranty'. Additional information about Octave is available at Please contribute if you find this software useful. For more information, visit Report bugs to (but first, please read to learn how to write a helpful report). octave:1> ans = 4 octave:2>

Initialization –.octaverc A sample.octaverc file: addpath('/opt/afni/afni_src/matlab'); addpath('/home/tomh/octave-extras'); pkg load all; crash_dumps_octave_core(0); page_screen_output(0); page_output_immediately(1); warning("off", "all");# see help warning_ids #ignore_function_time_stamp("all");# if.m files will not change, this is faster Invoke Octave with -f to skip all initialization files.

Editing Commands Octave uses readline The usual arrow editing keys can be used, and in addition, Octave will recall a previous command based on its prefix (even across sessions!): octave:1> x = 5; octave:2> sin(x) ans = octave:3> x [uparrow] = 5 * pi; octave:4> s[uparrow]in(x) ans = e-16

Script Files Normal.m files begin with the word “function” and can contain only one function definition. If an.m file does not begin with the word “function”, it is a script file and can contain many function definitions as well as executable statements. 1; # this trick forces the file to be a script file function y = f1(x), y = x + 1; end; function y = f2(x), y = x + 2; end; f2(f1(2)) The above file can be named anything.m.

Porting.m Files Logical And and Or Octave's operators shortcut like those in C: if a != 1 && foo()... # foo() will not be called if a == 1. && is a logical op. x = (a != 1) & (foo() == 2); # foo() is always called. & is an element by element op. In Matlab, single & and | shortcut! In Octave they do not. This is probably the most common problem for porting legacy Matlab code. Note that Matlab now has && and || which shortcut properly, while & and | still shortcut, but only in 'if' statements.

Porting.m Files (cont.) The Octave interpreter has many features that the Matlab interpreter does NOT have. If you use them, your code will not run in Matlab. Most Matlab features are available, but the syntax is sometimes different. Use the following construct to protect such code: if (exist ('OCTAVE_VERSION')) % Octave... else % Matlab... end

Porting.m Files (cont.) Octave allows double quotes, Matlab doesn't. s = “this is an octave-only string”; s = 'this works in both'; Octave allows the “#” comment character. # This is an Octave-only comment. % This works in both Octave and Matlab. Initialization file:.octaverc – can be in current directory or $HOME. startup.m – Matlab only.

Strings Octave's double quoted strings interpret backslash escapes: octave:1> a = "this\nthat" a = this that Single quoted strings do not: octave:2> a = 'this\nthat' a = this\nthat octave:3> a(5) ans = \

Porting.m Files (cont.) Octave allows ** and ^, Matlab only allows ^. x = 2**8;# works in Octave but not Matlab Octave allows != and ~=, Matlab only allows ~=. Matlab always requires “...” # Octave doesn't: x = rand(2, 2) Octave allows “endif”, etc., Matlab does not. if foo() # do stuff endif For “eig(A,B)” use “qz(A,B)”.

Porting.m Files (cont.) Octave doesn't have dbstack, use mfilename(): % get the name of the function try [st, i] = dbstack; name = st(i); catch name = mfilename('fullpath'); end # Or use the “OCTAVE_VERSION” trick instead of try/catch. # Or don't use dbstack. dbstep/dbnext commands have a different syntax.

Porting.m Files (cont.) Toolboxes Not all the Matlab toolboxes exist in Octave or Octave-forge. However many.m files can be found on the web (e.g., dpss.m and related functions). If you have a Matlab toolbox, e.g., stats, the functions will generally work (but are copyrighted so cannot be distributed).

Toolboxes Octave-forge provides a central location for people to contribute code, and for people to work on it in a collaborative way. It, like Octave, is a community project, and it is freely available. Some of the packages work well, some do not. But if you find a problem, it can be fixed. Example: the control toolbox uses classes. Octave doesn't have classes yet. The toolbox is there, but your code may need changes.

Plotting Octave uses gnuplot to render plots. High level commands such as “plot()” and “mesh()” are available, as well as access to all low level gnuplot features via “__gnuplot_raw__()”. “Handle” graphics.

Using the NIH Biowulf Cluster Octave vs. NFS Octave maintains a cache of.m file locations and modification times. When a file changes it is re-read. For certain NFS configurations, this can be very slow. Even with “ignore_function_time_stamp("all")” Octave still has to search the path many times. The Biowulf has a set of nodes (about 100) that maintain strict Unix semantics on /home mounts: the flag “noac” for “no attribute cache” is used. Octave is much slower on these nodes. Perhaps this is a temporary situation?

Using the NIH Biowulf Cluster An Octave build is available Add /home/holroydt/data/octave/build/bin to your $PATH (the Biowulf crew will put this up in a better place if we ask).

Using the NIH Biowulf Cluster Swarm If your task has many independent components, just run them in parallel using swarm. Create a file like: octave -q --eval “doit(1)” octave -q --eval “doit(2)” octave -q --eval “doit(3)” octave -q --eval “doit(4)” octave -q --eval “doit(5)” Then: swarm -f -l nodes=1

Using Swarm (cont.) To avoid the “noac” nodes, use a wrapper like this: #! /bin/sh if mount | grep noac > /dev/null; then echo “$1 must be redone” exit fi octave -q --eval “doit($1)” Calls to the above file can be batched and run with swarm, and the undone bits run later (automation helps). More elaborate checkpointing is often used anyway.

Using the NIH Biowulf Cluster Multiprocessor Octave-forge has a “parallel” package that uses socket I/O for communication. Use the newer “octave_sockets” package and do it yourself. Data can be sent via the filesystem, but that's slow.

Resources The main Octave website: The main Octave-forge website: The Octave-forge home page (has many links): The Wiki (many more links): Main documentation page: The “help” list:

Scripts used in this talk can be downloaded from: