gnu octave a free high-level tool for scientific computing · 2012-11-08 · gnu octave a free...

59
GNU Octave A free high-level tool for Scientific Computing Carlo de Falco, Jordi Guti´ errez Hermoso November 8, 2012

Upload: others

Post on 23-Mar-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

GNU OctaveA free high-level tool for Scientific Computing

Carlo de Falco Jordi Gutierrez Hermoso

November 8 2012

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 235

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 335

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 435

What is Octave Octave and

What is Octave

Octave

ldquoA free a numerical environment mostly compatible with Matlabrdquo

What is compatibility A point of much debate

If it works in Matlab it should work in Octave

If it breaks it is considered a bug

If it works in Octave it can break in Matlab

aldquofreerdquo = ldquoliberordquo 6= ldquogratisrdquo

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 535

What is Octave Octave and

Lines of code

The stuff Octave is made of

Core

About 600000 lines of C++

About 100000 lines of m-scripts

About 50000 lines of Fortran

Octave-Forge

About 200000 lines of C++

About 330000 lines of m-scripts

About 50000 lines of Fortran

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 635

What is Octave Octave and

Lines of code

The stuff Octave is made of

Core

About 600000 lines of C++

About 100000 lines of m-scripts

About 50000 lines of Fortran

Octave-Forge

About 200000 lines of C++

About 330000 lines of m-scripts

About 50000 lines of Fortran

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 635

What is Octave Octave and

Lines of code

The stuff Octave is made of

Core

About 600000 lines of C++

About 100000 lines of m-scripts

About 50000 lines of Fortran

Octave-Forge

About 200000 lines of C++

About 330000 lines of m-scripts

About 50000 lines of Fortran

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 635

What is Octave Octave and

Features

Current features

N-d arrays linear algebra sparse matrices

Nonlinear equations

OrdinaryAlgebraic Differential Equations

Image processing statistics special functions

Many more

Features in development

GUI

JIT compiling

classdef OOP

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 735

What is Octave Octave and

What does it look like

Primarily a CLI interface

Figure CLI screenshot

Most requested feature GUI Will ship with next release (40)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 835

What is Octave Octave and

What does it look like

Primarily a CLI interface

Most requested feature GUI Will ship with next release (40)

Figure Qt based GUI development started as J Dawidrsquos GSoC2012 project

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 835

What is Octave Octave and

What does it look like

Primarily a CLI interface

Most requested feature GUI Will ship with next release (40)

Figure Qt based GUI development started as J Dawidrsquos GSoC2012 project

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 835

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 935

What is Octave Octave and

In the beginning

Companion software for chemical reactor textbook by James BRawlings and John G Ekerdt

John W Eaton (hereafter jwe) started coding in 1993

Rawlings said

Why donrsquot you call it ldquoOctaverdquo

Octave refers to Octave Levenspiel nothing to do with music

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1035

What is Octave Octave and

In the beginning

Companion software for chemical reactor textbook by James BRawlings and John G Ekerdt

John W Eaton (hereafter jwe) started coding in 1993

Rawlings said

Why donrsquot you call it ldquoOctaverdquo

Octave refers to Octave Levenspiel nothing to do with music

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1035

What is Octave Octave and

jwe is a lone wolf

jwe works almost completely alone for first four or five years

In the very beginning

No mailing lists

No widespread announcements

No VCS (these were dark times)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1135

What is Octave Octave and

jwe is a lone wolf

jwe works almost completely alone for first four or five years

In the very beginning

No mailing lists

No widespread announcements

No VCS (these were dark times)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1135

What is Octave Octave and

Contributions slowly trickle in

Timeline

1989 Planning stages

1992 Development begins

1993 First public announcement

1994 Version 10

1996 Version 20

1998 Version 21 development

2004 Version 29 in preparation for 30 release

2007 Version 30 major upgrade

2010 Version 324 last before using hg

2011 Version 340

2012 Version 364

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1235

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1435

What is Octave Octave and

Web resources

Web pages

Octave website

Octave-Forge website

Octave wiki

Users communication

Octave users mailing list

Octave-Forge mailing list

octave channel in Freenode

Savannah bug tracker

Developers collaboration

Octave Mercurial repository

Octave-Forge Subversion repository

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1535

What is Octave Octave and

Web resources

Web pages

Octave website

Octave-Forge website

Octave wiki

Users communication

Octave users mailing list

Octave-Forge mailing list

octave channel in Freenode

Savannah bug tracker

Developers collaboration

Octave Mercurial repository

Octave-Forge Subversion repository

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1535

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer15 current Core developers (with write access to repo)49 currently registered rsquoForge developers (38 active)296 total contributors over all timeBen Abbott Andy Adler Giles Anderson Joel Andersson Muthiah Annamalai Marco Atzeri Shai Ayal Roger Banks Ben Barrowes

Alexander Barth David Bateman Heinz Bauschke Roman Belov Karl Berry David Billinghurst Don Bindner Jakub Bogusz Moritz

Borgmann Paul Boven Richard Bovey John Bradshaw Marcus Brinkmann Remy Bruno Ansgar Burchard Marco Caliari Daniel

Calvelo John C Campbell Juan Pablo Carbajal Jean-Francois Cardoso Joao Cardoso Larrie Carr David Castelow Vincent

Cautaerts Clinton Chee Albert Chin-A-Young Carsten Clark J D Cole Martin Costabel Michael Creel Jeff Cunningham Martin

Dalecki Jorge Barros de Abreu Carlo de Falco Jacob Dawid Thomas D Dean Philippe Defert Bill Denney Fabian Deutsch

Christos Dimitrakakis David M Doolin Carne Draug Pascal A Dupuis John W Eaton Dirk Eddelbuettel Pieter Eendebak Paul

Eggert Stephen Eglen Peter Ekberg Rolf Fabian Gunnar Farneback Stephen Fegan Ramon Garcia Fernandez Torsten Finke Jose

Daniel Munoz Frias Brad Froehle Castor Fu Eduardo Gallestey Walter Gautschi Klaus Gebhardt Driss Ghaddab Nicolo Giorgetti

Michael D Godfrey Michael Goffioul Glenn Golden Tomislav Goles Keith Goodman Brian Gough Steffen Groot Etienne

Grossmann David Grundberg Peter Gustafson Kai Habel Patrick Hacker William P Y Hadisoeseno Jaroslav Hajek Benjamin Hall

Kim Hansen Soslashren Hauberg Dave Hawthorne Daniel Heiserer Martin Helm Stefan Hepp Jordi Gutierrez Hermoso Yozo Hida Ryan

Hinton Roman Hodek A Scottedward Hodel Richard Allan Holcombe Tom Holroyd David Hoover Kurt Hornik Christopher

Hulbert Cyril Humbert Teemu Ikonen Alan W Irwin Geoff Jacobsen Mats Jansson Cai Jianming Steven G Johnson Heikki Junes

Matthias Juschke Atsushi Kajita Jarkko Kaleva Mohamed Kamoun Lute Kamstra Fotios Kasolis Thomas Kasper Joel Keay

Mumit Khan Paul Kienzle Aaron A King Arno J Klaassen Alexander Klein Geoffrey Knauth Heine Kolltveit Ken Kouno Kacper

Kowalik Daniel Kraft Aravindh Krishnamoorthy Oyvind Kristiansen Piotr Krzyzanowski Volker Kuhlmann Tetsuro Kurita

Miroslaw Kwasniak Rafael Laboissiere Kai Labusch Claude Lacoursiere Walter Landry Bill Lash Dirk Laurie Maurice LeBrun

Friedrich Leisch Jyh-miin Lin Timo Lindfors Benjamin Lindner Ross Lippert David Livings Sebastien Loisel Erik de Castro Lopo

Massimo Lorenzin Emil Lucretiu Hoxide Ma James Macnicol Jens-Uwe Mager Rob Mahurin Ricardo Marranita Orestes Mas

Makoto Matsumoto Tatsuro Matsuoka Laurent Mazet G D McBain Alexander Mamonov Christoph Mayer Julio Hoffimann

Mendes Thorsten Meyer Petr Mikulik Stefan Monnier Antoine Moreau Kai P Mueller Hannes Muller Victor Munoz Carmen

Navarrete Todd Neal Philip Nienhuis Al Niessner Rick Niles Takuji Nishimura Kai Noda Eric Norum Krzesimir Nowak Michael

OrsquoBrien Peter OrsquoGorman Thorsten Ohl Arno Onken Luis F Ortiz Scott Pakin Gabriele Pannocchia Sylvain Pelissier Per Persson

Primozz Peterlin Jim Peterson Danilo Piazzalunga Nicholas Piper Elias Pipping Robert Platt Hans Ekkehard Plesser Tom Poage

Orion Poplawski Ondrej Popp Jef Poskanzer Francesco Potortı Konstantinos Poulios Jarno Rajahalme James B Rawlings Eric S

Raymond Balint Reczey Joshua Redstone Lukas Reichlin Michael Reifenberger Anthony Richardson Jason Riedy E Joshua Rigler

Petter Risholm Matthew W Roberts Andrew Ross Mark van Rossum Joe Rothweiler Kevin Ruland Kristian Rumberg Ryan

Rusaw Olli Saarela Toni Saarela Juhani Saastamoinen Radek Salac Ben Sapp Aleksej Saushev Alois Schlogl Michel D Schmid

Julian Schnidder Nicol N Schraudolph Sebastian Schubert Ludwig Schwardt Thomas L Scofield Daniel J Sebald Dmitri A

Sergatskov Vanya Sergeev Baylis Shanks Andriy Shinkarchuck Robert T Short Joseph P Skudlarek John Smith Julius Smith

Shan G Smith Peter L Sondergaard Joerg Specht Quentin H Spencer Christoph Spiel Richard Stallman Russell Standish Brett

Stewart Doug Stewart Jonathan Stickel Judd Storrs Thomas Stuart Ivan Sutoris John Swensen Daisuke Takago Ariel Tankus

Matthew Tenny Georg Thimm Duncan Temple Lang Kris Thielemans Olaf Till Christophe Tournery Thomas Treichl Karsten

Trulsen Frederick Umminger Utkarsh Upadhyay Stefan van der Walt Peter Van Wieren James R Van Zandt Gregory Vanuxem

Ivana Varekova Thomas Walter Andreas Weber Olaf Weber Thomas Weber Rik Wehbring Bob Weigel Andreas Weingessel

Martin Weiser Michael Weitzel David Wells Fook Fah Yap Sean Young Michael Zeising Federico Zenith Alex Zvoleff

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

296 total contributors over all time

How many users Thousands Millions

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1935

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2035

What is Octave Octave and

Octave-Forge

Octave-Forge

Octave Forge Is a place for concurrently developing and distributingextension packages for Octave

Each package has a maintainer responsible for updating andreleasing new versions of the package

Some packages are maintained by The Community

Installation via an integrated package manager

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2135

What is Octave Octave and

PKG

1 gtgt pkg install minusforge miscellaneous2 For information about changes from previous versions of the larr

miscellaneous package run news ( miscellaneous ) 3 gtgt pkg list4 Package Name | Version | Installation directory5 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus6 bim | 1 1 1 | ˜ octavebimminus1117 fpl | 1 3 3 | ˜ octavefplminus1338 general | 1 3 1 | ˜ octavegeneral minus1319 geometry | 1 6 0 | ˜ octavegeometry minus160

10 miscellaneous | 1 2 0 | ˜ octavemiscellaneous minus12011 gtgt pkg load miscellaneous12 gtgt pkg list13 Package Name | Version | Installation directory14 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus15 bim | 1 1 1 | ˜ octavebimminus11116 fpl | 1 3 3 | ˜ octavefplminus13317 general | 1 3 1 | ˜ octavegeneral minus13118 geometry | 1 6 0 | ˜ octavegeometry minus16019 miscellaneous lowast| 1 2 0 | ˜ octavemiscellaneous minus120

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2235

What is Octave Octave and

PKG

1 gtgt pkg describe bim minusverbose2 minusminusminus3 Package name 4 bim5 Version 6 1 1 17 Short description 8 Package f o r solving Diffusion Advection Reaction ( DAR ) Partial larr

Differential Equations9 Status

10 Not loaded11 minusminusminus12 Provides 13 Matrix assembly14 bim1a_advection_diffusion15 bim1a_advection_upwind16 bim2a_advection_diffusion17 18 Preminusprocessing and Postminusprocessing computations19 bim2c_mesh_properties20 21 gtgt

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2335

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2535

What is Octave Octave and

Broadcasting

Since 360 Octave automatically broadcasts arrays when usingelementwise binary operators

Corresponding array dimensions must either be equal or one ofthem must be 1

In case all dimensions are equal ordinary element-by-elementarithmetic takes place

When one of the dimensions is 1 the array with that singletondimension gets copied along that dimension until it matches thedimension of the other array

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2635

What is Octave Octave and

Broadcasting

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Without broadcasting x + y would be an error because dimensions do not agree

With broadcasting it is as if the following operation were performed

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 10 20 3 0 10 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Other notable differences with Matlab listed in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2735

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2835

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 include lto c t a v e o c t hgt2

3 DEFUN_DLD ( dld args nargout dld (array) nreturn the elements of larrthe array in reverse ordern )

4 5 octave_value_list retval 6 int nargin = args length ( ) 7

8 if ( nargin = 1)9 print_usage ( )

10 else11 12 Arrayltdoublegt a = args ( 0 ) array_value ( ) 13 if ( error_state )14 15 Arrayltdoublegt b ( a )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

16 doublelowast ap = a fortran_vec ( ) 17 doublelowast bp = b fortran_vec ( ) 18 for ( octave_idx_type i = a numel ( ) minus 1 j = 0 i gt= 0 larr

iminusminus j++)19 bp [ i ] = ap [ j ] 20 retval = octave_value ( b ) 21 22 23 return retval 24

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 gtgt mkoctfile dld cc2 gtgt a = randn ( 5 )3 a =4

5 0395421 minus1425232 minus0176544 1055205 22293716 minus0241893 0035004 minus0296543 minus1710613 04443187 minus0752467 minus2220469 2380951 0766246 11961538 1404672 0623112 1182609 0196125 06093259 minus0687019 0646079 2239012 minus0495169 1488314

10

11 gtgt b = dld ( a )12 b =13

14 1488314 minus0495169 2239012 0646079 minus068701915 0609325 0196125 1182609 0623112 140467216 1196153 0766246 2380951 minus2220469 minus075246717 0444318 minus1710613 minus0296543 0035004 minus024189318 2229371 1055205 minus0176544 minus1425232 039542119

20 gtgt

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 2: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 235

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 335

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 435

What is Octave Octave and

What is Octave

Octave

ldquoA free a numerical environment mostly compatible with Matlabrdquo

What is compatibility A point of much debate

If it works in Matlab it should work in Octave

If it breaks it is considered a bug

If it works in Octave it can break in Matlab

aldquofreerdquo = ldquoliberordquo 6= ldquogratisrdquo

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 535

What is Octave Octave and

Lines of code

The stuff Octave is made of

Core

About 600000 lines of C++

About 100000 lines of m-scripts

About 50000 lines of Fortran

Octave-Forge

About 200000 lines of C++

About 330000 lines of m-scripts

About 50000 lines of Fortran

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 635

What is Octave Octave and

Lines of code

The stuff Octave is made of

Core

About 600000 lines of C++

About 100000 lines of m-scripts

About 50000 lines of Fortran

Octave-Forge

About 200000 lines of C++

About 330000 lines of m-scripts

About 50000 lines of Fortran

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 635

What is Octave Octave and

Lines of code

The stuff Octave is made of

Core

About 600000 lines of C++

About 100000 lines of m-scripts

About 50000 lines of Fortran

Octave-Forge

About 200000 lines of C++

About 330000 lines of m-scripts

About 50000 lines of Fortran

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 635

What is Octave Octave and

Features

Current features

N-d arrays linear algebra sparse matrices

Nonlinear equations

OrdinaryAlgebraic Differential Equations

Image processing statistics special functions

Many more

Features in development

GUI

JIT compiling

classdef OOP

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 735

What is Octave Octave and

What does it look like

Primarily a CLI interface

Figure CLI screenshot

Most requested feature GUI Will ship with next release (40)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 835

What is Octave Octave and

What does it look like

Primarily a CLI interface

Most requested feature GUI Will ship with next release (40)

Figure Qt based GUI development started as J Dawidrsquos GSoC2012 project

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 835

What is Octave Octave and

What does it look like

Primarily a CLI interface

Most requested feature GUI Will ship with next release (40)

Figure Qt based GUI development started as J Dawidrsquos GSoC2012 project

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 835

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 935

What is Octave Octave and

In the beginning

Companion software for chemical reactor textbook by James BRawlings and John G Ekerdt

John W Eaton (hereafter jwe) started coding in 1993

Rawlings said

Why donrsquot you call it ldquoOctaverdquo

Octave refers to Octave Levenspiel nothing to do with music

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1035

What is Octave Octave and

In the beginning

Companion software for chemical reactor textbook by James BRawlings and John G Ekerdt

John W Eaton (hereafter jwe) started coding in 1993

Rawlings said

Why donrsquot you call it ldquoOctaverdquo

Octave refers to Octave Levenspiel nothing to do with music

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1035

What is Octave Octave and

jwe is a lone wolf

jwe works almost completely alone for first four or five years

In the very beginning

No mailing lists

No widespread announcements

No VCS (these were dark times)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1135

What is Octave Octave and

jwe is a lone wolf

jwe works almost completely alone for first four or five years

In the very beginning

No mailing lists

No widespread announcements

No VCS (these were dark times)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1135

What is Octave Octave and

Contributions slowly trickle in

Timeline

1989 Planning stages

1992 Development begins

1993 First public announcement

1994 Version 10

1996 Version 20

1998 Version 21 development

2004 Version 29 in preparation for 30 release

2007 Version 30 major upgrade

2010 Version 324 last before using hg

2011 Version 340

2012 Version 364

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1235

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1435

What is Octave Octave and

Web resources

Web pages

Octave website

Octave-Forge website

Octave wiki

Users communication

Octave users mailing list

Octave-Forge mailing list

octave channel in Freenode

Savannah bug tracker

Developers collaboration

Octave Mercurial repository

Octave-Forge Subversion repository

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1535

What is Octave Octave and

Web resources

Web pages

Octave website

Octave-Forge website

Octave wiki

Users communication

Octave users mailing list

Octave-Forge mailing list

octave channel in Freenode

Savannah bug tracker

Developers collaboration

Octave Mercurial repository

Octave-Forge Subversion repository

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1535

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer15 current Core developers (with write access to repo)49 currently registered rsquoForge developers (38 active)296 total contributors over all timeBen Abbott Andy Adler Giles Anderson Joel Andersson Muthiah Annamalai Marco Atzeri Shai Ayal Roger Banks Ben Barrowes

Alexander Barth David Bateman Heinz Bauschke Roman Belov Karl Berry David Billinghurst Don Bindner Jakub Bogusz Moritz

Borgmann Paul Boven Richard Bovey John Bradshaw Marcus Brinkmann Remy Bruno Ansgar Burchard Marco Caliari Daniel

Calvelo John C Campbell Juan Pablo Carbajal Jean-Francois Cardoso Joao Cardoso Larrie Carr David Castelow Vincent

Cautaerts Clinton Chee Albert Chin-A-Young Carsten Clark J D Cole Martin Costabel Michael Creel Jeff Cunningham Martin

Dalecki Jorge Barros de Abreu Carlo de Falco Jacob Dawid Thomas D Dean Philippe Defert Bill Denney Fabian Deutsch

Christos Dimitrakakis David M Doolin Carne Draug Pascal A Dupuis John W Eaton Dirk Eddelbuettel Pieter Eendebak Paul

Eggert Stephen Eglen Peter Ekberg Rolf Fabian Gunnar Farneback Stephen Fegan Ramon Garcia Fernandez Torsten Finke Jose

Daniel Munoz Frias Brad Froehle Castor Fu Eduardo Gallestey Walter Gautschi Klaus Gebhardt Driss Ghaddab Nicolo Giorgetti

Michael D Godfrey Michael Goffioul Glenn Golden Tomislav Goles Keith Goodman Brian Gough Steffen Groot Etienne

Grossmann David Grundberg Peter Gustafson Kai Habel Patrick Hacker William P Y Hadisoeseno Jaroslav Hajek Benjamin Hall

Kim Hansen Soslashren Hauberg Dave Hawthorne Daniel Heiserer Martin Helm Stefan Hepp Jordi Gutierrez Hermoso Yozo Hida Ryan

Hinton Roman Hodek A Scottedward Hodel Richard Allan Holcombe Tom Holroyd David Hoover Kurt Hornik Christopher

Hulbert Cyril Humbert Teemu Ikonen Alan W Irwin Geoff Jacobsen Mats Jansson Cai Jianming Steven G Johnson Heikki Junes

Matthias Juschke Atsushi Kajita Jarkko Kaleva Mohamed Kamoun Lute Kamstra Fotios Kasolis Thomas Kasper Joel Keay

Mumit Khan Paul Kienzle Aaron A King Arno J Klaassen Alexander Klein Geoffrey Knauth Heine Kolltveit Ken Kouno Kacper

Kowalik Daniel Kraft Aravindh Krishnamoorthy Oyvind Kristiansen Piotr Krzyzanowski Volker Kuhlmann Tetsuro Kurita

Miroslaw Kwasniak Rafael Laboissiere Kai Labusch Claude Lacoursiere Walter Landry Bill Lash Dirk Laurie Maurice LeBrun

Friedrich Leisch Jyh-miin Lin Timo Lindfors Benjamin Lindner Ross Lippert David Livings Sebastien Loisel Erik de Castro Lopo

Massimo Lorenzin Emil Lucretiu Hoxide Ma James Macnicol Jens-Uwe Mager Rob Mahurin Ricardo Marranita Orestes Mas

Makoto Matsumoto Tatsuro Matsuoka Laurent Mazet G D McBain Alexander Mamonov Christoph Mayer Julio Hoffimann

Mendes Thorsten Meyer Petr Mikulik Stefan Monnier Antoine Moreau Kai P Mueller Hannes Muller Victor Munoz Carmen

Navarrete Todd Neal Philip Nienhuis Al Niessner Rick Niles Takuji Nishimura Kai Noda Eric Norum Krzesimir Nowak Michael

OrsquoBrien Peter OrsquoGorman Thorsten Ohl Arno Onken Luis F Ortiz Scott Pakin Gabriele Pannocchia Sylvain Pelissier Per Persson

Primozz Peterlin Jim Peterson Danilo Piazzalunga Nicholas Piper Elias Pipping Robert Platt Hans Ekkehard Plesser Tom Poage

Orion Poplawski Ondrej Popp Jef Poskanzer Francesco Potortı Konstantinos Poulios Jarno Rajahalme James B Rawlings Eric S

Raymond Balint Reczey Joshua Redstone Lukas Reichlin Michael Reifenberger Anthony Richardson Jason Riedy E Joshua Rigler

Petter Risholm Matthew W Roberts Andrew Ross Mark van Rossum Joe Rothweiler Kevin Ruland Kristian Rumberg Ryan

Rusaw Olli Saarela Toni Saarela Juhani Saastamoinen Radek Salac Ben Sapp Aleksej Saushev Alois Schlogl Michel D Schmid

Julian Schnidder Nicol N Schraudolph Sebastian Schubert Ludwig Schwardt Thomas L Scofield Daniel J Sebald Dmitri A

Sergatskov Vanya Sergeev Baylis Shanks Andriy Shinkarchuck Robert T Short Joseph P Skudlarek John Smith Julius Smith

Shan G Smith Peter L Sondergaard Joerg Specht Quentin H Spencer Christoph Spiel Richard Stallman Russell Standish Brett

Stewart Doug Stewart Jonathan Stickel Judd Storrs Thomas Stuart Ivan Sutoris John Swensen Daisuke Takago Ariel Tankus

Matthew Tenny Georg Thimm Duncan Temple Lang Kris Thielemans Olaf Till Christophe Tournery Thomas Treichl Karsten

Trulsen Frederick Umminger Utkarsh Upadhyay Stefan van der Walt Peter Van Wieren James R Van Zandt Gregory Vanuxem

Ivana Varekova Thomas Walter Andreas Weber Olaf Weber Thomas Weber Rik Wehbring Bob Weigel Andreas Weingessel

Martin Weiser Michael Weitzel David Wells Fook Fah Yap Sean Young Michael Zeising Federico Zenith Alex Zvoleff

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

296 total contributors over all time

How many users Thousands Millions

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1935

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2035

What is Octave Octave and

Octave-Forge

Octave-Forge

Octave Forge Is a place for concurrently developing and distributingextension packages for Octave

Each package has a maintainer responsible for updating andreleasing new versions of the package

Some packages are maintained by The Community

Installation via an integrated package manager

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2135

What is Octave Octave and

PKG

1 gtgt pkg install minusforge miscellaneous2 For information about changes from previous versions of the larr

miscellaneous package run news ( miscellaneous ) 3 gtgt pkg list4 Package Name | Version | Installation directory5 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus6 bim | 1 1 1 | ˜ octavebimminus1117 fpl | 1 3 3 | ˜ octavefplminus1338 general | 1 3 1 | ˜ octavegeneral minus1319 geometry | 1 6 0 | ˜ octavegeometry minus160

10 miscellaneous | 1 2 0 | ˜ octavemiscellaneous minus12011 gtgt pkg load miscellaneous12 gtgt pkg list13 Package Name | Version | Installation directory14 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus15 bim | 1 1 1 | ˜ octavebimminus11116 fpl | 1 3 3 | ˜ octavefplminus13317 general | 1 3 1 | ˜ octavegeneral minus13118 geometry | 1 6 0 | ˜ octavegeometry minus16019 miscellaneous lowast| 1 2 0 | ˜ octavemiscellaneous minus120

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2235

What is Octave Octave and

PKG

1 gtgt pkg describe bim minusverbose2 minusminusminus3 Package name 4 bim5 Version 6 1 1 17 Short description 8 Package f o r solving Diffusion Advection Reaction ( DAR ) Partial larr

Differential Equations9 Status

10 Not loaded11 minusminusminus12 Provides 13 Matrix assembly14 bim1a_advection_diffusion15 bim1a_advection_upwind16 bim2a_advection_diffusion17 18 Preminusprocessing and Postminusprocessing computations19 bim2c_mesh_properties20 21 gtgt

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2335

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2535

What is Octave Octave and

Broadcasting

Since 360 Octave automatically broadcasts arrays when usingelementwise binary operators

Corresponding array dimensions must either be equal or one ofthem must be 1

In case all dimensions are equal ordinary element-by-elementarithmetic takes place

When one of the dimensions is 1 the array with that singletondimension gets copied along that dimension until it matches thedimension of the other array

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2635

What is Octave Octave and

Broadcasting

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Without broadcasting x + y would be an error because dimensions do not agree

With broadcasting it is as if the following operation were performed

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 10 20 3 0 10 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Other notable differences with Matlab listed in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2735

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2835

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 include lto c t a v e o c t hgt2

3 DEFUN_DLD ( dld args nargout dld (array) nreturn the elements of larrthe array in reverse ordern )

4 5 octave_value_list retval 6 int nargin = args length ( ) 7

8 if ( nargin = 1)9 print_usage ( )

10 else11 12 Arrayltdoublegt a = args ( 0 ) array_value ( ) 13 if ( error_state )14 15 Arrayltdoublegt b ( a )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

16 doublelowast ap = a fortran_vec ( ) 17 doublelowast bp = b fortran_vec ( ) 18 for ( octave_idx_type i = a numel ( ) minus 1 j = 0 i gt= 0 larr

iminusminus j++)19 bp [ i ] = ap [ j ] 20 retval = octave_value ( b ) 21 22 23 return retval 24

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 gtgt mkoctfile dld cc2 gtgt a = randn ( 5 )3 a =4

5 0395421 minus1425232 minus0176544 1055205 22293716 minus0241893 0035004 minus0296543 minus1710613 04443187 minus0752467 minus2220469 2380951 0766246 11961538 1404672 0623112 1182609 0196125 06093259 minus0687019 0646079 2239012 minus0495169 1488314

10

11 gtgt b = dld ( a )12 b =13

14 1488314 minus0495169 2239012 0646079 minus068701915 0609325 0196125 1182609 0623112 140467216 1196153 0766246 2380951 minus2220469 minus075246717 0444318 minus1710613 minus0296543 0035004 minus024189318 2229371 1055205 minus0176544 minus1425232 039542119

20 gtgt

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 3: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 335

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 435

What is Octave Octave and

What is Octave

Octave

ldquoA free a numerical environment mostly compatible with Matlabrdquo

What is compatibility A point of much debate

If it works in Matlab it should work in Octave

If it breaks it is considered a bug

If it works in Octave it can break in Matlab

aldquofreerdquo = ldquoliberordquo 6= ldquogratisrdquo

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 535

What is Octave Octave and

Lines of code

The stuff Octave is made of

Core

About 600000 lines of C++

About 100000 lines of m-scripts

About 50000 lines of Fortran

Octave-Forge

About 200000 lines of C++

About 330000 lines of m-scripts

About 50000 lines of Fortran

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 635

What is Octave Octave and

Lines of code

The stuff Octave is made of

Core

About 600000 lines of C++

About 100000 lines of m-scripts

About 50000 lines of Fortran

Octave-Forge

About 200000 lines of C++

About 330000 lines of m-scripts

About 50000 lines of Fortran

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 635

What is Octave Octave and

Lines of code

The stuff Octave is made of

Core

About 600000 lines of C++

About 100000 lines of m-scripts

About 50000 lines of Fortran

Octave-Forge

About 200000 lines of C++

About 330000 lines of m-scripts

About 50000 lines of Fortran

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 635

What is Octave Octave and

Features

Current features

N-d arrays linear algebra sparse matrices

Nonlinear equations

OrdinaryAlgebraic Differential Equations

Image processing statistics special functions

Many more

Features in development

GUI

JIT compiling

classdef OOP

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 735

What is Octave Octave and

What does it look like

Primarily a CLI interface

Figure CLI screenshot

Most requested feature GUI Will ship with next release (40)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 835

What is Octave Octave and

What does it look like

Primarily a CLI interface

Most requested feature GUI Will ship with next release (40)

Figure Qt based GUI development started as J Dawidrsquos GSoC2012 project

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 835

What is Octave Octave and

What does it look like

Primarily a CLI interface

Most requested feature GUI Will ship with next release (40)

Figure Qt based GUI development started as J Dawidrsquos GSoC2012 project

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 835

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 935

What is Octave Octave and

In the beginning

Companion software for chemical reactor textbook by James BRawlings and John G Ekerdt

John W Eaton (hereafter jwe) started coding in 1993

Rawlings said

Why donrsquot you call it ldquoOctaverdquo

Octave refers to Octave Levenspiel nothing to do with music

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1035

What is Octave Octave and

In the beginning

Companion software for chemical reactor textbook by James BRawlings and John G Ekerdt

John W Eaton (hereafter jwe) started coding in 1993

Rawlings said

Why donrsquot you call it ldquoOctaverdquo

Octave refers to Octave Levenspiel nothing to do with music

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1035

What is Octave Octave and

jwe is a lone wolf

jwe works almost completely alone for first four or five years

In the very beginning

No mailing lists

No widespread announcements

No VCS (these were dark times)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1135

What is Octave Octave and

jwe is a lone wolf

jwe works almost completely alone for first four or five years

In the very beginning

No mailing lists

No widespread announcements

No VCS (these were dark times)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1135

What is Octave Octave and

Contributions slowly trickle in

Timeline

1989 Planning stages

1992 Development begins

1993 First public announcement

1994 Version 10

1996 Version 20

1998 Version 21 development

2004 Version 29 in preparation for 30 release

2007 Version 30 major upgrade

2010 Version 324 last before using hg

2011 Version 340

2012 Version 364

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1235

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1435

What is Octave Octave and

Web resources

Web pages

Octave website

Octave-Forge website

Octave wiki

Users communication

Octave users mailing list

Octave-Forge mailing list

octave channel in Freenode

Savannah bug tracker

Developers collaboration

Octave Mercurial repository

Octave-Forge Subversion repository

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1535

What is Octave Octave and

Web resources

Web pages

Octave website

Octave-Forge website

Octave wiki

Users communication

Octave users mailing list

Octave-Forge mailing list

octave channel in Freenode

Savannah bug tracker

Developers collaboration

Octave Mercurial repository

Octave-Forge Subversion repository

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1535

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer15 current Core developers (with write access to repo)49 currently registered rsquoForge developers (38 active)296 total contributors over all timeBen Abbott Andy Adler Giles Anderson Joel Andersson Muthiah Annamalai Marco Atzeri Shai Ayal Roger Banks Ben Barrowes

Alexander Barth David Bateman Heinz Bauschke Roman Belov Karl Berry David Billinghurst Don Bindner Jakub Bogusz Moritz

Borgmann Paul Boven Richard Bovey John Bradshaw Marcus Brinkmann Remy Bruno Ansgar Burchard Marco Caliari Daniel

Calvelo John C Campbell Juan Pablo Carbajal Jean-Francois Cardoso Joao Cardoso Larrie Carr David Castelow Vincent

Cautaerts Clinton Chee Albert Chin-A-Young Carsten Clark J D Cole Martin Costabel Michael Creel Jeff Cunningham Martin

Dalecki Jorge Barros de Abreu Carlo de Falco Jacob Dawid Thomas D Dean Philippe Defert Bill Denney Fabian Deutsch

Christos Dimitrakakis David M Doolin Carne Draug Pascal A Dupuis John W Eaton Dirk Eddelbuettel Pieter Eendebak Paul

Eggert Stephen Eglen Peter Ekberg Rolf Fabian Gunnar Farneback Stephen Fegan Ramon Garcia Fernandez Torsten Finke Jose

Daniel Munoz Frias Brad Froehle Castor Fu Eduardo Gallestey Walter Gautschi Klaus Gebhardt Driss Ghaddab Nicolo Giorgetti

Michael D Godfrey Michael Goffioul Glenn Golden Tomislav Goles Keith Goodman Brian Gough Steffen Groot Etienne

Grossmann David Grundberg Peter Gustafson Kai Habel Patrick Hacker William P Y Hadisoeseno Jaroslav Hajek Benjamin Hall

Kim Hansen Soslashren Hauberg Dave Hawthorne Daniel Heiserer Martin Helm Stefan Hepp Jordi Gutierrez Hermoso Yozo Hida Ryan

Hinton Roman Hodek A Scottedward Hodel Richard Allan Holcombe Tom Holroyd David Hoover Kurt Hornik Christopher

Hulbert Cyril Humbert Teemu Ikonen Alan W Irwin Geoff Jacobsen Mats Jansson Cai Jianming Steven G Johnson Heikki Junes

Matthias Juschke Atsushi Kajita Jarkko Kaleva Mohamed Kamoun Lute Kamstra Fotios Kasolis Thomas Kasper Joel Keay

Mumit Khan Paul Kienzle Aaron A King Arno J Klaassen Alexander Klein Geoffrey Knauth Heine Kolltveit Ken Kouno Kacper

Kowalik Daniel Kraft Aravindh Krishnamoorthy Oyvind Kristiansen Piotr Krzyzanowski Volker Kuhlmann Tetsuro Kurita

Miroslaw Kwasniak Rafael Laboissiere Kai Labusch Claude Lacoursiere Walter Landry Bill Lash Dirk Laurie Maurice LeBrun

Friedrich Leisch Jyh-miin Lin Timo Lindfors Benjamin Lindner Ross Lippert David Livings Sebastien Loisel Erik de Castro Lopo

Massimo Lorenzin Emil Lucretiu Hoxide Ma James Macnicol Jens-Uwe Mager Rob Mahurin Ricardo Marranita Orestes Mas

Makoto Matsumoto Tatsuro Matsuoka Laurent Mazet G D McBain Alexander Mamonov Christoph Mayer Julio Hoffimann

Mendes Thorsten Meyer Petr Mikulik Stefan Monnier Antoine Moreau Kai P Mueller Hannes Muller Victor Munoz Carmen

Navarrete Todd Neal Philip Nienhuis Al Niessner Rick Niles Takuji Nishimura Kai Noda Eric Norum Krzesimir Nowak Michael

OrsquoBrien Peter OrsquoGorman Thorsten Ohl Arno Onken Luis F Ortiz Scott Pakin Gabriele Pannocchia Sylvain Pelissier Per Persson

Primozz Peterlin Jim Peterson Danilo Piazzalunga Nicholas Piper Elias Pipping Robert Platt Hans Ekkehard Plesser Tom Poage

Orion Poplawski Ondrej Popp Jef Poskanzer Francesco Potortı Konstantinos Poulios Jarno Rajahalme James B Rawlings Eric S

Raymond Balint Reczey Joshua Redstone Lukas Reichlin Michael Reifenberger Anthony Richardson Jason Riedy E Joshua Rigler

Petter Risholm Matthew W Roberts Andrew Ross Mark van Rossum Joe Rothweiler Kevin Ruland Kristian Rumberg Ryan

Rusaw Olli Saarela Toni Saarela Juhani Saastamoinen Radek Salac Ben Sapp Aleksej Saushev Alois Schlogl Michel D Schmid

Julian Schnidder Nicol N Schraudolph Sebastian Schubert Ludwig Schwardt Thomas L Scofield Daniel J Sebald Dmitri A

Sergatskov Vanya Sergeev Baylis Shanks Andriy Shinkarchuck Robert T Short Joseph P Skudlarek John Smith Julius Smith

Shan G Smith Peter L Sondergaard Joerg Specht Quentin H Spencer Christoph Spiel Richard Stallman Russell Standish Brett

Stewart Doug Stewart Jonathan Stickel Judd Storrs Thomas Stuart Ivan Sutoris John Swensen Daisuke Takago Ariel Tankus

Matthew Tenny Georg Thimm Duncan Temple Lang Kris Thielemans Olaf Till Christophe Tournery Thomas Treichl Karsten

Trulsen Frederick Umminger Utkarsh Upadhyay Stefan van der Walt Peter Van Wieren James R Van Zandt Gregory Vanuxem

Ivana Varekova Thomas Walter Andreas Weber Olaf Weber Thomas Weber Rik Wehbring Bob Weigel Andreas Weingessel

Martin Weiser Michael Weitzel David Wells Fook Fah Yap Sean Young Michael Zeising Federico Zenith Alex Zvoleff

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

296 total contributors over all time

How many users Thousands Millions

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1935

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2035

What is Octave Octave and

Octave-Forge

Octave-Forge

Octave Forge Is a place for concurrently developing and distributingextension packages for Octave

Each package has a maintainer responsible for updating andreleasing new versions of the package

Some packages are maintained by The Community

Installation via an integrated package manager

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2135

What is Octave Octave and

PKG

1 gtgt pkg install minusforge miscellaneous2 For information about changes from previous versions of the larr

miscellaneous package run news ( miscellaneous ) 3 gtgt pkg list4 Package Name | Version | Installation directory5 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus6 bim | 1 1 1 | ˜ octavebimminus1117 fpl | 1 3 3 | ˜ octavefplminus1338 general | 1 3 1 | ˜ octavegeneral minus1319 geometry | 1 6 0 | ˜ octavegeometry minus160

10 miscellaneous | 1 2 0 | ˜ octavemiscellaneous minus12011 gtgt pkg load miscellaneous12 gtgt pkg list13 Package Name | Version | Installation directory14 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus15 bim | 1 1 1 | ˜ octavebimminus11116 fpl | 1 3 3 | ˜ octavefplminus13317 general | 1 3 1 | ˜ octavegeneral minus13118 geometry | 1 6 0 | ˜ octavegeometry minus16019 miscellaneous lowast| 1 2 0 | ˜ octavemiscellaneous minus120

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2235

What is Octave Octave and

PKG

1 gtgt pkg describe bim minusverbose2 minusminusminus3 Package name 4 bim5 Version 6 1 1 17 Short description 8 Package f o r solving Diffusion Advection Reaction ( DAR ) Partial larr

Differential Equations9 Status

10 Not loaded11 minusminusminus12 Provides 13 Matrix assembly14 bim1a_advection_diffusion15 bim1a_advection_upwind16 bim2a_advection_diffusion17 18 Preminusprocessing and Postminusprocessing computations19 bim2c_mesh_properties20 21 gtgt

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2335

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2535

What is Octave Octave and

Broadcasting

Since 360 Octave automatically broadcasts arrays when usingelementwise binary operators

Corresponding array dimensions must either be equal or one ofthem must be 1

In case all dimensions are equal ordinary element-by-elementarithmetic takes place

When one of the dimensions is 1 the array with that singletondimension gets copied along that dimension until it matches thedimension of the other array

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2635

What is Octave Octave and

Broadcasting

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Without broadcasting x + y would be an error because dimensions do not agree

With broadcasting it is as if the following operation were performed

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 10 20 3 0 10 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Other notable differences with Matlab listed in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2735

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2835

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 include lto c t a v e o c t hgt2

3 DEFUN_DLD ( dld args nargout dld (array) nreturn the elements of larrthe array in reverse ordern )

4 5 octave_value_list retval 6 int nargin = args length ( ) 7

8 if ( nargin = 1)9 print_usage ( )

10 else11 12 Arrayltdoublegt a = args ( 0 ) array_value ( ) 13 if ( error_state )14 15 Arrayltdoublegt b ( a )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

16 doublelowast ap = a fortran_vec ( ) 17 doublelowast bp = b fortran_vec ( ) 18 for ( octave_idx_type i = a numel ( ) minus 1 j = 0 i gt= 0 larr

iminusminus j++)19 bp [ i ] = ap [ j ] 20 retval = octave_value ( b ) 21 22 23 return retval 24

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 gtgt mkoctfile dld cc2 gtgt a = randn ( 5 )3 a =4

5 0395421 minus1425232 minus0176544 1055205 22293716 minus0241893 0035004 minus0296543 minus1710613 04443187 minus0752467 minus2220469 2380951 0766246 11961538 1404672 0623112 1182609 0196125 06093259 minus0687019 0646079 2239012 minus0495169 1488314

10

11 gtgt b = dld ( a )12 b =13

14 1488314 minus0495169 2239012 0646079 minus068701915 0609325 0196125 1182609 0623112 140467216 1196153 0766246 2380951 minus2220469 minus075246717 0444318 minus1710613 minus0296543 0035004 minus024189318 2229371 1055205 minus0176544 minus1425232 039542119

20 gtgt

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 4: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 435

What is Octave Octave and

What is Octave

Octave

ldquoA free a numerical environment mostly compatible with Matlabrdquo

What is compatibility A point of much debate

If it works in Matlab it should work in Octave

If it breaks it is considered a bug

If it works in Octave it can break in Matlab

aldquofreerdquo = ldquoliberordquo 6= ldquogratisrdquo

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 535

What is Octave Octave and

Lines of code

The stuff Octave is made of

Core

About 600000 lines of C++

About 100000 lines of m-scripts

About 50000 lines of Fortran

Octave-Forge

About 200000 lines of C++

About 330000 lines of m-scripts

About 50000 lines of Fortran

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 635

What is Octave Octave and

Lines of code

The stuff Octave is made of

Core

About 600000 lines of C++

About 100000 lines of m-scripts

About 50000 lines of Fortran

Octave-Forge

About 200000 lines of C++

About 330000 lines of m-scripts

About 50000 lines of Fortran

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 635

What is Octave Octave and

Lines of code

The stuff Octave is made of

Core

About 600000 lines of C++

About 100000 lines of m-scripts

About 50000 lines of Fortran

Octave-Forge

About 200000 lines of C++

About 330000 lines of m-scripts

About 50000 lines of Fortran

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 635

What is Octave Octave and

Features

Current features

N-d arrays linear algebra sparse matrices

Nonlinear equations

OrdinaryAlgebraic Differential Equations

Image processing statistics special functions

Many more

Features in development

GUI

JIT compiling

classdef OOP

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 735

What is Octave Octave and

What does it look like

Primarily a CLI interface

Figure CLI screenshot

Most requested feature GUI Will ship with next release (40)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 835

What is Octave Octave and

What does it look like

Primarily a CLI interface

Most requested feature GUI Will ship with next release (40)

Figure Qt based GUI development started as J Dawidrsquos GSoC2012 project

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 835

What is Octave Octave and

What does it look like

Primarily a CLI interface

Most requested feature GUI Will ship with next release (40)

Figure Qt based GUI development started as J Dawidrsquos GSoC2012 project

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 835

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 935

What is Octave Octave and

In the beginning

Companion software for chemical reactor textbook by James BRawlings and John G Ekerdt

John W Eaton (hereafter jwe) started coding in 1993

Rawlings said

Why donrsquot you call it ldquoOctaverdquo

Octave refers to Octave Levenspiel nothing to do with music

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1035

What is Octave Octave and

In the beginning

Companion software for chemical reactor textbook by James BRawlings and John G Ekerdt

John W Eaton (hereafter jwe) started coding in 1993

Rawlings said

Why donrsquot you call it ldquoOctaverdquo

Octave refers to Octave Levenspiel nothing to do with music

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1035

What is Octave Octave and

jwe is a lone wolf

jwe works almost completely alone for first four or five years

In the very beginning

No mailing lists

No widespread announcements

No VCS (these were dark times)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1135

What is Octave Octave and

jwe is a lone wolf

jwe works almost completely alone for first four or five years

In the very beginning

No mailing lists

No widespread announcements

No VCS (these were dark times)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1135

What is Octave Octave and

Contributions slowly trickle in

Timeline

1989 Planning stages

1992 Development begins

1993 First public announcement

1994 Version 10

1996 Version 20

1998 Version 21 development

2004 Version 29 in preparation for 30 release

2007 Version 30 major upgrade

2010 Version 324 last before using hg

2011 Version 340

2012 Version 364

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1235

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1435

What is Octave Octave and

Web resources

Web pages

Octave website

Octave-Forge website

Octave wiki

Users communication

Octave users mailing list

Octave-Forge mailing list

octave channel in Freenode

Savannah bug tracker

Developers collaboration

Octave Mercurial repository

Octave-Forge Subversion repository

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1535

What is Octave Octave and

Web resources

Web pages

Octave website

Octave-Forge website

Octave wiki

Users communication

Octave users mailing list

Octave-Forge mailing list

octave channel in Freenode

Savannah bug tracker

Developers collaboration

Octave Mercurial repository

Octave-Forge Subversion repository

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1535

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer15 current Core developers (with write access to repo)49 currently registered rsquoForge developers (38 active)296 total contributors over all timeBen Abbott Andy Adler Giles Anderson Joel Andersson Muthiah Annamalai Marco Atzeri Shai Ayal Roger Banks Ben Barrowes

Alexander Barth David Bateman Heinz Bauschke Roman Belov Karl Berry David Billinghurst Don Bindner Jakub Bogusz Moritz

Borgmann Paul Boven Richard Bovey John Bradshaw Marcus Brinkmann Remy Bruno Ansgar Burchard Marco Caliari Daniel

Calvelo John C Campbell Juan Pablo Carbajal Jean-Francois Cardoso Joao Cardoso Larrie Carr David Castelow Vincent

Cautaerts Clinton Chee Albert Chin-A-Young Carsten Clark J D Cole Martin Costabel Michael Creel Jeff Cunningham Martin

Dalecki Jorge Barros de Abreu Carlo de Falco Jacob Dawid Thomas D Dean Philippe Defert Bill Denney Fabian Deutsch

Christos Dimitrakakis David M Doolin Carne Draug Pascal A Dupuis John W Eaton Dirk Eddelbuettel Pieter Eendebak Paul

Eggert Stephen Eglen Peter Ekberg Rolf Fabian Gunnar Farneback Stephen Fegan Ramon Garcia Fernandez Torsten Finke Jose

Daniel Munoz Frias Brad Froehle Castor Fu Eduardo Gallestey Walter Gautschi Klaus Gebhardt Driss Ghaddab Nicolo Giorgetti

Michael D Godfrey Michael Goffioul Glenn Golden Tomislav Goles Keith Goodman Brian Gough Steffen Groot Etienne

Grossmann David Grundberg Peter Gustafson Kai Habel Patrick Hacker William P Y Hadisoeseno Jaroslav Hajek Benjamin Hall

Kim Hansen Soslashren Hauberg Dave Hawthorne Daniel Heiserer Martin Helm Stefan Hepp Jordi Gutierrez Hermoso Yozo Hida Ryan

Hinton Roman Hodek A Scottedward Hodel Richard Allan Holcombe Tom Holroyd David Hoover Kurt Hornik Christopher

Hulbert Cyril Humbert Teemu Ikonen Alan W Irwin Geoff Jacobsen Mats Jansson Cai Jianming Steven G Johnson Heikki Junes

Matthias Juschke Atsushi Kajita Jarkko Kaleva Mohamed Kamoun Lute Kamstra Fotios Kasolis Thomas Kasper Joel Keay

Mumit Khan Paul Kienzle Aaron A King Arno J Klaassen Alexander Klein Geoffrey Knauth Heine Kolltveit Ken Kouno Kacper

Kowalik Daniel Kraft Aravindh Krishnamoorthy Oyvind Kristiansen Piotr Krzyzanowski Volker Kuhlmann Tetsuro Kurita

Miroslaw Kwasniak Rafael Laboissiere Kai Labusch Claude Lacoursiere Walter Landry Bill Lash Dirk Laurie Maurice LeBrun

Friedrich Leisch Jyh-miin Lin Timo Lindfors Benjamin Lindner Ross Lippert David Livings Sebastien Loisel Erik de Castro Lopo

Massimo Lorenzin Emil Lucretiu Hoxide Ma James Macnicol Jens-Uwe Mager Rob Mahurin Ricardo Marranita Orestes Mas

Makoto Matsumoto Tatsuro Matsuoka Laurent Mazet G D McBain Alexander Mamonov Christoph Mayer Julio Hoffimann

Mendes Thorsten Meyer Petr Mikulik Stefan Monnier Antoine Moreau Kai P Mueller Hannes Muller Victor Munoz Carmen

Navarrete Todd Neal Philip Nienhuis Al Niessner Rick Niles Takuji Nishimura Kai Noda Eric Norum Krzesimir Nowak Michael

OrsquoBrien Peter OrsquoGorman Thorsten Ohl Arno Onken Luis F Ortiz Scott Pakin Gabriele Pannocchia Sylvain Pelissier Per Persson

Primozz Peterlin Jim Peterson Danilo Piazzalunga Nicholas Piper Elias Pipping Robert Platt Hans Ekkehard Plesser Tom Poage

Orion Poplawski Ondrej Popp Jef Poskanzer Francesco Potortı Konstantinos Poulios Jarno Rajahalme James B Rawlings Eric S

Raymond Balint Reczey Joshua Redstone Lukas Reichlin Michael Reifenberger Anthony Richardson Jason Riedy E Joshua Rigler

Petter Risholm Matthew W Roberts Andrew Ross Mark van Rossum Joe Rothweiler Kevin Ruland Kristian Rumberg Ryan

Rusaw Olli Saarela Toni Saarela Juhani Saastamoinen Radek Salac Ben Sapp Aleksej Saushev Alois Schlogl Michel D Schmid

Julian Schnidder Nicol N Schraudolph Sebastian Schubert Ludwig Schwardt Thomas L Scofield Daniel J Sebald Dmitri A

Sergatskov Vanya Sergeev Baylis Shanks Andriy Shinkarchuck Robert T Short Joseph P Skudlarek John Smith Julius Smith

Shan G Smith Peter L Sondergaard Joerg Specht Quentin H Spencer Christoph Spiel Richard Stallman Russell Standish Brett

Stewart Doug Stewart Jonathan Stickel Judd Storrs Thomas Stuart Ivan Sutoris John Swensen Daisuke Takago Ariel Tankus

Matthew Tenny Georg Thimm Duncan Temple Lang Kris Thielemans Olaf Till Christophe Tournery Thomas Treichl Karsten

Trulsen Frederick Umminger Utkarsh Upadhyay Stefan van der Walt Peter Van Wieren James R Van Zandt Gregory Vanuxem

Ivana Varekova Thomas Walter Andreas Weber Olaf Weber Thomas Weber Rik Wehbring Bob Weigel Andreas Weingessel

Martin Weiser Michael Weitzel David Wells Fook Fah Yap Sean Young Michael Zeising Federico Zenith Alex Zvoleff

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

296 total contributors over all time

How many users Thousands Millions

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1935

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2035

What is Octave Octave and

Octave-Forge

Octave-Forge

Octave Forge Is a place for concurrently developing and distributingextension packages for Octave

Each package has a maintainer responsible for updating andreleasing new versions of the package

Some packages are maintained by The Community

Installation via an integrated package manager

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2135

What is Octave Octave and

PKG

1 gtgt pkg install minusforge miscellaneous2 For information about changes from previous versions of the larr

miscellaneous package run news ( miscellaneous ) 3 gtgt pkg list4 Package Name | Version | Installation directory5 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus6 bim | 1 1 1 | ˜ octavebimminus1117 fpl | 1 3 3 | ˜ octavefplminus1338 general | 1 3 1 | ˜ octavegeneral minus1319 geometry | 1 6 0 | ˜ octavegeometry minus160

10 miscellaneous | 1 2 0 | ˜ octavemiscellaneous minus12011 gtgt pkg load miscellaneous12 gtgt pkg list13 Package Name | Version | Installation directory14 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus15 bim | 1 1 1 | ˜ octavebimminus11116 fpl | 1 3 3 | ˜ octavefplminus13317 general | 1 3 1 | ˜ octavegeneral minus13118 geometry | 1 6 0 | ˜ octavegeometry minus16019 miscellaneous lowast| 1 2 0 | ˜ octavemiscellaneous minus120

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2235

What is Octave Octave and

PKG

1 gtgt pkg describe bim minusverbose2 minusminusminus3 Package name 4 bim5 Version 6 1 1 17 Short description 8 Package f o r solving Diffusion Advection Reaction ( DAR ) Partial larr

Differential Equations9 Status

10 Not loaded11 minusminusminus12 Provides 13 Matrix assembly14 bim1a_advection_diffusion15 bim1a_advection_upwind16 bim2a_advection_diffusion17 18 Preminusprocessing and Postminusprocessing computations19 bim2c_mesh_properties20 21 gtgt

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2335

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2535

What is Octave Octave and

Broadcasting

Since 360 Octave automatically broadcasts arrays when usingelementwise binary operators

Corresponding array dimensions must either be equal or one ofthem must be 1

In case all dimensions are equal ordinary element-by-elementarithmetic takes place

When one of the dimensions is 1 the array with that singletondimension gets copied along that dimension until it matches thedimension of the other array

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2635

What is Octave Octave and

Broadcasting

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Without broadcasting x + y would be an error because dimensions do not agree

With broadcasting it is as if the following operation were performed

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 10 20 3 0 10 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Other notable differences with Matlab listed in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2735

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2835

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 include lto c t a v e o c t hgt2

3 DEFUN_DLD ( dld args nargout dld (array) nreturn the elements of larrthe array in reverse ordern )

4 5 octave_value_list retval 6 int nargin = args length ( ) 7

8 if ( nargin = 1)9 print_usage ( )

10 else11 12 Arrayltdoublegt a = args ( 0 ) array_value ( ) 13 if ( error_state )14 15 Arrayltdoublegt b ( a )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

16 doublelowast ap = a fortran_vec ( ) 17 doublelowast bp = b fortran_vec ( ) 18 for ( octave_idx_type i = a numel ( ) minus 1 j = 0 i gt= 0 larr

iminusminus j++)19 bp [ i ] = ap [ j ] 20 retval = octave_value ( b ) 21 22 23 return retval 24

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 gtgt mkoctfile dld cc2 gtgt a = randn ( 5 )3 a =4

5 0395421 minus1425232 minus0176544 1055205 22293716 minus0241893 0035004 minus0296543 minus1710613 04443187 minus0752467 minus2220469 2380951 0766246 11961538 1404672 0623112 1182609 0196125 06093259 minus0687019 0646079 2239012 minus0495169 1488314

10

11 gtgt b = dld ( a )12 b =13

14 1488314 minus0495169 2239012 0646079 minus068701915 0609325 0196125 1182609 0623112 140467216 1196153 0766246 2380951 minus2220469 minus075246717 0444318 minus1710613 minus0296543 0035004 minus024189318 2229371 1055205 minus0176544 minus1425232 039542119

20 gtgt

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 5: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

What is Octave

Octave

ldquoA free a numerical environment mostly compatible with Matlabrdquo

What is compatibility A point of much debate

If it works in Matlab it should work in Octave

If it breaks it is considered a bug

If it works in Octave it can break in Matlab

aldquofreerdquo = ldquoliberordquo 6= ldquogratisrdquo

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 535

What is Octave Octave and

Lines of code

The stuff Octave is made of

Core

About 600000 lines of C++

About 100000 lines of m-scripts

About 50000 lines of Fortran

Octave-Forge

About 200000 lines of C++

About 330000 lines of m-scripts

About 50000 lines of Fortran

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 635

What is Octave Octave and

Lines of code

The stuff Octave is made of

Core

About 600000 lines of C++

About 100000 lines of m-scripts

About 50000 lines of Fortran

Octave-Forge

About 200000 lines of C++

About 330000 lines of m-scripts

About 50000 lines of Fortran

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 635

What is Octave Octave and

Lines of code

The stuff Octave is made of

Core

About 600000 lines of C++

About 100000 lines of m-scripts

About 50000 lines of Fortran

Octave-Forge

About 200000 lines of C++

About 330000 lines of m-scripts

About 50000 lines of Fortran

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 635

What is Octave Octave and

Features

Current features

N-d arrays linear algebra sparse matrices

Nonlinear equations

OrdinaryAlgebraic Differential Equations

Image processing statistics special functions

Many more

Features in development

GUI

JIT compiling

classdef OOP

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 735

What is Octave Octave and

What does it look like

Primarily a CLI interface

Figure CLI screenshot

Most requested feature GUI Will ship with next release (40)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 835

What is Octave Octave and

What does it look like

Primarily a CLI interface

Most requested feature GUI Will ship with next release (40)

Figure Qt based GUI development started as J Dawidrsquos GSoC2012 project

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 835

What is Octave Octave and

What does it look like

Primarily a CLI interface

Most requested feature GUI Will ship with next release (40)

Figure Qt based GUI development started as J Dawidrsquos GSoC2012 project

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 835

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 935

What is Octave Octave and

In the beginning

Companion software for chemical reactor textbook by James BRawlings and John G Ekerdt

John W Eaton (hereafter jwe) started coding in 1993

Rawlings said

Why donrsquot you call it ldquoOctaverdquo

Octave refers to Octave Levenspiel nothing to do with music

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1035

What is Octave Octave and

In the beginning

Companion software for chemical reactor textbook by James BRawlings and John G Ekerdt

John W Eaton (hereafter jwe) started coding in 1993

Rawlings said

Why donrsquot you call it ldquoOctaverdquo

Octave refers to Octave Levenspiel nothing to do with music

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1035

What is Octave Octave and

jwe is a lone wolf

jwe works almost completely alone for first four or five years

In the very beginning

No mailing lists

No widespread announcements

No VCS (these were dark times)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1135

What is Octave Octave and

jwe is a lone wolf

jwe works almost completely alone for first four or five years

In the very beginning

No mailing lists

No widespread announcements

No VCS (these were dark times)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1135

What is Octave Octave and

Contributions slowly trickle in

Timeline

1989 Planning stages

1992 Development begins

1993 First public announcement

1994 Version 10

1996 Version 20

1998 Version 21 development

2004 Version 29 in preparation for 30 release

2007 Version 30 major upgrade

2010 Version 324 last before using hg

2011 Version 340

2012 Version 364

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1235

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1435

What is Octave Octave and

Web resources

Web pages

Octave website

Octave-Forge website

Octave wiki

Users communication

Octave users mailing list

Octave-Forge mailing list

octave channel in Freenode

Savannah bug tracker

Developers collaboration

Octave Mercurial repository

Octave-Forge Subversion repository

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1535

What is Octave Octave and

Web resources

Web pages

Octave website

Octave-Forge website

Octave wiki

Users communication

Octave users mailing list

Octave-Forge mailing list

octave channel in Freenode

Savannah bug tracker

Developers collaboration

Octave Mercurial repository

Octave-Forge Subversion repository

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1535

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer15 current Core developers (with write access to repo)49 currently registered rsquoForge developers (38 active)296 total contributors over all timeBen Abbott Andy Adler Giles Anderson Joel Andersson Muthiah Annamalai Marco Atzeri Shai Ayal Roger Banks Ben Barrowes

Alexander Barth David Bateman Heinz Bauschke Roman Belov Karl Berry David Billinghurst Don Bindner Jakub Bogusz Moritz

Borgmann Paul Boven Richard Bovey John Bradshaw Marcus Brinkmann Remy Bruno Ansgar Burchard Marco Caliari Daniel

Calvelo John C Campbell Juan Pablo Carbajal Jean-Francois Cardoso Joao Cardoso Larrie Carr David Castelow Vincent

Cautaerts Clinton Chee Albert Chin-A-Young Carsten Clark J D Cole Martin Costabel Michael Creel Jeff Cunningham Martin

Dalecki Jorge Barros de Abreu Carlo de Falco Jacob Dawid Thomas D Dean Philippe Defert Bill Denney Fabian Deutsch

Christos Dimitrakakis David M Doolin Carne Draug Pascal A Dupuis John W Eaton Dirk Eddelbuettel Pieter Eendebak Paul

Eggert Stephen Eglen Peter Ekberg Rolf Fabian Gunnar Farneback Stephen Fegan Ramon Garcia Fernandez Torsten Finke Jose

Daniel Munoz Frias Brad Froehle Castor Fu Eduardo Gallestey Walter Gautschi Klaus Gebhardt Driss Ghaddab Nicolo Giorgetti

Michael D Godfrey Michael Goffioul Glenn Golden Tomislav Goles Keith Goodman Brian Gough Steffen Groot Etienne

Grossmann David Grundberg Peter Gustafson Kai Habel Patrick Hacker William P Y Hadisoeseno Jaroslav Hajek Benjamin Hall

Kim Hansen Soslashren Hauberg Dave Hawthorne Daniel Heiserer Martin Helm Stefan Hepp Jordi Gutierrez Hermoso Yozo Hida Ryan

Hinton Roman Hodek A Scottedward Hodel Richard Allan Holcombe Tom Holroyd David Hoover Kurt Hornik Christopher

Hulbert Cyril Humbert Teemu Ikonen Alan W Irwin Geoff Jacobsen Mats Jansson Cai Jianming Steven G Johnson Heikki Junes

Matthias Juschke Atsushi Kajita Jarkko Kaleva Mohamed Kamoun Lute Kamstra Fotios Kasolis Thomas Kasper Joel Keay

Mumit Khan Paul Kienzle Aaron A King Arno J Klaassen Alexander Klein Geoffrey Knauth Heine Kolltveit Ken Kouno Kacper

Kowalik Daniel Kraft Aravindh Krishnamoorthy Oyvind Kristiansen Piotr Krzyzanowski Volker Kuhlmann Tetsuro Kurita

Miroslaw Kwasniak Rafael Laboissiere Kai Labusch Claude Lacoursiere Walter Landry Bill Lash Dirk Laurie Maurice LeBrun

Friedrich Leisch Jyh-miin Lin Timo Lindfors Benjamin Lindner Ross Lippert David Livings Sebastien Loisel Erik de Castro Lopo

Massimo Lorenzin Emil Lucretiu Hoxide Ma James Macnicol Jens-Uwe Mager Rob Mahurin Ricardo Marranita Orestes Mas

Makoto Matsumoto Tatsuro Matsuoka Laurent Mazet G D McBain Alexander Mamonov Christoph Mayer Julio Hoffimann

Mendes Thorsten Meyer Petr Mikulik Stefan Monnier Antoine Moreau Kai P Mueller Hannes Muller Victor Munoz Carmen

Navarrete Todd Neal Philip Nienhuis Al Niessner Rick Niles Takuji Nishimura Kai Noda Eric Norum Krzesimir Nowak Michael

OrsquoBrien Peter OrsquoGorman Thorsten Ohl Arno Onken Luis F Ortiz Scott Pakin Gabriele Pannocchia Sylvain Pelissier Per Persson

Primozz Peterlin Jim Peterson Danilo Piazzalunga Nicholas Piper Elias Pipping Robert Platt Hans Ekkehard Plesser Tom Poage

Orion Poplawski Ondrej Popp Jef Poskanzer Francesco Potortı Konstantinos Poulios Jarno Rajahalme James B Rawlings Eric S

Raymond Balint Reczey Joshua Redstone Lukas Reichlin Michael Reifenberger Anthony Richardson Jason Riedy E Joshua Rigler

Petter Risholm Matthew W Roberts Andrew Ross Mark van Rossum Joe Rothweiler Kevin Ruland Kristian Rumberg Ryan

Rusaw Olli Saarela Toni Saarela Juhani Saastamoinen Radek Salac Ben Sapp Aleksej Saushev Alois Schlogl Michel D Schmid

Julian Schnidder Nicol N Schraudolph Sebastian Schubert Ludwig Schwardt Thomas L Scofield Daniel J Sebald Dmitri A

Sergatskov Vanya Sergeev Baylis Shanks Andriy Shinkarchuck Robert T Short Joseph P Skudlarek John Smith Julius Smith

Shan G Smith Peter L Sondergaard Joerg Specht Quentin H Spencer Christoph Spiel Richard Stallman Russell Standish Brett

Stewart Doug Stewart Jonathan Stickel Judd Storrs Thomas Stuart Ivan Sutoris John Swensen Daisuke Takago Ariel Tankus

Matthew Tenny Georg Thimm Duncan Temple Lang Kris Thielemans Olaf Till Christophe Tournery Thomas Treichl Karsten

Trulsen Frederick Umminger Utkarsh Upadhyay Stefan van der Walt Peter Van Wieren James R Van Zandt Gregory Vanuxem

Ivana Varekova Thomas Walter Andreas Weber Olaf Weber Thomas Weber Rik Wehbring Bob Weigel Andreas Weingessel

Martin Weiser Michael Weitzel David Wells Fook Fah Yap Sean Young Michael Zeising Federico Zenith Alex Zvoleff

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

296 total contributors over all time

How many users Thousands Millions

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1935

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2035

What is Octave Octave and

Octave-Forge

Octave-Forge

Octave Forge Is a place for concurrently developing and distributingextension packages for Octave

Each package has a maintainer responsible for updating andreleasing new versions of the package

Some packages are maintained by The Community

Installation via an integrated package manager

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2135

What is Octave Octave and

PKG

1 gtgt pkg install minusforge miscellaneous2 For information about changes from previous versions of the larr

miscellaneous package run news ( miscellaneous ) 3 gtgt pkg list4 Package Name | Version | Installation directory5 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus6 bim | 1 1 1 | ˜ octavebimminus1117 fpl | 1 3 3 | ˜ octavefplminus1338 general | 1 3 1 | ˜ octavegeneral minus1319 geometry | 1 6 0 | ˜ octavegeometry minus160

10 miscellaneous | 1 2 0 | ˜ octavemiscellaneous minus12011 gtgt pkg load miscellaneous12 gtgt pkg list13 Package Name | Version | Installation directory14 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus15 bim | 1 1 1 | ˜ octavebimminus11116 fpl | 1 3 3 | ˜ octavefplminus13317 general | 1 3 1 | ˜ octavegeneral minus13118 geometry | 1 6 0 | ˜ octavegeometry minus16019 miscellaneous lowast| 1 2 0 | ˜ octavemiscellaneous minus120

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2235

What is Octave Octave and

PKG

1 gtgt pkg describe bim minusverbose2 minusminusminus3 Package name 4 bim5 Version 6 1 1 17 Short description 8 Package f o r solving Diffusion Advection Reaction ( DAR ) Partial larr

Differential Equations9 Status

10 Not loaded11 minusminusminus12 Provides 13 Matrix assembly14 bim1a_advection_diffusion15 bim1a_advection_upwind16 bim2a_advection_diffusion17 18 Preminusprocessing and Postminusprocessing computations19 bim2c_mesh_properties20 21 gtgt

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2335

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2535

What is Octave Octave and

Broadcasting

Since 360 Octave automatically broadcasts arrays when usingelementwise binary operators

Corresponding array dimensions must either be equal or one ofthem must be 1

In case all dimensions are equal ordinary element-by-elementarithmetic takes place

When one of the dimensions is 1 the array with that singletondimension gets copied along that dimension until it matches thedimension of the other array

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2635

What is Octave Octave and

Broadcasting

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Without broadcasting x + y would be an error because dimensions do not agree

With broadcasting it is as if the following operation were performed

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 10 20 3 0 10 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Other notable differences with Matlab listed in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2735

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2835

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 include lto c t a v e o c t hgt2

3 DEFUN_DLD ( dld args nargout dld (array) nreturn the elements of larrthe array in reverse ordern )

4 5 octave_value_list retval 6 int nargin = args length ( ) 7

8 if ( nargin = 1)9 print_usage ( )

10 else11 12 Arrayltdoublegt a = args ( 0 ) array_value ( ) 13 if ( error_state )14 15 Arrayltdoublegt b ( a )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

16 doublelowast ap = a fortran_vec ( ) 17 doublelowast bp = b fortran_vec ( ) 18 for ( octave_idx_type i = a numel ( ) minus 1 j = 0 i gt= 0 larr

iminusminus j++)19 bp [ i ] = ap [ j ] 20 retval = octave_value ( b ) 21 22 23 return retval 24

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 gtgt mkoctfile dld cc2 gtgt a = randn ( 5 )3 a =4

5 0395421 minus1425232 minus0176544 1055205 22293716 minus0241893 0035004 minus0296543 minus1710613 04443187 minus0752467 minus2220469 2380951 0766246 11961538 1404672 0623112 1182609 0196125 06093259 minus0687019 0646079 2239012 minus0495169 1488314

10

11 gtgt b = dld ( a )12 b =13

14 1488314 minus0495169 2239012 0646079 minus068701915 0609325 0196125 1182609 0623112 140467216 1196153 0766246 2380951 minus2220469 minus075246717 0444318 minus1710613 minus0296543 0035004 minus024189318 2229371 1055205 minus0176544 minus1425232 039542119

20 gtgt

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 6: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

Lines of code

The stuff Octave is made of

Core

About 600000 lines of C++

About 100000 lines of m-scripts

About 50000 lines of Fortran

Octave-Forge

About 200000 lines of C++

About 330000 lines of m-scripts

About 50000 lines of Fortran

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 635

What is Octave Octave and

Lines of code

The stuff Octave is made of

Core

About 600000 lines of C++

About 100000 lines of m-scripts

About 50000 lines of Fortran

Octave-Forge

About 200000 lines of C++

About 330000 lines of m-scripts

About 50000 lines of Fortran

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 635

What is Octave Octave and

Lines of code

The stuff Octave is made of

Core

About 600000 lines of C++

About 100000 lines of m-scripts

About 50000 lines of Fortran

Octave-Forge

About 200000 lines of C++

About 330000 lines of m-scripts

About 50000 lines of Fortran

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 635

What is Octave Octave and

Features

Current features

N-d arrays linear algebra sparse matrices

Nonlinear equations

OrdinaryAlgebraic Differential Equations

Image processing statistics special functions

Many more

Features in development

GUI

JIT compiling

classdef OOP

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 735

What is Octave Octave and

What does it look like

Primarily a CLI interface

Figure CLI screenshot

Most requested feature GUI Will ship with next release (40)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 835

What is Octave Octave and

What does it look like

Primarily a CLI interface

Most requested feature GUI Will ship with next release (40)

Figure Qt based GUI development started as J Dawidrsquos GSoC2012 project

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 835

What is Octave Octave and

What does it look like

Primarily a CLI interface

Most requested feature GUI Will ship with next release (40)

Figure Qt based GUI development started as J Dawidrsquos GSoC2012 project

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 835

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 935

What is Octave Octave and

In the beginning

Companion software for chemical reactor textbook by James BRawlings and John G Ekerdt

John W Eaton (hereafter jwe) started coding in 1993

Rawlings said

Why donrsquot you call it ldquoOctaverdquo

Octave refers to Octave Levenspiel nothing to do with music

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1035

What is Octave Octave and

In the beginning

Companion software for chemical reactor textbook by James BRawlings and John G Ekerdt

John W Eaton (hereafter jwe) started coding in 1993

Rawlings said

Why donrsquot you call it ldquoOctaverdquo

Octave refers to Octave Levenspiel nothing to do with music

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1035

What is Octave Octave and

jwe is a lone wolf

jwe works almost completely alone for first four or five years

In the very beginning

No mailing lists

No widespread announcements

No VCS (these were dark times)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1135

What is Octave Octave and

jwe is a lone wolf

jwe works almost completely alone for first four or five years

In the very beginning

No mailing lists

No widespread announcements

No VCS (these were dark times)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1135

What is Octave Octave and

Contributions slowly trickle in

Timeline

1989 Planning stages

1992 Development begins

1993 First public announcement

1994 Version 10

1996 Version 20

1998 Version 21 development

2004 Version 29 in preparation for 30 release

2007 Version 30 major upgrade

2010 Version 324 last before using hg

2011 Version 340

2012 Version 364

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1235

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1435

What is Octave Octave and

Web resources

Web pages

Octave website

Octave-Forge website

Octave wiki

Users communication

Octave users mailing list

Octave-Forge mailing list

octave channel in Freenode

Savannah bug tracker

Developers collaboration

Octave Mercurial repository

Octave-Forge Subversion repository

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1535

What is Octave Octave and

Web resources

Web pages

Octave website

Octave-Forge website

Octave wiki

Users communication

Octave users mailing list

Octave-Forge mailing list

octave channel in Freenode

Savannah bug tracker

Developers collaboration

Octave Mercurial repository

Octave-Forge Subversion repository

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1535

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer15 current Core developers (with write access to repo)49 currently registered rsquoForge developers (38 active)296 total contributors over all timeBen Abbott Andy Adler Giles Anderson Joel Andersson Muthiah Annamalai Marco Atzeri Shai Ayal Roger Banks Ben Barrowes

Alexander Barth David Bateman Heinz Bauschke Roman Belov Karl Berry David Billinghurst Don Bindner Jakub Bogusz Moritz

Borgmann Paul Boven Richard Bovey John Bradshaw Marcus Brinkmann Remy Bruno Ansgar Burchard Marco Caliari Daniel

Calvelo John C Campbell Juan Pablo Carbajal Jean-Francois Cardoso Joao Cardoso Larrie Carr David Castelow Vincent

Cautaerts Clinton Chee Albert Chin-A-Young Carsten Clark J D Cole Martin Costabel Michael Creel Jeff Cunningham Martin

Dalecki Jorge Barros de Abreu Carlo de Falco Jacob Dawid Thomas D Dean Philippe Defert Bill Denney Fabian Deutsch

Christos Dimitrakakis David M Doolin Carne Draug Pascal A Dupuis John W Eaton Dirk Eddelbuettel Pieter Eendebak Paul

Eggert Stephen Eglen Peter Ekberg Rolf Fabian Gunnar Farneback Stephen Fegan Ramon Garcia Fernandez Torsten Finke Jose

Daniel Munoz Frias Brad Froehle Castor Fu Eduardo Gallestey Walter Gautschi Klaus Gebhardt Driss Ghaddab Nicolo Giorgetti

Michael D Godfrey Michael Goffioul Glenn Golden Tomislav Goles Keith Goodman Brian Gough Steffen Groot Etienne

Grossmann David Grundberg Peter Gustafson Kai Habel Patrick Hacker William P Y Hadisoeseno Jaroslav Hajek Benjamin Hall

Kim Hansen Soslashren Hauberg Dave Hawthorne Daniel Heiserer Martin Helm Stefan Hepp Jordi Gutierrez Hermoso Yozo Hida Ryan

Hinton Roman Hodek A Scottedward Hodel Richard Allan Holcombe Tom Holroyd David Hoover Kurt Hornik Christopher

Hulbert Cyril Humbert Teemu Ikonen Alan W Irwin Geoff Jacobsen Mats Jansson Cai Jianming Steven G Johnson Heikki Junes

Matthias Juschke Atsushi Kajita Jarkko Kaleva Mohamed Kamoun Lute Kamstra Fotios Kasolis Thomas Kasper Joel Keay

Mumit Khan Paul Kienzle Aaron A King Arno J Klaassen Alexander Klein Geoffrey Knauth Heine Kolltveit Ken Kouno Kacper

Kowalik Daniel Kraft Aravindh Krishnamoorthy Oyvind Kristiansen Piotr Krzyzanowski Volker Kuhlmann Tetsuro Kurita

Miroslaw Kwasniak Rafael Laboissiere Kai Labusch Claude Lacoursiere Walter Landry Bill Lash Dirk Laurie Maurice LeBrun

Friedrich Leisch Jyh-miin Lin Timo Lindfors Benjamin Lindner Ross Lippert David Livings Sebastien Loisel Erik de Castro Lopo

Massimo Lorenzin Emil Lucretiu Hoxide Ma James Macnicol Jens-Uwe Mager Rob Mahurin Ricardo Marranita Orestes Mas

Makoto Matsumoto Tatsuro Matsuoka Laurent Mazet G D McBain Alexander Mamonov Christoph Mayer Julio Hoffimann

Mendes Thorsten Meyer Petr Mikulik Stefan Monnier Antoine Moreau Kai P Mueller Hannes Muller Victor Munoz Carmen

Navarrete Todd Neal Philip Nienhuis Al Niessner Rick Niles Takuji Nishimura Kai Noda Eric Norum Krzesimir Nowak Michael

OrsquoBrien Peter OrsquoGorman Thorsten Ohl Arno Onken Luis F Ortiz Scott Pakin Gabriele Pannocchia Sylvain Pelissier Per Persson

Primozz Peterlin Jim Peterson Danilo Piazzalunga Nicholas Piper Elias Pipping Robert Platt Hans Ekkehard Plesser Tom Poage

Orion Poplawski Ondrej Popp Jef Poskanzer Francesco Potortı Konstantinos Poulios Jarno Rajahalme James B Rawlings Eric S

Raymond Balint Reczey Joshua Redstone Lukas Reichlin Michael Reifenberger Anthony Richardson Jason Riedy E Joshua Rigler

Petter Risholm Matthew W Roberts Andrew Ross Mark van Rossum Joe Rothweiler Kevin Ruland Kristian Rumberg Ryan

Rusaw Olli Saarela Toni Saarela Juhani Saastamoinen Radek Salac Ben Sapp Aleksej Saushev Alois Schlogl Michel D Schmid

Julian Schnidder Nicol N Schraudolph Sebastian Schubert Ludwig Schwardt Thomas L Scofield Daniel J Sebald Dmitri A

Sergatskov Vanya Sergeev Baylis Shanks Andriy Shinkarchuck Robert T Short Joseph P Skudlarek John Smith Julius Smith

Shan G Smith Peter L Sondergaard Joerg Specht Quentin H Spencer Christoph Spiel Richard Stallman Russell Standish Brett

Stewart Doug Stewart Jonathan Stickel Judd Storrs Thomas Stuart Ivan Sutoris John Swensen Daisuke Takago Ariel Tankus

Matthew Tenny Georg Thimm Duncan Temple Lang Kris Thielemans Olaf Till Christophe Tournery Thomas Treichl Karsten

Trulsen Frederick Umminger Utkarsh Upadhyay Stefan van der Walt Peter Van Wieren James R Van Zandt Gregory Vanuxem

Ivana Varekova Thomas Walter Andreas Weber Olaf Weber Thomas Weber Rik Wehbring Bob Weigel Andreas Weingessel

Martin Weiser Michael Weitzel David Wells Fook Fah Yap Sean Young Michael Zeising Federico Zenith Alex Zvoleff

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

296 total contributors over all time

How many users Thousands Millions

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1935

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2035

What is Octave Octave and

Octave-Forge

Octave-Forge

Octave Forge Is a place for concurrently developing and distributingextension packages for Octave

Each package has a maintainer responsible for updating andreleasing new versions of the package

Some packages are maintained by The Community

Installation via an integrated package manager

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2135

What is Octave Octave and

PKG

1 gtgt pkg install minusforge miscellaneous2 For information about changes from previous versions of the larr

miscellaneous package run news ( miscellaneous ) 3 gtgt pkg list4 Package Name | Version | Installation directory5 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus6 bim | 1 1 1 | ˜ octavebimminus1117 fpl | 1 3 3 | ˜ octavefplminus1338 general | 1 3 1 | ˜ octavegeneral minus1319 geometry | 1 6 0 | ˜ octavegeometry minus160

10 miscellaneous | 1 2 0 | ˜ octavemiscellaneous minus12011 gtgt pkg load miscellaneous12 gtgt pkg list13 Package Name | Version | Installation directory14 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus15 bim | 1 1 1 | ˜ octavebimminus11116 fpl | 1 3 3 | ˜ octavefplminus13317 general | 1 3 1 | ˜ octavegeneral minus13118 geometry | 1 6 0 | ˜ octavegeometry minus16019 miscellaneous lowast| 1 2 0 | ˜ octavemiscellaneous minus120

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2235

What is Octave Octave and

PKG

1 gtgt pkg describe bim minusverbose2 minusminusminus3 Package name 4 bim5 Version 6 1 1 17 Short description 8 Package f o r solving Diffusion Advection Reaction ( DAR ) Partial larr

Differential Equations9 Status

10 Not loaded11 minusminusminus12 Provides 13 Matrix assembly14 bim1a_advection_diffusion15 bim1a_advection_upwind16 bim2a_advection_diffusion17 18 Preminusprocessing and Postminusprocessing computations19 bim2c_mesh_properties20 21 gtgt

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2335

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2535

What is Octave Octave and

Broadcasting

Since 360 Octave automatically broadcasts arrays when usingelementwise binary operators

Corresponding array dimensions must either be equal or one ofthem must be 1

In case all dimensions are equal ordinary element-by-elementarithmetic takes place

When one of the dimensions is 1 the array with that singletondimension gets copied along that dimension until it matches thedimension of the other array

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2635

What is Octave Octave and

Broadcasting

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Without broadcasting x + y would be an error because dimensions do not agree

With broadcasting it is as if the following operation were performed

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 10 20 3 0 10 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Other notable differences with Matlab listed in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2735

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2835

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 include lto c t a v e o c t hgt2

3 DEFUN_DLD ( dld args nargout dld (array) nreturn the elements of larrthe array in reverse ordern )

4 5 octave_value_list retval 6 int nargin = args length ( ) 7

8 if ( nargin = 1)9 print_usage ( )

10 else11 12 Arrayltdoublegt a = args ( 0 ) array_value ( ) 13 if ( error_state )14 15 Arrayltdoublegt b ( a )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

16 doublelowast ap = a fortran_vec ( ) 17 doublelowast bp = b fortran_vec ( ) 18 for ( octave_idx_type i = a numel ( ) minus 1 j = 0 i gt= 0 larr

iminusminus j++)19 bp [ i ] = ap [ j ] 20 retval = octave_value ( b ) 21 22 23 return retval 24

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 gtgt mkoctfile dld cc2 gtgt a = randn ( 5 )3 a =4

5 0395421 minus1425232 minus0176544 1055205 22293716 minus0241893 0035004 minus0296543 minus1710613 04443187 minus0752467 minus2220469 2380951 0766246 11961538 1404672 0623112 1182609 0196125 06093259 minus0687019 0646079 2239012 minus0495169 1488314

10

11 gtgt b = dld ( a )12 b =13

14 1488314 minus0495169 2239012 0646079 minus068701915 0609325 0196125 1182609 0623112 140467216 1196153 0766246 2380951 minus2220469 minus075246717 0444318 minus1710613 minus0296543 0035004 minus024189318 2229371 1055205 minus0176544 minus1425232 039542119

20 gtgt

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 7: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

Lines of code

The stuff Octave is made of

Core

About 600000 lines of C++

About 100000 lines of m-scripts

About 50000 lines of Fortran

Octave-Forge

About 200000 lines of C++

About 330000 lines of m-scripts

About 50000 lines of Fortran

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 635

What is Octave Octave and

Lines of code

The stuff Octave is made of

Core

About 600000 lines of C++

About 100000 lines of m-scripts

About 50000 lines of Fortran

Octave-Forge

About 200000 lines of C++

About 330000 lines of m-scripts

About 50000 lines of Fortran

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 635

What is Octave Octave and

Features

Current features

N-d arrays linear algebra sparse matrices

Nonlinear equations

OrdinaryAlgebraic Differential Equations

Image processing statistics special functions

Many more

Features in development

GUI

JIT compiling

classdef OOP

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 735

What is Octave Octave and

What does it look like

Primarily a CLI interface

Figure CLI screenshot

Most requested feature GUI Will ship with next release (40)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 835

What is Octave Octave and

What does it look like

Primarily a CLI interface

Most requested feature GUI Will ship with next release (40)

Figure Qt based GUI development started as J Dawidrsquos GSoC2012 project

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 835

What is Octave Octave and

What does it look like

Primarily a CLI interface

Most requested feature GUI Will ship with next release (40)

Figure Qt based GUI development started as J Dawidrsquos GSoC2012 project

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 835

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 935

What is Octave Octave and

In the beginning

Companion software for chemical reactor textbook by James BRawlings and John G Ekerdt

John W Eaton (hereafter jwe) started coding in 1993

Rawlings said

Why donrsquot you call it ldquoOctaverdquo

Octave refers to Octave Levenspiel nothing to do with music

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1035

What is Octave Octave and

In the beginning

Companion software for chemical reactor textbook by James BRawlings and John G Ekerdt

John W Eaton (hereafter jwe) started coding in 1993

Rawlings said

Why donrsquot you call it ldquoOctaverdquo

Octave refers to Octave Levenspiel nothing to do with music

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1035

What is Octave Octave and

jwe is a lone wolf

jwe works almost completely alone for first four or five years

In the very beginning

No mailing lists

No widespread announcements

No VCS (these were dark times)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1135

What is Octave Octave and

jwe is a lone wolf

jwe works almost completely alone for first four or five years

In the very beginning

No mailing lists

No widespread announcements

No VCS (these were dark times)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1135

What is Octave Octave and

Contributions slowly trickle in

Timeline

1989 Planning stages

1992 Development begins

1993 First public announcement

1994 Version 10

1996 Version 20

1998 Version 21 development

2004 Version 29 in preparation for 30 release

2007 Version 30 major upgrade

2010 Version 324 last before using hg

2011 Version 340

2012 Version 364

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1235

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1435

What is Octave Octave and

Web resources

Web pages

Octave website

Octave-Forge website

Octave wiki

Users communication

Octave users mailing list

Octave-Forge mailing list

octave channel in Freenode

Savannah bug tracker

Developers collaboration

Octave Mercurial repository

Octave-Forge Subversion repository

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1535

What is Octave Octave and

Web resources

Web pages

Octave website

Octave-Forge website

Octave wiki

Users communication

Octave users mailing list

Octave-Forge mailing list

octave channel in Freenode

Savannah bug tracker

Developers collaboration

Octave Mercurial repository

Octave-Forge Subversion repository

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1535

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer15 current Core developers (with write access to repo)49 currently registered rsquoForge developers (38 active)296 total contributors over all timeBen Abbott Andy Adler Giles Anderson Joel Andersson Muthiah Annamalai Marco Atzeri Shai Ayal Roger Banks Ben Barrowes

Alexander Barth David Bateman Heinz Bauschke Roman Belov Karl Berry David Billinghurst Don Bindner Jakub Bogusz Moritz

Borgmann Paul Boven Richard Bovey John Bradshaw Marcus Brinkmann Remy Bruno Ansgar Burchard Marco Caliari Daniel

Calvelo John C Campbell Juan Pablo Carbajal Jean-Francois Cardoso Joao Cardoso Larrie Carr David Castelow Vincent

Cautaerts Clinton Chee Albert Chin-A-Young Carsten Clark J D Cole Martin Costabel Michael Creel Jeff Cunningham Martin

Dalecki Jorge Barros de Abreu Carlo de Falco Jacob Dawid Thomas D Dean Philippe Defert Bill Denney Fabian Deutsch

Christos Dimitrakakis David M Doolin Carne Draug Pascal A Dupuis John W Eaton Dirk Eddelbuettel Pieter Eendebak Paul

Eggert Stephen Eglen Peter Ekberg Rolf Fabian Gunnar Farneback Stephen Fegan Ramon Garcia Fernandez Torsten Finke Jose

Daniel Munoz Frias Brad Froehle Castor Fu Eduardo Gallestey Walter Gautschi Klaus Gebhardt Driss Ghaddab Nicolo Giorgetti

Michael D Godfrey Michael Goffioul Glenn Golden Tomislav Goles Keith Goodman Brian Gough Steffen Groot Etienne

Grossmann David Grundberg Peter Gustafson Kai Habel Patrick Hacker William P Y Hadisoeseno Jaroslav Hajek Benjamin Hall

Kim Hansen Soslashren Hauberg Dave Hawthorne Daniel Heiserer Martin Helm Stefan Hepp Jordi Gutierrez Hermoso Yozo Hida Ryan

Hinton Roman Hodek A Scottedward Hodel Richard Allan Holcombe Tom Holroyd David Hoover Kurt Hornik Christopher

Hulbert Cyril Humbert Teemu Ikonen Alan W Irwin Geoff Jacobsen Mats Jansson Cai Jianming Steven G Johnson Heikki Junes

Matthias Juschke Atsushi Kajita Jarkko Kaleva Mohamed Kamoun Lute Kamstra Fotios Kasolis Thomas Kasper Joel Keay

Mumit Khan Paul Kienzle Aaron A King Arno J Klaassen Alexander Klein Geoffrey Knauth Heine Kolltveit Ken Kouno Kacper

Kowalik Daniel Kraft Aravindh Krishnamoorthy Oyvind Kristiansen Piotr Krzyzanowski Volker Kuhlmann Tetsuro Kurita

Miroslaw Kwasniak Rafael Laboissiere Kai Labusch Claude Lacoursiere Walter Landry Bill Lash Dirk Laurie Maurice LeBrun

Friedrich Leisch Jyh-miin Lin Timo Lindfors Benjamin Lindner Ross Lippert David Livings Sebastien Loisel Erik de Castro Lopo

Massimo Lorenzin Emil Lucretiu Hoxide Ma James Macnicol Jens-Uwe Mager Rob Mahurin Ricardo Marranita Orestes Mas

Makoto Matsumoto Tatsuro Matsuoka Laurent Mazet G D McBain Alexander Mamonov Christoph Mayer Julio Hoffimann

Mendes Thorsten Meyer Petr Mikulik Stefan Monnier Antoine Moreau Kai P Mueller Hannes Muller Victor Munoz Carmen

Navarrete Todd Neal Philip Nienhuis Al Niessner Rick Niles Takuji Nishimura Kai Noda Eric Norum Krzesimir Nowak Michael

OrsquoBrien Peter OrsquoGorman Thorsten Ohl Arno Onken Luis F Ortiz Scott Pakin Gabriele Pannocchia Sylvain Pelissier Per Persson

Primozz Peterlin Jim Peterson Danilo Piazzalunga Nicholas Piper Elias Pipping Robert Platt Hans Ekkehard Plesser Tom Poage

Orion Poplawski Ondrej Popp Jef Poskanzer Francesco Potortı Konstantinos Poulios Jarno Rajahalme James B Rawlings Eric S

Raymond Balint Reczey Joshua Redstone Lukas Reichlin Michael Reifenberger Anthony Richardson Jason Riedy E Joshua Rigler

Petter Risholm Matthew W Roberts Andrew Ross Mark van Rossum Joe Rothweiler Kevin Ruland Kristian Rumberg Ryan

Rusaw Olli Saarela Toni Saarela Juhani Saastamoinen Radek Salac Ben Sapp Aleksej Saushev Alois Schlogl Michel D Schmid

Julian Schnidder Nicol N Schraudolph Sebastian Schubert Ludwig Schwardt Thomas L Scofield Daniel J Sebald Dmitri A

Sergatskov Vanya Sergeev Baylis Shanks Andriy Shinkarchuck Robert T Short Joseph P Skudlarek John Smith Julius Smith

Shan G Smith Peter L Sondergaard Joerg Specht Quentin H Spencer Christoph Spiel Richard Stallman Russell Standish Brett

Stewart Doug Stewart Jonathan Stickel Judd Storrs Thomas Stuart Ivan Sutoris John Swensen Daisuke Takago Ariel Tankus

Matthew Tenny Georg Thimm Duncan Temple Lang Kris Thielemans Olaf Till Christophe Tournery Thomas Treichl Karsten

Trulsen Frederick Umminger Utkarsh Upadhyay Stefan van der Walt Peter Van Wieren James R Van Zandt Gregory Vanuxem

Ivana Varekova Thomas Walter Andreas Weber Olaf Weber Thomas Weber Rik Wehbring Bob Weigel Andreas Weingessel

Martin Weiser Michael Weitzel David Wells Fook Fah Yap Sean Young Michael Zeising Federico Zenith Alex Zvoleff

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

296 total contributors over all time

How many users Thousands Millions

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1935

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2035

What is Octave Octave and

Octave-Forge

Octave-Forge

Octave Forge Is a place for concurrently developing and distributingextension packages for Octave

Each package has a maintainer responsible for updating andreleasing new versions of the package

Some packages are maintained by The Community

Installation via an integrated package manager

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2135

What is Octave Octave and

PKG

1 gtgt pkg install minusforge miscellaneous2 For information about changes from previous versions of the larr

miscellaneous package run news ( miscellaneous ) 3 gtgt pkg list4 Package Name | Version | Installation directory5 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus6 bim | 1 1 1 | ˜ octavebimminus1117 fpl | 1 3 3 | ˜ octavefplminus1338 general | 1 3 1 | ˜ octavegeneral minus1319 geometry | 1 6 0 | ˜ octavegeometry minus160

10 miscellaneous | 1 2 0 | ˜ octavemiscellaneous minus12011 gtgt pkg load miscellaneous12 gtgt pkg list13 Package Name | Version | Installation directory14 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus15 bim | 1 1 1 | ˜ octavebimminus11116 fpl | 1 3 3 | ˜ octavefplminus13317 general | 1 3 1 | ˜ octavegeneral minus13118 geometry | 1 6 0 | ˜ octavegeometry minus16019 miscellaneous lowast| 1 2 0 | ˜ octavemiscellaneous minus120

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2235

What is Octave Octave and

PKG

1 gtgt pkg describe bim minusverbose2 minusminusminus3 Package name 4 bim5 Version 6 1 1 17 Short description 8 Package f o r solving Diffusion Advection Reaction ( DAR ) Partial larr

Differential Equations9 Status

10 Not loaded11 minusminusminus12 Provides 13 Matrix assembly14 bim1a_advection_diffusion15 bim1a_advection_upwind16 bim2a_advection_diffusion17 18 Preminusprocessing and Postminusprocessing computations19 bim2c_mesh_properties20 21 gtgt

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2335

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2535

What is Octave Octave and

Broadcasting

Since 360 Octave automatically broadcasts arrays when usingelementwise binary operators

Corresponding array dimensions must either be equal or one ofthem must be 1

In case all dimensions are equal ordinary element-by-elementarithmetic takes place

When one of the dimensions is 1 the array with that singletondimension gets copied along that dimension until it matches thedimension of the other array

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2635

What is Octave Octave and

Broadcasting

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Without broadcasting x + y would be an error because dimensions do not agree

With broadcasting it is as if the following operation were performed

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 10 20 3 0 10 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Other notable differences with Matlab listed in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2735

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2835

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 include lto c t a v e o c t hgt2

3 DEFUN_DLD ( dld args nargout dld (array) nreturn the elements of larrthe array in reverse ordern )

4 5 octave_value_list retval 6 int nargin = args length ( ) 7

8 if ( nargin = 1)9 print_usage ( )

10 else11 12 Arrayltdoublegt a = args ( 0 ) array_value ( ) 13 if ( error_state )14 15 Arrayltdoublegt b ( a )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

16 doublelowast ap = a fortran_vec ( ) 17 doublelowast bp = b fortran_vec ( ) 18 for ( octave_idx_type i = a numel ( ) minus 1 j = 0 i gt= 0 larr

iminusminus j++)19 bp [ i ] = ap [ j ] 20 retval = octave_value ( b ) 21 22 23 return retval 24

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 gtgt mkoctfile dld cc2 gtgt a = randn ( 5 )3 a =4

5 0395421 minus1425232 minus0176544 1055205 22293716 minus0241893 0035004 minus0296543 minus1710613 04443187 minus0752467 minus2220469 2380951 0766246 11961538 1404672 0623112 1182609 0196125 06093259 minus0687019 0646079 2239012 minus0495169 1488314

10

11 gtgt b = dld ( a )12 b =13

14 1488314 minus0495169 2239012 0646079 minus068701915 0609325 0196125 1182609 0623112 140467216 1196153 0766246 2380951 minus2220469 minus075246717 0444318 minus1710613 minus0296543 0035004 minus024189318 2229371 1055205 minus0176544 minus1425232 039542119

20 gtgt

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 8: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

Lines of code

The stuff Octave is made of

Core

About 600000 lines of C++

About 100000 lines of m-scripts

About 50000 lines of Fortran

Octave-Forge

About 200000 lines of C++

About 330000 lines of m-scripts

About 50000 lines of Fortran

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 635

What is Octave Octave and

Features

Current features

N-d arrays linear algebra sparse matrices

Nonlinear equations

OrdinaryAlgebraic Differential Equations

Image processing statistics special functions

Many more

Features in development

GUI

JIT compiling

classdef OOP

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 735

What is Octave Octave and

What does it look like

Primarily a CLI interface

Figure CLI screenshot

Most requested feature GUI Will ship with next release (40)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 835

What is Octave Octave and

What does it look like

Primarily a CLI interface

Most requested feature GUI Will ship with next release (40)

Figure Qt based GUI development started as J Dawidrsquos GSoC2012 project

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 835

What is Octave Octave and

What does it look like

Primarily a CLI interface

Most requested feature GUI Will ship with next release (40)

Figure Qt based GUI development started as J Dawidrsquos GSoC2012 project

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 835

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 935

What is Octave Octave and

In the beginning

Companion software for chemical reactor textbook by James BRawlings and John G Ekerdt

John W Eaton (hereafter jwe) started coding in 1993

Rawlings said

Why donrsquot you call it ldquoOctaverdquo

Octave refers to Octave Levenspiel nothing to do with music

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1035

What is Octave Octave and

In the beginning

Companion software for chemical reactor textbook by James BRawlings and John G Ekerdt

John W Eaton (hereafter jwe) started coding in 1993

Rawlings said

Why donrsquot you call it ldquoOctaverdquo

Octave refers to Octave Levenspiel nothing to do with music

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1035

What is Octave Octave and

jwe is a lone wolf

jwe works almost completely alone for first four or five years

In the very beginning

No mailing lists

No widespread announcements

No VCS (these were dark times)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1135

What is Octave Octave and

jwe is a lone wolf

jwe works almost completely alone for first four or five years

In the very beginning

No mailing lists

No widespread announcements

No VCS (these were dark times)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1135

What is Octave Octave and

Contributions slowly trickle in

Timeline

1989 Planning stages

1992 Development begins

1993 First public announcement

1994 Version 10

1996 Version 20

1998 Version 21 development

2004 Version 29 in preparation for 30 release

2007 Version 30 major upgrade

2010 Version 324 last before using hg

2011 Version 340

2012 Version 364

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1235

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1435

What is Octave Octave and

Web resources

Web pages

Octave website

Octave-Forge website

Octave wiki

Users communication

Octave users mailing list

Octave-Forge mailing list

octave channel in Freenode

Savannah bug tracker

Developers collaboration

Octave Mercurial repository

Octave-Forge Subversion repository

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1535

What is Octave Octave and

Web resources

Web pages

Octave website

Octave-Forge website

Octave wiki

Users communication

Octave users mailing list

Octave-Forge mailing list

octave channel in Freenode

Savannah bug tracker

Developers collaboration

Octave Mercurial repository

Octave-Forge Subversion repository

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1535

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer15 current Core developers (with write access to repo)49 currently registered rsquoForge developers (38 active)296 total contributors over all timeBen Abbott Andy Adler Giles Anderson Joel Andersson Muthiah Annamalai Marco Atzeri Shai Ayal Roger Banks Ben Barrowes

Alexander Barth David Bateman Heinz Bauschke Roman Belov Karl Berry David Billinghurst Don Bindner Jakub Bogusz Moritz

Borgmann Paul Boven Richard Bovey John Bradshaw Marcus Brinkmann Remy Bruno Ansgar Burchard Marco Caliari Daniel

Calvelo John C Campbell Juan Pablo Carbajal Jean-Francois Cardoso Joao Cardoso Larrie Carr David Castelow Vincent

Cautaerts Clinton Chee Albert Chin-A-Young Carsten Clark J D Cole Martin Costabel Michael Creel Jeff Cunningham Martin

Dalecki Jorge Barros de Abreu Carlo de Falco Jacob Dawid Thomas D Dean Philippe Defert Bill Denney Fabian Deutsch

Christos Dimitrakakis David M Doolin Carne Draug Pascal A Dupuis John W Eaton Dirk Eddelbuettel Pieter Eendebak Paul

Eggert Stephen Eglen Peter Ekberg Rolf Fabian Gunnar Farneback Stephen Fegan Ramon Garcia Fernandez Torsten Finke Jose

Daniel Munoz Frias Brad Froehle Castor Fu Eduardo Gallestey Walter Gautschi Klaus Gebhardt Driss Ghaddab Nicolo Giorgetti

Michael D Godfrey Michael Goffioul Glenn Golden Tomislav Goles Keith Goodman Brian Gough Steffen Groot Etienne

Grossmann David Grundberg Peter Gustafson Kai Habel Patrick Hacker William P Y Hadisoeseno Jaroslav Hajek Benjamin Hall

Kim Hansen Soslashren Hauberg Dave Hawthorne Daniel Heiserer Martin Helm Stefan Hepp Jordi Gutierrez Hermoso Yozo Hida Ryan

Hinton Roman Hodek A Scottedward Hodel Richard Allan Holcombe Tom Holroyd David Hoover Kurt Hornik Christopher

Hulbert Cyril Humbert Teemu Ikonen Alan W Irwin Geoff Jacobsen Mats Jansson Cai Jianming Steven G Johnson Heikki Junes

Matthias Juschke Atsushi Kajita Jarkko Kaleva Mohamed Kamoun Lute Kamstra Fotios Kasolis Thomas Kasper Joel Keay

Mumit Khan Paul Kienzle Aaron A King Arno J Klaassen Alexander Klein Geoffrey Knauth Heine Kolltveit Ken Kouno Kacper

Kowalik Daniel Kraft Aravindh Krishnamoorthy Oyvind Kristiansen Piotr Krzyzanowski Volker Kuhlmann Tetsuro Kurita

Miroslaw Kwasniak Rafael Laboissiere Kai Labusch Claude Lacoursiere Walter Landry Bill Lash Dirk Laurie Maurice LeBrun

Friedrich Leisch Jyh-miin Lin Timo Lindfors Benjamin Lindner Ross Lippert David Livings Sebastien Loisel Erik de Castro Lopo

Massimo Lorenzin Emil Lucretiu Hoxide Ma James Macnicol Jens-Uwe Mager Rob Mahurin Ricardo Marranita Orestes Mas

Makoto Matsumoto Tatsuro Matsuoka Laurent Mazet G D McBain Alexander Mamonov Christoph Mayer Julio Hoffimann

Mendes Thorsten Meyer Petr Mikulik Stefan Monnier Antoine Moreau Kai P Mueller Hannes Muller Victor Munoz Carmen

Navarrete Todd Neal Philip Nienhuis Al Niessner Rick Niles Takuji Nishimura Kai Noda Eric Norum Krzesimir Nowak Michael

OrsquoBrien Peter OrsquoGorman Thorsten Ohl Arno Onken Luis F Ortiz Scott Pakin Gabriele Pannocchia Sylvain Pelissier Per Persson

Primozz Peterlin Jim Peterson Danilo Piazzalunga Nicholas Piper Elias Pipping Robert Platt Hans Ekkehard Plesser Tom Poage

Orion Poplawski Ondrej Popp Jef Poskanzer Francesco Potortı Konstantinos Poulios Jarno Rajahalme James B Rawlings Eric S

Raymond Balint Reczey Joshua Redstone Lukas Reichlin Michael Reifenberger Anthony Richardson Jason Riedy E Joshua Rigler

Petter Risholm Matthew W Roberts Andrew Ross Mark van Rossum Joe Rothweiler Kevin Ruland Kristian Rumberg Ryan

Rusaw Olli Saarela Toni Saarela Juhani Saastamoinen Radek Salac Ben Sapp Aleksej Saushev Alois Schlogl Michel D Schmid

Julian Schnidder Nicol N Schraudolph Sebastian Schubert Ludwig Schwardt Thomas L Scofield Daniel J Sebald Dmitri A

Sergatskov Vanya Sergeev Baylis Shanks Andriy Shinkarchuck Robert T Short Joseph P Skudlarek John Smith Julius Smith

Shan G Smith Peter L Sondergaard Joerg Specht Quentin H Spencer Christoph Spiel Richard Stallman Russell Standish Brett

Stewart Doug Stewart Jonathan Stickel Judd Storrs Thomas Stuart Ivan Sutoris John Swensen Daisuke Takago Ariel Tankus

Matthew Tenny Georg Thimm Duncan Temple Lang Kris Thielemans Olaf Till Christophe Tournery Thomas Treichl Karsten

Trulsen Frederick Umminger Utkarsh Upadhyay Stefan van der Walt Peter Van Wieren James R Van Zandt Gregory Vanuxem

Ivana Varekova Thomas Walter Andreas Weber Olaf Weber Thomas Weber Rik Wehbring Bob Weigel Andreas Weingessel

Martin Weiser Michael Weitzel David Wells Fook Fah Yap Sean Young Michael Zeising Federico Zenith Alex Zvoleff

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

296 total contributors over all time

How many users Thousands Millions

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1935

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2035

What is Octave Octave and

Octave-Forge

Octave-Forge

Octave Forge Is a place for concurrently developing and distributingextension packages for Octave

Each package has a maintainer responsible for updating andreleasing new versions of the package

Some packages are maintained by The Community

Installation via an integrated package manager

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2135

What is Octave Octave and

PKG

1 gtgt pkg install minusforge miscellaneous2 For information about changes from previous versions of the larr

miscellaneous package run news ( miscellaneous ) 3 gtgt pkg list4 Package Name | Version | Installation directory5 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus6 bim | 1 1 1 | ˜ octavebimminus1117 fpl | 1 3 3 | ˜ octavefplminus1338 general | 1 3 1 | ˜ octavegeneral minus1319 geometry | 1 6 0 | ˜ octavegeometry minus160

10 miscellaneous | 1 2 0 | ˜ octavemiscellaneous minus12011 gtgt pkg load miscellaneous12 gtgt pkg list13 Package Name | Version | Installation directory14 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus15 bim | 1 1 1 | ˜ octavebimminus11116 fpl | 1 3 3 | ˜ octavefplminus13317 general | 1 3 1 | ˜ octavegeneral minus13118 geometry | 1 6 0 | ˜ octavegeometry minus16019 miscellaneous lowast| 1 2 0 | ˜ octavemiscellaneous minus120

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2235

What is Octave Octave and

PKG

1 gtgt pkg describe bim minusverbose2 minusminusminus3 Package name 4 bim5 Version 6 1 1 17 Short description 8 Package f o r solving Diffusion Advection Reaction ( DAR ) Partial larr

Differential Equations9 Status

10 Not loaded11 minusminusminus12 Provides 13 Matrix assembly14 bim1a_advection_diffusion15 bim1a_advection_upwind16 bim2a_advection_diffusion17 18 Preminusprocessing and Postminusprocessing computations19 bim2c_mesh_properties20 21 gtgt

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2335

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2535

What is Octave Octave and

Broadcasting

Since 360 Octave automatically broadcasts arrays when usingelementwise binary operators

Corresponding array dimensions must either be equal or one ofthem must be 1

In case all dimensions are equal ordinary element-by-elementarithmetic takes place

When one of the dimensions is 1 the array with that singletondimension gets copied along that dimension until it matches thedimension of the other array

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2635

What is Octave Octave and

Broadcasting

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Without broadcasting x + y would be an error because dimensions do not agree

With broadcasting it is as if the following operation were performed

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 10 20 3 0 10 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Other notable differences with Matlab listed in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2735

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2835

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 include lto c t a v e o c t hgt2

3 DEFUN_DLD ( dld args nargout dld (array) nreturn the elements of larrthe array in reverse ordern )

4 5 octave_value_list retval 6 int nargin = args length ( ) 7

8 if ( nargin = 1)9 print_usage ( )

10 else11 12 Arrayltdoublegt a = args ( 0 ) array_value ( ) 13 if ( error_state )14 15 Arrayltdoublegt b ( a )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

16 doublelowast ap = a fortran_vec ( ) 17 doublelowast bp = b fortran_vec ( ) 18 for ( octave_idx_type i = a numel ( ) minus 1 j = 0 i gt= 0 larr

iminusminus j++)19 bp [ i ] = ap [ j ] 20 retval = octave_value ( b ) 21 22 23 return retval 24

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 gtgt mkoctfile dld cc2 gtgt a = randn ( 5 )3 a =4

5 0395421 minus1425232 minus0176544 1055205 22293716 minus0241893 0035004 minus0296543 minus1710613 04443187 minus0752467 minus2220469 2380951 0766246 11961538 1404672 0623112 1182609 0196125 06093259 minus0687019 0646079 2239012 minus0495169 1488314

10

11 gtgt b = dld ( a )12 b =13

14 1488314 minus0495169 2239012 0646079 minus068701915 0609325 0196125 1182609 0623112 140467216 1196153 0766246 2380951 minus2220469 minus075246717 0444318 minus1710613 minus0296543 0035004 minus024189318 2229371 1055205 minus0176544 minus1425232 039542119

20 gtgt

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 9: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

Features

Current features

N-d arrays linear algebra sparse matrices

Nonlinear equations

OrdinaryAlgebraic Differential Equations

Image processing statistics special functions

Many more

Features in development

GUI

JIT compiling

classdef OOP

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 735

What is Octave Octave and

What does it look like

Primarily a CLI interface

Figure CLI screenshot

Most requested feature GUI Will ship with next release (40)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 835

What is Octave Octave and

What does it look like

Primarily a CLI interface

Most requested feature GUI Will ship with next release (40)

Figure Qt based GUI development started as J Dawidrsquos GSoC2012 project

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 835

What is Octave Octave and

What does it look like

Primarily a CLI interface

Most requested feature GUI Will ship with next release (40)

Figure Qt based GUI development started as J Dawidrsquos GSoC2012 project

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 835

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 935

What is Octave Octave and

In the beginning

Companion software for chemical reactor textbook by James BRawlings and John G Ekerdt

John W Eaton (hereafter jwe) started coding in 1993

Rawlings said

Why donrsquot you call it ldquoOctaverdquo

Octave refers to Octave Levenspiel nothing to do with music

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1035

What is Octave Octave and

In the beginning

Companion software for chemical reactor textbook by James BRawlings and John G Ekerdt

John W Eaton (hereafter jwe) started coding in 1993

Rawlings said

Why donrsquot you call it ldquoOctaverdquo

Octave refers to Octave Levenspiel nothing to do with music

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1035

What is Octave Octave and

jwe is a lone wolf

jwe works almost completely alone for first four or five years

In the very beginning

No mailing lists

No widespread announcements

No VCS (these were dark times)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1135

What is Octave Octave and

jwe is a lone wolf

jwe works almost completely alone for first four or five years

In the very beginning

No mailing lists

No widespread announcements

No VCS (these were dark times)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1135

What is Octave Octave and

Contributions slowly trickle in

Timeline

1989 Planning stages

1992 Development begins

1993 First public announcement

1994 Version 10

1996 Version 20

1998 Version 21 development

2004 Version 29 in preparation for 30 release

2007 Version 30 major upgrade

2010 Version 324 last before using hg

2011 Version 340

2012 Version 364

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1235

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1435

What is Octave Octave and

Web resources

Web pages

Octave website

Octave-Forge website

Octave wiki

Users communication

Octave users mailing list

Octave-Forge mailing list

octave channel in Freenode

Savannah bug tracker

Developers collaboration

Octave Mercurial repository

Octave-Forge Subversion repository

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1535

What is Octave Octave and

Web resources

Web pages

Octave website

Octave-Forge website

Octave wiki

Users communication

Octave users mailing list

Octave-Forge mailing list

octave channel in Freenode

Savannah bug tracker

Developers collaboration

Octave Mercurial repository

Octave-Forge Subversion repository

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1535

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer15 current Core developers (with write access to repo)49 currently registered rsquoForge developers (38 active)296 total contributors over all timeBen Abbott Andy Adler Giles Anderson Joel Andersson Muthiah Annamalai Marco Atzeri Shai Ayal Roger Banks Ben Barrowes

Alexander Barth David Bateman Heinz Bauschke Roman Belov Karl Berry David Billinghurst Don Bindner Jakub Bogusz Moritz

Borgmann Paul Boven Richard Bovey John Bradshaw Marcus Brinkmann Remy Bruno Ansgar Burchard Marco Caliari Daniel

Calvelo John C Campbell Juan Pablo Carbajal Jean-Francois Cardoso Joao Cardoso Larrie Carr David Castelow Vincent

Cautaerts Clinton Chee Albert Chin-A-Young Carsten Clark J D Cole Martin Costabel Michael Creel Jeff Cunningham Martin

Dalecki Jorge Barros de Abreu Carlo de Falco Jacob Dawid Thomas D Dean Philippe Defert Bill Denney Fabian Deutsch

Christos Dimitrakakis David M Doolin Carne Draug Pascal A Dupuis John W Eaton Dirk Eddelbuettel Pieter Eendebak Paul

Eggert Stephen Eglen Peter Ekberg Rolf Fabian Gunnar Farneback Stephen Fegan Ramon Garcia Fernandez Torsten Finke Jose

Daniel Munoz Frias Brad Froehle Castor Fu Eduardo Gallestey Walter Gautschi Klaus Gebhardt Driss Ghaddab Nicolo Giorgetti

Michael D Godfrey Michael Goffioul Glenn Golden Tomislav Goles Keith Goodman Brian Gough Steffen Groot Etienne

Grossmann David Grundberg Peter Gustafson Kai Habel Patrick Hacker William P Y Hadisoeseno Jaroslav Hajek Benjamin Hall

Kim Hansen Soslashren Hauberg Dave Hawthorne Daniel Heiserer Martin Helm Stefan Hepp Jordi Gutierrez Hermoso Yozo Hida Ryan

Hinton Roman Hodek A Scottedward Hodel Richard Allan Holcombe Tom Holroyd David Hoover Kurt Hornik Christopher

Hulbert Cyril Humbert Teemu Ikonen Alan W Irwin Geoff Jacobsen Mats Jansson Cai Jianming Steven G Johnson Heikki Junes

Matthias Juschke Atsushi Kajita Jarkko Kaleva Mohamed Kamoun Lute Kamstra Fotios Kasolis Thomas Kasper Joel Keay

Mumit Khan Paul Kienzle Aaron A King Arno J Klaassen Alexander Klein Geoffrey Knauth Heine Kolltveit Ken Kouno Kacper

Kowalik Daniel Kraft Aravindh Krishnamoorthy Oyvind Kristiansen Piotr Krzyzanowski Volker Kuhlmann Tetsuro Kurita

Miroslaw Kwasniak Rafael Laboissiere Kai Labusch Claude Lacoursiere Walter Landry Bill Lash Dirk Laurie Maurice LeBrun

Friedrich Leisch Jyh-miin Lin Timo Lindfors Benjamin Lindner Ross Lippert David Livings Sebastien Loisel Erik de Castro Lopo

Massimo Lorenzin Emil Lucretiu Hoxide Ma James Macnicol Jens-Uwe Mager Rob Mahurin Ricardo Marranita Orestes Mas

Makoto Matsumoto Tatsuro Matsuoka Laurent Mazet G D McBain Alexander Mamonov Christoph Mayer Julio Hoffimann

Mendes Thorsten Meyer Petr Mikulik Stefan Monnier Antoine Moreau Kai P Mueller Hannes Muller Victor Munoz Carmen

Navarrete Todd Neal Philip Nienhuis Al Niessner Rick Niles Takuji Nishimura Kai Noda Eric Norum Krzesimir Nowak Michael

OrsquoBrien Peter OrsquoGorman Thorsten Ohl Arno Onken Luis F Ortiz Scott Pakin Gabriele Pannocchia Sylvain Pelissier Per Persson

Primozz Peterlin Jim Peterson Danilo Piazzalunga Nicholas Piper Elias Pipping Robert Platt Hans Ekkehard Plesser Tom Poage

Orion Poplawski Ondrej Popp Jef Poskanzer Francesco Potortı Konstantinos Poulios Jarno Rajahalme James B Rawlings Eric S

Raymond Balint Reczey Joshua Redstone Lukas Reichlin Michael Reifenberger Anthony Richardson Jason Riedy E Joshua Rigler

Petter Risholm Matthew W Roberts Andrew Ross Mark van Rossum Joe Rothweiler Kevin Ruland Kristian Rumberg Ryan

Rusaw Olli Saarela Toni Saarela Juhani Saastamoinen Radek Salac Ben Sapp Aleksej Saushev Alois Schlogl Michel D Schmid

Julian Schnidder Nicol N Schraudolph Sebastian Schubert Ludwig Schwardt Thomas L Scofield Daniel J Sebald Dmitri A

Sergatskov Vanya Sergeev Baylis Shanks Andriy Shinkarchuck Robert T Short Joseph P Skudlarek John Smith Julius Smith

Shan G Smith Peter L Sondergaard Joerg Specht Quentin H Spencer Christoph Spiel Richard Stallman Russell Standish Brett

Stewart Doug Stewart Jonathan Stickel Judd Storrs Thomas Stuart Ivan Sutoris John Swensen Daisuke Takago Ariel Tankus

Matthew Tenny Georg Thimm Duncan Temple Lang Kris Thielemans Olaf Till Christophe Tournery Thomas Treichl Karsten

Trulsen Frederick Umminger Utkarsh Upadhyay Stefan van der Walt Peter Van Wieren James R Van Zandt Gregory Vanuxem

Ivana Varekova Thomas Walter Andreas Weber Olaf Weber Thomas Weber Rik Wehbring Bob Weigel Andreas Weingessel

Martin Weiser Michael Weitzel David Wells Fook Fah Yap Sean Young Michael Zeising Federico Zenith Alex Zvoleff

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

296 total contributors over all time

How many users Thousands Millions

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1935

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2035

What is Octave Octave and

Octave-Forge

Octave-Forge

Octave Forge Is a place for concurrently developing and distributingextension packages for Octave

Each package has a maintainer responsible for updating andreleasing new versions of the package

Some packages are maintained by The Community

Installation via an integrated package manager

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2135

What is Octave Octave and

PKG

1 gtgt pkg install minusforge miscellaneous2 For information about changes from previous versions of the larr

miscellaneous package run news ( miscellaneous ) 3 gtgt pkg list4 Package Name | Version | Installation directory5 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus6 bim | 1 1 1 | ˜ octavebimminus1117 fpl | 1 3 3 | ˜ octavefplminus1338 general | 1 3 1 | ˜ octavegeneral minus1319 geometry | 1 6 0 | ˜ octavegeometry minus160

10 miscellaneous | 1 2 0 | ˜ octavemiscellaneous minus12011 gtgt pkg load miscellaneous12 gtgt pkg list13 Package Name | Version | Installation directory14 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus15 bim | 1 1 1 | ˜ octavebimminus11116 fpl | 1 3 3 | ˜ octavefplminus13317 general | 1 3 1 | ˜ octavegeneral minus13118 geometry | 1 6 0 | ˜ octavegeometry minus16019 miscellaneous lowast| 1 2 0 | ˜ octavemiscellaneous minus120

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2235

What is Octave Octave and

PKG

1 gtgt pkg describe bim minusverbose2 minusminusminus3 Package name 4 bim5 Version 6 1 1 17 Short description 8 Package f o r solving Diffusion Advection Reaction ( DAR ) Partial larr

Differential Equations9 Status

10 Not loaded11 minusminusminus12 Provides 13 Matrix assembly14 bim1a_advection_diffusion15 bim1a_advection_upwind16 bim2a_advection_diffusion17 18 Preminusprocessing and Postminusprocessing computations19 bim2c_mesh_properties20 21 gtgt

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2335

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2535

What is Octave Octave and

Broadcasting

Since 360 Octave automatically broadcasts arrays when usingelementwise binary operators

Corresponding array dimensions must either be equal or one ofthem must be 1

In case all dimensions are equal ordinary element-by-elementarithmetic takes place

When one of the dimensions is 1 the array with that singletondimension gets copied along that dimension until it matches thedimension of the other array

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2635

What is Octave Octave and

Broadcasting

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Without broadcasting x + y would be an error because dimensions do not agree

With broadcasting it is as if the following operation were performed

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 10 20 3 0 10 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Other notable differences with Matlab listed in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2735

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2835

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 include lto c t a v e o c t hgt2

3 DEFUN_DLD ( dld args nargout dld (array) nreturn the elements of larrthe array in reverse ordern )

4 5 octave_value_list retval 6 int nargin = args length ( ) 7

8 if ( nargin = 1)9 print_usage ( )

10 else11 12 Arrayltdoublegt a = args ( 0 ) array_value ( ) 13 if ( error_state )14 15 Arrayltdoublegt b ( a )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

16 doublelowast ap = a fortran_vec ( ) 17 doublelowast bp = b fortran_vec ( ) 18 for ( octave_idx_type i = a numel ( ) minus 1 j = 0 i gt= 0 larr

iminusminus j++)19 bp [ i ] = ap [ j ] 20 retval = octave_value ( b ) 21 22 23 return retval 24

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 gtgt mkoctfile dld cc2 gtgt a = randn ( 5 )3 a =4

5 0395421 minus1425232 minus0176544 1055205 22293716 minus0241893 0035004 minus0296543 minus1710613 04443187 minus0752467 minus2220469 2380951 0766246 11961538 1404672 0623112 1182609 0196125 06093259 minus0687019 0646079 2239012 minus0495169 1488314

10

11 gtgt b = dld ( a )12 b =13

14 1488314 minus0495169 2239012 0646079 minus068701915 0609325 0196125 1182609 0623112 140467216 1196153 0766246 2380951 minus2220469 minus075246717 0444318 minus1710613 minus0296543 0035004 minus024189318 2229371 1055205 minus0176544 minus1425232 039542119

20 gtgt

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 10: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

What does it look like

Primarily a CLI interface

Figure CLI screenshot

Most requested feature GUI Will ship with next release (40)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 835

What is Octave Octave and

What does it look like

Primarily a CLI interface

Most requested feature GUI Will ship with next release (40)

Figure Qt based GUI development started as J Dawidrsquos GSoC2012 project

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 835

What is Octave Octave and

What does it look like

Primarily a CLI interface

Most requested feature GUI Will ship with next release (40)

Figure Qt based GUI development started as J Dawidrsquos GSoC2012 project

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 835

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 935

What is Octave Octave and

In the beginning

Companion software for chemical reactor textbook by James BRawlings and John G Ekerdt

John W Eaton (hereafter jwe) started coding in 1993

Rawlings said

Why donrsquot you call it ldquoOctaverdquo

Octave refers to Octave Levenspiel nothing to do with music

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1035

What is Octave Octave and

In the beginning

Companion software for chemical reactor textbook by James BRawlings and John G Ekerdt

John W Eaton (hereafter jwe) started coding in 1993

Rawlings said

Why donrsquot you call it ldquoOctaverdquo

Octave refers to Octave Levenspiel nothing to do with music

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1035

What is Octave Octave and

jwe is a lone wolf

jwe works almost completely alone for first four or five years

In the very beginning

No mailing lists

No widespread announcements

No VCS (these were dark times)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1135

What is Octave Octave and

jwe is a lone wolf

jwe works almost completely alone for first four or five years

In the very beginning

No mailing lists

No widespread announcements

No VCS (these were dark times)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1135

What is Octave Octave and

Contributions slowly trickle in

Timeline

1989 Planning stages

1992 Development begins

1993 First public announcement

1994 Version 10

1996 Version 20

1998 Version 21 development

2004 Version 29 in preparation for 30 release

2007 Version 30 major upgrade

2010 Version 324 last before using hg

2011 Version 340

2012 Version 364

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1235

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1435

What is Octave Octave and

Web resources

Web pages

Octave website

Octave-Forge website

Octave wiki

Users communication

Octave users mailing list

Octave-Forge mailing list

octave channel in Freenode

Savannah bug tracker

Developers collaboration

Octave Mercurial repository

Octave-Forge Subversion repository

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1535

What is Octave Octave and

Web resources

Web pages

Octave website

Octave-Forge website

Octave wiki

Users communication

Octave users mailing list

Octave-Forge mailing list

octave channel in Freenode

Savannah bug tracker

Developers collaboration

Octave Mercurial repository

Octave-Forge Subversion repository

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1535

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer15 current Core developers (with write access to repo)49 currently registered rsquoForge developers (38 active)296 total contributors over all timeBen Abbott Andy Adler Giles Anderson Joel Andersson Muthiah Annamalai Marco Atzeri Shai Ayal Roger Banks Ben Barrowes

Alexander Barth David Bateman Heinz Bauschke Roman Belov Karl Berry David Billinghurst Don Bindner Jakub Bogusz Moritz

Borgmann Paul Boven Richard Bovey John Bradshaw Marcus Brinkmann Remy Bruno Ansgar Burchard Marco Caliari Daniel

Calvelo John C Campbell Juan Pablo Carbajal Jean-Francois Cardoso Joao Cardoso Larrie Carr David Castelow Vincent

Cautaerts Clinton Chee Albert Chin-A-Young Carsten Clark J D Cole Martin Costabel Michael Creel Jeff Cunningham Martin

Dalecki Jorge Barros de Abreu Carlo de Falco Jacob Dawid Thomas D Dean Philippe Defert Bill Denney Fabian Deutsch

Christos Dimitrakakis David M Doolin Carne Draug Pascal A Dupuis John W Eaton Dirk Eddelbuettel Pieter Eendebak Paul

Eggert Stephen Eglen Peter Ekberg Rolf Fabian Gunnar Farneback Stephen Fegan Ramon Garcia Fernandez Torsten Finke Jose

Daniel Munoz Frias Brad Froehle Castor Fu Eduardo Gallestey Walter Gautschi Klaus Gebhardt Driss Ghaddab Nicolo Giorgetti

Michael D Godfrey Michael Goffioul Glenn Golden Tomislav Goles Keith Goodman Brian Gough Steffen Groot Etienne

Grossmann David Grundberg Peter Gustafson Kai Habel Patrick Hacker William P Y Hadisoeseno Jaroslav Hajek Benjamin Hall

Kim Hansen Soslashren Hauberg Dave Hawthorne Daniel Heiserer Martin Helm Stefan Hepp Jordi Gutierrez Hermoso Yozo Hida Ryan

Hinton Roman Hodek A Scottedward Hodel Richard Allan Holcombe Tom Holroyd David Hoover Kurt Hornik Christopher

Hulbert Cyril Humbert Teemu Ikonen Alan W Irwin Geoff Jacobsen Mats Jansson Cai Jianming Steven G Johnson Heikki Junes

Matthias Juschke Atsushi Kajita Jarkko Kaleva Mohamed Kamoun Lute Kamstra Fotios Kasolis Thomas Kasper Joel Keay

Mumit Khan Paul Kienzle Aaron A King Arno J Klaassen Alexander Klein Geoffrey Knauth Heine Kolltveit Ken Kouno Kacper

Kowalik Daniel Kraft Aravindh Krishnamoorthy Oyvind Kristiansen Piotr Krzyzanowski Volker Kuhlmann Tetsuro Kurita

Miroslaw Kwasniak Rafael Laboissiere Kai Labusch Claude Lacoursiere Walter Landry Bill Lash Dirk Laurie Maurice LeBrun

Friedrich Leisch Jyh-miin Lin Timo Lindfors Benjamin Lindner Ross Lippert David Livings Sebastien Loisel Erik de Castro Lopo

Massimo Lorenzin Emil Lucretiu Hoxide Ma James Macnicol Jens-Uwe Mager Rob Mahurin Ricardo Marranita Orestes Mas

Makoto Matsumoto Tatsuro Matsuoka Laurent Mazet G D McBain Alexander Mamonov Christoph Mayer Julio Hoffimann

Mendes Thorsten Meyer Petr Mikulik Stefan Monnier Antoine Moreau Kai P Mueller Hannes Muller Victor Munoz Carmen

Navarrete Todd Neal Philip Nienhuis Al Niessner Rick Niles Takuji Nishimura Kai Noda Eric Norum Krzesimir Nowak Michael

OrsquoBrien Peter OrsquoGorman Thorsten Ohl Arno Onken Luis F Ortiz Scott Pakin Gabriele Pannocchia Sylvain Pelissier Per Persson

Primozz Peterlin Jim Peterson Danilo Piazzalunga Nicholas Piper Elias Pipping Robert Platt Hans Ekkehard Plesser Tom Poage

Orion Poplawski Ondrej Popp Jef Poskanzer Francesco Potortı Konstantinos Poulios Jarno Rajahalme James B Rawlings Eric S

Raymond Balint Reczey Joshua Redstone Lukas Reichlin Michael Reifenberger Anthony Richardson Jason Riedy E Joshua Rigler

Petter Risholm Matthew W Roberts Andrew Ross Mark van Rossum Joe Rothweiler Kevin Ruland Kristian Rumberg Ryan

Rusaw Olli Saarela Toni Saarela Juhani Saastamoinen Radek Salac Ben Sapp Aleksej Saushev Alois Schlogl Michel D Schmid

Julian Schnidder Nicol N Schraudolph Sebastian Schubert Ludwig Schwardt Thomas L Scofield Daniel J Sebald Dmitri A

Sergatskov Vanya Sergeev Baylis Shanks Andriy Shinkarchuck Robert T Short Joseph P Skudlarek John Smith Julius Smith

Shan G Smith Peter L Sondergaard Joerg Specht Quentin H Spencer Christoph Spiel Richard Stallman Russell Standish Brett

Stewart Doug Stewart Jonathan Stickel Judd Storrs Thomas Stuart Ivan Sutoris John Swensen Daisuke Takago Ariel Tankus

Matthew Tenny Georg Thimm Duncan Temple Lang Kris Thielemans Olaf Till Christophe Tournery Thomas Treichl Karsten

Trulsen Frederick Umminger Utkarsh Upadhyay Stefan van der Walt Peter Van Wieren James R Van Zandt Gregory Vanuxem

Ivana Varekova Thomas Walter Andreas Weber Olaf Weber Thomas Weber Rik Wehbring Bob Weigel Andreas Weingessel

Martin Weiser Michael Weitzel David Wells Fook Fah Yap Sean Young Michael Zeising Federico Zenith Alex Zvoleff

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

296 total contributors over all time

How many users Thousands Millions

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1935

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2035

What is Octave Octave and

Octave-Forge

Octave-Forge

Octave Forge Is a place for concurrently developing and distributingextension packages for Octave

Each package has a maintainer responsible for updating andreleasing new versions of the package

Some packages are maintained by The Community

Installation via an integrated package manager

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2135

What is Octave Octave and

PKG

1 gtgt pkg install minusforge miscellaneous2 For information about changes from previous versions of the larr

miscellaneous package run news ( miscellaneous ) 3 gtgt pkg list4 Package Name | Version | Installation directory5 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus6 bim | 1 1 1 | ˜ octavebimminus1117 fpl | 1 3 3 | ˜ octavefplminus1338 general | 1 3 1 | ˜ octavegeneral minus1319 geometry | 1 6 0 | ˜ octavegeometry minus160

10 miscellaneous | 1 2 0 | ˜ octavemiscellaneous minus12011 gtgt pkg load miscellaneous12 gtgt pkg list13 Package Name | Version | Installation directory14 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus15 bim | 1 1 1 | ˜ octavebimminus11116 fpl | 1 3 3 | ˜ octavefplminus13317 general | 1 3 1 | ˜ octavegeneral minus13118 geometry | 1 6 0 | ˜ octavegeometry minus16019 miscellaneous lowast| 1 2 0 | ˜ octavemiscellaneous minus120

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2235

What is Octave Octave and

PKG

1 gtgt pkg describe bim minusverbose2 minusminusminus3 Package name 4 bim5 Version 6 1 1 17 Short description 8 Package f o r solving Diffusion Advection Reaction ( DAR ) Partial larr

Differential Equations9 Status

10 Not loaded11 minusminusminus12 Provides 13 Matrix assembly14 bim1a_advection_diffusion15 bim1a_advection_upwind16 bim2a_advection_diffusion17 18 Preminusprocessing and Postminusprocessing computations19 bim2c_mesh_properties20 21 gtgt

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2335

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2535

What is Octave Octave and

Broadcasting

Since 360 Octave automatically broadcasts arrays when usingelementwise binary operators

Corresponding array dimensions must either be equal or one ofthem must be 1

In case all dimensions are equal ordinary element-by-elementarithmetic takes place

When one of the dimensions is 1 the array with that singletondimension gets copied along that dimension until it matches thedimension of the other array

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2635

What is Octave Octave and

Broadcasting

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Without broadcasting x + y would be an error because dimensions do not agree

With broadcasting it is as if the following operation were performed

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 10 20 3 0 10 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Other notable differences with Matlab listed in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2735

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2835

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 include lto c t a v e o c t hgt2

3 DEFUN_DLD ( dld args nargout dld (array) nreturn the elements of larrthe array in reverse ordern )

4 5 octave_value_list retval 6 int nargin = args length ( ) 7

8 if ( nargin = 1)9 print_usage ( )

10 else11 12 Arrayltdoublegt a = args ( 0 ) array_value ( ) 13 if ( error_state )14 15 Arrayltdoublegt b ( a )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

16 doublelowast ap = a fortran_vec ( ) 17 doublelowast bp = b fortran_vec ( ) 18 for ( octave_idx_type i = a numel ( ) minus 1 j = 0 i gt= 0 larr

iminusminus j++)19 bp [ i ] = ap [ j ] 20 retval = octave_value ( b ) 21 22 23 return retval 24

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 gtgt mkoctfile dld cc2 gtgt a = randn ( 5 )3 a =4

5 0395421 minus1425232 minus0176544 1055205 22293716 minus0241893 0035004 minus0296543 minus1710613 04443187 minus0752467 minus2220469 2380951 0766246 11961538 1404672 0623112 1182609 0196125 06093259 minus0687019 0646079 2239012 minus0495169 1488314

10

11 gtgt b = dld ( a )12 b =13

14 1488314 minus0495169 2239012 0646079 minus068701915 0609325 0196125 1182609 0623112 140467216 1196153 0766246 2380951 minus2220469 minus075246717 0444318 minus1710613 minus0296543 0035004 minus024189318 2229371 1055205 minus0176544 minus1425232 039542119

20 gtgt

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 11: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

What does it look like

Primarily a CLI interface

Most requested feature GUI Will ship with next release (40)

Figure Qt based GUI development started as J Dawidrsquos GSoC2012 project

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 835

What is Octave Octave and

What does it look like

Primarily a CLI interface

Most requested feature GUI Will ship with next release (40)

Figure Qt based GUI development started as J Dawidrsquos GSoC2012 project

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 835

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 935

What is Octave Octave and

In the beginning

Companion software for chemical reactor textbook by James BRawlings and John G Ekerdt

John W Eaton (hereafter jwe) started coding in 1993

Rawlings said

Why donrsquot you call it ldquoOctaverdquo

Octave refers to Octave Levenspiel nothing to do with music

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1035

What is Octave Octave and

In the beginning

Companion software for chemical reactor textbook by James BRawlings and John G Ekerdt

John W Eaton (hereafter jwe) started coding in 1993

Rawlings said

Why donrsquot you call it ldquoOctaverdquo

Octave refers to Octave Levenspiel nothing to do with music

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1035

What is Octave Octave and

jwe is a lone wolf

jwe works almost completely alone for first four or five years

In the very beginning

No mailing lists

No widespread announcements

No VCS (these were dark times)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1135

What is Octave Octave and

jwe is a lone wolf

jwe works almost completely alone for first four or five years

In the very beginning

No mailing lists

No widespread announcements

No VCS (these were dark times)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1135

What is Octave Octave and

Contributions slowly trickle in

Timeline

1989 Planning stages

1992 Development begins

1993 First public announcement

1994 Version 10

1996 Version 20

1998 Version 21 development

2004 Version 29 in preparation for 30 release

2007 Version 30 major upgrade

2010 Version 324 last before using hg

2011 Version 340

2012 Version 364

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1235

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1435

What is Octave Octave and

Web resources

Web pages

Octave website

Octave-Forge website

Octave wiki

Users communication

Octave users mailing list

Octave-Forge mailing list

octave channel in Freenode

Savannah bug tracker

Developers collaboration

Octave Mercurial repository

Octave-Forge Subversion repository

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1535

What is Octave Octave and

Web resources

Web pages

Octave website

Octave-Forge website

Octave wiki

Users communication

Octave users mailing list

Octave-Forge mailing list

octave channel in Freenode

Savannah bug tracker

Developers collaboration

Octave Mercurial repository

Octave-Forge Subversion repository

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1535

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer15 current Core developers (with write access to repo)49 currently registered rsquoForge developers (38 active)296 total contributors over all timeBen Abbott Andy Adler Giles Anderson Joel Andersson Muthiah Annamalai Marco Atzeri Shai Ayal Roger Banks Ben Barrowes

Alexander Barth David Bateman Heinz Bauschke Roman Belov Karl Berry David Billinghurst Don Bindner Jakub Bogusz Moritz

Borgmann Paul Boven Richard Bovey John Bradshaw Marcus Brinkmann Remy Bruno Ansgar Burchard Marco Caliari Daniel

Calvelo John C Campbell Juan Pablo Carbajal Jean-Francois Cardoso Joao Cardoso Larrie Carr David Castelow Vincent

Cautaerts Clinton Chee Albert Chin-A-Young Carsten Clark J D Cole Martin Costabel Michael Creel Jeff Cunningham Martin

Dalecki Jorge Barros de Abreu Carlo de Falco Jacob Dawid Thomas D Dean Philippe Defert Bill Denney Fabian Deutsch

Christos Dimitrakakis David M Doolin Carne Draug Pascal A Dupuis John W Eaton Dirk Eddelbuettel Pieter Eendebak Paul

Eggert Stephen Eglen Peter Ekberg Rolf Fabian Gunnar Farneback Stephen Fegan Ramon Garcia Fernandez Torsten Finke Jose

Daniel Munoz Frias Brad Froehle Castor Fu Eduardo Gallestey Walter Gautschi Klaus Gebhardt Driss Ghaddab Nicolo Giorgetti

Michael D Godfrey Michael Goffioul Glenn Golden Tomislav Goles Keith Goodman Brian Gough Steffen Groot Etienne

Grossmann David Grundberg Peter Gustafson Kai Habel Patrick Hacker William P Y Hadisoeseno Jaroslav Hajek Benjamin Hall

Kim Hansen Soslashren Hauberg Dave Hawthorne Daniel Heiserer Martin Helm Stefan Hepp Jordi Gutierrez Hermoso Yozo Hida Ryan

Hinton Roman Hodek A Scottedward Hodel Richard Allan Holcombe Tom Holroyd David Hoover Kurt Hornik Christopher

Hulbert Cyril Humbert Teemu Ikonen Alan W Irwin Geoff Jacobsen Mats Jansson Cai Jianming Steven G Johnson Heikki Junes

Matthias Juschke Atsushi Kajita Jarkko Kaleva Mohamed Kamoun Lute Kamstra Fotios Kasolis Thomas Kasper Joel Keay

Mumit Khan Paul Kienzle Aaron A King Arno J Klaassen Alexander Klein Geoffrey Knauth Heine Kolltveit Ken Kouno Kacper

Kowalik Daniel Kraft Aravindh Krishnamoorthy Oyvind Kristiansen Piotr Krzyzanowski Volker Kuhlmann Tetsuro Kurita

Miroslaw Kwasniak Rafael Laboissiere Kai Labusch Claude Lacoursiere Walter Landry Bill Lash Dirk Laurie Maurice LeBrun

Friedrich Leisch Jyh-miin Lin Timo Lindfors Benjamin Lindner Ross Lippert David Livings Sebastien Loisel Erik de Castro Lopo

Massimo Lorenzin Emil Lucretiu Hoxide Ma James Macnicol Jens-Uwe Mager Rob Mahurin Ricardo Marranita Orestes Mas

Makoto Matsumoto Tatsuro Matsuoka Laurent Mazet G D McBain Alexander Mamonov Christoph Mayer Julio Hoffimann

Mendes Thorsten Meyer Petr Mikulik Stefan Monnier Antoine Moreau Kai P Mueller Hannes Muller Victor Munoz Carmen

Navarrete Todd Neal Philip Nienhuis Al Niessner Rick Niles Takuji Nishimura Kai Noda Eric Norum Krzesimir Nowak Michael

OrsquoBrien Peter OrsquoGorman Thorsten Ohl Arno Onken Luis F Ortiz Scott Pakin Gabriele Pannocchia Sylvain Pelissier Per Persson

Primozz Peterlin Jim Peterson Danilo Piazzalunga Nicholas Piper Elias Pipping Robert Platt Hans Ekkehard Plesser Tom Poage

Orion Poplawski Ondrej Popp Jef Poskanzer Francesco Potortı Konstantinos Poulios Jarno Rajahalme James B Rawlings Eric S

Raymond Balint Reczey Joshua Redstone Lukas Reichlin Michael Reifenberger Anthony Richardson Jason Riedy E Joshua Rigler

Petter Risholm Matthew W Roberts Andrew Ross Mark van Rossum Joe Rothweiler Kevin Ruland Kristian Rumberg Ryan

Rusaw Olli Saarela Toni Saarela Juhani Saastamoinen Radek Salac Ben Sapp Aleksej Saushev Alois Schlogl Michel D Schmid

Julian Schnidder Nicol N Schraudolph Sebastian Schubert Ludwig Schwardt Thomas L Scofield Daniel J Sebald Dmitri A

Sergatskov Vanya Sergeev Baylis Shanks Andriy Shinkarchuck Robert T Short Joseph P Skudlarek John Smith Julius Smith

Shan G Smith Peter L Sondergaard Joerg Specht Quentin H Spencer Christoph Spiel Richard Stallman Russell Standish Brett

Stewart Doug Stewart Jonathan Stickel Judd Storrs Thomas Stuart Ivan Sutoris John Swensen Daisuke Takago Ariel Tankus

Matthew Tenny Georg Thimm Duncan Temple Lang Kris Thielemans Olaf Till Christophe Tournery Thomas Treichl Karsten

Trulsen Frederick Umminger Utkarsh Upadhyay Stefan van der Walt Peter Van Wieren James R Van Zandt Gregory Vanuxem

Ivana Varekova Thomas Walter Andreas Weber Olaf Weber Thomas Weber Rik Wehbring Bob Weigel Andreas Weingessel

Martin Weiser Michael Weitzel David Wells Fook Fah Yap Sean Young Michael Zeising Federico Zenith Alex Zvoleff

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

296 total contributors over all time

How many users Thousands Millions

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1935

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2035

What is Octave Octave and

Octave-Forge

Octave-Forge

Octave Forge Is a place for concurrently developing and distributingextension packages for Octave

Each package has a maintainer responsible for updating andreleasing new versions of the package

Some packages are maintained by The Community

Installation via an integrated package manager

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2135

What is Octave Octave and

PKG

1 gtgt pkg install minusforge miscellaneous2 For information about changes from previous versions of the larr

miscellaneous package run news ( miscellaneous ) 3 gtgt pkg list4 Package Name | Version | Installation directory5 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus6 bim | 1 1 1 | ˜ octavebimminus1117 fpl | 1 3 3 | ˜ octavefplminus1338 general | 1 3 1 | ˜ octavegeneral minus1319 geometry | 1 6 0 | ˜ octavegeometry minus160

10 miscellaneous | 1 2 0 | ˜ octavemiscellaneous minus12011 gtgt pkg load miscellaneous12 gtgt pkg list13 Package Name | Version | Installation directory14 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus15 bim | 1 1 1 | ˜ octavebimminus11116 fpl | 1 3 3 | ˜ octavefplminus13317 general | 1 3 1 | ˜ octavegeneral minus13118 geometry | 1 6 0 | ˜ octavegeometry minus16019 miscellaneous lowast| 1 2 0 | ˜ octavemiscellaneous minus120

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2235

What is Octave Octave and

PKG

1 gtgt pkg describe bim minusverbose2 minusminusminus3 Package name 4 bim5 Version 6 1 1 17 Short description 8 Package f o r solving Diffusion Advection Reaction ( DAR ) Partial larr

Differential Equations9 Status

10 Not loaded11 minusminusminus12 Provides 13 Matrix assembly14 bim1a_advection_diffusion15 bim1a_advection_upwind16 bim2a_advection_diffusion17 18 Preminusprocessing and Postminusprocessing computations19 bim2c_mesh_properties20 21 gtgt

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2335

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2535

What is Octave Octave and

Broadcasting

Since 360 Octave automatically broadcasts arrays when usingelementwise binary operators

Corresponding array dimensions must either be equal or one ofthem must be 1

In case all dimensions are equal ordinary element-by-elementarithmetic takes place

When one of the dimensions is 1 the array with that singletondimension gets copied along that dimension until it matches thedimension of the other array

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2635

What is Octave Octave and

Broadcasting

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Without broadcasting x + y would be an error because dimensions do not agree

With broadcasting it is as if the following operation were performed

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 10 20 3 0 10 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Other notable differences with Matlab listed in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2735

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2835

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 include lto c t a v e o c t hgt2

3 DEFUN_DLD ( dld args nargout dld (array) nreturn the elements of larrthe array in reverse ordern )

4 5 octave_value_list retval 6 int nargin = args length ( ) 7

8 if ( nargin = 1)9 print_usage ( )

10 else11 12 Arrayltdoublegt a = args ( 0 ) array_value ( ) 13 if ( error_state )14 15 Arrayltdoublegt b ( a )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

16 doublelowast ap = a fortran_vec ( ) 17 doublelowast bp = b fortran_vec ( ) 18 for ( octave_idx_type i = a numel ( ) minus 1 j = 0 i gt= 0 larr

iminusminus j++)19 bp [ i ] = ap [ j ] 20 retval = octave_value ( b ) 21 22 23 return retval 24

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 gtgt mkoctfile dld cc2 gtgt a = randn ( 5 )3 a =4

5 0395421 minus1425232 minus0176544 1055205 22293716 minus0241893 0035004 minus0296543 minus1710613 04443187 minus0752467 minus2220469 2380951 0766246 11961538 1404672 0623112 1182609 0196125 06093259 minus0687019 0646079 2239012 minus0495169 1488314

10

11 gtgt b = dld ( a )12 b =13

14 1488314 minus0495169 2239012 0646079 minus068701915 0609325 0196125 1182609 0623112 140467216 1196153 0766246 2380951 minus2220469 minus075246717 0444318 minus1710613 minus0296543 0035004 minus024189318 2229371 1055205 minus0176544 minus1425232 039542119

20 gtgt

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 12: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

What does it look like

Primarily a CLI interface

Most requested feature GUI Will ship with next release (40)

Figure Qt based GUI development started as J Dawidrsquos GSoC2012 project

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 835

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 935

What is Octave Octave and

In the beginning

Companion software for chemical reactor textbook by James BRawlings and John G Ekerdt

John W Eaton (hereafter jwe) started coding in 1993

Rawlings said

Why donrsquot you call it ldquoOctaverdquo

Octave refers to Octave Levenspiel nothing to do with music

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1035

What is Octave Octave and

In the beginning

Companion software for chemical reactor textbook by James BRawlings and John G Ekerdt

John W Eaton (hereafter jwe) started coding in 1993

Rawlings said

Why donrsquot you call it ldquoOctaverdquo

Octave refers to Octave Levenspiel nothing to do with music

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1035

What is Octave Octave and

jwe is a lone wolf

jwe works almost completely alone for first four or five years

In the very beginning

No mailing lists

No widespread announcements

No VCS (these were dark times)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1135

What is Octave Octave and

jwe is a lone wolf

jwe works almost completely alone for first four or five years

In the very beginning

No mailing lists

No widespread announcements

No VCS (these were dark times)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1135

What is Octave Octave and

Contributions slowly trickle in

Timeline

1989 Planning stages

1992 Development begins

1993 First public announcement

1994 Version 10

1996 Version 20

1998 Version 21 development

2004 Version 29 in preparation for 30 release

2007 Version 30 major upgrade

2010 Version 324 last before using hg

2011 Version 340

2012 Version 364

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1235

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1435

What is Octave Octave and

Web resources

Web pages

Octave website

Octave-Forge website

Octave wiki

Users communication

Octave users mailing list

Octave-Forge mailing list

octave channel in Freenode

Savannah bug tracker

Developers collaboration

Octave Mercurial repository

Octave-Forge Subversion repository

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1535

What is Octave Octave and

Web resources

Web pages

Octave website

Octave-Forge website

Octave wiki

Users communication

Octave users mailing list

Octave-Forge mailing list

octave channel in Freenode

Savannah bug tracker

Developers collaboration

Octave Mercurial repository

Octave-Forge Subversion repository

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1535

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer15 current Core developers (with write access to repo)49 currently registered rsquoForge developers (38 active)296 total contributors over all timeBen Abbott Andy Adler Giles Anderson Joel Andersson Muthiah Annamalai Marco Atzeri Shai Ayal Roger Banks Ben Barrowes

Alexander Barth David Bateman Heinz Bauschke Roman Belov Karl Berry David Billinghurst Don Bindner Jakub Bogusz Moritz

Borgmann Paul Boven Richard Bovey John Bradshaw Marcus Brinkmann Remy Bruno Ansgar Burchard Marco Caliari Daniel

Calvelo John C Campbell Juan Pablo Carbajal Jean-Francois Cardoso Joao Cardoso Larrie Carr David Castelow Vincent

Cautaerts Clinton Chee Albert Chin-A-Young Carsten Clark J D Cole Martin Costabel Michael Creel Jeff Cunningham Martin

Dalecki Jorge Barros de Abreu Carlo de Falco Jacob Dawid Thomas D Dean Philippe Defert Bill Denney Fabian Deutsch

Christos Dimitrakakis David M Doolin Carne Draug Pascal A Dupuis John W Eaton Dirk Eddelbuettel Pieter Eendebak Paul

Eggert Stephen Eglen Peter Ekberg Rolf Fabian Gunnar Farneback Stephen Fegan Ramon Garcia Fernandez Torsten Finke Jose

Daniel Munoz Frias Brad Froehle Castor Fu Eduardo Gallestey Walter Gautschi Klaus Gebhardt Driss Ghaddab Nicolo Giorgetti

Michael D Godfrey Michael Goffioul Glenn Golden Tomislav Goles Keith Goodman Brian Gough Steffen Groot Etienne

Grossmann David Grundberg Peter Gustafson Kai Habel Patrick Hacker William P Y Hadisoeseno Jaroslav Hajek Benjamin Hall

Kim Hansen Soslashren Hauberg Dave Hawthorne Daniel Heiserer Martin Helm Stefan Hepp Jordi Gutierrez Hermoso Yozo Hida Ryan

Hinton Roman Hodek A Scottedward Hodel Richard Allan Holcombe Tom Holroyd David Hoover Kurt Hornik Christopher

Hulbert Cyril Humbert Teemu Ikonen Alan W Irwin Geoff Jacobsen Mats Jansson Cai Jianming Steven G Johnson Heikki Junes

Matthias Juschke Atsushi Kajita Jarkko Kaleva Mohamed Kamoun Lute Kamstra Fotios Kasolis Thomas Kasper Joel Keay

Mumit Khan Paul Kienzle Aaron A King Arno J Klaassen Alexander Klein Geoffrey Knauth Heine Kolltveit Ken Kouno Kacper

Kowalik Daniel Kraft Aravindh Krishnamoorthy Oyvind Kristiansen Piotr Krzyzanowski Volker Kuhlmann Tetsuro Kurita

Miroslaw Kwasniak Rafael Laboissiere Kai Labusch Claude Lacoursiere Walter Landry Bill Lash Dirk Laurie Maurice LeBrun

Friedrich Leisch Jyh-miin Lin Timo Lindfors Benjamin Lindner Ross Lippert David Livings Sebastien Loisel Erik de Castro Lopo

Massimo Lorenzin Emil Lucretiu Hoxide Ma James Macnicol Jens-Uwe Mager Rob Mahurin Ricardo Marranita Orestes Mas

Makoto Matsumoto Tatsuro Matsuoka Laurent Mazet G D McBain Alexander Mamonov Christoph Mayer Julio Hoffimann

Mendes Thorsten Meyer Petr Mikulik Stefan Monnier Antoine Moreau Kai P Mueller Hannes Muller Victor Munoz Carmen

Navarrete Todd Neal Philip Nienhuis Al Niessner Rick Niles Takuji Nishimura Kai Noda Eric Norum Krzesimir Nowak Michael

OrsquoBrien Peter OrsquoGorman Thorsten Ohl Arno Onken Luis F Ortiz Scott Pakin Gabriele Pannocchia Sylvain Pelissier Per Persson

Primozz Peterlin Jim Peterson Danilo Piazzalunga Nicholas Piper Elias Pipping Robert Platt Hans Ekkehard Plesser Tom Poage

Orion Poplawski Ondrej Popp Jef Poskanzer Francesco Potortı Konstantinos Poulios Jarno Rajahalme James B Rawlings Eric S

Raymond Balint Reczey Joshua Redstone Lukas Reichlin Michael Reifenberger Anthony Richardson Jason Riedy E Joshua Rigler

Petter Risholm Matthew W Roberts Andrew Ross Mark van Rossum Joe Rothweiler Kevin Ruland Kristian Rumberg Ryan

Rusaw Olli Saarela Toni Saarela Juhani Saastamoinen Radek Salac Ben Sapp Aleksej Saushev Alois Schlogl Michel D Schmid

Julian Schnidder Nicol N Schraudolph Sebastian Schubert Ludwig Schwardt Thomas L Scofield Daniel J Sebald Dmitri A

Sergatskov Vanya Sergeev Baylis Shanks Andriy Shinkarchuck Robert T Short Joseph P Skudlarek John Smith Julius Smith

Shan G Smith Peter L Sondergaard Joerg Specht Quentin H Spencer Christoph Spiel Richard Stallman Russell Standish Brett

Stewart Doug Stewart Jonathan Stickel Judd Storrs Thomas Stuart Ivan Sutoris John Swensen Daisuke Takago Ariel Tankus

Matthew Tenny Georg Thimm Duncan Temple Lang Kris Thielemans Olaf Till Christophe Tournery Thomas Treichl Karsten

Trulsen Frederick Umminger Utkarsh Upadhyay Stefan van der Walt Peter Van Wieren James R Van Zandt Gregory Vanuxem

Ivana Varekova Thomas Walter Andreas Weber Olaf Weber Thomas Weber Rik Wehbring Bob Weigel Andreas Weingessel

Martin Weiser Michael Weitzel David Wells Fook Fah Yap Sean Young Michael Zeising Federico Zenith Alex Zvoleff

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

296 total contributors over all time

How many users Thousands Millions

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1935

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2035

What is Octave Octave and

Octave-Forge

Octave-Forge

Octave Forge Is a place for concurrently developing and distributingextension packages for Octave

Each package has a maintainer responsible for updating andreleasing new versions of the package

Some packages are maintained by The Community

Installation via an integrated package manager

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2135

What is Octave Octave and

PKG

1 gtgt pkg install minusforge miscellaneous2 For information about changes from previous versions of the larr

miscellaneous package run news ( miscellaneous ) 3 gtgt pkg list4 Package Name | Version | Installation directory5 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus6 bim | 1 1 1 | ˜ octavebimminus1117 fpl | 1 3 3 | ˜ octavefplminus1338 general | 1 3 1 | ˜ octavegeneral minus1319 geometry | 1 6 0 | ˜ octavegeometry minus160

10 miscellaneous | 1 2 0 | ˜ octavemiscellaneous minus12011 gtgt pkg load miscellaneous12 gtgt pkg list13 Package Name | Version | Installation directory14 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus15 bim | 1 1 1 | ˜ octavebimminus11116 fpl | 1 3 3 | ˜ octavefplminus13317 general | 1 3 1 | ˜ octavegeneral minus13118 geometry | 1 6 0 | ˜ octavegeometry minus16019 miscellaneous lowast| 1 2 0 | ˜ octavemiscellaneous minus120

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2235

What is Octave Octave and

PKG

1 gtgt pkg describe bim minusverbose2 minusminusminus3 Package name 4 bim5 Version 6 1 1 17 Short description 8 Package f o r solving Diffusion Advection Reaction ( DAR ) Partial larr

Differential Equations9 Status

10 Not loaded11 minusminusminus12 Provides 13 Matrix assembly14 bim1a_advection_diffusion15 bim1a_advection_upwind16 bim2a_advection_diffusion17 18 Preminusprocessing and Postminusprocessing computations19 bim2c_mesh_properties20 21 gtgt

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2335

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2535

What is Octave Octave and

Broadcasting

Since 360 Octave automatically broadcasts arrays when usingelementwise binary operators

Corresponding array dimensions must either be equal or one ofthem must be 1

In case all dimensions are equal ordinary element-by-elementarithmetic takes place

When one of the dimensions is 1 the array with that singletondimension gets copied along that dimension until it matches thedimension of the other array

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2635

What is Octave Octave and

Broadcasting

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Without broadcasting x + y would be an error because dimensions do not agree

With broadcasting it is as if the following operation were performed

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 10 20 3 0 10 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Other notable differences with Matlab listed in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2735

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2835

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 include lto c t a v e o c t hgt2

3 DEFUN_DLD ( dld args nargout dld (array) nreturn the elements of larrthe array in reverse ordern )

4 5 octave_value_list retval 6 int nargin = args length ( ) 7

8 if ( nargin = 1)9 print_usage ( )

10 else11 12 Arrayltdoublegt a = args ( 0 ) array_value ( ) 13 if ( error_state )14 15 Arrayltdoublegt b ( a )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

16 doublelowast ap = a fortran_vec ( ) 17 doublelowast bp = b fortran_vec ( ) 18 for ( octave_idx_type i = a numel ( ) minus 1 j = 0 i gt= 0 larr

iminusminus j++)19 bp [ i ] = ap [ j ] 20 retval = octave_value ( b ) 21 22 23 return retval 24

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 gtgt mkoctfile dld cc2 gtgt a = randn ( 5 )3 a =4

5 0395421 minus1425232 minus0176544 1055205 22293716 minus0241893 0035004 minus0296543 minus1710613 04443187 minus0752467 minus2220469 2380951 0766246 11961538 1404672 0623112 1182609 0196125 06093259 minus0687019 0646079 2239012 minus0495169 1488314

10

11 gtgt b = dld ( a )12 b =13

14 1488314 minus0495169 2239012 0646079 minus068701915 0609325 0196125 1182609 0623112 140467216 1196153 0766246 2380951 minus2220469 minus075246717 0444318 minus1710613 minus0296543 0035004 minus024189318 2229371 1055205 minus0176544 minus1425232 039542119

20 gtgt

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 13: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 935

What is Octave Octave and

In the beginning

Companion software for chemical reactor textbook by James BRawlings and John G Ekerdt

John W Eaton (hereafter jwe) started coding in 1993

Rawlings said

Why donrsquot you call it ldquoOctaverdquo

Octave refers to Octave Levenspiel nothing to do with music

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1035

What is Octave Octave and

In the beginning

Companion software for chemical reactor textbook by James BRawlings and John G Ekerdt

John W Eaton (hereafter jwe) started coding in 1993

Rawlings said

Why donrsquot you call it ldquoOctaverdquo

Octave refers to Octave Levenspiel nothing to do with music

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1035

What is Octave Octave and

jwe is a lone wolf

jwe works almost completely alone for first four or five years

In the very beginning

No mailing lists

No widespread announcements

No VCS (these were dark times)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1135

What is Octave Octave and

jwe is a lone wolf

jwe works almost completely alone for first four or five years

In the very beginning

No mailing lists

No widespread announcements

No VCS (these were dark times)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1135

What is Octave Octave and

Contributions slowly trickle in

Timeline

1989 Planning stages

1992 Development begins

1993 First public announcement

1994 Version 10

1996 Version 20

1998 Version 21 development

2004 Version 29 in preparation for 30 release

2007 Version 30 major upgrade

2010 Version 324 last before using hg

2011 Version 340

2012 Version 364

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1235

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1435

What is Octave Octave and

Web resources

Web pages

Octave website

Octave-Forge website

Octave wiki

Users communication

Octave users mailing list

Octave-Forge mailing list

octave channel in Freenode

Savannah bug tracker

Developers collaboration

Octave Mercurial repository

Octave-Forge Subversion repository

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1535

What is Octave Octave and

Web resources

Web pages

Octave website

Octave-Forge website

Octave wiki

Users communication

Octave users mailing list

Octave-Forge mailing list

octave channel in Freenode

Savannah bug tracker

Developers collaboration

Octave Mercurial repository

Octave-Forge Subversion repository

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1535

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer15 current Core developers (with write access to repo)49 currently registered rsquoForge developers (38 active)296 total contributors over all timeBen Abbott Andy Adler Giles Anderson Joel Andersson Muthiah Annamalai Marco Atzeri Shai Ayal Roger Banks Ben Barrowes

Alexander Barth David Bateman Heinz Bauschke Roman Belov Karl Berry David Billinghurst Don Bindner Jakub Bogusz Moritz

Borgmann Paul Boven Richard Bovey John Bradshaw Marcus Brinkmann Remy Bruno Ansgar Burchard Marco Caliari Daniel

Calvelo John C Campbell Juan Pablo Carbajal Jean-Francois Cardoso Joao Cardoso Larrie Carr David Castelow Vincent

Cautaerts Clinton Chee Albert Chin-A-Young Carsten Clark J D Cole Martin Costabel Michael Creel Jeff Cunningham Martin

Dalecki Jorge Barros de Abreu Carlo de Falco Jacob Dawid Thomas D Dean Philippe Defert Bill Denney Fabian Deutsch

Christos Dimitrakakis David M Doolin Carne Draug Pascal A Dupuis John W Eaton Dirk Eddelbuettel Pieter Eendebak Paul

Eggert Stephen Eglen Peter Ekberg Rolf Fabian Gunnar Farneback Stephen Fegan Ramon Garcia Fernandez Torsten Finke Jose

Daniel Munoz Frias Brad Froehle Castor Fu Eduardo Gallestey Walter Gautschi Klaus Gebhardt Driss Ghaddab Nicolo Giorgetti

Michael D Godfrey Michael Goffioul Glenn Golden Tomislav Goles Keith Goodman Brian Gough Steffen Groot Etienne

Grossmann David Grundberg Peter Gustafson Kai Habel Patrick Hacker William P Y Hadisoeseno Jaroslav Hajek Benjamin Hall

Kim Hansen Soslashren Hauberg Dave Hawthorne Daniel Heiserer Martin Helm Stefan Hepp Jordi Gutierrez Hermoso Yozo Hida Ryan

Hinton Roman Hodek A Scottedward Hodel Richard Allan Holcombe Tom Holroyd David Hoover Kurt Hornik Christopher

Hulbert Cyril Humbert Teemu Ikonen Alan W Irwin Geoff Jacobsen Mats Jansson Cai Jianming Steven G Johnson Heikki Junes

Matthias Juschke Atsushi Kajita Jarkko Kaleva Mohamed Kamoun Lute Kamstra Fotios Kasolis Thomas Kasper Joel Keay

Mumit Khan Paul Kienzle Aaron A King Arno J Klaassen Alexander Klein Geoffrey Knauth Heine Kolltveit Ken Kouno Kacper

Kowalik Daniel Kraft Aravindh Krishnamoorthy Oyvind Kristiansen Piotr Krzyzanowski Volker Kuhlmann Tetsuro Kurita

Miroslaw Kwasniak Rafael Laboissiere Kai Labusch Claude Lacoursiere Walter Landry Bill Lash Dirk Laurie Maurice LeBrun

Friedrich Leisch Jyh-miin Lin Timo Lindfors Benjamin Lindner Ross Lippert David Livings Sebastien Loisel Erik de Castro Lopo

Massimo Lorenzin Emil Lucretiu Hoxide Ma James Macnicol Jens-Uwe Mager Rob Mahurin Ricardo Marranita Orestes Mas

Makoto Matsumoto Tatsuro Matsuoka Laurent Mazet G D McBain Alexander Mamonov Christoph Mayer Julio Hoffimann

Mendes Thorsten Meyer Petr Mikulik Stefan Monnier Antoine Moreau Kai P Mueller Hannes Muller Victor Munoz Carmen

Navarrete Todd Neal Philip Nienhuis Al Niessner Rick Niles Takuji Nishimura Kai Noda Eric Norum Krzesimir Nowak Michael

OrsquoBrien Peter OrsquoGorman Thorsten Ohl Arno Onken Luis F Ortiz Scott Pakin Gabriele Pannocchia Sylvain Pelissier Per Persson

Primozz Peterlin Jim Peterson Danilo Piazzalunga Nicholas Piper Elias Pipping Robert Platt Hans Ekkehard Plesser Tom Poage

Orion Poplawski Ondrej Popp Jef Poskanzer Francesco Potortı Konstantinos Poulios Jarno Rajahalme James B Rawlings Eric S

Raymond Balint Reczey Joshua Redstone Lukas Reichlin Michael Reifenberger Anthony Richardson Jason Riedy E Joshua Rigler

Petter Risholm Matthew W Roberts Andrew Ross Mark van Rossum Joe Rothweiler Kevin Ruland Kristian Rumberg Ryan

Rusaw Olli Saarela Toni Saarela Juhani Saastamoinen Radek Salac Ben Sapp Aleksej Saushev Alois Schlogl Michel D Schmid

Julian Schnidder Nicol N Schraudolph Sebastian Schubert Ludwig Schwardt Thomas L Scofield Daniel J Sebald Dmitri A

Sergatskov Vanya Sergeev Baylis Shanks Andriy Shinkarchuck Robert T Short Joseph P Skudlarek John Smith Julius Smith

Shan G Smith Peter L Sondergaard Joerg Specht Quentin H Spencer Christoph Spiel Richard Stallman Russell Standish Brett

Stewart Doug Stewart Jonathan Stickel Judd Storrs Thomas Stuart Ivan Sutoris John Swensen Daisuke Takago Ariel Tankus

Matthew Tenny Georg Thimm Duncan Temple Lang Kris Thielemans Olaf Till Christophe Tournery Thomas Treichl Karsten

Trulsen Frederick Umminger Utkarsh Upadhyay Stefan van der Walt Peter Van Wieren James R Van Zandt Gregory Vanuxem

Ivana Varekova Thomas Walter Andreas Weber Olaf Weber Thomas Weber Rik Wehbring Bob Weigel Andreas Weingessel

Martin Weiser Michael Weitzel David Wells Fook Fah Yap Sean Young Michael Zeising Federico Zenith Alex Zvoleff

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

296 total contributors over all time

How many users Thousands Millions

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1935

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2035

What is Octave Octave and

Octave-Forge

Octave-Forge

Octave Forge Is a place for concurrently developing and distributingextension packages for Octave

Each package has a maintainer responsible for updating andreleasing new versions of the package

Some packages are maintained by The Community

Installation via an integrated package manager

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2135

What is Octave Octave and

PKG

1 gtgt pkg install minusforge miscellaneous2 For information about changes from previous versions of the larr

miscellaneous package run news ( miscellaneous ) 3 gtgt pkg list4 Package Name | Version | Installation directory5 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus6 bim | 1 1 1 | ˜ octavebimminus1117 fpl | 1 3 3 | ˜ octavefplminus1338 general | 1 3 1 | ˜ octavegeneral minus1319 geometry | 1 6 0 | ˜ octavegeometry minus160

10 miscellaneous | 1 2 0 | ˜ octavemiscellaneous minus12011 gtgt pkg load miscellaneous12 gtgt pkg list13 Package Name | Version | Installation directory14 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus15 bim | 1 1 1 | ˜ octavebimminus11116 fpl | 1 3 3 | ˜ octavefplminus13317 general | 1 3 1 | ˜ octavegeneral minus13118 geometry | 1 6 0 | ˜ octavegeometry minus16019 miscellaneous lowast| 1 2 0 | ˜ octavemiscellaneous minus120

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2235

What is Octave Octave and

PKG

1 gtgt pkg describe bim minusverbose2 minusminusminus3 Package name 4 bim5 Version 6 1 1 17 Short description 8 Package f o r solving Diffusion Advection Reaction ( DAR ) Partial larr

Differential Equations9 Status

10 Not loaded11 minusminusminus12 Provides 13 Matrix assembly14 bim1a_advection_diffusion15 bim1a_advection_upwind16 bim2a_advection_diffusion17 18 Preminusprocessing and Postminusprocessing computations19 bim2c_mesh_properties20 21 gtgt

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2335

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2535

What is Octave Octave and

Broadcasting

Since 360 Octave automatically broadcasts arrays when usingelementwise binary operators

Corresponding array dimensions must either be equal or one ofthem must be 1

In case all dimensions are equal ordinary element-by-elementarithmetic takes place

When one of the dimensions is 1 the array with that singletondimension gets copied along that dimension until it matches thedimension of the other array

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2635

What is Octave Octave and

Broadcasting

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Without broadcasting x + y would be an error because dimensions do not agree

With broadcasting it is as if the following operation were performed

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 10 20 3 0 10 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Other notable differences with Matlab listed in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2735

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2835

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 include lto c t a v e o c t hgt2

3 DEFUN_DLD ( dld args nargout dld (array) nreturn the elements of larrthe array in reverse ordern )

4 5 octave_value_list retval 6 int nargin = args length ( ) 7

8 if ( nargin = 1)9 print_usage ( )

10 else11 12 Arrayltdoublegt a = args ( 0 ) array_value ( ) 13 if ( error_state )14 15 Arrayltdoublegt b ( a )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

16 doublelowast ap = a fortran_vec ( ) 17 doublelowast bp = b fortran_vec ( ) 18 for ( octave_idx_type i = a numel ( ) minus 1 j = 0 i gt= 0 larr

iminusminus j++)19 bp [ i ] = ap [ j ] 20 retval = octave_value ( b ) 21 22 23 return retval 24

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 gtgt mkoctfile dld cc2 gtgt a = randn ( 5 )3 a =4

5 0395421 minus1425232 minus0176544 1055205 22293716 minus0241893 0035004 minus0296543 minus1710613 04443187 minus0752467 minus2220469 2380951 0766246 11961538 1404672 0623112 1182609 0196125 06093259 minus0687019 0646079 2239012 minus0495169 1488314

10

11 gtgt b = dld ( a )12 b =13

14 1488314 minus0495169 2239012 0646079 minus068701915 0609325 0196125 1182609 0623112 140467216 1196153 0766246 2380951 minus2220469 minus075246717 0444318 minus1710613 minus0296543 0035004 minus024189318 2229371 1055205 minus0176544 minus1425232 039542119

20 gtgt

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 14: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

In the beginning

Companion software for chemical reactor textbook by James BRawlings and John G Ekerdt

John W Eaton (hereafter jwe) started coding in 1993

Rawlings said

Why donrsquot you call it ldquoOctaverdquo

Octave refers to Octave Levenspiel nothing to do with music

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1035

What is Octave Octave and

In the beginning

Companion software for chemical reactor textbook by James BRawlings and John G Ekerdt

John W Eaton (hereafter jwe) started coding in 1993

Rawlings said

Why donrsquot you call it ldquoOctaverdquo

Octave refers to Octave Levenspiel nothing to do with music

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1035

What is Octave Octave and

jwe is a lone wolf

jwe works almost completely alone for first four or five years

In the very beginning

No mailing lists

No widespread announcements

No VCS (these were dark times)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1135

What is Octave Octave and

jwe is a lone wolf

jwe works almost completely alone for first four or five years

In the very beginning

No mailing lists

No widespread announcements

No VCS (these were dark times)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1135

What is Octave Octave and

Contributions slowly trickle in

Timeline

1989 Planning stages

1992 Development begins

1993 First public announcement

1994 Version 10

1996 Version 20

1998 Version 21 development

2004 Version 29 in preparation for 30 release

2007 Version 30 major upgrade

2010 Version 324 last before using hg

2011 Version 340

2012 Version 364

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1235

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1435

What is Octave Octave and

Web resources

Web pages

Octave website

Octave-Forge website

Octave wiki

Users communication

Octave users mailing list

Octave-Forge mailing list

octave channel in Freenode

Savannah bug tracker

Developers collaboration

Octave Mercurial repository

Octave-Forge Subversion repository

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1535

What is Octave Octave and

Web resources

Web pages

Octave website

Octave-Forge website

Octave wiki

Users communication

Octave users mailing list

Octave-Forge mailing list

octave channel in Freenode

Savannah bug tracker

Developers collaboration

Octave Mercurial repository

Octave-Forge Subversion repository

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1535

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer15 current Core developers (with write access to repo)49 currently registered rsquoForge developers (38 active)296 total contributors over all timeBen Abbott Andy Adler Giles Anderson Joel Andersson Muthiah Annamalai Marco Atzeri Shai Ayal Roger Banks Ben Barrowes

Alexander Barth David Bateman Heinz Bauschke Roman Belov Karl Berry David Billinghurst Don Bindner Jakub Bogusz Moritz

Borgmann Paul Boven Richard Bovey John Bradshaw Marcus Brinkmann Remy Bruno Ansgar Burchard Marco Caliari Daniel

Calvelo John C Campbell Juan Pablo Carbajal Jean-Francois Cardoso Joao Cardoso Larrie Carr David Castelow Vincent

Cautaerts Clinton Chee Albert Chin-A-Young Carsten Clark J D Cole Martin Costabel Michael Creel Jeff Cunningham Martin

Dalecki Jorge Barros de Abreu Carlo de Falco Jacob Dawid Thomas D Dean Philippe Defert Bill Denney Fabian Deutsch

Christos Dimitrakakis David M Doolin Carne Draug Pascal A Dupuis John W Eaton Dirk Eddelbuettel Pieter Eendebak Paul

Eggert Stephen Eglen Peter Ekberg Rolf Fabian Gunnar Farneback Stephen Fegan Ramon Garcia Fernandez Torsten Finke Jose

Daniel Munoz Frias Brad Froehle Castor Fu Eduardo Gallestey Walter Gautschi Klaus Gebhardt Driss Ghaddab Nicolo Giorgetti

Michael D Godfrey Michael Goffioul Glenn Golden Tomislav Goles Keith Goodman Brian Gough Steffen Groot Etienne

Grossmann David Grundberg Peter Gustafson Kai Habel Patrick Hacker William P Y Hadisoeseno Jaroslav Hajek Benjamin Hall

Kim Hansen Soslashren Hauberg Dave Hawthorne Daniel Heiserer Martin Helm Stefan Hepp Jordi Gutierrez Hermoso Yozo Hida Ryan

Hinton Roman Hodek A Scottedward Hodel Richard Allan Holcombe Tom Holroyd David Hoover Kurt Hornik Christopher

Hulbert Cyril Humbert Teemu Ikonen Alan W Irwin Geoff Jacobsen Mats Jansson Cai Jianming Steven G Johnson Heikki Junes

Matthias Juschke Atsushi Kajita Jarkko Kaleva Mohamed Kamoun Lute Kamstra Fotios Kasolis Thomas Kasper Joel Keay

Mumit Khan Paul Kienzle Aaron A King Arno J Klaassen Alexander Klein Geoffrey Knauth Heine Kolltveit Ken Kouno Kacper

Kowalik Daniel Kraft Aravindh Krishnamoorthy Oyvind Kristiansen Piotr Krzyzanowski Volker Kuhlmann Tetsuro Kurita

Miroslaw Kwasniak Rafael Laboissiere Kai Labusch Claude Lacoursiere Walter Landry Bill Lash Dirk Laurie Maurice LeBrun

Friedrich Leisch Jyh-miin Lin Timo Lindfors Benjamin Lindner Ross Lippert David Livings Sebastien Loisel Erik de Castro Lopo

Massimo Lorenzin Emil Lucretiu Hoxide Ma James Macnicol Jens-Uwe Mager Rob Mahurin Ricardo Marranita Orestes Mas

Makoto Matsumoto Tatsuro Matsuoka Laurent Mazet G D McBain Alexander Mamonov Christoph Mayer Julio Hoffimann

Mendes Thorsten Meyer Petr Mikulik Stefan Monnier Antoine Moreau Kai P Mueller Hannes Muller Victor Munoz Carmen

Navarrete Todd Neal Philip Nienhuis Al Niessner Rick Niles Takuji Nishimura Kai Noda Eric Norum Krzesimir Nowak Michael

OrsquoBrien Peter OrsquoGorman Thorsten Ohl Arno Onken Luis F Ortiz Scott Pakin Gabriele Pannocchia Sylvain Pelissier Per Persson

Primozz Peterlin Jim Peterson Danilo Piazzalunga Nicholas Piper Elias Pipping Robert Platt Hans Ekkehard Plesser Tom Poage

Orion Poplawski Ondrej Popp Jef Poskanzer Francesco Potortı Konstantinos Poulios Jarno Rajahalme James B Rawlings Eric S

Raymond Balint Reczey Joshua Redstone Lukas Reichlin Michael Reifenberger Anthony Richardson Jason Riedy E Joshua Rigler

Petter Risholm Matthew W Roberts Andrew Ross Mark van Rossum Joe Rothweiler Kevin Ruland Kristian Rumberg Ryan

Rusaw Olli Saarela Toni Saarela Juhani Saastamoinen Radek Salac Ben Sapp Aleksej Saushev Alois Schlogl Michel D Schmid

Julian Schnidder Nicol N Schraudolph Sebastian Schubert Ludwig Schwardt Thomas L Scofield Daniel J Sebald Dmitri A

Sergatskov Vanya Sergeev Baylis Shanks Andriy Shinkarchuck Robert T Short Joseph P Skudlarek John Smith Julius Smith

Shan G Smith Peter L Sondergaard Joerg Specht Quentin H Spencer Christoph Spiel Richard Stallman Russell Standish Brett

Stewart Doug Stewart Jonathan Stickel Judd Storrs Thomas Stuart Ivan Sutoris John Swensen Daisuke Takago Ariel Tankus

Matthew Tenny Georg Thimm Duncan Temple Lang Kris Thielemans Olaf Till Christophe Tournery Thomas Treichl Karsten

Trulsen Frederick Umminger Utkarsh Upadhyay Stefan van der Walt Peter Van Wieren James R Van Zandt Gregory Vanuxem

Ivana Varekova Thomas Walter Andreas Weber Olaf Weber Thomas Weber Rik Wehbring Bob Weigel Andreas Weingessel

Martin Weiser Michael Weitzel David Wells Fook Fah Yap Sean Young Michael Zeising Federico Zenith Alex Zvoleff

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

296 total contributors over all time

How many users Thousands Millions

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1935

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2035

What is Octave Octave and

Octave-Forge

Octave-Forge

Octave Forge Is a place for concurrently developing and distributingextension packages for Octave

Each package has a maintainer responsible for updating andreleasing new versions of the package

Some packages are maintained by The Community

Installation via an integrated package manager

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2135

What is Octave Octave and

PKG

1 gtgt pkg install minusforge miscellaneous2 For information about changes from previous versions of the larr

miscellaneous package run news ( miscellaneous ) 3 gtgt pkg list4 Package Name | Version | Installation directory5 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus6 bim | 1 1 1 | ˜ octavebimminus1117 fpl | 1 3 3 | ˜ octavefplminus1338 general | 1 3 1 | ˜ octavegeneral minus1319 geometry | 1 6 0 | ˜ octavegeometry minus160

10 miscellaneous | 1 2 0 | ˜ octavemiscellaneous minus12011 gtgt pkg load miscellaneous12 gtgt pkg list13 Package Name | Version | Installation directory14 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus15 bim | 1 1 1 | ˜ octavebimminus11116 fpl | 1 3 3 | ˜ octavefplminus13317 general | 1 3 1 | ˜ octavegeneral minus13118 geometry | 1 6 0 | ˜ octavegeometry minus16019 miscellaneous lowast| 1 2 0 | ˜ octavemiscellaneous minus120

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2235

What is Octave Octave and

PKG

1 gtgt pkg describe bim minusverbose2 minusminusminus3 Package name 4 bim5 Version 6 1 1 17 Short description 8 Package f o r solving Diffusion Advection Reaction ( DAR ) Partial larr

Differential Equations9 Status

10 Not loaded11 minusminusminus12 Provides 13 Matrix assembly14 bim1a_advection_diffusion15 bim1a_advection_upwind16 bim2a_advection_diffusion17 18 Preminusprocessing and Postminusprocessing computations19 bim2c_mesh_properties20 21 gtgt

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2335

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2535

What is Octave Octave and

Broadcasting

Since 360 Octave automatically broadcasts arrays when usingelementwise binary operators

Corresponding array dimensions must either be equal or one ofthem must be 1

In case all dimensions are equal ordinary element-by-elementarithmetic takes place

When one of the dimensions is 1 the array with that singletondimension gets copied along that dimension until it matches thedimension of the other array

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2635

What is Octave Octave and

Broadcasting

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Without broadcasting x + y would be an error because dimensions do not agree

With broadcasting it is as if the following operation were performed

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 10 20 3 0 10 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Other notable differences with Matlab listed in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2735

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2835

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 include lto c t a v e o c t hgt2

3 DEFUN_DLD ( dld args nargout dld (array) nreturn the elements of larrthe array in reverse ordern )

4 5 octave_value_list retval 6 int nargin = args length ( ) 7

8 if ( nargin = 1)9 print_usage ( )

10 else11 12 Arrayltdoublegt a = args ( 0 ) array_value ( ) 13 if ( error_state )14 15 Arrayltdoublegt b ( a )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

16 doublelowast ap = a fortran_vec ( ) 17 doublelowast bp = b fortran_vec ( ) 18 for ( octave_idx_type i = a numel ( ) minus 1 j = 0 i gt= 0 larr

iminusminus j++)19 bp [ i ] = ap [ j ] 20 retval = octave_value ( b ) 21 22 23 return retval 24

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 gtgt mkoctfile dld cc2 gtgt a = randn ( 5 )3 a =4

5 0395421 minus1425232 minus0176544 1055205 22293716 minus0241893 0035004 minus0296543 minus1710613 04443187 minus0752467 minus2220469 2380951 0766246 11961538 1404672 0623112 1182609 0196125 06093259 minus0687019 0646079 2239012 minus0495169 1488314

10

11 gtgt b = dld ( a )12 b =13

14 1488314 minus0495169 2239012 0646079 minus068701915 0609325 0196125 1182609 0623112 140467216 1196153 0766246 2380951 minus2220469 minus075246717 0444318 minus1710613 minus0296543 0035004 minus024189318 2229371 1055205 minus0176544 minus1425232 039542119

20 gtgt

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 15: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

In the beginning

Companion software for chemical reactor textbook by James BRawlings and John G Ekerdt

John W Eaton (hereafter jwe) started coding in 1993

Rawlings said

Why donrsquot you call it ldquoOctaverdquo

Octave refers to Octave Levenspiel nothing to do with music

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1035

What is Octave Octave and

jwe is a lone wolf

jwe works almost completely alone for first four or five years

In the very beginning

No mailing lists

No widespread announcements

No VCS (these were dark times)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1135

What is Octave Octave and

jwe is a lone wolf

jwe works almost completely alone for first four or five years

In the very beginning

No mailing lists

No widespread announcements

No VCS (these were dark times)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1135

What is Octave Octave and

Contributions slowly trickle in

Timeline

1989 Planning stages

1992 Development begins

1993 First public announcement

1994 Version 10

1996 Version 20

1998 Version 21 development

2004 Version 29 in preparation for 30 release

2007 Version 30 major upgrade

2010 Version 324 last before using hg

2011 Version 340

2012 Version 364

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1235

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1435

What is Octave Octave and

Web resources

Web pages

Octave website

Octave-Forge website

Octave wiki

Users communication

Octave users mailing list

Octave-Forge mailing list

octave channel in Freenode

Savannah bug tracker

Developers collaboration

Octave Mercurial repository

Octave-Forge Subversion repository

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1535

What is Octave Octave and

Web resources

Web pages

Octave website

Octave-Forge website

Octave wiki

Users communication

Octave users mailing list

Octave-Forge mailing list

octave channel in Freenode

Savannah bug tracker

Developers collaboration

Octave Mercurial repository

Octave-Forge Subversion repository

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1535

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer15 current Core developers (with write access to repo)49 currently registered rsquoForge developers (38 active)296 total contributors over all timeBen Abbott Andy Adler Giles Anderson Joel Andersson Muthiah Annamalai Marco Atzeri Shai Ayal Roger Banks Ben Barrowes

Alexander Barth David Bateman Heinz Bauschke Roman Belov Karl Berry David Billinghurst Don Bindner Jakub Bogusz Moritz

Borgmann Paul Boven Richard Bovey John Bradshaw Marcus Brinkmann Remy Bruno Ansgar Burchard Marco Caliari Daniel

Calvelo John C Campbell Juan Pablo Carbajal Jean-Francois Cardoso Joao Cardoso Larrie Carr David Castelow Vincent

Cautaerts Clinton Chee Albert Chin-A-Young Carsten Clark J D Cole Martin Costabel Michael Creel Jeff Cunningham Martin

Dalecki Jorge Barros de Abreu Carlo de Falco Jacob Dawid Thomas D Dean Philippe Defert Bill Denney Fabian Deutsch

Christos Dimitrakakis David M Doolin Carne Draug Pascal A Dupuis John W Eaton Dirk Eddelbuettel Pieter Eendebak Paul

Eggert Stephen Eglen Peter Ekberg Rolf Fabian Gunnar Farneback Stephen Fegan Ramon Garcia Fernandez Torsten Finke Jose

Daniel Munoz Frias Brad Froehle Castor Fu Eduardo Gallestey Walter Gautschi Klaus Gebhardt Driss Ghaddab Nicolo Giorgetti

Michael D Godfrey Michael Goffioul Glenn Golden Tomislav Goles Keith Goodman Brian Gough Steffen Groot Etienne

Grossmann David Grundberg Peter Gustafson Kai Habel Patrick Hacker William P Y Hadisoeseno Jaroslav Hajek Benjamin Hall

Kim Hansen Soslashren Hauberg Dave Hawthorne Daniel Heiserer Martin Helm Stefan Hepp Jordi Gutierrez Hermoso Yozo Hida Ryan

Hinton Roman Hodek A Scottedward Hodel Richard Allan Holcombe Tom Holroyd David Hoover Kurt Hornik Christopher

Hulbert Cyril Humbert Teemu Ikonen Alan W Irwin Geoff Jacobsen Mats Jansson Cai Jianming Steven G Johnson Heikki Junes

Matthias Juschke Atsushi Kajita Jarkko Kaleva Mohamed Kamoun Lute Kamstra Fotios Kasolis Thomas Kasper Joel Keay

Mumit Khan Paul Kienzle Aaron A King Arno J Klaassen Alexander Klein Geoffrey Knauth Heine Kolltveit Ken Kouno Kacper

Kowalik Daniel Kraft Aravindh Krishnamoorthy Oyvind Kristiansen Piotr Krzyzanowski Volker Kuhlmann Tetsuro Kurita

Miroslaw Kwasniak Rafael Laboissiere Kai Labusch Claude Lacoursiere Walter Landry Bill Lash Dirk Laurie Maurice LeBrun

Friedrich Leisch Jyh-miin Lin Timo Lindfors Benjamin Lindner Ross Lippert David Livings Sebastien Loisel Erik de Castro Lopo

Massimo Lorenzin Emil Lucretiu Hoxide Ma James Macnicol Jens-Uwe Mager Rob Mahurin Ricardo Marranita Orestes Mas

Makoto Matsumoto Tatsuro Matsuoka Laurent Mazet G D McBain Alexander Mamonov Christoph Mayer Julio Hoffimann

Mendes Thorsten Meyer Petr Mikulik Stefan Monnier Antoine Moreau Kai P Mueller Hannes Muller Victor Munoz Carmen

Navarrete Todd Neal Philip Nienhuis Al Niessner Rick Niles Takuji Nishimura Kai Noda Eric Norum Krzesimir Nowak Michael

OrsquoBrien Peter OrsquoGorman Thorsten Ohl Arno Onken Luis F Ortiz Scott Pakin Gabriele Pannocchia Sylvain Pelissier Per Persson

Primozz Peterlin Jim Peterson Danilo Piazzalunga Nicholas Piper Elias Pipping Robert Platt Hans Ekkehard Plesser Tom Poage

Orion Poplawski Ondrej Popp Jef Poskanzer Francesco Potortı Konstantinos Poulios Jarno Rajahalme James B Rawlings Eric S

Raymond Balint Reczey Joshua Redstone Lukas Reichlin Michael Reifenberger Anthony Richardson Jason Riedy E Joshua Rigler

Petter Risholm Matthew W Roberts Andrew Ross Mark van Rossum Joe Rothweiler Kevin Ruland Kristian Rumberg Ryan

Rusaw Olli Saarela Toni Saarela Juhani Saastamoinen Radek Salac Ben Sapp Aleksej Saushev Alois Schlogl Michel D Schmid

Julian Schnidder Nicol N Schraudolph Sebastian Schubert Ludwig Schwardt Thomas L Scofield Daniel J Sebald Dmitri A

Sergatskov Vanya Sergeev Baylis Shanks Andriy Shinkarchuck Robert T Short Joseph P Skudlarek John Smith Julius Smith

Shan G Smith Peter L Sondergaard Joerg Specht Quentin H Spencer Christoph Spiel Richard Stallman Russell Standish Brett

Stewart Doug Stewart Jonathan Stickel Judd Storrs Thomas Stuart Ivan Sutoris John Swensen Daisuke Takago Ariel Tankus

Matthew Tenny Georg Thimm Duncan Temple Lang Kris Thielemans Olaf Till Christophe Tournery Thomas Treichl Karsten

Trulsen Frederick Umminger Utkarsh Upadhyay Stefan van der Walt Peter Van Wieren James R Van Zandt Gregory Vanuxem

Ivana Varekova Thomas Walter Andreas Weber Olaf Weber Thomas Weber Rik Wehbring Bob Weigel Andreas Weingessel

Martin Weiser Michael Weitzel David Wells Fook Fah Yap Sean Young Michael Zeising Federico Zenith Alex Zvoleff

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

296 total contributors over all time

How many users Thousands Millions

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1935

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2035

What is Octave Octave and

Octave-Forge

Octave-Forge

Octave Forge Is a place for concurrently developing and distributingextension packages for Octave

Each package has a maintainer responsible for updating andreleasing new versions of the package

Some packages are maintained by The Community

Installation via an integrated package manager

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2135

What is Octave Octave and

PKG

1 gtgt pkg install minusforge miscellaneous2 For information about changes from previous versions of the larr

miscellaneous package run news ( miscellaneous ) 3 gtgt pkg list4 Package Name | Version | Installation directory5 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus6 bim | 1 1 1 | ˜ octavebimminus1117 fpl | 1 3 3 | ˜ octavefplminus1338 general | 1 3 1 | ˜ octavegeneral minus1319 geometry | 1 6 0 | ˜ octavegeometry minus160

10 miscellaneous | 1 2 0 | ˜ octavemiscellaneous minus12011 gtgt pkg load miscellaneous12 gtgt pkg list13 Package Name | Version | Installation directory14 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus15 bim | 1 1 1 | ˜ octavebimminus11116 fpl | 1 3 3 | ˜ octavefplminus13317 general | 1 3 1 | ˜ octavegeneral minus13118 geometry | 1 6 0 | ˜ octavegeometry minus16019 miscellaneous lowast| 1 2 0 | ˜ octavemiscellaneous minus120

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2235

What is Octave Octave and

PKG

1 gtgt pkg describe bim minusverbose2 minusminusminus3 Package name 4 bim5 Version 6 1 1 17 Short description 8 Package f o r solving Diffusion Advection Reaction ( DAR ) Partial larr

Differential Equations9 Status

10 Not loaded11 minusminusminus12 Provides 13 Matrix assembly14 bim1a_advection_diffusion15 bim1a_advection_upwind16 bim2a_advection_diffusion17 18 Preminusprocessing and Postminusprocessing computations19 bim2c_mesh_properties20 21 gtgt

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2335

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2535

What is Octave Octave and

Broadcasting

Since 360 Octave automatically broadcasts arrays when usingelementwise binary operators

Corresponding array dimensions must either be equal or one ofthem must be 1

In case all dimensions are equal ordinary element-by-elementarithmetic takes place

When one of the dimensions is 1 the array with that singletondimension gets copied along that dimension until it matches thedimension of the other array

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2635

What is Octave Octave and

Broadcasting

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Without broadcasting x + y would be an error because dimensions do not agree

With broadcasting it is as if the following operation were performed

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 10 20 3 0 10 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Other notable differences with Matlab listed in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2735

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2835

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 include lto c t a v e o c t hgt2

3 DEFUN_DLD ( dld args nargout dld (array) nreturn the elements of larrthe array in reverse ordern )

4 5 octave_value_list retval 6 int nargin = args length ( ) 7

8 if ( nargin = 1)9 print_usage ( )

10 else11 12 Arrayltdoublegt a = args ( 0 ) array_value ( ) 13 if ( error_state )14 15 Arrayltdoublegt b ( a )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

16 doublelowast ap = a fortran_vec ( ) 17 doublelowast bp = b fortran_vec ( ) 18 for ( octave_idx_type i = a numel ( ) minus 1 j = 0 i gt= 0 larr

iminusminus j++)19 bp [ i ] = ap [ j ] 20 retval = octave_value ( b ) 21 22 23 return retval 24

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 gtgt mkoctfile dld cc2 gtgt a = randn ( 5 )3 a =4

5 0395421 minus1425232 minus0176544 1055205 22293716 minus0241893 0035004 minus0296543 minus1710613 04443187 minus0752467 minus2220469 2380951 0766246 11961538 1404672 0623112 1182609 0196125 06093259 minus0687019 0646079 2239012 minus0495169 1488314

10

11 gtgt b = dld ( a )12 b =13

14 1488314 minus0495169 2239012 0646079 minus068701915 0609325 0196125 1182609 0623112 140467216 1196153 0766246 2380951 minus2220469 minus075246717 0444318 minus1710613 minus0296543 0035004 minus024189318 2229371 1055205 minus0176544 minus1425232 039542119

20 gtgt

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 16: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

jwe is a lone wolf

jwe works almost completely alone for first four or five years

In the very beginning

No mailing lists

No widespread announcements

No VCS (these were dark times)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1135

What is Octave Octave and

jwe is a lone wolf

jwe works almost completely alone for first four or five years

In the very beginning

No mailing lists

No widespread announcements

No VCS (these were dark times)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1135

What is Octave Octave and

Contributions slowly trickle in

Timeline

1989 Planning stages

1992 Development begins

1993 First public announcement

1994 Version 10

1996 Version 20

1998 Version 21 development

2004 Version 29 in preparation for 30 release

2007 Version 30 major upgrade

2010 Version 324 last before using hg

2011 Version 340

2012 Version 364

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1235

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1435

What is Octave Octave and

Web resources

Web pages

Octave website

Octave-Forge website

Octave wiki

Users communication

Octave users mailing list

Octave-Forge mailing list

octave channel in Freenode

Savannah bug tracker

Developers collaboration

Octave Mercurial repository

Octave-Forge Subversion repository

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1535

What is Octave Octave and

Web resources

Web pages

Octave website

Octave-Forge website

Octave wiki

Users communication

Octave users mailing list

Octave-Forge mailing list

octave channel in Freenode

Savannah bug tracker

Developers collaboration

Octave Mercurial repository

Octave-Forge Subversion repository

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1535

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer15 current Core developers (with write access to repo)49 currently registered rsquoForge developers (38 active)296 total contributors over all timeBen Abbott Andy Adler Giles Anderson Joel Andersson Muthiah Annamalai Marco Atzeri Shai Ayal Roger Banks Ben Barrowes

Alexander Barth David Bateman Heinz Bauschke Roman Belov Karl Berry David Billinghurst Don Bindner Jakub Bogusz Moritz

Borgmann Paul Boven Richard Bovey John Bradshaw Marcus Brinkmann Remy Bruno Ansgar Burchard Marco Caliari Daniel

Calvelo John C Campbell Juan Pablo Carbajal Jean-Francois Cardoso Joao Cardoso Larrie Carr David Castelow Vincent

Cautaerts Clinton Chee Albert Chin-A-Young Carsten Clark J D Cole Martin Costabel Michael Creel Jeff Cunningham Martin

Dalecki Jorge Barros de Abreu Carlo de Falco Jacob Dawid Thomas D Dean Philippe Defert Bill Denney Fabian Deutsch

Christos Dimitrakakis David M Doolin Carne Draug Pascal A Dupuis John W Eaton Dirk Eddelbuettel Pieter Eendebak Paul

Eggert Stephen Eglen Peter Ekberg Rolf Fabian Gunnar Farneback Stephen Fegan Ramon Garcia Fernandez Torsten Finke Jose

Daniel Munoz Frias Brad Froehle Castor Fu Eduardo Gallestey Walter Gautschi Klaus Gebhardt Driss Ghaddab Nicolo Giorgetti

Michael D Godfrey Michael Goffioul Glenn Golden Tomislav Goles Keith Goodman Brian Gough Steffen Groot Etienne

Grossmann David Grundberg Peter Gustafson Kai Habel Patrick Hacker William P Y Hadisoeseno Jaroslav Hajek Benjamin Hall

Kim Hansen Soslashren Hauberg Dave Hawthorne Daniel Heiserer Martin Helm Stefan Hepp Jordi Gutierrez Hermoso Yozo Hida Ryan

Hinton Roman Hodek A Scottedward Hodel Richard Allan Holcombe Tom Holroyd David Hoover Kurt Hornik Christopher

Hulbert Cyril Humbert Teemu Ikonen Alan W Irwin Geoff Jacobsen Mats Jansson Cai Jianming Steven G Johnson Heikki Junes

Matthias Juschke Atsushi Kajita Jarkko Kaleva Mohamed Kamoun Lute Kamstra Fotios Kasolis Thomas Kasper Joel Keay

Mumit Khan Paul Kienzle Aaron A King Arno J Klaassen Alexander Klein Geoffrey Knauth Heine Kolltveit Ken Kouno Kacper

Kowalik Daniel Kraft Aravindh Krishnamoorthy Oyvind Kristiansen Piotr Krzyzanowski Volker Kuhlmann Tetsuro Kurita

Miroslaw Kwasniak Rafael Laboissiere Kai Labusch Claude Lacoursiere Walter Landry Bill Lash Dirk Laurie Maurice LeBrun

Friedrich Leisch Jyh-miin Lin Timo Lindfors Benjamin Lindner Ross Lippert David Livings Sebastien Loisel Erik de Castro Lopo

Massimo Lorenzin Emil Lucretiu Hoxide Ma James Macnicol Jens-Uwe Mager Rob Mahurin Ricardo Marranita Orestes Mas

Makoto Matsumoto Tatsuro Matsuoka Laurent Mazet G D McBain Alexander Mamonov Christoph Mayer Julio Hoffimann

Mendes Thorsten Meyer Petr Mikulik Stefan Monnier Antoine Moreau Kai P Mueller Hannes Muller Victor Munoz Carmen

Navarrete Todd Neal Philip Nienhuis Al Niessner Rick Niles Takuji Nishimura Kai Noda Eric Norum Krzesimir Nowak Michael

OrsquoBrien Peter OrsquoGorman Thorsten Ohl Arno Onken Luis F Ortiz Scott Pakin Gabriele Pannocchia Sylvain Pelissier Per Persson

Primozz Peterlin Jim Peterson Danilo Piazzalunga Nicholas Piper Elias Pipping Robert Platt Hans Ekkehard Plesser Tom Poage

Orion Poplawski Ondrej Popp Jef Poskanzer Francesco Potortı Konstantinos Poulios Jarno Rajahalme James B Rawlings Eric S

Raymond Balint Reczey Joshua Redstone Lukas Reichlin Michael Reifenberger Anthony Richardson Jason Riedy E Joshua Rigler

Petter Risholm Matthew W Roberts Andrew Ross Mark van Rossum Joe Rothweiler Kevin Ruland Kristian Rumberg Ryan

Rusaw Olli Saarela Toni Saarela Juhani Saastamoinen Radek Salac Ben Sapp Aleksej Saushev Alois Schlogl Michel D Schmid

Julian Schnidder Nicol N Schraudolph Sebastian Schubert Ludwig Schwardt Thomas L Scofield Daniel J Sebald Dmitri A

Sergatskov Vanya Sergeev Baylis Shanks Andriy Shinkarchuck Robert T Short Joseph P Skudlarek John Smith Julius Smith

Shan G Smith Peter L Sondergaard Joerg Specht Quentin H Spencer Christoph Spiel Richard Stallman Russell Standish Brett

Stewart Doug Stewart Jonathan Stickel Judd Storrs Thomas Stuart Ivan Sutoris John Swensen Daisuke Takago Ariel Tankus

Matthew Tenny Georg Thimm Duncan Temple Lang Kris Thielemans Olaf Till Christophe Tournery Thomas Treichl Karsten

Trulsen Frederick Umminger Utkarsh Upadhyay Stefan van der Walt Peter Van Wieren James R Van Zandt Gregory Vanuxem

Ivana Varekova Thomas Walter Andreas Weber Olaf Weber Thomas Weber Rik Wehbring Bob Weigel Andreas Weingessel

Martin Weiser Michael Weitzel David Wells Fook Fah Yap Sean Young Michael Zeising Federico Zenith Alex Zvoleff

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

296 total contributors over all time

How many users Thousands Millions

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1935

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2035

What is Octave Octave and

Octave-Forge

Octave-Forge

Octave Forge Is a place for concurrently developing and distributingextension packages for Octave

Each package has a maintainer responsible for updating andreleasing new versions of the package

Some packages are maintained by The Community

Installation via an integrated package manager

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2135

What is Octave Octave and

PKG

1 gtgt pkg install minusforge miscellaneous2 For information about changes from previous versions of the larr

miscellaneous package run news ( miscellaneous ) 3 gtgt pkg list4 Package Name | Version | Installation directory5 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus6 bim | 1 1 1 | ˜ octavebimminus1117 fpl | 1 3 3 | ˜ octavefplminus1338 general | 1 3 1 | ˜ octavegeneral minus1319 geometry | 1 6 0 | ˜ octavegeometry minus160

10 miscellaneous | 1 2 0 | ˜ octavemiscellaneous minus12011 gtgt pkg load miscellaneous12 gtgt pkg list13 Package Name | Version | Installation directory14 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus15 bim | 1 1 1 | ˜ octavebimminus11116 fpl | 1 3 3 | ˜ octavefplminus13317 general | 1 3 1 | ˜ octavegeneral minus13118 geometry | 1 6 0 | ˜ octavegeometry minus16019 miscellaneous lowast| 1 2 0 | ˜ octavemiscellaneous minus120

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2235

What is Octave Octave and

PKG

1 gtgt pkg describe bim minusverbose2 minusminusminus3 Package name 4 bim5 Version 6 1 1 17 Short description 8 Package f o r solving Diffusion Advection Reaction ( DAR ) Partial larr

Differential Equations9 Status

10 Not loaded11 minusminusminus12 Provides 13 Matrix assembly14 bim1a_advection_diffusion15 bim1a_advection_upwind16 bim2a_advection_diffusion17 18 Preminusprocessing and Postminusprocessing computations19 bim2c_mesh_properties20 21 gtgt

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2335

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2535

What is Octave Octave and

Broadcasting

Since 360 Octave automatically broadcasts arrays when usingelementwise binary operators

Corresponding array dimensions must either be equal or one ofthem must be 1

In case all dimensions are equal ordinary element-by-elementarithmetic takes place

When one of the dimensions is 1 the array with that singletondimension gets copied along that dimension until it matches thedimension of the other array

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2635

What is Octave Octave and

Broadcasting

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Without broadcasting x + y would be an error because dimensions do not agree

With broadcasting it is as if the following operation were performed

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 10 20 3 0 10 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Other notable differences with Matlab listed in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2735

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2835

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 include lto c t a v e o c t hgt2

3 DEFUN_DLD ( dld args nargout dld (array) nreturn the elements of larrthe array in reverse ordern )

4 5 octave_value_list retval 6 int nargin = args length ( ) 7

8 if ( nargin = 1)9 print_usage ( )

10 else11 12 Arrayltdoublegt a = args ( 0 ) array_value ( ) 13 if ( error_state )14 15 Arrayltdoublegt b ( a )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

16 doublelowast ap = a fortran_vec ( ) 17 doublelowast bp = b fortran_vec ( ) 18 for ( octave_idx_type i = a numel ( ) minus 1 j = 0 i gt= 0 larr

iminusminus j++)19 bp [ i ] = ap [ j ] 20 retval = octave_value ( b ) 21 22 23 return retval 24

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 gtgt mkoctfile dld cc2 gtgt a = randn ( 5 )3 a =4

5 0395421 minus1425232 minus0176544 1055205 22293716 minus0241893 0035004 minus0296543 minus1710613 04443187 minus0752467 minus2220469 2380951 0766246 11961538 1404672 0623112 1182609 0196125 06093259 minus0687019 0646079 2239012 minus0495169 1488314

10

11 gtgt b = dld ( a )12 b =13

14 1488314 minus0495169 2239012 0646079 minus068701915 0609325 0196125 1182609 0623112 140467216 1196153 0766246 2380951 minus2220469 minus075246717 0444318 minus1710613 minus0296543 0035004 minus024189318 2229371 1055205 minus0176544 minus1425232 039542119

20 gtgt

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 17: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

jwe is a lone wolf

jwe works almost completely alone for first four or five years

In the very beginning

No mailing lists

No widespread announcements

No VCS (these were dark times)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1135

What is Octave Octave and

Contributions slowly trickle in

Timeline

1989 Planning stages

1992 Development begins

1993 First public announcement

1994 Version 10

1996 Version 20

1998 Version 21 development

2004 Version 29 in preparation for 30 release

2007 Version 30 major upgrade

2010 Version 324 last before using hg

2011 Version 340

2012 Version 364

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1235

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1435

What is Octave Octave and

Web resources

Web pages

Octave website

Octave-Forge website

Octave wiki

Users communication

Octave users mailing list

Octave-Forge mailing list

octave channel in Freenode

Savannah bug tracker

Developers collaboration

Octave Mercurial repository

Octave-Forge Subversion repository

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1535

What is Octave Octave and

Web resources

Web pages

Octave website

Octave-Forge website

Octave wiki

Users communication

Octave users mailing list

Octave-Forge mailing list

octave channel in Freenode

Savannah bug tracker

Developers collaboration

Octave Mercurial repository

Octave-Forge Subversion repository

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1535

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer15 current Core developers (with write access to repo)49 currently registered rsquoForge developers (38 active)296 total contributors over all timeBen Abbott Andy Adler Giles Anderson Joel Andersson Muthiah Annamalai Marco Atzeri Shai Ayal Roger Banks Ben Barrowes

Alexander Barth David Bateman Heinz Bauschke Roman Belov Karl Berry David Billinghurst Don Bindner Jakub Bogusz Moritz

Borgmann Paul Boven Richard Bovey John Bradshaw Marcus Brinkmann Remy Bruno Ansgar Burchard Marco Caliari Daniel

Calvelo John C Campbell Juan Pablo Carbajal Jean-Francois Cardoso Joao Cardoso Larrie Carr David Castelow Vincent

Cautaerts Clinton Chee Albert Chin-A-Young Carsten Clark J D Cole Martin Costabel Michael Creel Jeff Cunningham Martin

Dalecki Jorge Barros de Abreu Carlo de Falco Jacob Dawid Thomas D Dean Philippe Defert Bill Denney Fabian Deutsch

Christos Dimitrakakis David M Doolin Carne Draug Pascal A Dupuis John W Eaton Dirk Eddelbuettel Pieter Eendebak Paul

Eggert Stephen Eglen Peter Ekberg Rolf Fabian Gunnar Farneback Stephen Fegan Ramon Garcia Fernandez Torsten Finke Jose

Daniel Munoz Frias Brad Froehle Castor Fu Eduardo Gallestey Walter Gautschi Klaus Gebhardt Driss Ghaddab Nicolo Giorgetti

Michael D Godfrey Michael Goffioul Glenn Golden Tomislav Goles Keith Goodman Brian Gough Steffen Groot Etienne

Grossmann David Grundberg Peter Gustafson Kai Habel Patrick Hacker William P Y Hadisoeseno Jaroslav Hajek Benjamin Hall

Kim Hansen Soslashren Hauberg Dave Hawthorne Daniel Heiserer Martin Helm Stefan Hepp Jordi Gutierrez Hermoso Yozo Hida Ryan

Hinton Roman Hodek A Scottedward Hodel Richard Allan Holcombe Tom Holroyd David Hoover Kurt Hornik Christopher

Hulbert Cyril Humbert Teemu Ikonen Alan W Irwin Geoff Jacobsen Mats Jansson Cai Jianming Steven G Johnson Heikki Junes

Matthias Juschke Atsushi Kajita Jarkko Kaleva Mohamed Kamoun Lute Kamstra Fotios Kasolis Thomas Kasper Joel Keay

Mumit Khan Paul Kienzle Aaron A King Arno J Klaassen Alexander Klein Geoffrey Knauth Heine Kolltveit Ken Kouno Kacper

Kowalik Daniel Kraft Aravindh Krishnamoorthy Oyvind Kristiansen Piotr Krzyzanowski Volker Kuhlmann Tetsuro Kurita

Miroslaw Kwasniak Rafael Laboissiere Kai Labusch Claude Lacoursiere Walter Landry Bill Lash Dirk Laurie Maurice LeBrun

Friedrich Leisch Jyh-miin Lin Timo Lindfors Benjamin Lindner Ross Lippert David Livings Sebastien Loisel Erik de Castro Lopo

Massimo Lorenzin Emil Lucretiu Hoxide Ma James Macnicol Jens-Uwe Mager Rob Mahurin Ricardo Marranita Orestes Mas

Makoto Matsumoto Tatsuro Matsuoka Laurent Mazet G D McBain Alexander Mamonov Christoph Mayer Julio Hoffimann

Mendes Thorsten Meyer Petr Mikulik Stefan Monnier Antoine Moreau Kai P Mueller Hannes Muller Victor Munoz Carmen

Navarrete Todd Neal Philip Nienhuis Al Niessner Rick Niles Takuji Nishimura Kai Noda Eric Norum Krzesimir Nowak Michael

OrsquoBrien Peter OrsquoGorman Thorsten Ohl Arno Onken Luis F Ortiz Scott Pakin Gabriele Pannocchia Sylvain Pelissier Per Persson

Primozz Peterlin Jim Peterson Danilo Piazzalunga Nicholas Piper Elias Pipping Robert Platt Hans Ekkehard Plesser Tom Poage

Orion Poplawski Ondrej Popp Jef Poskanzer Francesco Potortı Konstantinos Poulios Jarno Rajahalme James B Rawlings Eric S

Raymond Balint Reczey Joshua Redstone Lukas Reichlin Michael Reifenberger Anthony Richardson Jason Riedy E Joshua Rigler

Petter Risholm Matthew W Roberts Andrew Ross Mark van Rossum Joe Rothweiler Kevin Ruland Kristian Rumberg Ryan

Rusaw Olli Saarela Toni Saarela Juhani Saastamoinen Radek Salac Ben Sapp Aleksej Saushev Alois Schlogl Michel D Schmid

Julian Schnidder Nicol N Schraudolph Sebastian Schubert Ludwig Schwardt Thomas L Scofield Daniel J Sebald Dmitri A

Sergatskov Vanya Sergeev Baylis Shanks Andriy Shinkarchuck Robert T Short Joseph P Skudlarek John Smith Julius Smith

Shan G Smith Peter L Sondergaard Joerg Specht Quentin H Spencer Christoph Spiel Richard Stallman Russell Standish Brett

Stewart Doug Stewart Jonathan Stickel Judd Storrs Thomas Stuart Ivan Sutoris John Swensen Daisuke Takago Ariel Tankus

Matthew Tenny Georg Thimm Duncan Temple Lang Kris Thielemans Olaf Till Christophe Tournery Thomas Treichl Karsten

Trulsen Frederick Umminger Utkarsh Upadhyay Stefan van der Walt Peter Van Wieren James R Van Zandt Gregory Vanuxem

Ivana Varekova Thomas Walter Andreas Weber Olaf Weber Thomas Weber Rik Wehbring Bob Weigel Andreas Weingessel

Martin Weiser Michael Weitzel David Wells Fook Fah Yap Sean Young Michael Zeising Federico Zenith Alex Zvoleff

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

296 total contributors over all time

How many users Thousands Millions

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1935

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2035

What is Octave Octave and

Octave-Forge

Octave-Forge

Octave Forge Is a place for concurrently developing and distributingextension packages for Octave

Each package has a maintainer responsible for updating andreleasing new versions of the package

Some packages are maintained by The Community

Installation via an integrated package manager

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2135

What is Octave Octave and

PKG

1 gtgt pkg install minusforge miscellaneous2 For information about changes from previous versions of the larr

miscellaneous package run news ( miscellaneous ) 3 gtgt pkg list4 Package Name | Version | Installation directory5 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus6 bim | 1 1 1 | ˜ octavebimminus1117 fpl | 1 3 3 | ˜ octavefplminus1338 general | 1 3 1 | ˜ octavegeneral minus1319 geometry | 1 6 0 | ˜ octavegeometry minus160

10 miscellaneous | 1 2 0 | ˜ octavemiscellaneous minus12011 gtgt pkg load miscellaneous12 gtgt pkg list13 Package Name | Version | Installation directory14 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus15 bim | 1 1 1 | ˜ octavebimminus11116 fpl | 1 3 3 | ˜ octavefplminus13317 general | 1 3 1 | ˜ octavegeneral minus13118 geometry | 1 6 0 | ˜ octavegeometry minus16019 miscellaneous lowast| 1 2 0 | ˜ octavemiscellaneous minus120

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2235

What is Octave Octave and

PKG

1 gtgt pkg describe bim minusverbose2 minusminusminus3 Package name 4 bim5 Version 6 1 1 17 Short description 8 Package f o r solving Diffusion Advection Reaction ( DAR ) Partial larr

Differential Equations9 Status

10 Not loaded11 minusminusminus12 Provides 13 Matrix assembly14 bim1a_advection_diffusion15 bim1a_advection_upwind16 bim2a_advection_diffusion17 18 Preminusprocessing and Postminusprocessing computations19 bim2c_mesh_properties20 21 gtgt

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2335

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2535

What is Octave Octave and

Broadcasting

Since 360 Octave automatically broadcasts arrays when usingelementwise binary operators

Corresponding array dimensions must either be equal or one ofthem must be 1

In case all dimensions are equal ordinary element-by-elementarithmetic takes place

When one of the dimensions is 1 the array with that singletondimension gets copied along that dimension until it matches thedimension of the other array

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2635

What is Octave Octave and

Broadcasting

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Without broadcasting x + y would be an error because dimensions do not agree

With broadcasting it is as if the following operation were performed

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 10 20 3 0 10 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Other notable differences with Matlab listed in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2735

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2835

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 include lto c t a v e o c t hgt2

3 DEFUN_DLD ( dld args nargout dld (array) nreturn the elements of larrthe array in reverse ordern )

4 5 octave_value_list retval 6 int nargin = args length ( ) 7

8 if ( nargin = 1)9 print_usage ( )

10 else11 12 Arrayltdoublegt a = args ( 0 ) array_value ( ) 13 if ( error_state )14 15 Arrayltdoublegt b ( a )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

16 doublelowast ap = a fortran_vec ( ) 17 doublelowast bp = b fortran_vec ( ) 18 for ( octave_idx_type i = a numel ( ) minus 1 j = 0 i gt= 0 larr

iminusminus j++)19 bp [ i ] = ap [ j ] 20 retval = octave_value ( b ) 21 22 23 return retval 24

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 gtgt mkoctfile dld cc2 gtgt a = randn ( 5 )3 a =4

5 0395421 minus1425232 minus0176544 1055205 22293716 minus0241893 0035004 minus0296543 minus1710613 04443187 minus0752467 minus2220469 2380951 0766246 11961538 1404672 0623112 1182609 0196125 06093259 minus0687019 0646079 2239012 minus0495169 1488314

10

11 gtgt b = dld ( a )12 b =13

14 1488314 minus0495169 2239012 0646079 minus068701915 0609325 0196125 1182609 0623112 140467216 1196153 0766246 2380951 minus2220469 minus075246717 0444318 minus1710613 minus0296543 0035004 minus024189318 2229371 1055205 minus0176544 minus1425232 039542119

20 gtgt

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 18: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

Contributions slowly trickle in

Timeline

1989 Planning stages

1992 Development begins

1993 First public announcement

1994 Version 10

1996 Version 20

1998 Version 21 development

2004 Version 29 in preparation for 30 release

2007 Version 30 major upgrade

2010 Version 324 last before using hg

2011 Version 340

2012 Version 364

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1235

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1435

What is Octave Octave and

Web resources

Web pages

Octave website

Octave-Forge website

Octave wiki

Users communication

Octave users mailing list

Octave-Forge mailing list

octave channel in Freenode

Savannah bug tracker

Developers collaboration

Octave Mercurial repository

Octave-Forge Subversion repository

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1535

What is Octave Octave and

Web resources

Web pages

Octave website

Octave-Forge website

Octave wiki

Users communication

Octave users mailing list

Octave-Forge mailing list

octave channel in Freenode

Savannah bug tracker

Developers collaboration

Octave Mercurial repository

Octave-Forge Subversion repository

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1535

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer15 current Core developers (with write access to repo)49 currently registered rsquoForge developers (38 active)296 total contributors over all timeBen Abbott Andy Adler Giles Anderson Joel Andersson Muthiah Annamalai Marco Atzeri Shai Ayal Roger Banks Ben Barrowes

Alexander Barth David Bateman Heinz Bauschke Roman Belov Karl Berry David Billinghurst Don Bindner Jakub Bogusz Moritz

Borgmann Paul Boven Richard Bovey John Bradshaw Marcus Brinkmann Remy Bruno Ansgar Burchard Marco Caliari Daniel

Calvelo John C Campbell Juan Pablo Carbajal Jean-Francois Cardoso Joao Cardoso Larrie Carr David Castelow Vincent

Cautaerts Clinton Chee Albert Chin-A-Young Carsten Clark J D Cole Martin Costabel Michael Creel Jeff Cunningham Martin

Dalecki Jorge Barros de Abreu Carlo de Falco Jacob Dawid Thomas D Dean Philippe Defert Bill Denney Fabian Deutsch

Christos Dimitrakakis David M Doolin Carne Draug Pascal A Dupuis John W Eaton Dirk Eddelbuettel Pieter Eendebak Paul

Eggert Stephen Eglen Peter Ekberg Rolf Fabian Gunnar Farneback Stephen Fegan Ramon Garcia Fernandez Torsten Finke Jose

Daniel Munoz Frias Brad Froehle Castor Fu Eduardo Gallestey Walter Gautschi Klaus Gebhardt Driss Ghaddab Nicolo Giorgetti

Michael D Godfrey Michael Goffioul Glenn Golden Tomislav Goles Keith Goodman Brian Gough Steffen Groot Etienne

Grossmann David Grundberg Peter Gustafson Kai Habel Patrick Hacker William P Y Hadisoeseno Jaroslav Hajek Benjamin Hall

Kim Hansen Soslashren Hauberg Dave Hawthorne Daniel Heiserer Martin Helm Stefan Hepp Jordi Gutierrez Hermoso Yozo Hida Ryan

Hinton Roman Hodek A Scottedward Hodel Richard Allan Holcombe Tom Holroyd David Hoover Kurt Hornik Christopher

Hulbert Cyril Humbert Teemu Ikonen Alan W Irwin Geoff Jacobsen Mats Jansson Cai Jianming Steven G Johnson Heikki Junes

Matthias Juschke Atsushi Kajita Jarkko Kaleva Mohamed Kamoun Lute Kamstra Fotios Kasolis Thomas Kasper Joel Keay

Mumit Khan Paul Kienzle Aaron A King Arno J Klaassen Alexander Klein Geoffrey Knauth Heine Kolltveit Ken Kouno Kacper

Kowalik Daniel Kraft Aravindh Krishnamoorthy Oyvind Kristiansen Piotr Krzyzanowski Volker Kuhlmann Tetsuro Kurita

Miroslaw Kwasniak Rafael Laboissiere Kai Labusch Claude Lacoursiere Walter Landry Bill Lash Dirk Laurie Maurice LeBrun

Friedrich Leisch Jyh-miin Lin Timo Lindfors Benjamin Lindner Ross Lippert David Livings Sebastien Loisel Erik de Castro Lopo

Massimo Lorenzin Emil Lucretiu Hoxide Ma James Macnicol Jens-Uwe Mager Rob Mahurin Ricardo Marranita Orestes Mas

Makoto Matsumoto Tatsuro Matsuoka Laurent Mazet G D McBain Alexander Mamonov Christoph Mayer Julio Hoffimann

Mendes Thorsten Meyer Petr Mikulik Stefan Monnier Antoine Moreau Kai P Mueller Hannes Muller Victor Munoz Carmen

Navarrete Todd Neal Philip Nienhuis Al Niessner Rick Niles Takuji Nishimura Kai Noda Eric Norum Krzesimir Nowak Michael

OrsquoBrien Peter OrsquoGorman Thorsten Ohl Arno Onken Luis F Ortiz Scott Pakin Gabriele Pannocchia Sylvain Pelissier Per Persson

Primozz Peterlin Jim Peterson Danilo Piazzalunga Nicholas Piper Elias Pipping Robert Platt Hans Ekkehard Plesser Tom Poage

Orion Poplawski Ondrej Popp Jef Poskanzer Francesco Potortı Konstantinos Poulios Jarno Rajahalme James B Rawlings Eric S

Raymond Balint Reczey Joshua Redstone Lukas Reichlin Michael Reifenberger Anthony Richardson Jason Riedy E Joshua Rigler

Petter Risholm Matthew W Roberts Andrew Ross Mark van Rossum Joe Rothweiler Kevin Ruland Kristian Rumberg Ryan

Rusaw Olli Saarela Toni Saarela Juhani Saastamoinen Radek Salac Ben Sapp Aleksej Saushev Alois Schlogl Michel D Schmid

Julian Schnidder Nicol N Schraudolph Sebastian Schubert Ludwig Schwardt Thomas L Scofield Daniel J Sebald Dmitri A

Sergatskov Vanya Sergeev Baylis Shanks Andriy Shinkarchuck Robert T Short Joseph P Skudlarek John Smith Julius Smith

Shan G Smith Peter L Sondergaard Joerg Specht Quentin H Spencer Christoph Spiel Richard Stallman Russell Standish Brett

Stewart Doug Stewart Jonathan Stickel Judd Storrs Thomas Stuart Ivan Sutoris John Swensen Daisuke Takago Ariel Tankus

Matthew Tenny Georg Thimm Duncan Temple Lang Kris Thielemans Olaf Till Christophe Tournery Thomas Treichl Karsten

Trulsen Frederick Umminger Utkarsh Upadhyay Stefan van der Walt Peter Van Wieren James R Van Zandt Gregory Vanuxem

Ivana Varekova Thomas Walter Andreas Weber Olaf Weber Thomas Weber Rik Wehbring Bob Weigel Andreas Weingessel

Martin Weiser Michael Weitzel David Wells Fook Fah Yap Sean Young Michael Zeising Federico Zenith Alex Zvoleff

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

296 total contributors over all time

How many users Thousands Millions

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1935

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2035

What is Octave Octave and

Octave-Forge

Octave-Forge

Octave Forge Is a place for concurrently developing and distributingextension packages for Octave

Each package has a maintainer responsible for updating andreleasing new versions of the package

Some packages are maintained by The Community

Installation via an integrated package manager

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2135

What is Octave Octave and

PKG

1 gtgt pkg install minusforge miscellaneous2 For information about changes from previous versions of the larr

miscellaneous package run news ( miscellaneous ) 3 gtgt pkg list4 Package Name | Version | Installation directory5 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus6 bim | 1 1 1 | ˜ octavebimminus1117 fpl | 1 3 3 | ˜ octavefplminus1338 general | 1 3 1 | ˜ octavegeneral minus1319 geometry | 1 6 0 | ˜ octavegeometry minus160

10 miscellaneous | 1 2 0 | ˜ octavemiscellaneous minus12011 gtgt pkg load miscellaneous12 gtgt pkg list13 Package Name | Version | Installation directory14 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus15 bim | 1 1 1 | ˜ octavebimminus11116 fpl | 1 3 3 | ˜ octavefplminus13317 general | 1 3 1 | ˜ octavegeneral minus13118 geometry | 1 6 0 | ˜ octavegeometry minus16019 miscellaneous lowast| 1 2 0 | ˜ octavemiscellaneous minus120

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2235

What is Octave Octave and

PKG

1 gtgt pkg describe bim minusverbose2 minusminusminus3 Package name 4 bim5 Version 6 1 1 17 Short description 8 Package f o r solving Diffusion Advection Reaction ( DAR ) Partial larr

Differential Equations9 Status

10 Not loaded11 minusminusminus12 Provides 13 Matrix assembly14 bim1a_advection_diffusion15 bim1a_advection_upwind16 bim2a_advection_diffusion17 18 Preminusprocessing and Postminusprocessing computations19 bim2c_mesh_properties20 21 gtgt

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2335

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2535

What is Octave Octave and

Broadcasting

Since 360 Octave automatically broadcasts arrays when usingelementwise binary operators

Corresponding array dimensions must either be equal or one ofthem must be 1

In case all dimensions are equal ordinary element-by-elementarithmetic takes place

When one of the dimensions is 1 the array with that singletondimension gets copied along that dimension until it matches thedimension of the other array

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2635

What is Octave Octave and

Broadcasting

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Without broadcasting x + y would be an error because dimensions do not agree

With broadcasting it is as if the following operation were performed

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 10 20 3 0 10 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Other notable differences with Matlab listed in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2735

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2835

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 include lto c t a v e o c t hgt2

3 DEFUN_DLD ( dld args nargout dld (array) nreturn the elements of larrthe array in reverse ordern )

4 5 octave_value_list retval 6 int nargin = args length ( ) 7

8 if ( nargin = 1)9 print_usage ( )

10 else11 12 Arrayltdoublegt a = args ( 0 ) array_value ( ) 13 if ( error_state )14 15 Arrayltdoublegt b ( a )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

16 doublelowast ap = a fortran_vec ( ) 17 doublelowast bp = b fortran_vec ( ) 18 for ( octave_idx_type i = a numel ( ) minus 1 j = 0 i gt= 0 larr

iminusminus j++)19 bp [ i ] = ap [ j ] 20 retval = octave_value ( b ) 21 22 23 return retval 24

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 gtgt mkoctfile dld cc2 gtgt a = randn ( 5 )3 a =4

5 0395421 minus1425232 minus0176544 1055205 22293716 minus0241893 0035004 minus0296543 minus1710613 04443187 minus0752467 minus2220469 2380951 0766246 11961538 1404672 0623112 1182609 0196125 06093259 minus0687019 0646079 2239012 minus0495169 1488314

10

11 gtgt b = dld ( a )12 b =13

14 1488314 minus0495169 2239012 0646079 minus068701915 0609325 0196125 1182609 0623112 140467216 1196153 0766246 2380951 minus2220469 minus075246717 0444318 minus1710613 minus0296543 0035004 minus024189318 2229371 1055205 minus0176544 minus1425232 039542119

20 gtgt

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 19: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1435

What is Octave Octave and

Web resources

Web pages

Octave website

Octave-Forge website

Octave wiki

Users communication

Octave users mailing list

Octave-Forge mailing list

octave channel in Freenode

Savannah bug tracker

Developers collaboration

Octave Mercurial repository

Octave-Forge Subversion repository

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1535

What is Octave Octave and

Web resources

Web pages

Octave website

Octave-Forge website

Octave wiki

Users communication

Octave users mailing list

Octave-Forge mailing list

octave channel in Freenode

Savannah bug tracker

Developers collaboration

Octave Mercurial repository

Octave-Forge Subversion repository

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1535

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer15 current Core developers (with write access to repo)49 currently registered rsquoForge developers (38 active)296 total contributors over all timeBen Abbott Andy Adler Giles Anderson Joel Andersson Muthiah Annamalai Marco Atzeri Shai Ayal Roger Banks Ben Barrowes

Alexander Barth David Bateman Heinz Bauschke Roman Belov Karl Berry David Billinghurst Don Bindner Jakub Bogusz Moritz

Borgmann Paul Boven Richard Bovey John Bradshaw Marcus Brinkmann Remy Bruno Ansgar Burchard Marco Caliari Daniel

Calvelo John C Campbell Juan Pablo Carbajal Jean-Francois Cardoso Joao Cardoso Larrie Carr David Castelow Vincent

Cautaerts Clinton Chee Albert Chin-A-Young Carsten Clark J D Cole Martin Costabel Michael Creel Jeff Cunningham Martin

Dalecki Jorge Barros de Abreu Carlo de Falco Jacob Dawid Thomas D Dean Philippe Defert Bill Denney Fabian Deutsch

Christos Dimitrakakis David M Doolin Carne Draug Pascal A Dupuis John W Eaton Dirk Eddelbuettel Pieter Eendebak Paul

Eggert Stephen Eglen Peter Ekberg Rolf Fabian Gunnar Farneback Stephen Fegan Ramon Garcia Fernandez Torsten Finke Jose

Daniel Munoz Frias Brad Froehle Castor Fu Eduardo Gallestey Walter Gautschi Klaus Gebhardt Driss Ghaddab Nicolo Giorgetti

Michael D Godfrey Michael Goffioul Glenn Golden Tomislav Goles Keith Goodman Brian Gough Steffen Groot Etienne

Grossmann David Grundberg Peter Gustafson Kai Habel Patrick Hacker William P Y Hadisoeseno Jaroslav Hajek Benjamin Hall

Kim Hansen Soslashren Hauberg Dave Hawthorne Daniel Heiserer Martin Helm Stefan Hepp Jordi Gutierrez Hermoso Yozo Hida Ryan

Hinton Roman Hodek A Scottedward Hodel Richard Allan Holcombe Tom Holroyd David Hoover Kurt Hornik Christopher

Hulbert Cyril Humbert Teemu Ikonen Alan W Irwin Geoff Jacobsen Mats Jansson Cai Jianming Steven G Johnson Heikki Junes

Matthias Juschke Atsushi Kajita Jarkko Kaleva Mohamed Kamoun Lute Kamstra Fotios Kasolis Thomas Kasper Joel Keay

Mumit Khan Paul Kienzle Aaron A King Arno J Klaassen Alexander Klein Geoffrey Knauth Heine Kolltveit Ken Kouno Kacper

Kowalik Daniel Kraft Aravindh Krishnamoorthy Oyvind Kristiansen Piotr Krzyzanowski Volker Kuhlmann Tetsuro Kurita

Miroslaw Kwasniak Rafael Laboissiere Kai Labusch Claude Lacoursiere Walter Landry Bill Lash Dirk Laurie Maurice LeBrun

Friedrich Leisch Jyh-miin Lin Timo Lindfors Benjamin Lindner Ross Lippert David Livings Sebastien Loisel Erik de Castro Lopo

Massimo Lorenzin Emil Lucretiu Hoxide Ma James Macnicol Jens-Uwe Mager Rob Mahurin Ricardo Marranita Orestes Mas

Makoto Matsumoto Tatsuro Matsuoka Laurent Mazet G D McBain Alexander Mamonov Christoph Mayer Julio Hoffimann

Mendes Thorsten Meyer Petr Mikulik Stefan Monnier Antoine Moreau Kai P Mueller Hannes Muller Victor Munoz Carmen

Navarrete Todd Neal Philip Nienhuis Al Niessner Rick Niles Takuji Nishimura Kai Noda Eric Norum Krzesimir Nowak Michael

OrsquoBrien Peter OrsquoGorman Thorsten Ohl Arno Onken Luis F Ortiz Scott Pakin Gabriele Pannocchia Sylvain Pelissier Per Persson

Primozz Peterlin Jim Peterson Danilo Piazzalunga Nicholas Piper Elias Pipping Robert Platt Hans Ekkehard Plesser Tom Poage

Orion Poplawski Ondrej Popp Jef Poskanzer Francesco Potortı Konstantinos Poulios Jarno Rajahalme James B Rawlings Eric S

Raymond Balint Reczey Joshua Redstone Lukas Reichlin Michael Reifenberger Anthony Richardson Jason Riedy E Joshua Rigler

Petter Risholm Matthew W Roberts Andrew Ross Mark van Rossum Joe Rothweiler Kevin Ruland Kristian Rumberg Ryan

Rusaw Olli Saarela Toni Saarela Juhani Saastamoinen Radek Salac Ben Sapp Aleksej Saushev Alois Schlogl Michel D Schmid

Julian Schnidder Nicol N Schraudolph Sebastian Schubert Ludwig Schwardt Thomas L Scofield Daniel J Sebald Dmitri A

Sergatskov Vanya Sergeev Baylis Shanks Andriy Shinkarchuck Robert T Short Joseph P Skudlarek John Smith Julius Smith

Shan G Smith Peter L Sondergaard Joerg Specht Quentin H Spencer Christoph Spiel Richard Stallman Russell Standish Brett

Stewart Doug Stewart Jonathan Stickel Judd Storrs Thomas Stuart Ivan Sutoris John Swensen Daisuke Takago Ariel Tankus

Matthew Tenny Georg Thimm Duncan Temple Lang Kris Thielemans Olaf Till Christophe Tournery Thomas Treichl Karsten

Trulsen Frederick Umminger Utkarsh Upadhyay Stefan van der Walt Peter Van Wieren James R Van Zandt Gregory Vanuxem

Ivana Varekova Thomas Walter Andreas Weber Olaf Weber Thomas Weber Rik Wehbring Bob Weigel Andreas Weingessel

Martin Weiser Michael Weitzel David Wells Fook Fah Yap Sean Young Michael Zeising Federico Zenith Alex Zvoleff

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

296 total contributors over all time

How many users Thousands Millions

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1935

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2035

What is Octave Octave and

Octave-Forge

Octave-Forge

Octave Forge Is a place for concurrently developing and distributingextension packages for Octave

Each package has a maintainer responsible for updating andreleasing new versions of the package

Some packages are maintained by The Community

Installation via an integrated package manager

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2135

What is Octave Octave and

PKG

1 gtgt pkg install minusforge miscellaneous2 For information about changes from previous versions of the larr

miscellaneous package run news ( miscellaneous ) 3 gtgt pkg list4 Package Name | Version | Installation directory5 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus6 bim | 1 1 1 | ˜ octavebimminus1117 fpl | 1 3 3 | ˜ octavefplminus1338 general | 1 3 1 | ˜ octavegeneral minus1319 geometry | 1 6 0 | ˜ octavegeometry minus160

10 miscellaneous | 1 2 0 | ˜ octavemiscellaneous minus12011 gtgt pkg load miscellaneous12 gtgt pkg list13 Package Name | Version | Installation directory14 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus15 bim | 1 1 1 | ˜ octavebimminus11116 fpl | 1 3 3 | ˜ octavefplminus13317 general | 1 3 1 | ˜ octavegeneral minus13118 geometry | 1 6 0 | ˜ octavegeometry minus16019 miscellaneous lowast| 1 2 0 | ˜ octavemiscellaneous minus120

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2235

What is Octave Octave and

PKG

1 gtgt pkg describe bim minusverbose2 minusminusminus3 Package name 4 bim5 Version 6 1 1 17 Short description 8 Package f o r solving Diffusion Advection Reaction ( DAR ) Partial larr

Differential Equations9 Status

10 Not loaded11 minusminusminus12 Provides 13 Matrix assembly14 bim1a_advection_diffusion15 bim1a_advection_upwind16 bim2a_advection_diffusion17 18 Preminusprocessing and Postminusprocessing computations19 bim2c_mesh_properties20 21 gtgt

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2335

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2535

What is Octave Octave and

Broadcasting

Since 360 Octave automatically broadcasts arrays when usingelementwise binary operators

Corresponding array dimensions must either be equal or one ofthem must be 1

In case all dimensions are equal ordinary element-by-elementarithmetic takes place

When one of the dimensions is 1 the array with that singletondimension gets copied along that dimension until it matches thedimension of the other array

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2635

What is Octave Octave and

Broadcasting

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Without broadcasting x + y would be an error because dimensions do not agree

With broadcasting it is as if the following operation were performed

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 10 20 3 0 10 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Other notable differences with Matlab listed in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2735

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2835

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 include lto c t a v e o c t hgt2

3 DEFUN_DLD ( dld args nargout dld (array) nreturn the elements of larrthe array in reverse ordern )

4 5 octave_value_list retval 6 int nargin = args length ( ) 7

8 if ( nargin = 1)9 print_usage ( )

10 else11 12 Arrayltdoublegt a = args ( 0 ) array_value ( ) 13 if ( error_state )14 15 Arrayltdoublegt b ( a )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

16 doublelowast ap = a fortran_vec ( ) 17 doublelowast bp = b fortran_vec ( ) 18 for ( octave_idx_type i = a numel ( ) minus 1 j = 0 i gt= 0 larr

iminusminus j++)19 bp [ i ] = ap [ j ] 20 retval = octave_value ( b ) 21 22 23 return retval 24

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 gtgt mkoctfile dld cc2 gtgt a = randn ( 5 )3 a =4

5 0395421 minus1425232 minus0176544 1055205 22293716 minus0241893 0035004 minus0296543 minus1710613 04443187 minus0752467 minus2220469 2380951 0766246 11961538 1404672 0623112 1182609 0196125 06093259 minus0687019 0646079 2239012 minus0495169 1488314

10

11 gtgt b = dld ( a )12 b =13

14 1488314 minus0495169 2239012 0646079 minus068701915 0609325 0196125 1182609 0623112 140467216 1196153 0766246 2380951 minus2220469 minus075246717 0444318 minus1710613 minus0296543 0035004 minus024189318 2229371 1055205 minus0176544 minus1425232 039542119

20 gtgt

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 20: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1435

What is Octave Octave and

Web resources

Web pages

Octave website

Octave-Forge website

Octave wiki

Users communication

Octave users mailing list

Octave-Forge mailing list

octave channel in Freenode

Savannah bug tracker

Developers collaboration

Octave Mercurial repository

Octave-Forge Subversion repository

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1535

What is Octave Octave and

Web resources

Web pages

Octave website

Octave-Forge website

Octave wiki

Users communication

Octave users mailing list

Octave-Forge mailing list

octave channel in Freenode

Savannah bug tracker

Developers collaboration

Octave Mercurial repository

Octave-Forge Subversion repository

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1535

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer15 current Core developers (with write access to repo)49 currently registered rsquoForge developers (38 active)296 total contributors over all timeBen Abbott Andy Adler Giles Anderson Joel Andersson Muthiah Annamalai Marco Atzeri Shai Ayal Roger Banks Ben Barrowes

Alexander Barth David Bateman Heinz Bauschke Roman Belov Karl Berry David Billinghurst Don Bindner Jakub Bogusz Moritz

Borgmann Paul Boven Richard Bovey John Bradshaw Marcus Brinkmann Remy Bruno Ansgar Burchard Marco Caliari Daniel

Calvelo John C Campbell Juan Pablo Carbajal Jean-Francois Cardoso Joao Cardoso Larrie Carr David Castelow Vincent

Cautaerts Clinton Chee Albert Chin-A-Young Carsten Clark J D Cole Martin Costabel Michael Creel Jeff Cunningham Martin

Dalecki Jorge Barros de Abreu Carlo de Falco Jacob Dawid Thomas D Dean Philippe Defert Bill Denney Fabian Deutsch

Christos Dimitrakakis David M Doolin Carne Draug Pascal A Dupuis John W Eaton Dirk Eddelbuettel Pieter Eendebak Paul

Eggert Stephen Eglen Peter Ekberg Rolf Fabian Gunnar Farneback Stephen Fegan Ramon Garcia Fernandez Torsten Finke Jose

Daniel Munoz Frias Brad Froehle Castor Fu Eduardo Gallestey Walter Gautschi Klaus Gebhardt Driss Ghaddab Nicolo Giorgetti

Michael D Godfrey Michael Goffioul Glenn Golden Tomislav Goles Keith Goodman Brian Gough Steffen Groot Etienne

Grossmann David Grundberg Peter Gustafson Kai Habel Patrick Hacker William P Y Hadisoeseno Jaroslav Hajek Benjamin Hall

Kim Hansen Soslashren Hauberg Dave Hawthorne Daniel Heiserer Martin Helm Stefan Hepp Jordi Gutierrez Hermoso Yozo Hida Ryan

Hinton Roman Hodek A Scottedward Hodel Richard Allan Holcombe Tom Holroyd David Hoover Kurt Hornik Christopher

Hulbert Cyril Humbert Teemu Ikonen Alan W Irwin Geoff Jacobsen Mats Jansson Cai Jianming Steven G Johnson Heikki Junes

Matthias Juschke Atsushi Kajita Jarkko Kaleva Mohamed Kamoun Lute Kamstra Fotios Kasolis Thomas Kasper Joel Keay

Mumit Khan Paul Kienzle Aaron A King Arno J Klaassen Alexander Klein Geoffrey Knauth Heine Kolltveit Ken Kouno Kacper

Kowalik Daniel Kraft Aravindh Krishnamoorthy Oyvind Kristiansen Piotr Krzyzanowski Volker Kuhlmann Tetsuro Kurita

Miroslaw Kwasniak Rafael Laboissiere Kai Labusch Claude Lacoursiere Walter Landry Bill Lash Dirk Laurie Maurice LeBrun

Friedrich Leisch Jyh-miin Lin Timo Lindfors Benjamin Lindner Ross Lippert David Livings Sebastien Loisel Erik de Castro Lopo

Massimo Lorenzin Emil Lucretiu Hoxide Ma James Macnicol Jens-Uwe Mager Rob Mahurin Ricardo Marranita Orestes Mas

Makoto Matsumoto Tatsuro Matsuoka Laurent Mazet G D McBain Alexander Mamonov Christoph Mayer Julio Hoffimann

Mendes Thorsten Meyer Petr Mikulik Stefan Monnier Antoine Moreau Kai P Mueller Hannes Muller Victor Munoz Carmen

Navarrete Todd Neal Philip Nienhuis Al Niessner Rick Niles Takuji Nishimura Kai Noda Eric Norum Krzesimir Nowak Michael

OrsquoBrien Peter OrsquoGorman Thorsten Ohl Arno Onken Luis F Ortiz Scott Pakin Gabriele Pannocchia Sylvain Pelissier Per Persson

Primozz Peterlin Jim Peterson Danilo Piazzalunga Nicholas Piper Elias Pipping Robert Platt Hans Ekkehard Plesser Tom Poage

Orion Poplawski Ondrej Popp Jef Poskanzer Francesco Potortı Konstantinos Poulios Jarno Rajahalme James B Rawlings Eric S

Raymond Balint Reczey Joshua Redstone Lukas Reichlin Michael Reifenberger Anthony Richardson Jason Riedy E Joshua Rigler

Petter Risholm Matthew W Roberts Andrew Ross Mark van Rossum Joe Rothweiler Kevin Ruland Kristian Rumberg Ryan

Rusaw Olli Saarela Toni Saarela Juhani Saastamoinen Radek Salac Ben Sapp Aleksej Saushev Alois Schlogl Michel D Schmid

Julian Schnidder Nicol N Schraudolph Sebastian Schubert Ludwig Schwardt Thomas L Scofield Daniel J Sebald Dmitri A

Sergatskov Vanya Sergeev Baylis Shanks Andriy Shinkarchuck Robert T Short Joseph P Skudlarek John Smith Julius Smith

Shan G Smith Peter L Sondergaard Joerg Specht Quentin H Spencer Christoph Spiel Richard Stallman Russell Standish Brett

Stewart Doug Stewart Jonathan Stickel Judd Storrs Thomas Stuart Ivan Sutoris John Swensen Daisuke Takago Ariel Tankus

Matthew Tenny Georg Thimm Duncan Temple Lang Kris Thielemans Olaf Till Christophe Tournery Thomas Treichl Karsten

Trulsen Frederick Umminger Utkarsh Upadhyay Stefan van der Walt Peter Van Wieren James R Van Zandt Gregory Vanuxem

Ivana Varekova Thomas Walter Andreas Weber Olaf Weber Thomas Weber Rik Wehbring Bob Weigel Andreas Weingessel

Martin Weiser Michael Weitzel David Wells Fook Fah Yap Sean Young Michael Zeising Federico Zenith Alex Zvoleff

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

296 total contributors over all time

How many users Thousands Millions

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1935

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2035

What is Octave Octave and

Octave-Forge

Octave-Forge

Octave Forge Is a place for concurrently developing and distributingextension packages for Octave

Each package has a maintainer responsible for updating andreleasing new versions of the package

Some packages are maintained by The Community

Installation via an integrated package manager

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2135

What is Octave Octave and

PKG

1 gtgt pkg install minusforge miscellaneous2 For information about changes from previous versions of the larr

miscellaneous package run news ( miscellaneous ) 3 gtgt pkg list4 Package Name | Version | Installation directory5 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus6 bim | 1 1 1 | ˜ octavebimminus1117 fpl | 1 3 3 | ˜ octavefplminus1338 general | 1 3 1 | ˜ octavegeneral minus1319 geometry | 1 6 0 | ˜ octavegeometry minus160

10 miscellaneous | 1 2 0 | ˜ octavemiscellaneous minus12011 gtgt pkg load miscellaneous12 gtgt pkg list13 Package Name | Version | Installation directory14 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus15 bim | 1 1 1 | ˜ octavebimminus11116 fpl | 1 3 3 | ˜ octavefplminus13317 general | 1 3 1 | ˜ octavegeneral minus13118 geometry | 1 6 0 | ˜ octavegeometry minus16019 miscellaneous lowast| 1 2 0 | ˜ octavemiscellaneous minus120

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2235

What is Octave Octave and

PKG

1 gtgt pkg describe bim minusverbose2 minusminusminus3 Package name 4 bim5 Version 6 1 1 17 Short description 8 Package f o r solving Diffusion Advection Reaction ( DAR ) Partial larr

Differential Equations9 Status

10 Not loaded11 minusminusminus12 Provides 13 Matrix assembly14 bim1a_advection_diffusion15 bim1a_advection_upwind16 bim2a_advection_diffusion17 18 Preminusprocessing and Postminusprocessing computations19 bim2c_mesh_properties20 21 gtgt

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2335

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2535

What is Octave Octave and

Broadcasting

Since 360 Octave automatically broadcasts arrays when usingelementwise binary operators

Corresponding array dimensions must either be equal or one ofthem must be 1

In case all dimensions are equal ordinary element-by-elementarithmetic takes place

When one of the dimensions is 1 the array with that singletondimension gets copied along that dimension until it matches thedimension of the other array

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2635

What is Octave Octave and

Broadcasting

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Without broadcasting x + y would be an error because dimensions do not agree

With broadcasting it is as if the following operation were performed

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 10 20 3 0 10 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Other notable differences with Matlab listed in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2735

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2835

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 include lto c t a v e o c t hgt2

3 DEFUN_DLD ( dld args nargout dld (array) nreturn the elements of larrthe array in reverse ordern )

4 5 octave_value_list retval 6 int nargin = args length ( ) 7

8 if ( nargin = 1)9 print_usage ( )

10 else11 12 Arrayltdoublegt a = args ( 0 ) array_value ( ) 13 if ( error_state )14 15 Arrayltdoublegt b ( a )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

16 doublelowast ap = a fortran_vec ( ) 17 doublelowast bp = b fortran_vec ( ) 18 for ( octave_idx_type i = a numel ( ) minus 1 j = 0 i gt= 0 larr

iminusminus j++)19 bp [ i ] = ap [ j ] 20 retval = octave_value ( b ) 21 22 23 return retval 24

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 gtgt mkoctfile dld cc2 gtgt a = randn ( 5 )3 a =4

5 0395421 minus1425232 minus0176544 1055205 22293716 minus0241893 0035004 minus0296543 minus1710613 04443187 minus0752467 minus2220469 2380951 0766246 11961538 1404672 0623112 1182609 0196125 06093259 minus0687019 0646079 2239012 minus0495169 1488314

10

11 gtgt b = dld ( a )12 b =13

14 1488314 minus0495169 2239012 0646079 minus068701915 0609325 0196125 1182609 0623112 140467216 1196153 0766246 2380951 minus2220469 minus075246717 0444318 minus1710613 minus0296543 0035004 minus024189318 2229371 1055205 minus0176544 minus1425232 039542119

20 gtgt

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 21: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

Contributions slowly trickle in

Milestones

1994 Most of the current basic functionality already in (Much waswritten during its first two years)

1995 Structs Matlab-style plot() command

1998 Original sparse matrix implementation

2001 Octave-Forgersquos first commit

2006 MEX interface in core

2007 Implementation of handle graphics full support for sparse matrices

2009 OpenGL plotting

2010 -forge option for pkgm

2011 Profiler

2012 Nested functions

2013 GUI JIT compiling

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1335

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1435

What is Octave Octave and

Web resources

Web pages

Octave website

Octave-Forge website

Octave wiki

Users communication

Octave users mailing list

Octave-Forge mailing list

octave channel in Freenode

Savannah bug tracker

Developers collaboration

Octave Mercurial repository

Octave-Forge Subversion repository

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1535

What is Octave Octave and

Web resources

Web pages

Octave website

Octave-Forge website

Octave wiki

Users communication

Octave users mailing list

Octave-Forge mailing list

octave channel in Freenode

Savannah bug tracker

Developers collaboration

Octave Mercurial repository

Octave-Forge Subversion repository

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1535

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer15 current Core developers (with write access to repo)49 currently registered rsquoForge developers (38 active)296 total contributors over all timeBen Abbott Andy Adler Giles Anderson Joel Andersson Muthiah Annamalai Marco Atzeri Shai Ayal Roger Banks Ben Barrowes

Alexander Barth David Bateman Heinz Bauschke Roman Belov Karl Berry David Billinghurst Don Bindner Jakub Bogusz Moritz

Borgmann Paul Boven Richard Bovey John Bradshaw Marcus Brinkmann Remy Bruno Ansgar Burchard Marco Caliari Daniel

Calvelo John C Campbell Juan Pablo Carbajal Jean-Francois Cardoso Joao Cardoso Larrie Carr David Castelow Vincent

Cautaerts Clinton Chee Albert Chin-A-Young Carsten Clark J D Cole Martin Costabel Michael Creel Jeff Cunningham Martin

Dalecki Jorge Barros de Abreu Carlo de Falco Jacob Dawid Thomas D Dean Philippe Defert Bill Denney Fabian Deutsch

Christos Dimitrakakis David M Doolin Carne Draug Pascal A Dupuis John W Eaton Dirk Eddelbuettel Pieter Eendebak Paul

Eggert Stephen Eglen Peter Ekberg Rolf Fabian Gunnar Farneback Stephen Fegan Ramon Garcia Fernandez Torsten Finke Jose

Daniel Munoz Frias Brad Froehle Castor Fu Eduardo Gallestey Walter Gautschi Klaus Gebhardt Driss Ghaddab Nicolo Giorgetti

Michael D Godfrey Michael Goffioul Glenn Golden Tomislav Goles Keith Goodman Brian Gough Steffen Groot Etienne

Grossmann David Grundberg Peter Gustafson Kai Habel Patrick Hacker William P Y Hadisoeseno Jaroslav Hajek Benjamin Hall

Kim Hansen Soslashren Hauberg Dave Hawthorne Daniel Heiserer Martin Helm Stefan Hepp Jordi Gutierrez Hermoso Yozo Hida Ryan

Hinton Roman Hodek A Scottedward Hodel Richard Allan Holcombe Tom Holroyd David Hoover Kurt Hornik Christopher

Hulbert Cyril Humbert Teemu Ikonen Alan W Irwin Geoff Jacobsen Mats Jansson Cai Jianming Steven G Johnson Heikki Junes

Matthias Juschke Atsushi Kajita Jarkko Kaleva Mohamed Kamoun Lute Kamstra Fotios Kasolis Thomas Kasper Joel Keay

Mumit Khan Paul Kienzle Aaron A King Arno J Klaassen Alexander Klein Geoffrey Knauth Heine Kolltveit Ken Kouno Kacper

Kowalik Daniel Kraft Aravindh Krishnamoorthy Oyvind Kristiansen Piotr Krzyzanowski Volker Kuhlmann Tetsuro Kurita

Miroslaw Kwasniak Rafael Laboissiere Kai Labusch Claude Lacoursiere Walter Landry Bill Lash Dirk Laurie Maurice LeBrun

Friedrich Leisch Jyh-miin Lin Timo Lindfors Benjamin Lindner Ross Lippert David Livings Sebastien Loisel Erik de Castro Lopo

Massimo Lorenzin Emil Lucretiu Hoxide Ma James Macnicol Jens-Uwe Mager Rob Mahurin Ricardo Marranita Orestes Mas

Makoto Matsumoto Tatsuro Matsuoka Laurent Mazet G D McBain Alexander Mamonov Christoph Mayer Julio Hoffimann

Mendes Thorsten Meyer Petr Mikulik Stefan Monnier Antoine Moreau Kai P Mueller Hannes Muller Victor Munoz Carmen

Navarrete Todd Neal Philip Nienhuis Al Niessner Rick Niles Takuji Nishimura Kai Noda Eric Norum Krzesimir Nowak Michael

OrsquoBrien Peter OrsquoGorman Thorsten Ohl Arno Onken Luis F Ortiz Scott Pakin Gabriele Pannocchia Sylvain Pelissier Per Persson

Primozz Peterlin Jim Peterson Danilo Piazzalunga Nicholas Piper Elias Pipping Robert Platt Hans Ekkehard Plesser Tom Poage

Orion Poplawski Ondrej Popp Jef Poskanzer Francesco Potortı Konstantinos Poulios Jarno Rajahalme James B Rawlings Eric S

Raymond Balint Reczey Joshua Redstone Lukas Reichlin Michael Reifenberger Anthony Richardson Jason Riedy E Joshua Rigler

Petter Risholm Matthew W Roberts Andrew Ross Mark van Rossum Joe Rothweiler Kevin Ruland Kristian Rumberg Ryan

Rusaw Olli Saarela Toni Saarela Juhani Saastamoinen Radek Salac Ben Sapp Aleksej Saushev Alois Schlogl Michel D Schmid

Julian Schnidder Nicol N Schraudolph Sebastian Schubert Ludwig Schwardt Thomas L Scofield Daniel J Sebald Dmitri A

Sergatskov Vanya Sergeev Baylis Shanks Andriy Shinkarchuck Robert T Short Joseph P Skudlarek John Smith Julius Smith

Shan G Smith Peter L Sondergaard Joerg Specht Quentin H Spencer Christoph Spiel Richard Stallman Russell Standish Brett

Stewart Doug Stewart Jonathan Stickel Judd Storrs Thomas Stuart Ivan Sutoris John Swensen Daisuke Takago Ariel Tankus

Matthew Tenny Georg Thimm Duncan Temple Lang Kris Thielemans Olaf Till Christophe Tournery Thomas Treichl Karsten

Trulsen Frederick Umminger Utkarsh Upadhyay Stefan van der Walt Peter Van Wieren James R Van Zandt Gregory Vanuxem

Ivana Varekova Thomas Walter Andreas Weber Olaf Weber Thomas Weber Rik Wehbring Bob Weigel Andreas Weingessel

Martin Weiser Michael Weitzel David Wells Fook Fah Yap Sean Young Michael Zeising Federico Zenith Alex Zvoleff

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

296 total contributors over all time

How many users Thousands Millions

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1935

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2035

What is Octave Octave and

Octave-Forge

Octave-Forge

Octave Forge Is a place for concurrently developing and distributingextension packages for Octave

Each package has a maintainer responsible for updating andreleasing new versions of the package

Some packages are maintained by The Community

Installation via an integrated package manager

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2135

What is Octave Octave and

PKG

1 gtgt pkg install minusforge miscellaneous2 For information about changes from previous versions of the larr

miscellaneous package run news ( miscellaneous ) 3 gtgt pkg list4 Package Name | Version | Installation directory5 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus6 bim | 1 1 1 | ˜ octavebimminus1117 fpl | 1 3 3 | ˜ octavefplminus1338 general | 1 3 1 | ˜ octavegeneral minus1319 geometry | 1 6 0 | ˜ octavegeometry minus160

10 miscellaneous | 1 2 0 | ˜ octavemiscellaneous minus12011 gtgt pkg load miscellaneous12 gtgt pkg list13 Package Name | Version | Installation directory14 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus15 bim | 1 1 1 | ˜ octavebimminus11116 fpl | 1 3 3 | ˜ octavefplminus13317 general | 1 3 1 | ˜ octavegeneral minus13118 geometry | 1 6 0 | ˜ octavegeometry minus16019 miscellaneous lowast| 1 2 0 | ˜ octavemiscellaneous minus120

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2235

What is Octave Octave and

PKG

1 gtgt pkg describe bim minusverbose2 minusminusminus3 Package name 4 bim5 Version 6 1 1 17 Short description 8 Package f o r solving Diffusion Advection Reaction ( DAR ) Partial larr

Differential Equations9 Status

10 Not loaded11 minusminusminus12 Provides 13 Matrix assembly14 bim1a_advection_diffusion15 bim1a_advection_upwind16 bim2a_advection_diffusion17 18 Preminusprocessing and Postminusprocessing computations19 bim2c_mesh_properties20 21 gtgt

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2335

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2535

What is Octave Octave and

Broadcasting

Since 360 Octave automatically broadcasts arrays when usingelementwise binary operators

Corresponding array dimensions must either be equal or one ofthem must be 1

In case all dimensions are equal ordinary element-by-elementarithmetic takes place

When one of the dimensions is 1 the array with that singletondimension gets copied along that dimension until it matches thedimension of the other array

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2635

What is Octave Octave and

Broadcasting

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Without broadcasting x + y would be an error because dimensions do not agree

With broadcasting it is as if the following operation were performed

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 10 20 3 0 10 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Other notable differences with Matlab listed in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2735

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2835

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 include lto c t a v e o c t hgt2

3 DEFUN_DLD ( dld args nargout dld (array) nreturn the elements of larrthe array in reverse ordern )

4 5 octave_value_list retval 6 int nargin = args length ( ) 7

8 if ( nargin = 1)9 print_usage ( )

10 else11 12 Arrayltdoublegt a = args ( 0 ) array_value ( ) 13 if ( error_state )14 15 Arrayltdoublegt b ( a )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

16 doublelowast ap = a fortran_vec ( ) 17 doublelowast bp = b fortran_vec ( ) 18 for ( octave_idx_type i = a numel ( ) minus 1 j = 0 i gt= 0 larr

iminusminus j++)19 bp [ i ] = ap [ j ] 20 retval = octave_value ( b ) 21 22 23 return retval 24

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 gtgt mkoctfile dld cc2 gtgt a = randn ( 5 )3 a =4

5 0395421 minus1425232 minus0176544 1055205 22293716 minus0241893 0035004 minus0296543 minus1710613 04443187 minus0752467 minus2220469 2380951 0766246 11961538 1404672 0623112 1182609 0196125 06093259 minus0687019 0646079 2239012 minus0495169 1488314

10

11 gtgt b = dld ( a )12 b =13

14 1488314 minus0495169 2239012 0646079 minus068701915 0609325 0196125 1182609 0623112 140467216 1196153 0766246 2380951 minus2220469 minus075246717 0444318 minus1710613 minus0296543 0035004 minus024189318 2229371 1055205 minus0176544 minus1425232 039542119

20 gtgt

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 22: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1435

What is Octave Octave and

Web resources

Web pages

Octave website

Octave-Forge website

Octave wiki

Users communication

Octave users mailing list

Octave-Forge mailing list

octave channel in Freenode

Savannah bug tracker

Developers collaboration

Octave Mercurial repository

Octave-Forge Subversion repository

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1535

What is Octave Octave and

Web resources

Web pages

Octave website

Octave-Forge website

Octave wiki

Users communication

Octave users mailing list

Octave-Forge mailing list

octave channel in Freenode

Savannah bug tracker

Developers collaboration

Octave Mercurial repository

Octave-Forge Subversion repository

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1535

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer15 current Core developers (with write access to repo)49 currently registered rsquoForge developers (38 active)296 total contributors over all timeBen Abbott Andy Adler Giles Anderson Joel Andersson Muthiah Annamalai Marco Atzeri Shai Ayal Roger Banks Ben Barrowes

Alexander Barth David Bateman Heinz Bauschke Roman Belov Karl Berry David Billinghurst Don Bindner Jakub Bogusz Moritz

Borgmann Paul Boven Richard Bovey John Bradshaw Marcus Brinkmann Remy Bruno Ansgar Burchard Marco Caliari Daniel

Calvelo John C Campbell Juan Pablo Carbajal Jean-Francois Cardoso Joao Cardoso Larrie Carr David Castelow Vincent

Cautaerts Clinton Chee Albert Chin-A-Young Carsten Clark J D Cole Martin Costabel Michael Creel Jeff Cunningham Martin

Dalecki Jorge Barros de Abreu Carlo de Falco Jacob Dawid Thomas D Dean Philippe Defert Bill Denney Fabian Deutsch

Christos Dimitrakakis David M Doolin Carne Draug Pascal A Dupuis John W Eaton Dirk Eddelbuettel Pieter Eendebak Paul

Eggert Stephen Eglen Peter Ekberg Rolf Fabian Gunnar Farneback Stephen Fegan Ramon Garcia Fernandez Torsten Finke Jose

Daniel Munoz Frias Brad Froehle Castor Fu Eduardo Gallestey Walter Gautschi Klaus Gebhardt Driss Ghaddab Nicolo Giorgetti

Michael D Godfrey Michael Goffioul Glenn Golden Tomislav Goles Keith Goodman Brian Gough Steffen Groot Etienne

Grossmann David Grundberg Peter Gustafson Kai Habel Patrick Hacker William P Y Hadisoeseno Jaroslav Hajek Benjamin Hall

Kim Hansen Soslashren Hauberg Dave Hawthorne Daniel Heiserer Martin Helm Stefan Hepp Jordi Gutierrez Hermoso Yozo Hida Ryan

Hinton Roman Hodek A Scottedward Hodel Richard Allan Holcombe Tom Holroyd David Hoover Kurt Hornik Christopher

Hulbert Cyril Humbert Teemu Ikonen Alan W Irwin Geoff Jacobsen Mats Jansson Cai Jianming Steven G Johnson Heikki Junes

Matthias Juschke Atsushi Kajita Jarkko Kaleva Mohamed Kamoun Lute Kamstra Fotios Kasolis Thomas Kasper Joel Keay

Mumit Khan Paul Kienzle Aaron A King Arno J Klaassen Alexander Klein Geoffrey Knauth Heine Kolltveit Ken Kouno Kacper

Kowalik Daniel Kraft Aravindh Krishnamoorthy Oyvind Kristiansen Piotr Krzyzanowski Volker Kuhlmann Tetsuro Kurita

Miroslaw Kwasniak Rafael Laboissiere Kai Labusch Claude Lacoursiere Walter Landry Bill Lash Dirk Laurie Maurice LeBrun

Friedrich Leisch Jyh-miin Lin Timo Lindfors Benjamin Lindner Ross Lippert David Livings Sebastien Loisel Erik de Castro Lopo

Massimo Lorenzin Emil Lucretiu Hoxide Ma James Macnicol Jens-Uwe Mager Rob Mahurin Ricardo Marranita Orestes Mas

Makoto Matsumoto Tatsuro Matsuoka Laurent Mazet G D McBain Alexander Mamonov Christoph Mayer Julio Hoffimann

Mendes Thorsten Meyer Petr Mikulik Stefan Monnier Antoine Moreau Kai P Mueller Hannes Muller Victor Munoz Carmen

Navarrete Todd Neal Philip Nienhuis Al Niessner Rick Niles Takuji Nishimura Kai Noda Eric Norum Krzesimir Nowak Michael

OrsquoBrien Peter OrsquoGorman Thorsten Ohl Arno Onken Luis F Ortiz Scott Pakin Gabriele Pannocchia Sylvain Pelissier Per Persson

Primozz Peterlin Jim Peterson Danilo Piazzalunga Nicholas Piper Elias Pipping Robert Platt Hans Ekkehard Plesser Tom Poage

Orion Poplawski Ondrej Popp Jef Poskanzer Francesco Potortı Konstantinos Poulios Jarno Rajahalme James B Rawlings Eric S

Raymond Balint Reczey Joshua Redstone Lukas Reichlin Michael Reifenberger Anthony Richardson Jason Riedy E Joshua Rigler

Petter Risholm Matthew W Roberts Andrew Ross Mark van Rossum Joe Rothweiler Kevin Ruland Kristian Rumberg Ryan

Rusaw Olli Saarela Toni Saarela Juhani Saastamoinen Radek Salac Ben Sapp Aleksej Saushev Alois Schlogl Michel D Schmid

Julian Schnidder Nicol N Schraudolph Sebastian Schubert Ludwig Schwardt Thomas L Scofield Daniel J Sebald Dmitri A

Sergatskov Vanya Sergeev Baylis Shanks Andriy Shinkarchuck Robert T Short Joseph P Skudlarek John Smith Julius Smith

Shan G Smith Peter L Sondergaard Joerg Specht Quentin H Spencer Christoph Spiel Richard Stallman Russell Standish Brett

Stewart Doug Stewart Jonathan Stickel Judd Storrs Thomas Stuart Ivan Sutoris John Swensen Daisuke Takago Ariel Tankus

Matthew Tenny Georg Thimm Duncan Temple Lang Kris Thielemans Olaf Till Christophe Tournery Thomas Treichl Karsten

Trulsen Frederick Umminger Utkarsh Upadhyay Stefan van der Walt Peter Van Wieren James R Van Zandt Gregory Vanuxem

Ivana Varekova Thomas Walter Andreas Weber Olaf Weber Thomas Weber Rik Wehbring Bob Weigel Andreas Weingessel

Martin Weiser Michael Weitzel David Wells Fook Fah Yap Sean Young Michael Zeising Federico Zenith Alex Zvoleff

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

296 total contributors over all time

How many users Thousands Millions

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1935

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2035

What is Octave Octave and

Octave-Forge

Octave-Forge

Octave Forge Is a place for concurrently developing and distributingextension packages for Octave

Each package has a maintainer responsible for updating andreleasing new versions of the package

Some packages are maintained by The Community

Installation via an integrated package manager

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2135

What is Octave Octave and

PKG

1 gtgt pkg install minusforge miscellaneous2 For information about changes from previous versions of the larr

miscellaneous package run news ( miscellaneous ) 3 gtgt pkg list4 Package Name | Version | Installation directory5 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus6 bim | 1 1 1 | ˜ octavebimminus1117 fpl | 1 3 3 | ˜ octavefplminus1338 general | 1 3 1 | ˜ octavegeneral minus1319 geometry | 1 6 0 | ˜ octavegeometry minus160

10 miscellaneous | 1 2 0 | ˜ octavemiscellaneous minus12011 gtgt pkg load miscellaneous12 gtgt pkg list13 Package Name | Version | Installation directory14 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus15 bim | 1 1 1 | ˜ octavebimminus11116 fpl | 1 3 3 | ˜ octavefplminus13317 general | 1 3 1 | ˜ octavegeneral minus13118 geometry | 1 6 0 | ˜ octavegeometry minus16019 miscellaneous lowast| 1 2 0 | ˜ octavemiscellaneous minus120

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2235

What is Octave Octave and

PKG

1 gtgt pkg describe bim minusverbose2 minusminusminus3 Package name 4 bim5 Version 6 1 1 17 Short description 8 Package f o r solving Diffusion Advection Reaction ( DAR ) Partial larr

Differential Equations9 Status

10 Not loaded11 minusminusminus12 Provides 13 Matrix assembly14 bim1a_advection_diffusion15 bim1a_advection_upwind16 bim2a_advection_diffusion17 18 Preminusprocessing and Postminusprocessing computations19 bim2c_mesh_properties20 21 gtgt

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2335

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2535

What is Octave Octave and

Broadcasting

Since 360 Octave automatically broadcasts arrays when usingelementwise binary operators

Corresponding array dimensions must either be equal or one ofthem must be 1

In case all dimensions are equal ordinary element-by-elementarithmetic takes place

When one of the dimensions is 1 the array with that singletondimension gets copied along that dimension until it matches thedimension of the other array

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2635

What is Octave Octave and

Broadcasting

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Without broadcasting x + y would be an error because dimensions do not agree

With broadcasting it is as if the following operation were performed

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 10 20 3 0 10 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Other notable differences with Matlab listed in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2735

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2835

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 include lto c t a v e o c t hgt2

3 DEFUN_DLD ( dld args nargout dld (array) nreturn the elements of larrthe array in reverse ordern )

4 5 octave_value_list retval 6 int nargin = args length ( ) 7

8 if ( nargin = 1)9 print_usage ( )

10 else11 12 Arrayltdoublegt a = args ( 0 ) array_value ( ) 13 if ( error_state )14 15 Arrayltdoublegt b ( a )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

16 doublelowast ap = a fortran_vec ( ) 17 doublelowast bp = b fortran_vec ( ) 18 for ( octave_idx_type i = a numel ( ) minus 1 j = 0 i gt= 0 larr

iminusminus j++)19 bp [ i ] = ap [ j ] 20 retval = octave_value ( b ) 21 22 23 return retval 24

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 gtgt mkoctfile dld cc2 gtgt a = randn ( 5 )3 a =4

5 0395421 minus1425232 minus0176544 1055205 22293716 minus0241893 0035004 minus0296543 minus1710613 04443187 minus0752467 minus2220469 2380951 0766246 11961538 1404672 0623112 1182609 0196125 06093259 minus0687019 0646079 2239012 minus0495169 1488314

10

11 gtgt b = dld ( a )12 b =13

14 1488314 minus0495169 2239012 0646079 minus068701915 0609325 0196125 1182609 0623112 140467216 1196153 0766246 2380951 minus2220469 minus075246717 0444318 minus1710613 minus0296543 0035004 minus024189318 2229371 1055205 minus0176544 minus1425232 039542119

20 gtgt

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 23: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

Web resources

Web pages

Octave website

Octave-Forge website

Octave wiki

Users communication

Octave users mailing list

Octave-Forge mailing list

octave channel in Freenode

Savannah bug tracker

Developers collaboration

Octave Mercurial repository

Octave-Forge Subversion repository

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1535

What is Octave Octave and

Web resources

Web pages

Octave website

Octave-Forge website

Octave wiki

Users communication

Octave users mailing list

Octave-Forge mailing list

octave channel in Freenode

Savannah bug tracker

Developers collaboration

Octave Mercurial repository

Octave-Forge Subversion repository

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1535

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer15 current Core developers (with write access to repo)49 currently registered rsquoForge developers (38 active)296 total contributors over all timeBen Abbott Andy Adler Giles Anderson Joel Andersson Muthiah Annamalai Marco Atzeri Shai Ayal Roger Banks Ben Barrowes

Alexander Barth David Bateman Heinz Bauschke Roman Belov Karl Berry David Billinghurst Don Bindner Jakub Bogusz Moritz

Borgmann Paul Boven Richard Bovey John Bradshaw Marcus Brinkmann Remy Bruno Ansgar Burchard Marco Caliari Daniel

Calvelo John C Campbell Juan Pablo Carbajal Jean-Francois Cardoso Joao Cardoso Larrie Carr David Castelow Vincent

Cautaerts Clinton Chee Albert Chin-A-Young Carsten Clark J D Cole Martin Costabel Michael Creel Jeff Cunningham Martin

Dalecki Jorge Barros de Abreu Carlo de Falco Jacob Dawid Thomas D Dean Philippe Defert Bill Denney Fabian Deutsch

Christos Dimitrakakis David M Doolin Carne Draug Pascal A Dupuis John W Eaton Dirk Eddelbuettel Pieter Eendebak Paul

Eggert Stephen Eglen Peter Ekberg Rolf Fabian Gunnar Farneback Stephen Fegan Ramon Garcia Fernandez Torsten Finke Jose

Daniel Munoz Frias Brad Froehle Castor Fu Eduardo Gallestey Walter Gautschi Klaus Gebhardt Driss Ghaddab Nicolo Giorgetti

Michael D Godfrey Michael Goffioul Glenn Golden Tomislav Goles Keith Goodman Brian Gough Steffen Groot Etienne

Grossmann David Grundberg Peter Gustafson Kai Habel Patrick Hacker William P Y Hadisoeseno Jaroslav Hajek Benjamin Hall

Kim Hansen Soslashren Hauberg Dave Hawthorne Daniel Heiserer Martin Helm Stefan Hepp Jordi Gutierrez Hermoso Yozo Hida Ryan

Hinton Roman Hodek A Scottedward Hodel Richard Allan Holcombe Tom Holroyd David Hoover Kurt Hornik Christopher

Hulbert Cyril Humbert Teemu Ikonen Alan W Irwin Geoff Jacobsen Mats Jansson Cai Jianming Steven G Johnson Heikki Junes

Matthias Juschke Atsushi Kajita Jarkko Kaleva Mohamed Kamoun Lute Kamstra Fotios Kasolis Thomas Kasper Joel Keay

Mumit Khan Paul Kienzle Aaron A King Arno J Klaassen Alexander Klein Geoffrey Knauth Heine Kolltveit Ken Kouno Kacper

Kowalik Daniel Kraft Aravindh Krishnamoorthy Oyvind Kristiansen Piotr Krzyzanowski Volker Kuhlmann Tetsuro Kurita

Miroslaw Kwasniak Rafael Laboissiere Kai Labusch Claude Lacoursiere Walter Landry Bill Lash Dirk Laurie Maurice LeBrun

Friedrich Leisch Jyh-miin Lin Timo Lindfors Benjamin Lindner Ross Lippert David Livings Sebastien Loisel Erik de Castro Lopo

Massimo Lorenzin Emil Lucretiu Hoxide Ma James Macnicol Jens-Uwe Mager Rob Mahurin Ricardo Marranita Orestes Mas

Makoto Matsumoto Tatsuro Matsuoka Laurent Mazet G D McBain Alexander Mamonov Christoph Mayer Julio Hoffimann

Mendes Thorsten Meyer Petr Mikulik Stefan Monnier Antoine Moreau Kai P Mueller Hannes Muller Victor Munoz Carmen

Navarrete Todd Neal Philip Nienhuis Al Niessner Rick Niles Takuji Nishimura Kai Noda Eric Norum Krzesimir Nowak Michael

OrsquoBrien Peter OrsquoGorman Thorsten Ohl Arno Onken Luis F Ortiz Scott Pakin Gabriele Pannocchia Sylvain Pelissier Per Persson

Primozz Peterlin Jim Peterson Danilo Piazzalunga Nicholas Piper Elias Pipping Robert Platt Hans Ekkehard Plesser Tom Poage

Orion Poplawski Ondrej Popp Jef Poskanzer Francesco Potortı Konstantinos Poulios Jarno Rajahalme James B Rawlings Eric S

Raymond Balint Reczey Joshua Redstone Lukas Reichlin Michael Reifenberger Anthony Richardson Jason Riedy E Joshua Rigler

Petter Risholm Matthew W Roberts Andrew Ross Mark van Rossum Joe Rothweiler Kevin Ruland Kristian Rumberg Ryan

Rusaw Olli Saarela Toni Saarela Juhani Saastamoinen Radek Salac Ben Sapp Aleksej Saushev Alois Schlogl Michel D Schmid

Julian Schnidder Nicol N Schraudolph Sebastian Schubert Ludwig Schwardt Thomas L Scofield Daniel J Sebald Dmitri A

Sergatskov Vanya Sergeev Baylis Shanks Andriy Shinkarchuck Robert T Short Joseph P Skudlarek John Smith Julius Smith

Shan G Smith Peter L Sondergaard Joerg Specht Quentin H Spencer Christoph Spiel Richard Stallman Russell Standish Brett

Stewart Doug Stewart Jonathan Stickel Judd Storrs Thomas Stuart Ivan Sutoris John Swensen Daisuke Takago Ariel Tankus

Matthew Tenny Georg Thimm Duncan Temple Lang Kris Thielemans Olaf Till Christophe Tournery Thomas Treichl Karsten

Trulsen Frederick Umminger Utkarsh Upadhyay Stefan van der Walt Peter Van Wieren James R Van Zandt Gregory Vanuxem

Ivana Varekova Thomas Walter Andreas Weber Olaf Weber Thomas Weber Rik Wehbring Bob Weigel Andreas Weingessel

Martin Weiser Michael Weitzel David Wells Fook Fah Yap Sean Young Michael Zeising Federico Zenith Alex Zvoleff

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

296 total contributors over all time

How many users Thousands Millions

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1935

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2035

What is Octave Octave and

Octave-Forge

Octave-Forge

Octave Forge Is a place for concurrently developing and distributingextension packages for Octave

Each package has a maintainer responsible for updating andreleasing new versions of the package

Some packages are maintained by The Community

Installation via an integrated package manager

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2135

What is Octave Octave and

PKG

1 gtgt pkg install minusforge miscellaneous2 For information about changes from previous versions of the larr

miscellaneous package run news ( miscellaneous ) 3 gtgt pkg list4 Package Name | Version | Installation directory5 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus6 bim | 1 1 1 | ˜ octavebimminus1117 fpl | 1 3 3 | ˜ octavefplminus1338 general | 1 3 1 | ˜ octavegeneral minus1319 geometry | 1 6 0 | ˜ octavegeometry minus160

10 miscellaneous | 1 2 0 | ˜ octavemiscellaneous minus12011 gtgt pkg load miscellaneous12 gtgt pkg list13 Package Name | Version | Installation directory14 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus15 bim | 1 1 1 | ˜ octavebimminus11116 fpl | 1 3 3 | ˜ octavefplminus13317 general | 1 3 1 | ˜ octavegeneral minus13118 geometry | 1 6 0 | ˜ octavegeometry minus16019 miscellaneous lowast| 1 2 0 | ˜ octavemiscellaneous minus120

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2235

What is Octave Octave and

PKG

1 gtgt pkg describe bim minusverbose2 minusminusminus3 Package name 4 bim5 Version 6 1 1 17 Short description 8 Package f o r solving Diffusion Advection Reaction ( DAR ) Partial larr

Differential Equations9 Status

10 Not loaded11 minusminusminus12 Provides 13 Matrix assembly14 bim1a_advection_diffusion15 bim1a_advection_upwind16 bim2a_advection_diffusion17 18 Preminusprocessing and Postminusprocessing computations19 bim2c_mesh_properties20 21 gtgt

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2335

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2535

What is Octave Octave and

Broadcasting

Since 360 Octave automatically broadcasts arrays when usingelementwise binary operators

Corresponding array dimensions must either be equal or one ofthem must be 1

In case all dimensions are equal ordinary element-by-elementarithmetic takes place

When one of the dimensions is 1 the array with that singletondimension gets copied along that dimension until it matches thedimension of the other array

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2635

What is Octave Octave and

Broadcasting

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Without broadcasting x + y would be an error because dimensions do not agree

With broadcasting it is as if the following operation were performed

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 10 20 3 0 10 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Other notable differences with Matlab listed in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2735

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2835

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 include lto c t a v e o c t hgt2

3 DEFUN_DLD ( dld args nargout dld (array) nreturn the elements of larrthe array in reverse ordern )

4 5 octave_value_list retval 6 int nargin = args length ( ) 7

8 if ( nargin = 1)9 print_usage ( )

10 else11 12 Arrayltdoublegt a = args ( 0 ) array_value ( ) 13 if ( error_state )14 15 Arrayltdoublegt b ( a )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

16 doublelowast ap = a fortran_vec ( ) 17 doublelowast bp = b fortran_vec ( ) 18 for ( octave_idx_type i = a numel ( ) minus 1 j = 0 i gt= 0 larr

iminusminus j++)19 bp [ i ] = ap [ j ] 20 retval = octave_value ( b ) 21 22 23 return retval 24

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 gtgt mkoctfile dld cc2 gtgt a = randn ( 5 )3 a =4

5 0395421 minus1425232 minus0176544 1055205 22293716 minus0241893 0035004 minus0296543 minus1710613 04443187 minus0752467 minus2220469 2380951 0766246 11961538 1404672 0623112 1182609 0196125 06093259 minus0687019 0646079 2239012 minus0495169 1488314

10

11 gtgt b = dld ( a )12 b =13

14 1488314 minus0495169 2239012 0646079 minus068701915 0609325 0196125 1182609 0623112 140467216 1196153 0766246 2380951 minus2220469 minus075246717 0444318 minus1710613 minus0296543 0035004 minus024189318 2229371 1055205 minus0176544 minus1425232 039542119

20 gtgt

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 24: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

Web resources

Web pages

Octave website

Octave-Forge website

Octave wiki

Users communication

Octave users mailing list

Octave-Forge mailing list

octave channel in Freenode

Savannah bug tracker

Developers collaboration

Octave Mercurial repository

Octave-Forge Subversion repository

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1535

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer15 current Core developers (with write access to repo)49 currently registered rsquoForge developers (38 active)296 total contributors over all timeBen Abbott Andy Adler Giles Anderson Joel Andersson Muthiah Annamalai Marco Atzeri Shai Ayal Roger Banks Ben Barrowes

Alexander Barth David Bateman Heinz Bauschke Roman Belov Karl Berry David Billinghurst Don Bindner Jakub Bogusz Moritz

Borgmann Paul Boven Richard Bovey John Bradshaw Marcus Brinkmann Remy Bruno Ansgar Burchard Marco Caliari Daniel

Calvelo John C Campbell Juan Pablo Carbajal Jean-Francois Cardoso Joao Cardoso Larrie Carr David Castelow Vincent

Cautaerts Clinton Chee Albert Chin-A-Young Carsten Clark J D Cole Martin Costabel Michael Creel Jeff Cunningham Martin

Dalecki Jorge Barros de Abreu Carlo de Falco Jacob Dawid Thomas D Dean Philippe Defert Bill Denney Fabian Deutsch

Christos Dimitrakakis David M Doolin Carne Draug Pascal A Dupuis John W Eaton Dirk Eddelbuettel Pieter Eendebak Paul

Eggert Stephen Eglen Peter Ekberg Rolf Fabian Gunnar Farneback Stephen Fegan Ramon Garcia Fernandez Torsten Finke Jose

Daniel Munoz Frias Brad Froehle Castor Fu Eduardo Gallestey Walter Gautschi Klaus Gebhardt Driss Ghaddab Nicolo Giorgetti

Michael D Godfrey Michael Goffioul Glenn Golden Tomislav Goles Keith Goodman Brian Gough Steffen Groot Etienne

Grossmann David Grundberg Peter Gustafson Kai Habel Patrick Hacker William P Y Hadisoeseno Jaroslav Hajek Benjamin Hall

Kim Hansen Soslashren Hauberg Dave Hawthorne Daniel Heiserer Martin Helm Stefan Hepp Jordi Gutierrez Hermoso Yozo Hida Ryan

Hinton Roman Hodek A Scottedward Hodel Richard Allan Holcombe Tom Holroyd David Hoover Kurt Hornik Christopher

Hulbert Cyril Humbert Teemu Ikonen Alan W Irwin Geoff Jacobsen Mats Jansson Cai Jianming Steven G Johnson Heikki Junes

Matthias Juschke Atsushi Kajita Jarkko Kaleva Mohamed Kamoun Lute Kamstra Fotios Kasolis Thomas Kasper Joel Keay

Mumit Khan Paul Kienzle Aaron A King Arno J Klaassen Alexander Klein Geoffrey Knauth Heine Kolltveit Ken Kouno Kacper

Kowalik Daniel Kraft Aravindh Krishnamoorthy Oyvind Kristiansen Piotr Krzyzanowski Volker Kuhlmann Tetsuro Kurita

Miroslaw Kwasniak Rafael Laboissiere Kai Labusch Claude Lacoursiere Walter Landry Bill Lash Dirk Laurie Maurice LeBrun

Friedrich Leisch Jyh-miin Lin Timo Lindfors Benjamin Lindner Ross Lippert David Livings Sebastien Loisel Erik de Castro Lopo

Massimo Lorenzin Emil Lucretiu Hoxide Ma James Macnicol Jens-Uwe Mager Rob Mahurin Ricardo Marranita Orestes Mas

Makoto Matsumoto Tatsuro Matsuoka Laurent Mazet G D McBain Alexander Mamonov Christoph Mayer Julio Hoffimann

Mendes Thorsten Meyer Petr Mikulik Stefan Monnier Antoine Moreau Kai P Mueller Hannes Muller Victor Munoz Carmen

Navarrete Todd Neal Philip Nienhuis Al Niessner Rick Niles Takuji Nishimura Kai Noda Eric Norum Krzesimir Nowak Michael

OrsquoBrien Peter OrsquoGorman Thorsten Ohl Arno Onken Luis F Ortiz Scott Pakin Gabriele Pannocchia Sylvain Pelissier Per Persson

Primozz Peterlin Jim Peterson Danilo Piazzalunga Nicholas Piper Elias Pipping Robert Platt Hans Ekkehard Plesser Tom Poage

Orion Poplawski Ondrej Popp Jef Poskanzer Francesco Potortı Konstantinos Poulios Jarno Rajahalme James B Rawlings Eric S

Raymond Balint Reczey Joshua Redstone Lukas Reichlin Michael Reifenberger Anthony Richardson Jason Riedy E Joshua Rigler

Petter Risholm Matthew W Roberts Andrew Ross Mark van Rossum Joe Rothweiler Kevin Ruland Kristian Rumberg Ryan

Rusaw Olli Saarela Toni Saarela Juhani Saastamoinen Radek Salac Ben Sapp Aleksej Saushev Alois Schlogl Michel D Schmid

Julian Schnidder Nicol N Schraudolph Sebastian Schubert Ludwig Schwardt Thomas L Scofield Daniel J Sebald Dmitri A

Sergatskov Vanya Sergeev Baylis Shanks Andriy Shinkarchuck Robert T Short Joseph P Skudlarek John Smith Julius Smith

Shan G Smith Peter L Sondergaard Joerg Specht Quentin H Spencer Christoph Spiel Richard Stallman Russell Standish Brett

Stewart Doug Stewart Jonathan Stickel Judd Storrs Thomas Stuart Ivan Sutoris John Swensen Daisuke Takago Ariel Tankus

Matthew Tenny Georg Thimm Duncan Temple Lang Kris Thielemans Olaf Till Christophe Tournery Thomas Treichl Karsten

Trulsen Frederick Umminger Utkarsh Upadhyay Stefan van der Walt Peter Van Wieren James R Van Zandt Gregory Vanuxem

Ivana Varekova Thomas Walter Andreas Weber Olaf Weber Thomas Weber Rik Wehbring Bob Weigel Andreas Weingessel

Martin Weiser Michael Weitzel David Wells Fook Fah Yap Sean Young Michael Zeising Federico Zenith Alex Zvoleff

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

296 total contributors over all time

How many users Thousands Millions

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1935

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2035

What is Octave Octave and

Octave-Forge

Octave-Forge

Octave Forge Is a place for concurrently developing and distributingextension packages for Octave

Each package has a maintainer responsible for updating andreleasing new versions of the package

Some packages are maintained by The Community

Installation via an integrated package manager

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2135

What is Octave Octave and

PKG

1 gtgt pkg install minusforge miscellaneous2 For information about changes from previous versions of the larr

miscellaneous package run news ( miscellaneous ) 3 gtgt pkg list4 Package Name | Version | Installation directory5 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus6 bim | 1 1 1 | ˜ octavebimminus1117 fpl | 1 3 3 | ˜ octavefplminus1338 general | 1 3 1 | ˜ octavegeneral minus1319 geometry | 1 6 0 | ˜ octavegeometry minus160

10 miscellaneous | 1 2 0 | ˜ octavemiscellaneous minus12011 gtgt pkg load miscellaneous12 gtgt pkg list13 Package Name | Version | Installation directory14 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus15 bim | 1 1 1 | ˜ octavebimminus11116 fpl | 1 3 3 | ˜ octavefplminus13317 general | 1 3 1 | ˜ octavegeneral minus13118 geometry | 1 6 0 | ˜ octavegeometry minus16019 miscellaneous lowast| 1 2 0 | ˜ octavemiscellaneous minus120

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2235

What is Octave Octave and

PKG

1 gtgt pkg describe bim minusverbose2 minusminusminus3 Package name 4 bim5 Version 6 1 1 17 Short description 8 Package f o r solving Diffusion Advection Reaction ( DAR ) Partial larr

Differential Equations9 Status

10 Not loaded11 minusminusminus12 Provides 13 Matrix assembly14 bim1a_advection_diffusion15 bim1a_advection_upwind16 bim2a_advection_diffusion17 18 Preminusprocessing and Postminusprocessing computations19 bim2c_mesh_properties20 21 gtgt

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2335

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2535

What is Octave Octave and

Broadcasting

Since 360 Octave automatically broadcasts arrays when usingelementwise binary operators

Corresponding array dimensions must either be equal or one ofthem must be 1

In case all dimensions are equal ordinary element-by-elementarithmetic takes place

When one of the dimensions is 1 the array with that singletondimension gets copied along that dimension until it matches thedimension of the other array

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2635

What is Octave Octave and

Broadcasting

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Without broadcasting x + y would be an error because dimensions do not agree

With broadcasting it is as if the following operation were performed

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 10 20 3 0 10 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Other notable differences with Matlab listed in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2735

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2835

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 include lto c t a v e o c t hgt2

3 DEFUN_DLD ( dld args nargout dld (array) nreturn the elements of larrthe array in reverse ordern )

4 5 octave_value_list retval 6 int nargin = args length ( ) 7

8 if ( nargin = 1)9 print_usage ( )

10 else11 12 Arrayltdoublegt a = args ( 0 ) array_value ( ) 13 if ( error_state )14 15 Arrayltdoublegt b ( a )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

16 doublelowast ap = a fortran_vec ( ) 17 doublelowast bp = b fortran_vec ( ) 18 for ( octave_idx_type i = a numel ( ) minus 1 j = 0 i gt= 0 larr

iminusminus j++)19 bp [ i ] = ap [ j ] 20 retval = octave_value ( b ) 21 22 23 return retval 24

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 gtgt mkoctfile dld cc2 gtgt a = randn ( 5 )3 a =4

5 0395421 minus1425232 minus0176544 1055205 22293716 minus0241893 0035004 minus0296543 minus1710613 04443187 minus0752467 minus2220469 2380951 0766246 11961538 1404672 0623112 1182609 0196125 06093259 minus0687019 0646079 2239012 minus0495169 1488314

10

11 gtgt b = dld ( a )12 b =13

14 1488314 minus0495169 2239012 0646079 minus068701915 0609325 0196125 1182609 0623112 140467216 1196153 0766246 2380951 minus2220469 minus075246717 0444318 minus1710613 minus0296543 0035004 minus024189318 2229371 1055205 minus0176544 minus1425232 039542119

20 gtgt

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 25: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer15 current Core developers (with write access to repo)49 currently registered rsquoForge developers (38 active)296 total contributors over all timeBen Abbott Andy Adler Giles Anderson Joel Andersson Muthiah Annamalai Marco Atzeri Shai Ayal Roger Banks Ben Barrowes

Alexander Barth David Bateman Heinz Bauschke Roman Belov Karl Berry David Billinghurst Don Bindner Jakub Bogusz Moritz

Borgmann Paul Boven Richard Bovey John Bradshaw Marcus Brinkmann Remy Bruno Ansgar Burchard Marco Caliari Daniel

Calvelo John C Campbell Juan Pablo Carbajal Jean-Francois Cardoso Joao Cardoso Larrie Carr David Castelow Vincent

Cautaerts Clinton Chee Albert Chin-A-Young Carsten Clark J D Cole Martin Costabel Michael Creel Jeff Cunningham Martin

Dalecki Jorge Barros de Abreu Carlo de Falco Jacob Dawid Thomas D Dean Philippe Defert Bill Denney Fabian Deutsch

Christos Dimitrakakis David M Doolin Carne Draug Pascal A Dupuis John W Eaton Dirk Eddelbuettel Pieter Eendebak Paul

Eggert Stephen Eglen Peter Ekberg Rolf Fabian Gunnar Farneback Stephen Fegan Ramon Garcia Fernandez Torsten Finke Jose

Daniel Munoz Frias Brad Froehle Castor Fu Eduardo Gallestey Walter Gautschi Klaus Gebhardt Driss Ghaddab Nicolo Giorgetti

Michael D Godfrey Michael Goffioul Glenn Golden Tomislav Goles Keith Goodman Brian Gough Steffen Groot Etienne

Grossmann David Grundberg Peter Gustafson Kai Habel Patrick Hacker William P Y Hadisoeseno Jaroslav Hajek Benjamin Hall

Kim Hansen Soslashren Hauberg Dave Hawthorne Daniel Heiserer Martin Helm Stefan Hepp Jordi Gutierrez Hermoso Yozo Hida Ryan

Hinton Roman Hodek A Scottedward Hodel Richard Allan Holcombe Tom Holroyd David Hoover Kurt Hornik Christopher

Hulbert Cyril Humbert Teemu Ikonen Alan W Irwin Geoff Jacobsen Mats Jansson Cai Jianming Steven G Johnson Heikki Junes

Matthias Juschke Atsushi Kajita Jarkko Kaleva Mohamed Kamoun Lute Kamstra Fotios Kasolis Thomas Kasper Joel Keay

Mumit Khan Paul Kienzle Aaron A King Arno J Klaassen Alexander Klein Geoffrey Knauth Heine Kolltveit Ken Kouno Kacper

Kowalik Daniel Kraft Aravindh Krishnamoorthy Oyvind Kristiansen Piotr Krzyzanowski Volker Kuhlmann Tetsuro Kurita

Miroslaw Kwasniak Rafael Laboissiere Kai Labusch Claude Lacoursiere Walter Landry Bill Lash Dirk Laurie Maurice LeBrun

Friedrich Leisch Jyh-miin Lin Timo Lindfors Benjamin Lindner Ross Lippert David Livings Sebastien Loisel Erik de Castro Lopo

Massimo Lorenzin Emil Lucretiu Hoxide Ma James Macnicol Jens-Uwe Mager Rob Mahurin Ricardo Marranita Orestes Mas

Makoto Matsumoto Tatsuro Matsuoka Laurent Mazet G D McBain Alexander Mamonov Christoph Mayer Julio Hoffimann

Mendes Thorsten Meyer Petr Mikulik Stefan Monnier Antoine Moreau Kai P Mueller Hannes Muller Victor Munoz Carmen

Navarrete Todd Neal Philip Nienhuis Al Niessner Rick Niles Takuji Nishimura Kai Noda Eric Norum Krzesimir Nowak Michael

OrsquoBrien Peter OrsquoGorman Thorsten Ohl Arno Onken Luis F Ortiz Scott Pakin Gabriele Pannocchia Sylvain Pelissier Per Persson

Primozz Peterlin Jim Peterson Danilo Piazzalunga Nicholas Piper Elias Pipping Robert Platt Hans Ekkehard Plesser Tom Poage

Orion Poplawski Ondrej Popp Jef Poskanzer Francesco Potortı Konstantinos Poulios Jarno Rajahalme James B Rawlings Eric S

Raymond Balint Reczey Joshua Redstone Lukas Reichlin Michael Reifenberger Anthony Richardson Jason Riedy E Joshua Rigler

Petter Risholm Matthew W Roberts Andrew Ross Mark van Rossum Joe Rothweiler Kevin Ruland Kristian Rumberg Ryan

Rusaw Olli Saarela Toni Saarela Juhani Saastamoinen Radek Salac Ben Sapp Aleksej Saushev Alois Schlogl Michel D Schmid

Julian Schnidder Nicol N Schraudolph Sebastian Schubert Ludwig Schwardt Thomas L Scofield Daniel J Sebald Dmitri A

Sergatskov Vanya Sergeev Baylis Shanks Andriy Shinkarchuck Robert T Short Joseph P Skudlarek John Smith Julius Smith

Shan G Smith Peter L Sondergaard Joerg Specht Quentin H Spencer Christoph Spiel Richard Stallman Russell Standish Brett

Stewart Doug Stewart Jonathan Stickel Judd Storrs Thomas Stuart Ivan Sutoris John Swensen Daisuke Takago Ariel Tankus

Matthew Tenny Georg Thimm Duncan Temple Lang Kris Thielemans Olaf Till Christophe Tournery Thomas Treichl Karsten

Trulsen Frederick Umminger Utkarsh Upadhyay Stefan van der Walt Peter Van Wieren James R Van Zandt Gregory Vanuxem

Ivana Varekova Thomas Walter Andreas Weber Olaf Weber Thomas Weber Rik Wehbring Bob Weigel Andreas Weingessel

Martin Weiser Michael Weitzel David Wells Fook Fah Yap Sean Young Michael Zeising Federico Zenith Alex Zvoleff

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

296 total contributors over all time

How many users Thousands Millions

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1935

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2035

What is Octave Octave and

Octave-Forge

Octave-Forge

Octave Forge Is a place for concurrently developing and distributingextension packages for Octave

Each package has a maintainer responsible for updating andreleasing new versions of the package

Some packages are maintained by The Community

Installation via an integrated package manager

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2135

What is Octave Octave and

PKG

1 gtgt pkg install minusforge miscellaneous2 For information about changes from previous versions of the larr

miscellaneous package run news ( miscellaneous ) 3 gtgt pkg list4 Package Name | Version | Installation directory5 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus6 bim | 1 1 1 | ˜ octavebimminus1117 fpl | 1 3 3 | ˜ octavefplminus1338 general | 1 3 1 | ˜ octavegeneral minus1319 geometry | 1 6 0 | ˜ octavegeometry minus160

10 miscellaneous | 1 2 0 | ˜ octavemiscellaneous minus12011 gtgt pkg load miscellaneous12 gtgt pkg list13 Package Name | Version | Installation directory14 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus15 bim | 1 1 1 | ˜ octavebimminus11116 fpl | 1 3 3 | ˜ octavefplminus13317 general | 1 3 1 | ˜ octavegeneral minus13118 geometry | 1 6 0 | ˜ octavegeometry minus16019 miscellaneous lowast| 1 2 0 | ˜ octavemiscellaneous minus120

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2235

What is Octave Octave and

PKG

1 gtgt pkg describe bim minusverbose2 minusminusminus3 Package name 4 bim5 Version 6 1 1 17 Short description 8 Package f o r solving Diffusion Advection Reaction ( DAR ) Partial larr

Differential Equations9 Status

10 Not loaded11 minusminusminus12 Provides 13 Matrix assembly14 bim1a_advection_diffusion15 bim1a_advection_upwind16 bim2a_advection_diffusion17 18 Preminusprocessing and Postminusprocessing computations19 bim2c_mesh_properties20 21 gtgt

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2335

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2535

What is Octave Octave and

Broadcasting

Since 360 Octave automatically broadcasts arrays when usingelementwise binary operators

Corresponding array dimensions must either be equal or one ofthem must be 1

In case all dimensions are equal ordinary element-by-elementarithmetic takes place

When one of the dimensions is 1 the array with that singletondimension gets copied along that dimension until it matches thedimension of the other array

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2635

What is Octave Octave and

Broadcasting

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Without broadcasting x + y would be an error because dimensions do not agree

With broadcasting it is as if the following operation were performed

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 10 20 3 0 10 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Other notable differences with Matlab listed in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2735

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2835

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 include lto c t a v e o c t hgt2

3 DEFUN_DLD ( dld args nargout dld (array) nreturn the elements of larrthe array in reverse ordern )

4 5 octave_value_list retval 6 int nargin = args length ( ) 7

8 if ( nargin = 1)9 print_usage ( )

10 else11 12 Arrayltdoublegt a = args ( 0 ) array_value ( ) 13 if ( error_state )14 15 Arrayltdoublegt b ( a )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

16 doublelowast ap = a fortran_vec ( ) 17 doublelowast bp = b fortran_vec ( ) 18 for ( octave_idx_type i = a numel ( ) minus 1 j = 0 i gt= 0 larr

iminusminus j++)19 bp [ i ] = ap [ j ] 20 retval = octave_value ( b ) 21 22 23 return retval 24

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 gtgt mkoctfile dld cc2 gtgt a = randn ( 5 )3 a =4

5 0395421 minus1425232 minus0176544 1055205 22293716 minus0241893 0035004 minus0296543 minus1710613 04443187 minus0752467 minus2220469 2380951 0766246 11961538 1404672 0623112 1182609 0196125 06093259 minus0687019 0646079 2239012 minus0495169 1488314

10

11 gtgt b = dld ( a )12 b =13

14 1488314 minus0495169 2239012 0646079 minus068701915 0609325 0196125 1182609 0623112 140467216 1196153 0766246 2380951 minus2220469 minus075246717 0444318 minus1710613 minus0296543 0035004 minus024189318 2229371 1055205 minus0176544 minus1425232 039542119

20 gtgt

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 26: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer15 current Core developers (with write access to repo)49 currently registered rsquoForge developers (38 active)296 total contributors over all timeBen Abbott Andy Adler Giles Anderson Joel Andersson Muthiah Annamalai Marco Atzeri Shai Ayal Roger Banks Ben Barrowes

Alexander Barth David Bateman Heinz Bauschke Roman Belov Karl Berry David Billinghurst Don Bindner Jakub Bogusz Moritz

Borgmann Paul Boven Richard Bovey John Bradshaw Marcus Brinkmann Remy Bruno Ansgar Burchard Marco Caliari Daniel

Calvelo John C Campbell Juan Pablo Carbajal Jean-Francois Cardoso Joao Cardoso Larrie Carr David Castelow Vincent

Cautaerts Clinton Chee Albert Chin-A-Young Carsten Clark J D Cole Martin Costabel Michael Creel Jeff Cunningham Martin

Dalecki Jorge Barros de Abreu Carlo de Falco Jacob Dawid Thomas D Dean Philippe Defert Bill Denney Fabian Deutsch

Christos Dimitrakakis David M Doolin Carne Draug Pascal A Dupuis John W Eaton Dirk Eddelbuettel Pieter Eendebak Paul

Eggert Stephen Eglen Peter Ekberg Rolf Fabian Gunnar Farneback Stephen Fegan Ramon Garcia Fernandez Torsten Finke Jose

Daniel Munoz Frias Brad Froehle Castor Fu Eduardo Gallestey Walter Gautschi Klaus Gebhardt Driss Ghaddab Nicolo Giorgetti

Michael D Godfrey Michael Goffioul Glenn Golden Tomislav Goles Keith Goodman Brian Gough Steffen Groot Etienne

Grossmann David Grundberg Peter Gustafson Kai Habel Patrick Hacker William P Y Hadisoeseno Jaroslav Hajek Benjamin Hall

Kim Hansen Soslashren Hauberg Dave Hawthorne Daniel Heiserer Martin Helm Stefan Hepp Jordi Gutierrez Hermoso Yozo Hida Ryan

Hinton Roman Hodek A Scottedward Hodel Richard Allan Holcombe Tom Holroyd David Hoover Kurt Hornik Christopher

Hulbert Cyril Humbert Teemu Ikonen Alan W Irwin Geoff Jacobsen Mats Jansson Cai Jianming Steven G Johnson Heikki Junes

Matthias Juschke Atsushi Kajita Jarkko Kaleva Mohamed Kamoun Lute Kamstra Fotios Kasolis Thomas Kasper Joel Keay

Mumit Khan Paul Kienzle Aaron A King Arno J Klaassen Alexander Klein Geoffrey Knauth Heine Kolltveit Ken Kouno Kacper

Kowalik Daniel Kraft Aravindh Krishnamoorthy Oyvind Kristiansen Piotr Krzyzanowski Volker Kuhlmann Tetsuro Kurita

Miroslaw Kwasniak Rafael Laboissiere Kai Labusch Claude Lacoursiere Walter Landry Bill Lash Dirk Laurie Maurice LeBrun

Friedrich Leisch Jyh-miin Lin Timo Lindfors Benjamin Lindner Ross Lippert David Livings Sebastien Loisel Erik de Castro Lopo

Massimo Lorenzin Emil Lucretiu Hoxide Ma James Macnicol Jens-Uwe Mager Rob Mahurin Ricardo Marranita Orestes Mas

Makoto Matsumoto Tatsuro Matsuoka Laurent Mazet G D McBain Alexander Mamonov Christoph Mayer Julio Hoffimann

Mendes Thorsten Meyer Petr Mikulik Stefan Monnier Antoine Moreau Kai P Mueller Hannes Muller Victor Munoz Carmen

Navarrete Todd Neal Philip Nienhuis Al Niessner Rick Niles Takuji Nishimura Kai Noda Eric Norum Krzesimir Nowak Michael

OrsquoBrien Peter OrsquoGorman Thorsten Ohl Arno Onken Luis F Ortiz Scott Pakin Gabriele Pannocchia Sylvain Pelissier Per Persson

Primozz Peterlin Jim Peterson Danilo Piazzalunga Nicholas Piper Elias Pipping Robert Platt Hans Ekkehard Plesser Tom Poage

Orion Poplawski Ondrej Popp Jef Poskanzer Francesco Potortı Konstantinos Poulios Jarno Rajahalme James B Rawlings Eric S

Raymond Balint Reczey Joshua Redstone Lukas Reichlin Michael Reifenberger Anthony Richardson Jason Riedy E Joshua Rigler

Petter Risholm Matthew W Roberts Andrew Ross Mark van Rossum Joe Rothweiler Kevin Ruland Kristian Rumberg Ryan

Rusaw Olli Saarela Toni Saarela Juhani Saastamoinen Radek Salac Ben Sapp Aleksej Saushev Alois Schlogl Michel D Schmid

Julian Schnidder Nicol N Schraudolph Sebastian Schubert Ludwig Schwardt Thomas L Scofield Daniel J Sebald Dmitri A

Sergatskov Vanya Sergeev Baylis Shanks Andriy Shinkarchuck Robert T Short Joseph P Skudlarek John Smith Julius Smith

Shan G Smith Peter L Sondergaard Joerg Specht Quentin H Spencer Christoph Spiel Richard Stallman Russell Standish Brett

Stewart Doug Stewart Jonathan Stickel Judd Storrs Thomas Stuart Ivan Sutoris John Swensen Daisuke Takago Ariel Tankus

Matthew Tenny Georg Thimm Duncan Temple Lang Kris Thielemans Olaf Till Christophe Tournery Thomas Treichl Karsten

Trulsen Frederick Umminger Utkarsh Upadhyay Stefan van der Walt Peter Van Wieren James R Van Zandt Gregory Vanuxem

Ivana Varekova Thomas Walter Andreas Weber Olaf Weber Thomas Weber Rik Wehbring Bob Weigel Andreas Weingessel

Martin Weiser Michael Weitzel David Wells Fook Fah Yap Sean Young Michael Zeising Federico Zenith Alex Zvoleff

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

296 total contributors over all time

How many users Thousands Millions

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1935

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2035

What is Octave Octave and

Octave-Forge

Octave-Forge

Octave Forge Is a place for concurrently developing and distributingextension packages for Octave

Each package has a maintainer responsible for updating andreleasing new versions of the package

Some packages are maintained by The Community

Installation via an integrated package manager

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2135

What is Octave Octave and

PKG

1 gtgt pkg install minusforge miscellaneous2 For information about changes from previous versions of the larr

miscellaneous package run news ( miscellaneous ) 3 gtgt pkg list4 Package Name | Version | Installation directory5 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus6 bim | 1 1 1 | ˜ octavebimminus1117 fpl | 1 3 3 | ˜ octavefplminus1338 general | 1 3 1 | ˜ octavegeneral minus1319 geometry | 1 6 0 | ˜ octavegeometry minus160

10 miscellaneous | 1 2 0 | ˜ octavemiscellaneous minus12011 gtgt pkg load miscellaneous12 gtgt pkg list13 Package Name | Version | Installation directory14 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus15 bim | 1 1 1 | ˜ octavebimminus11116 fpl | 1 3 3 | ˜ octavefplminus13317 general | 1 3 1 | ˜ octavegeneral minus13118 geometry | 1 6 0 | ˜ octavegeometry minus16019 miscellaneous lowast| 1 2 0 | ˜ octavemiscellaneous minus120

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2235

What is Octave Octave and

PKG

1 gtgt pkg describe bim minusverbose2 minusminusminus3 Package name 4 bim5 Version 6 1 1 17 Short description 8 Package f o r solving Diffusion Advection Reaction ( DAR ) Partial larr

Differential Equations9 Status

10 Not loaded11 minusminusminus12 Provides 13 Matrix assembly14 bim1a_advection_diffusion15 bim1a_advection_upwind16 bim2a_advection_diffusion17 18 Preminusprocessing and Postminusprocessing computations19 bim2c_mesh_properties20 21 gtgt

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2335

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2535

What is Octave Octave and

Broadcasting

Since 360 Octave automatically broadcasts arrays when usingelementwise binary operators

Corresponding array dimensions must either be equal or one ofthem must be 1

In case all dimensions are equal ordinary element-by-elementarithmetic takes place

When one of the dimensions is 1 the array with that singletondimension gets copied along that dimension until it matches thedimension of the other array

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2635

What is Octave Octave and

Broadcasting

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Without broadcasting x + y would be an error because dimensions do not agree

With broadcasting it is as if the following operation were performed

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 10 20 3 0 10 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Other notable differences with Matlab listed in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2735

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2835

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 include lto c t a v e o c t hgt2

3 DEFUN_DLD ( dld args nargout dld (array) nreturn the elements of larrthe array in reverse ordern )

4 5 octave_value_list retval 6 int nargin = args length ( ) 7

8 if ( nargin = 1)9 print_usage ( )

10 else11 12 Arrayltdoublegt a = args ( 0 ) array_value ( ) 13 if ( error_state )14 15 Arrayltdoublegt b ( a )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

16 doublelowast ap = a fortran_vec ( ) 17 doublelowast bp = b fortran_vec ( ) 18 for ( octave_idx_type i = a numel ( ) minus 1 j = 0 i gt= 0 larr

iminusminus j++)19 bp [ i ] = ap [ j ] 20 retval = octave_value ( b ) 21 22 23 return retval 24

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 gtgt mkoctfile dld cc2 gtgt a = randn ( 5 )3 a =4

5 0395421 minus1425232 minus0176544 1055205 22293716 minus0241893 0035004 minus0296543 minus1710613 04443187 minus0752467 minus2220469 2380951 0766246 11961538 1404672 0623112 1182609 0196125 06093259 minus0687019 0646079 2239012 minus0495169 1488314

10

11 gtgt b = dld ( a )12 b =13

14 1488314 minus0495169 2239012 0646079 minus068701915 0609325 0196125 1182609 0623112 140467216 1196153 0766246 2380951 minus2220469 minus075246717 0444318 minus1710613 minus0296543 0035004 minus024189318 2229371 1055205 minus0176544 minus1425232 039542119

20 gtgt

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 27: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer15 current Core developers (with write access to repo)49 currently registered rsquoForge developers (38 active)296 total contributors over all timeBen Abbott Andy Adler Giles Anderson Joel Andersson Muthiah Annamalai Marco Atzeri Shai Ayal Roger Banks Ben Barrowes

Alexander Barth David Bateman Heinz Bauschke Roman Belov Karl Berry David Billinghurst Don Bindner Jakub Bogusz Moritz

Borgmann Paul Boven Richard Bovey John Bradshaw Marcus Brinkmann Remy Bruno Ansgar Burchard Marco Caliari Daniel

Calvelo John C Campbell Juan Pablo Carbajal Jean-Francois Cardoso Joao Cardoso Larrie Carr David Castelow Vincent

Cautaerts Clinton Chee Albert Chin-A-Young Carsten Clark J D Cole Martin Costabel Michael Creel Jeff Cunningham Martin

Dalecki Jorge Barros de Abreu Carlo de Falco Jacob Dawid Thomas D Dean Philippe Defert Bill Denney Fabian Deutsch

Christos Dimitrakakis David M Doolin Carne Draug Pascal A Dupuis John W Eaton Dirk Eddelbuettel Pieter Eendebak Paul

Eggert Stephen Eglen Peter Ekberg Rolf Fabian Gunnar Farneback Stephen Fegan Ramon Garcia Fernandez Torsten Finke Jose

Daniel Munoz Frias Brad Froehle Castor Fu Eduardo Gallestey Walter Gautschi Klaus Gebhardt Driss Ghaddab Nicolo Giorgetti

Michael D Godfrey Michael Goffioul Glenn Golden Tomislav Goles Keith Goodman Brian Gough Steffen Groot Etienne

Grossmann David Grundberg Peter Gustafson Kai Habel Patrick Hacker William P Y Hadisoeseno Jaroslav Hajek Benjamin Hall

Kim Hansen Soslashren Hauberg Dave Hawthorne Daniel Heiserer Martin Helm Stefan Hepp Jordi Gutierrez Hermoso Yozo Hida Ryan

Hinton Roman Hodek A Scottedward Hodel Richard Allan Holcombe Tom Holroyd David Hoover Kurt Hornik Christopher

Hulbert Cyril Humbert Teemu Ikonen Alan W Irwin Geoff Jacobsen Mats Jansson Cai Jianming Steven G Johnson Heikki Junes

Matthias Juschke Atsushi Kajita Jarkko Kaleva Mohamed Kamoun Lute Kamstra Fotios Kasolis Thomas Kasper Joel Keay

Mumit Khan Paul Kienzle Aaron A King Arno J Klaassen Alexander Klein Geoffrey Knauth Heine Kolltveit Ken Kouno Kacper

Kowalik Daniel Kraft Aravindh Krishnamoorthy Oyvind Kristiansen Piotr Krzyzanowski Volker Kuhlmann Tetsuro Kurita

Miroslaw Kwasniak Rafael Laboissiere Kai Labusch Claude Lacoursiere Walter Landry Bill Lash Dirk Laurie Maurice LeBrun

Friedrich Leisch Jyh-miin Lin Timo Lindfors Benjamin Lindner Ross Lippert David Livings Sebastien Loisel Erik de Castro Lopo

Massimo Lorenzin Emil Lucretiu Hoxide Ma James Macnicol Jens-Uwe Mager Rob Mahurin Ricardo Marranita Orestes Mas

Makoto Matsumoto Tatsuro Matsuoka Laurent Mazet G D McBain Alexander Mamonov Christoph Mayer Julio Hoffimann

Mendes Thorsten Meyer Petr Mikulik Stefan Monnier Antoine Moreau Kai P Mueller Hannes Muller Victor Munoz Carmen

Navarrete Todd Neal Philip Nienhuis Al Niessner Rick Niles Takuji Nishimura Kai Noda Eric Norum Krzesimir Nowak Michael

OrsquoBrien Peter OrsquoGorman Thorsten Ohl Arno Onken Luis F Ortiz Scott Pakin Gabriele Pannocchia Sylvain Pelissier Per Persson

Primozz Peterlin Jim Peterson Danilo Piazzalunga Nicholas Piper Elias Pipping Robert Platt Hans Ekkehard Plesser Tom Poage

Orion Poplawski Ondrej Popp Jef Poskanzer Francesco Potortı Konstantinos Poulios Jarno Rajahalme James B Rawlings Eric S

Raymond Balint Reczey Joshua Redstone Lukas Reichlin Michael Reifenberger Anthony Richardson Jason Riedy E Joshua Rigler

Petter Risholm Matthew W Roberts Andrew Ross Mark van Rossum Joe Rothweiler Kevin Ruland Kristian Rumberg Ryan

Rusaw Olli Saarela Toni Saarela Juhani Saastamoinen Radek Salac Ben Sapp Aleksej Saushev Alois Schlogl Michel D Schmid

Julian Schnidder Nicol N Schraudolph Sebastian Schubert Ludwig Schwardt Thomas L Scofield Daniel J Sebald Dmitri A

Sergatskov Vanya Sergeev Baylis Shanks Andriy Shinkarchuck Robert T Short Joseph P Skudlarek John Smith Julius Smith

Shan G Smith Peter L Sondergaard Joerg Specht Quentin H Spencer Christoph Spiel Richard Stallman Russell Standish Brett

Stewart Doug Stewart Jonathan Stickel Judd Storrs Thomas Stuart Ivan Sutoris John Swensen Daisuke Takago Ariel Tankus

Matthew Tenny Georg Thimm Duncan Temple Lang Kris Thielemans Olaf Till Christophe Tournery Thomas Treichl Karsten

Trulsen Frederick Umminger Utkarsh Upadhyay Stefan van der Walt Peter Van Wieren James R Van Zandt Gregory Vanuxem

Ivana Varekova Thomas Walter Andreas Weber Olaf Weber Thomas Weber Rik Wehbring Bob Weigel Andreas Weingessel

Martin Weiser Michael Weitzel David Wells Fook Fah Yap Sean Young Michael Zeising Federico Zenith Alex Zvoleff

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

296 total contributors over all time

How many users Thousands Millions

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1935

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2035

What is Octave Octave and

Octave-Forge

Octave-Forge

Octave Forge Is a place for concurrently developing and distributingextension packages for Octave

Each package has a maintainer responsible for updating andreleasing new versions of the package

Some packages are maintained by The Community

Installation via an integrated package manager

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2135

What is Octave Octave and

PKG

1 gtgt pkg install minusforge miscellaneous2 For information about changes from previous versions of the larr

miscellaneous package run news ( miscellaneous ) 3 gtgt pkg list4 Package Name | Version | Installation directory5 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus6 bim | 1 1 1 | ˜ octavebimminus1117 fpl | 1 3 3 | ˜ octavefplminus1338 general | 1 3 1 | ˜ octavegeneral minus1319 geometry | 1 6 0 | ˜ octavegeometry minus160

10 miscellaneous | 1 2 0 | ˜ octavemiscellaneous minus12011 gtgt pkg load miscellaneous12 gtgt pkg list13 Package Name | Version | Installation directory14 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus15 bim | 1 1 1 | ˜ octavebimminus11116 fpl | 1 3 3 | ˜ octavefplminus13317 general | 1 3 1 | ˜ octavegeneral minus13118 geometry | 1 6 0 | ˜ octavegeometry minus16019 miscellaneous lowast| 1 2 0 | ˜ octavemiscellaneous minus120

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2235

What is Octave Octave and

PKG

1 gtgt pkg describe bim minusverbose2 minusminusminus3 Package name 4 bim5 Version 6 1 1 17 Short description 8 Package f o r solving Diffusion Advection Reaction ( DAR ) Partial larr

Differential Equations9 Status

10 Not loaded11 minusminusminus12 Provides 13 Matrix assembly14 bim1a_advection_diffusion15 bim1a_advection_upwind16 bim2a_advection_diffusion17 18 Preminusprocessing and Postminusprocessing computations19 bim2c_mesh_properties20 21 gtgt

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2335

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2535

What is Octave Octave and

Broadcasting

Since 360 Octave automatically broadcasts arrays when usingelementwise binary operators

Corresponding array dimensions must either be equal or one ofthem must be 1

In case all dimensions are equal ordinary element-by-elementarithmetic takes place

When one of the dimensions is 1 the array with that singletondimension gets copied along that dimension until it matches thedimension of the other array

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2635

What is Octave Octave and

Broadcasting

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Without broadcasting x + y would be an error because dimensions do not agree

With broadcasting it is as if the following operation were performed

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 10 20 3 0 10 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Other notable differences with Matlab listed in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2735

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2835

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 include lto c t a v e o c t hgt2

3 DEFUN_DLD ( dld args nargout dld (array) nreturn the elements of larrthe array in reverse ordern )

4 5 octave_value_list retval 6 int nargin = args length ( ) 7

8 if ( nargin = 1)9 print_usage ( )

10 else11 12 Arrayltdoublegt a = args ( 0 ) array_value ( ) 13 if ( error_state )14 15 Arrayltdoublegt b ( a )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

16 doublelowast ap = a fortran_vec ( ) 17 doublelowast bp = b fortran_vec ( ) 18 for ( octave_idx_type i = a numel ( ) minus 1 j = 0 i gt= 0 larr

iminusminus j++)19 bp [ i ] = ap [ j ] 20 retval = octave_value ( b ) 21 22 23 return retval 24

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 gtgt mkoctfile dld cc2 gtgt a = randn ( 5 )3 a =4

5 0395421 minus1425232 minus0176544 1055205 22293716 minus0241893 0035004 minus0296543 minus1710613 04443187 minus0752467 minus2220469 2380951 0766246 11961538 1404672 0623112 1182609 0196125 06093259 minus0687019 0646079 2239012 minus0495169 1488314

10

11 gtgt b = dld ( a )12 b =13

14 1488314 minus0495169 2239012 0646079 minus068701915 0609325 0196125 1182609 0623112 140467216 1196153 0766246 2380951 minus2220469 minus075246717 0444318 minus1710613 minus0296543 0035004 minus024189318 2229371 1055205 minus0176544 minus1425232 039542119

20 gtgt

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 28: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

Social structure

Like all free projects every user is a potential developer

15 current Core developers (with write access to repo)

49 currently registered rsquoForge developers (38 active)

296 total contributors over all time

How many users Thousands Millions

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1635

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1935

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2035

What is Octave Octave and

Octave-Forge

Octave-Forge

Octave Forge Is a place for concurrently developing and distributingextension packages for Octave

Each package has a maintainer responsible for updating andreleasing new versions of the package

Some packages are maintained by The Community

Installation via an integrated package manager

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2135

What is Octave Octave and

PKG

1 gtgt pkg install minusforge miscellaneous2 For information about changes from previous versions of the larr

miscellaneous package run news ( miscellaneous ) 3 gtgt pkg list4 Package Name | Version | Installation directory5 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus6 bim | 1 1 1 | ˜ octavebimminus1117 fpl | 1 3 3 | ˜ octavefplminus1338 general | 1 3 1 | ˜ octavegeneral minus1319 geometry | 1 6 0 | ˜ octavegeometry minus160

10 miscellaneous | 1 2 0 | ˜ octavemiscellaneous minus12011 gtgt pkg load miscellaneous12 gtgt pkg list13 Package Name | Version | Installation directory14 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus15 bim | 1 1 1 | ˜ octavebimminus11116 fpl | 1 3 3 | ˜ octavefplminus13317 general | 1 3 1 | ˜ octavegeneral minus13118 geometry | 1 6 0 | ˜ octavegeometry minus16019 miscellaneous lowast| 1 2 0 | ˜ octavemiscellaneous minus120

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2235

What is Octave Octave and

PKG

1 gtgt pkg describe bim minusverbose2 minusminusminus3 Package name 4 bim5 Version 6 1 1 17 Short description 8 Package f o r solving Diffusion Advection Reaction ( DAR ) Partial larr

Differential Equations9 Status

10 Not loaded11 minusminusminus12 Provides 13 Matrix assembly14 bim1a_advection_diffusion15 bim1a_advection_upwind16 bim2a_advection_diffusion17 18 Preminusprocessing and Postminusprocessing computations19 bim2c_mesh_properties20 21 gtgt

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2335

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2535

What is Octave Octave and

Broadcasting

Since 360 Octave automatically broadcasts arrays when usingelementwise binary operators

Corresponding array dimensions must either be equal or one ofthem must be 1

In case all dimensions are equal ordinary element-by-elementarithmetic takes place

When one of the dimensions is 1 the array with that singletondimension gets copied along that dimension until it matches thedimension of the other array

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2635

What is Octave Octave and

Broadcasting

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Without broadcasting x + y would be an error because dimensions do not agree

With broadcasting it is as if the following operation were performed

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 10 20 3 0 10 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Other notable differences with Matlab listed in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2735

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2835

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 include lto c t a v e o c t hgt2

3 DEFUN_DLD ( dld args nargout dld (array) nreturn the elements of larrthe array in reverse ordern )

4 5 octave_value_list retval 6 int nargin = args length ( ) 7

8 if ( nargin = 1)9 print_usage ( )

10 else11 12 Arrayltdoublegt a = args ( 0 ) array_value ( ) 13 if ( error_state )14 15 Arrayltdoublegt b ( a )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

16 doublelowast ap = a fortran_vec ( ) 17 doublelowast bp = b fortran_vec ( ) 18 for ( octave_idx_type i = a numel ( ) minus 1 j = 0 i gt= 0 larr

iminusminus j++)19 bp [ i ] = ap [ j ] 20 retval = octave_value ( b ) 21 22 23 return retval 24

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 gtgt mkoctfile dld cc2 gtgt a = randn ( 5 )3 a =4

5 0395421 minus1425232 minus0176544 1055205 22293716 minus0241893 0035004 minus0296543 minus1710613 04443187 minus0752467 minus2220469 2380951 0766246 11961538 1404672 0623112 1182609 0196125 06093259 minus0687019 0646079 2239012 minus0495169 1488314

10

11 gtgt b = dld ( a )12 b =13

14 1488314 minus0495169 2239012 0646079 minus068701915 0609325 0196125 1182609 0623112 140467216 1196153 0766246 2380951 minus2220469 minus075246717 0444318 minus1710613 minus0296543 0035004 minus024189318 2229371 1055205 minus0176544 minus1425232 039542119

20 gtgt

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 29: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1935

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2035

What is Octave Octave and

Octave-Forge

Octave-Forge

Octave Forge Is a place for concurrently developing and distributingextension packages for Octave

Each package has a maintainer responsible for updating andreleasing new versions of the package

Some packages are maintained by The Community

Installation via an integrated package manager

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2135

What is Octave Octave and

PKG

1 gtgt pkg install minusforge miscellaneous2 For information about changes from previous versions of the larr

miscellaneous package run news ( miscellaneous ) 3 gtgt pkg list4 Package Name | Version | Installation directory5 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus6 bim | 1 1 1 | ˜ octavebimminus1117 fpl | 1 3 3 | ˜ octavefplminus1338 general | 1 3 1 | ˜ octavegeneral minus1319 geometry | 1 6 0 | ˜ octavegeometry minus160

10 miscellaneous | 1 2 0 | ˜ octavemiscellaneous minus12011 gtgt pkg load miscellaneous12 gtgt pkg list13 Package Name | Version | Installation directory14 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus15 bim | 1 1 1 | ˜ octavebimminus11116 fpl | 1 3 3 | ˜ octavefplminus13317 general | 1 3 1 | ˜ octavegeneral minus13118 geometry | 1 6 0 | ˜ octavegeometry minus16019 miscellaneous lowast| 1 2 0 | ˜ octavemiscellaneous minus120

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2235

What is Octave Octave and

PKG

1 gtgt pkg describe bim minusverbose2 minusminusminus3 Package name 4 bim5 Version 6 1 1 17 Short description 8 Package f o r solving Diffusion Advection Reaction ( DAR ) Partial larr

Differential Equations9 Status

10 Not loaded11 minusminusminus12 Provides 13 Matrix assembly14 bim1a_advection_diffusion15 bim1a_advection_upwind16 bim2a_advection_diffusion17 18 Preminusprocessing and Postminusprocessing computations19 bim2c_mesh_properties20 21 gtgt

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2335

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2535

What is Octave Octave and

Broadcasting

Since 360 Octave automatically broadcasts arrays when usingelementwise binary operators

Corresponding array dimensions must either be equal or one ofthem must be 1

In case all dimensions are equal ordinary element-by-elementarithmetic takes place

When one of the dimensions is 1 the array with that singletondimension gets copied along that dimension until it matches thedimension of the other array

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2635

What is Octave Octave and

Broadcasting

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Without broadcasting x + y would be an error because dimensions do not agree

With broadcasting it is as if the following operation were performed

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 10 20 3 0 10 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Other notable differences with Matlab listed in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2735

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2835

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 include lto c t a v e o c t hgt2

3 DEFUN_DLD ( dld args nargout dld (array) nreturn the elements of larrthe array in reverse ordern )

4 5 octave_value_list retval 6 int nargin = args length ( ) 7

8 if ( nargin = 1)9 print_usage ( )

10 else11 12 Arrayltdoublegt a = args ( 0 ) array_value ( ) 13 if ( error_state )14 15 Arrayltdoublegt b ( a )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

16 doublelowast ap = a fortran_vec ( ) 17 doublelowast bp = b fortran_vec ( ) 18 for ( octave_idx_type i = a numel ( ) minus 1 j = 0 i gt= 0 larr

iminusminus j++)19 bp [ i ] = ap [ j ] 20 retval = octave_value ( b ) 21 22 23 return retval 24

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 gtgt mkoctfile dld cc2 gtgt a = randn ( 5 )3 a =4

5 0395421 minus1425232 minus0176544 1055205 22293716 minus0241893 0035004 minus0296543 minus1710613 04443187 minus0752467 minus2220469 2380951 0766246 11961538 1404672 0623112 1182609 0196125 06093259 minus0687019 0646079 2239012 minus0495169 1488314

10

11 gtgt b = dld ( a )12 b =13

14 1488314 minus0495169 2239012 0646079 minus068701915 0609325 0196125 1182609 0623112 140467216 1196153 0766246 2380951 minus2220469 minus075246717 0444318 minus1710613 minus0296543 0035004 minus024189318 2229371 1055205 minus0176544 minus1425232 039542119

20 gtgt

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 30: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1935

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2035

What is Octave Octave and

Octave-Forge

Octave-Forge

Octave Forge Is a place for concurrently developing and distributingextension packages for Octave

Each package has a maintainer responsible for updating andreleasing new versions of the package

Some packages are maintained by The Community

Installation via an integrated package manager

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2135

What is Octave Octave and

PKG

1 gtgt pkg install minusforge miscellaneous2 For information about changes from previous versions of the larr

miscellaneous package run news ( miscellaneous ) 3 gtgt pkg list4 Package Name | Version | Installation directory5 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus6 bim | 1 1 1 | ˜ octavebimminus1117 fpl | 1 3 3 | ˜ octavefplminus1338 general | 1 3 1 | ˜ octavegeneral minus1319 geometry | 1 6 0 | ˜ octavegeometry minus160

10 miscellaneous | 1 2 0 | ˜ octavemiscellaneous minus12011 gtgt pkg load miscellaneous12 gtgt pkg list13 Package Name | Version | Installation directory14 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus15 bim | 1 1 1 | ˜ octavebimminus11116 fpl | 1 3 3 | ˜ octavefplminus13317 general | 1 3 1 | ˜ octavegeneral minus13118 geometry | 1 6 0 | ˜ octavegeometry minus16019 miscellaneous lowast| 1 2 0 | ˜ octavemiscellaneous minus120

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2235

What is Octave Octave and

PKG

1 gtgt pkg describe bim minusverbose2 minusminusminus3 Package name 4 bim5 Version 6 1 1 17 Short description 8 Package f o r solving Diffusion Advection Reaction ( DAR ) Partial larr

Differential Equations9 Status

10 Not loaded11 minusminusminus12 Provides 13 Matrix assembly14 bim1a_advection_diffusion15 bim1a_advection_upwind16 bim2a_advection_diffusion17 18 Preminusprocessing and Postminusprocessing computations19 bim2c_mesh_properties20 21 gtgt

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2335

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2535

What is Octave Octave and

Broadcasting

Since 360 Octave automatically broadcasts arrays when usingelementwise binary operators

Corresponding array dimensions must either be equal or one ofthem must be 1

In case all dimensions are equal ordinary element-by-elementarithmetic takes place

When one of the dimensions is 1 the array with that singletondimension gets copied along that dimension until it matches thedimension of the other array

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2635

What is Octave Octave and

Broadcasting

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Without broadcasting x + y would be an error because dimensions do not agree

With broadcasting it is as if the following operation were performed

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 10 20 3 0 10 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Other notable differences with Matlab listed in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2735

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2835

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 include lto c t a v e o c t hgt2

3 DEFUN_DLD ( dld args nargout dld (array) nreturn the elements of larrthe array in reverse ordern )

4 5 octave_value_list retval 6 int nargin = args length ( ) 7

8 if ( nargin = 1)9 print_usage ( )

10 else11 12 Arrayltdoublegt a = args ( 0 ) array_value ( ) 13 if ( error_state )14 15 Arrayltdoublegt b ( a )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

16 doublelowast ap = a fortran_vec ( ) 17 doublelowast bp = b fortran_vec ( ) 18 for ( octave_idx_type i = a numel ( ) minus 1 j = 0 i gt= 0 larr

iminusminus j++)19 bp [ i ] = ap [ j ] 20 retval = octave_value ( b ) 21 22 23 return retval 24

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 gtgt mkoctfile dld cc2 gtgt a = randn ( 5 )3 a =4

5 0395421 minus1425232 minus0176544 1055205 22293716 minus0241893 0035004 minus0296543 minus1710613 04443187 minus0752467 minus2220469 2380951 0766246 11961538 1404672 0623112 1182609 0196125 06093259 minus0687019 0646079 2239012 minus0495169 1488314

10

11 gtgt b = dld ( a )12 b =13

14 1488314 minus0495169 2239012 0646079 minus068701915 0609325 0196125 1182609 0623112 140467216 1196153 0766246 2380951 minus2220469 minus075246717 0444318 minus1710613 minus0296543 0035004 minus024189318 2229371 1055205 minus0176544 minus1425232 039542119

20 gtgt

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 31: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

From user to developer

This is a FAQ

How can I contribute

Code (obviously)

Money (pay-what-you-need)

Documentation (especially examples)

Wiki maintenance

Help in the mailing list

Bug reporting

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1735

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1935

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2035

What is Octave Octave and

Octave-Forge

Octave-Forge

Octave Forge Is a place for concurrently developing and distributingextension packages for Octave

Each package has a maintainer responsible for updating andreleasing new versions of the package

Some packages are maintained by The Community

Installation via an integrated package manager

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2135

What is Octave Octave and

PKG

1 gtgt pkg install minusforge miscellaneous2 For information about changes from previous versions of the larr

miscellaneous package run news ( miscellaneous ) 3 gtgt pkg list4 Package Name | Version | Installation directory5 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus6 bim | 1 1 1 | ˜ octavebimminus1117 fpl | 1 3 3 | ˜ octavefplminus1338 general | 1 3 1 | ˜ octavegeneral minus1319 geometry | 1 6 0 | ˜ octavegeometry minus160

10 miscellaneous | 1 2 0 | ˜ octavemiscellaneous minus12011 gtgt pkg load miscellaneous12 gtgt pkg list13 Package Name | Version | Installation directory14 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus15 bim | 1 1 1 | ˜ octavebimminus11116 fpl | 1 3 3 | ˜ octavefplminus13317 general | 1 3 1 | ˜ octavegeneral minus13118 geometry | 1 6 0 | ˜ octavegeometry minus16019 miscellaneous lowast| 1 2 0 | ˜ octavemiscellaneous minus120

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2235

What is Octave Octave and

PKG

1 gtgt pkg describe bim minusverbose2 minusminusminus3 Package name 4 bim5 Version 6 1 1 17 Short description 8 Package f o r solving Diffusion Advection Reaction ( DAR ) Partial larr

Differential Equations9 Status

10 Not loaded11 minusminusminus12 Provides 13 Matrix assembly14 bim1a_advection_diffusion15 bim1a_advection_upwind16 bim2a_advection_diffusion17 18 Preminusprocessing and Postminusprocessing computations19 bim2c_mesh_properties20 21 gtgt

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2335

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2535

What is Octave Octave and

Broadcasting

Since 360 Octave automatically broadcasts arrays when usingelementwise binary operators

Corresponding array dimensions must either be equal or one ofthem must be 1

In case all dimensions are equal ordinary element-by-elementarithmetic takes place

When one of the dimensions is 1 the array with that singletondimension gets copied along that dimension until it matches thedimension of the other array

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2635

What is Octave Octave and

Broadcasting

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Without broadcasting x + y would be an error because dimensions do not agree

With broadcasting it is as if the following operation were performed

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 10 20 3 0 10 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Other notable differences with Matlab listed in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2735

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2835

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 include lto c t a v e o c t hgt2

3 DEFUN_DLD ( dld args nargout dld (array) nreturn the elements of larrthe array in reverse ordern )

4 5 octave_value_list retval 6 int nargin = args length ( ) 7

8 if ( nargin = 1)9 print_usage ( )

10 else11 12 Arrayltdoublegt a = args ( 0 ) array_value ( ) 13 if ( error_state )14 15 Arrayltdoublegt b ( a )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

16 doublelowast ap = a fortran_vec ( ) 17 doublelowast bp = b fortran_vec ( ) 18 for ( octave_idx_type i = a numel ( ) minus 1 j = 0 i gt= 0 larr

iminusminus j++)19 bp [ i ] = ap [ j ] 20 retval = octave_value ( b ) 21 22 23 return retval 24

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 gtgt mkoctfile dld cc2 gtgt a = randn ( 5 )3 a =4

5 0395421 minus1425232 minus0176544 1055205 22293716 minus0241893 0035004 minus0296543 minus1710613 04443187 minus0752467 minus2220469 2380951 0766246 11961538 1404672 0623112 1182609 0196125 06093259 minus0687019 0646079 2239012 minus0495169 1488314

10

11 gtgt b = dld ( a )12 b =13

14 1488314 minus0495169 2239012 0646079 minus068701915 0609325 0196125 1182609 0623112 140467216 1196153 0766246 2380951 minus2220469 minus075246717 0444318 minus1710613 minus0296543 0035004 minus024189318 2229371 1055205 minus0176544 minus1425232 039542119

20 gtgt

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 32: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1935

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2035

What is Octave Octave and

Octave-Forge

Octave-Forge

Octave Forge Is a place for concurrently developing and distributingextension packages for Octave

Each package has a maintainer responsible for updating andreleasing new versions of the package

Some packages are maintained by The Community

Installation via an integrated package manager

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2135

What is Octave Octave and

PKG

1 gtgt pkg install minusforge miscellaneous2 For information about changes from previous versions of the larr

miscellaneous package run news ( miscellaneous ) 3 gtgt pkg list4 Package Name | Version | Installation directory5 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus6 bim | 1 1 1 | ˜ octavebimminus1117 fpl | 1 3 3 | ˜ octavefplminus1338 general | 1 3 1 | ˜ octavegeneral minus1319 geometry | 1 6 0 | ˜ octavegeometry minus160

10 miscellaneous | 1 2 0 | ˜ octavemiscellaneous minus12011 gtgt pkg load miscellaneous12 gtgt pkg list13 Package Name | Version | Installation directory14 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus15 bim | 1 1 1 | ˜ octavebimminus11116 fpl | 1 3 3 | ˜ octavefplminus13317 general | 1 3 1 | ˜ octavegeneral minus13118 geometry | 1 6 0 | ˜ octavegeometry minus16019 miscellaneous lowast| 1 2 0 | ˜ octavemiscellaneous minus120

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2235

What is Octave Octave and

PKG

1 gtgt pkg describe bim minusverbose2 minusminusminus3 Package name 4 bim5 Version 6 1 1 17 Short description 8 Package f o r solving Diffusion Advection Reaction ( DAR ) Partial larr

Differential Equations9 Status

10 Not loaded11 minusminusminus12 Provides 13 Matrix assembly14 bim1a_advection_diffusion15 bim1a_advection_upwind16 bim2a_advection_diffusion17 18 Preminusprocessing and Postminusprocessing computations19 bim2c_mesh_properties20 21 gtgt

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2335

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2535

What is Octave Octave and

Broadcasting

Since 360 Octave automatically broadcasts arrays when usingelementwise binary operators

Corresponding array dimensions must either be equal or one ofthem must be 1

In case all dimensions are equal ordinary element-by-elementarithmetic takes place

When one of the dimensions is 1 the array with that singletondimension gets copied along that dimension until it matches thedimension of the other array

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2635

What is Octave Octave and

Broadcasting

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Without broadcasting x + y would be an error because dimensions do not agree

With broadcasting it is as if the following operation were performed

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 10 20 3 0 10 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Other notable differences with Matlab listed in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2735

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2835

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 include lto c t a v e o c t hgt2

3 DEFUN_DLD ( dld args nargout dld (array) nreturn the elements of larrthe array in reverse ordern )

4 5 octave_value_list retval 6 int nargin = args length ( ) 7

8 if ( nargin = 1)9 print_usage ( )

10 else11 12 Arrayltdoublegt a = args ( 0 ) array_value ( ) 13 if ( error_state )14 15 Arrayltdoublegt b ( a )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

16 doublelowast ap = a fortran_vec ( ) 17 doublelowast bp = b fortran_vec ( ) 18 for ( octave_idx_type i = a numel ( ) minus 1 j = 0 i gt= 0 larr

iminusminus j++)19 bp [ i ] = ap [ j ] 20 retval = octave_value ( b ) 21 22 23 return retval 24

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 gtgt mkoctfile dld cc2 gtgt a = randn ( 5 )3 a =4

5 0395421 minus1425232 minus0176544 1055205 22293716 minus0241893 0035004 minus0296543 minus1710613 04443187 minus0752467 minus2220469 2380951 0766246 11961538 1404672 0623112 1182609 0196125 06093259 minus0687019 0646079 2239012 minus0495169 1488314

10

11 gtgt b = dld ( a )12 b =13

14 1488314 minus0495169 2239012 0646079 minus068701915 0609325 0196125 1182609 0623112 140467216 1196153 0766246 2380951 minus2220469 minus075246717 0444318 minus1710613 minus0296543 0035004 minus024189318 2229371 1055205 minus0176544 minus1425232 039542119

20 gtgt

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 33: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

Student projects

Google Summer of Code

GSoC 2011

Daniel Kraft Profiler

GSoC 2012

Jacob Dawid Qt GUIMax Brister JITBen Lewis Lest Squares Spectral Analysis

European Space Agencyrsquos Summer of Code in Space

SOCIS 2012

Wendy Liu Agora OctaveAndrius Sutas Instrument-Control

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1835

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1935

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2035

What is Octave Octave and

Octave-Forge

Octave-Forge

Octave Forge Is a place for concurrently developing and distributingextension packages for Octave

Each package has a maintainer responsible for updating andreleasing new versions of the package

Some packages are maintained by The Community

Installation via an integrated package manager

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2135

What is Octave Octave and

PKG

1 gtgt pkg install minusforge miscellaneous2 For information about changes from previous versions of the larr

miscellaneous package run news ( miscellaneous ) 3 gtgt pkg list4 Package Name | Version | Installation directory5 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus6 bim | 1 1 1 | ˜ octavebimminus1117 fpl | 1 3 3 | ˜ octavefplminus1338 general | 1 3 1 | ˜ octavegeneral minus1319 geometry | 1 6 0 | ˜ octavegeometry minus160

10 miscellaneous | 1 2 0 | ˜ octavemiscellaneous minus12011 gtgt pkg load miscellaneous12 gtgt pkg list13 Package Name | Version | Installation directory14 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus15 bim | 1 1 1 | ˜ octavebimminus11116 fpl | 1 3 3 | ˜ octavefplminus13317 general | 1 3 1 | ˜ octavegeneral minus13118 geometry | 1 6 0 | ˜ octavegeometry minus16019 miscellaneous lowast| 1 2 0 | ˜ octavemiscellaneous minus120

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2235

What is Octave Octave and

PKG

1 gtgt pkg describe bim minusverbose2 minusminusminus3 Package name 4 bim5 Version 6 1 1 17 Short description 8 Package f o r solving Diffusion Advection Reaction ( DAR ) Partial larr

Differential Equations9 Status

10 Not loaded11 minusminusminus12 Provides 13 Matrix assembly14 bim1a_advection_diffusion15 bim1a_advection_upwind16 bim2a_advection_diffusion17 18 Preminusprocessing and Postminusprocessing computations19 bim2c_mesh_properties20 21 gtgt

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2335

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2535

What is Octave Octave and

Broadcasting

Since 360 Octave automatically broadcasts arrays when usingelementwise binary operators

Corresponding array dimensions must either be equal or one ofthem must be 1

In case all dimensions are equal ordinary element-by-elementarithmetic takes place

When one of the dimensions is 1 the array with that singletondimension gets copied along that dimension until it matches thedimension of the other array

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2635

What is Octave Octave and

Broadcasting

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Without broadcasting x + y would be an error because dimensions do not agree

With broadcasting it is as if the following operation were performed

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 10 20 3 0 10 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Other notable differences with Matlab listed in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2735

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2835

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 include lto c t a v e o c t hgt2

3 DEFUN_DLD ( dld args nargout dld (array) nreturn the elements of larrthe array in reverse ordern )

4 5 octave_value_list retval 6 int nargin = args length ( ) 7

8 if ( nargin = 1)9 print_usage ( )

10 else11 12 Arrayltdoublegt a = args ( 0 ) array_value ( ) 13 if ( error_state )14 15 Arrayltdoublegt b ( a )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

16 doublelowast ap = a fortran_vec ( ) 17 doublelowast bp = b fortran_vec ( ) 18 for ( octave_idx_type i = a numel ( ) minus 1 j = 0 i gt= 0 larr

iminusminus j++)19 bp [ i ] = ap [ j ] 20 retval = octave_value ( b ) 21 22 23 return retval 24

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 gtgt mkoctfile dld cc2 gtgt a = randn ( 5 )3 a =4

5 0395421 minus1425232 minus0176544 1055205 22293716 minus0241893 0035004 minus0296543 minus1710613 04443187 minus0752467 minus2220469 2380951 0766246 11961538 1404672 0623112 1182609 0196125 06093259 minus0687019 0646079 2239012 minus0495169 1488314

10

11 gtgt b = dld ( a )12 b =13

14 1488314 minus0495169 2239012 0646079 minus068701915 0609325 0196125 1182609 0623112 140467216 1196153 0766246 2380951 minus2220469 minus075246717 0444318 minus1710613 minus0296543 0035004 minus024189318 2229371 1055205 minus0176544 minus1425232 039542119

20 gtgt

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 34: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

Outline

1 What is OctaveDefinitionHistoryCommunity dynamics

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 1935

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2035

What is Octave Octave and

Octave-Forge

Octave-Forge

Octave Forge Is a place for concurrently developing and distributingextension packages for Octave

Each package has a maintainer responsible for updating andreleasing new versions of the package

Some packages are maintained by The Community

Installation via an integrated package manager

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2135

What is Octave Octave and

PKG

1 gtgt pkg install minusforge miscellaneous2 For information about changes from previous versions of the larr

miscellaneous package run news ( miscellaneous ) 3 gtgt pkg list4 Package Name | Version | Installation directory5 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus6 bim | 1 1 1 | ˜ octavebimminus1117 fpl | 1 3 3 | ˜ octavefplminus1338 general | 1 3 1 | ˜ octavegeneral minus1319 geometry | 1 6 0 | ˜ octavegeometry minus160

10 miscellaneous | 1 2 0 | ˜ octavemiscellaneous minus12011 gtgt pkg load miscellaneous12 gtgt pkg list13 Package Name | Version | Installation directory14 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus15 bim | 1 1 1 | ˜ octavebimminus11116 fpl | 1 3 3 | ˜ octavefplminus13317 general | 1 3 1 | ˜ octavegeneral minus13118 geometry | 1 6 0 | ˜ octavegeometry minus16019 miscellaneous lowast| 1 2 0 | ˜ octavemiscellaneous minus120

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2235

What is Octave Octave and

PKG

1 gtgt pkg describe bim minusverbose2 minusminusminus3 Package name 4 bim5 Version 6 1 1 17 Short description 8 Package f o r solving Diffusion Advection Reaction ( DAR ) Partial larr

Differential Equations9 Status

10 Not loaded11 minusminusminus12 Provides 13 Matrix assembly14 bim1a_advection_diffusion15 bim1a_advection_upwind16 bim2a_advection_diffusion17 18 Preminusprocessing and Postminusprocessing computations19 bim2c_mesh_properties20 21 gtgt

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2335

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2535

What is Octave Octave and

Broadcasting

Since 360 Octave automatically broadcasts arrays when usingelementwise binary operators

Corresponding array dimensions must either be equal or one ofthem must be 1

In case all dimensions are equal ordinary element-by-elementarithmetic takes place

When one of the dimensions is 1 the array with that singletondimension gets copied along that dimension until it matches thedimension of the other array

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2635

What is Octave Octave and

Broadcasting

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Without broadcasting x + y would be an error because dimensions do not agree

With broadcasting it is as if the following operation were performed

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 10 20 3 0 10 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Other notable differences with Matlab listed in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2735

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2835

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 include lto c t a v e o c t hgt2

3 DEFUN_DLD ( dld args nargout dld (array) nreturn the elements of larrthe array in reverse ordern )

4 5 octave_value_list retval 6 int nargin = args length ( ) 7

8 if ( nargin = 1)9 print_usage ( )

10 else11 12 Arrayltdoublegt a = args ( 0 ) array_value ( ) 13 if ( error_state )14 15 Arrayltdoublegt b ( a )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

16 doublelowast ap = a fortran_vec ( ) 17 doublelowast bp = b fortran_vec ( ) 18 for ( octave_idx_type i = a numel ( ) minus 1 j = 0 i gt= 0 larr

iminusminus j++)19 bp [ i ] = ap [ j ] 20 retval = octave_value ( b ) 21 22 23 return retval 24

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 gtgt mkoctfile dld cc2 gtgt a = randn ( 5 )3 a =4

5 0395421 minus1425232 minus0176544 1055205 22293716 minus0241893 0035004 minus0296543 minus1710613 04443187 minus0752467 minus2220469 2380951 0766246 11961538 1404672 0623112 1182609 0196125 06093259 minus0687019 0646079 2239012 minus0495169 1488314

10

11 gtgt b = dld ( a )12 b =13

14 1488314 minus0495169 2239012 0646079 minus068701915 0609325 0196125 1182609 0623112 140467216 1196153 0766246 2380951 minus2220469 minus075246717 0444318 minus1710613 minus0296543 0035004 minus024189318 2229371 1055205 minus0176544 minus1425232 039542119

20 gtgt

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 35: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2035

What is Octave Octave and

Octave-Forge

Octave-Forge

Octave Forge Is a place for concurrently developing and distributingextension packages for Octave

Each package has a maintainer responsible for updating andreleasing new versions of the package

Some packages are maintained by The Community

Installation via an integrated package manager

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2135

What is Octave Octave and

PKG

1 gtgt pkg install minusforge miscellaneous2 For information about changes from previous versions of the larr

miscellaneous package run news ( miscellaneous ) 3 gtgt pkg list4 Package Name | Version | Installation directory5 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus6 bim | 1 1 1 | ˜ octavebimminus1117 fpl | 1 3 3 | ˜ octavefplminus1338 general | 1 3 1 | ˜ octavegeneral minus1319 geometry | 1 6 0 | ˜ octavegeometry minus160

10 miscellaneous | 1 2 0 | ˜ octavemiscellaneous minus12011 gtgt pkg load miscellaneous12 gtgt pkg list13 Package Name | Version | Installation directory14 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus15 bim | 1 1 1 | ˜ octavebimminus11116 fpl | 1 3 3 | ˜ octavefplminus13317 general | 1 3 1 | ˜ octavegeneral minus13118 geometry | 1 6 0 | ˜ octavegeometry minus16019 miscellaneous lowast| 1 2 0 | ˜ octavemiscellaneous minus120

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2235

What is Octave Octave and

PKG

1 gtgt pkg describe bim minusverbose2 minusminusminus3 Package name 4 bim5 Version 6 1 1 17 Short description 8 Package f o r solving Diffusion Advection Reaction ( DAR ) Partial larr

Differential Equations9 Status

10 Not loaded11 minusminusminus12 Provides 13 Matrix assembly14 bim1a_advection_diffusion15 bim1a_advection_upwind16 bim2a_advection_diffusion17 18 Preminusprocessing and Postminusprocessing computations19 bim2c_mesh_properties20 21 gtgt

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2335

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2535

What is Octave Octave and

Broadcasting

Since 360 Octave automatically broadcasts arrays when usingelementwise binary operators

Corresponding array dimensions must either be equal or one ofthem must be 1

In case all dimensions are equal ordinary element-by-elementarithmetic takes place

When one of the dimensions is 1 the array with that singletondimension gets copied along that dimension until it matches thedimension of the other array

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2635

What is Octave Octave and

Broadcasting

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Without broadcasting x + y would be an error because dimensions do not agree

With broadcasting it is as if the following operation were performed

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 10 20 3 0 10 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Other notable differences with Matlab listed in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2735

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2835

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 include lto c t a v e o c t hgt2

3 DEFUN_DLD ( dld args nargout dld (array) nreturn the elements of larrthe array in reverse ordern )

4 5 octave_value_list retval 6 int nargin = args length ( ) 7

8 if ( nargin = 1)9 print_usage ( )

10 else11 12 Arrayltdoublegt a = args ( 0 ) array_value ( ) 13 if ( error_state )14 15 Arrayltdoublegt b ( a )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

16 doublelowast ap = a fortran_vec ( ) 17 doublelowast bp = b fortran_vec ( ) 18 for ( octave_idx_type i = a numel ( ) minus 1 j = 0 i gt= 0 larr

iminusminus j++)19 bp [ i ] = ap [ j ] 20 retval = octave_value ( b ) 21 22 23 return retval 24

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 gtgt mkoctfile dld cc2 gtgt a = randn ( 5 )3 a =4

5 0395421 minus1425232 minus0176544 1055205 22293716 minus0241893 0035004 minus0296543 minus1710613 04443187 minus0752467 minus2220469 2380951 0766246 11961538 1404672 0623112 1182609 0196125 06093259 minus0687019 0646079 2239012 minus0495169 1488314

10

11 gtgt b = dld ( a )12 b =13

14 1488314 minus0495169 2239012 0646079 minus068701915 0609325 0196125 1182609 0623112 140467216 1196153 0766246 2380951 minus2220469 minus075246717 0444318 minus1710613 minus0296543 0035004 minus024189318 2229371 1055205 minus0176544 minus1425232 039542119

20 gtgt

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 36: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

Octave-Forge

Octave-Forge

Octave Forge Is a place for concurrently developing and distributingextension packages for Octave

Each package has a maintainer responsible for updating andreleasing new versions of the package

Some packages are maintained by The Community

Installation via an integrated package manager

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2135

What is Octave Octave and

PKG

1 gtgt pkg install minusforge miscellaneous2 For information about changes from previous versions of the larr

miscellaneous package run news ( miscellaneous ) 3 gtgt pkg list4 Package Name | Version | Installation directory5 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus6 bim | 1 1 1 | ˜ octavebimminus1117 fpl | 1 3 3 | ˜ octavefplminus1338 general | 1 3 1 | ˜ octavegeneral minus1319 geometry | 1 6 0 | ˜ octavegeometry minus160

10 miscellaneous | 1 2 0 | ˜ octavemiscellaneous minus12011 gtgt pkg load miscellaneous12 gtgt pkg list13 Package Name | Version | Installation directory14 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus15 bim | 1 1 1 | ˜ octavebimminus11116 fpl | 1 3 3 | ˜ octavefplminus13317 general | 1 3 1 | ˜ octavegeneral minus13118 geometry | 1 6 0 | ˜ octavegeometry minus16019 miscellaneous lowast| 1 2 0 | ˜ octavemiscellaneous minus120

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2235

What is Octave Octave and

PKG

1 gtgt pkg describe bim minusverbose2 minusminusminus3 Package name 4 bim5 Version 6 1 1 17 Short description 8 Package f o r solving Diffusion Advection Reaction ( DAR ) Partial larr

Differential Equations9 Status

10 Not loaded11 minusminusminus12 Provides 13 Matrix assembly14 bim1a_advection_diffusion15 bim1a_advection_upwind16 bim2a_advection_diffusion17 18 Preminusprocessing and Postminusprocessing computations19 bim2c_mesh_properties20 21 gtgt

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2335

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2535

What is Octave Octave and

Broadcasting

Since 360 Octave automatically broadcasts arrays when usingelementwise binary operators

Corresponding array dimensions must either be equal or one ofthem must be 1

In case all dimensions are equal ordinary element-by-elementarithmetic takes place

When one of the dimensions is 1 the array with that singletondimension gets copied along that dimension until it matches thedimension of the other array

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2635

What is Octave Octave and

Broadcasting

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Without broadcasting x + y would be an error because dimensions do not agree

With broadcasting it is as if the following operation were performed

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 10 20 3 0 10 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Other notable differences with Matlab listed in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2735

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2835

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 include lto c t a v e o c t hgt2

3 DEFUN_DLD ( dld args nargout dld (array) nreturn the elements of larrthe array in reverse ordern )

4 5 octave_value_list retval 6 int nargin = args length ( ) 7

8 if ( nargin = 1)9 print_usage ( )

10 else11 12 Arrayltdoublegt a = args ( 0 ) array_value ( ) 13 if ( error_state )14 15 Arrayltdoublegt b ( a )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

16 doublelowast ap = a fortran_vec ( ) 17 doublelowast bp = b fortran_vec ( ) 18 for ( octave_idx_type i = a numel ( ) minus 1 j = 0 i gt= 0 larr

iminusminus j++)19 bp [ i ] = ap [ j ] 20 retval = octave_value ( b ) 21 22 23 return retval 24

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 gtgt mkoctfile dld cc2 gtgt a = randn ( 5 )3 a =4

5 0395421 minus1425232 minus0176544 1055205 22293716 minus0241893 0035004 minus0296543 minus1710613 04443187 minus0752467 minus2220469 2380951 0766246 11961538 1404672 0623112 1182609 0196125 06093259 minus0687019 0646079 2239012 minus0495169 1488314

10

11 gtgt b = dld ( a )12 b =13

14 1488314 minus0495169 2239012 0646079 minus068701915 0609325 0196125 1182609 0623112 140467216 1196153 0766246 2380951 minus2220469 minus075246717 0444318 minus1710613 minus0296543 0035004 minus024189318 2229371 1055205 minus0176544 minus1425232 039542119

20 gtgt

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 37: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

PKG

1 gtgt pkg install minusforge miscellaneous2 For information about changes from previous versions of the larr

miscellaneous package run news ( miscellaneous ) 3 gtgt pkg list4 Package Name | Version | Installation directory5 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus6 bim | 1 1 1 | ˜ octavebimminus1117 fpl | 1 3 3 | ˜ octavefplminus1338 general | 1 3 1 | ˜ octavegeneral minus1319 geometry | 1 6 0 | ˜ octavegeometry minus160

10 miscellaneous | 1 2 0 | ˜ octavemiscellaneous minus12011 gtgt pkg load miscellaneous12 gtgt pkg list13 Package Name | Version | Installation directory14 minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminus+minusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminusminus15 bim | 1 1 1 | ˜ octavebimminus11116 fpl | 1 3 3 | ˜ octavefplminus13317 general | 1 3 1 | ˜ octavegeneral minus13118 geometry | 1 6 0 | ˜ octavegeometry minus16019 miscellaneous lowast| 1 2 0 | ˜ octavemiscellaneous minus120

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2235

What is Octave Octave and

PKG

1 gtgt pkg describe bim minusverbose2 minusminusminus3 Package name 4 bim5 Version 6 1 1 17 Short description 8 Package f o r solving Diffusion Advection Reaction ( DAR ) Partial larr

Differential Equations9 Status

10 Not loaded11 minusminusminus12 Provides 13 Matrix assembly14 bim1a_advection_diffusion15 bim1a_advection_upwind16 bim2a_advection_diffusion17 18 Preminusprocessing and Postminusprocessing computations19 bim2c_mesh_properties20 21 gtgt

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2335

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2535

What is Octave Octave and

Broadcasting

Since 360 Octave automatically broadcasts arrays when usingelementwise binary operators

Corresponding array dimensions must either be equal or one ofthem must be 1

In case all dimensions are equal ordinary element-by-elementarithmetic takes place

When one of the dimensions is 1 the array with that singletondimension gets copied along that dimension until it matches thedimension of the other array

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2635

What is Octave Octave and

Broadcasting

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Without broadcasting x + y would be an error because dimensions do not agree

With broadcasting it is as if the following operation were performed

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 10 20 3 0 10 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Other notable differences with Matlab listed in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2735

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2835

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 include lto c t a v e o c t hgt2

3 DEFUN_DLD ( dld args nargout dld (array) nreturn the elements of larrthe array in reverse ordern )

4 5 octave_value_list retval 6 int nargin = args length ( ) 7

8 if ( nargin = 1)9 print_usage ( )

10 else11 12 Arrayltdoublegt a = args ( 0 ) array_value ( ) 13 if ( error_state )14 15 Arrayltdoublegt b ( a )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

16 doublelowast ap = a fortran_vec ( ) 17 doublelowast bp = b fortran_vec ( ) 18 for ( octave_idx_type i = a numel ( ) minus 1 j = 0 i gt= 0 larr

iminusminus j++)19 bp [ i ] = ap [ j ] 20 retval = octave_value ( b ) 21 22 23 return retval 24

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 gtgt mkoctfile dld cc2 gtgt a = randn ( 5 )3 a =4

5 0395421 minus1425232 minus0176544 1055205 22293716 minus0241893 0035004 minus0296543 minus1710613 04443187 minus0752467 minus2220469 2380951 0766246 11961538 1404672 0623112 1182609 0196125 06093259 minus0687019 0646079 2239012 minus0495169 1488314

10

11 gtgt b = dld ( a )12 b =13

14 1488314 minus0495169 2239012 0646079 minus068701915 0609325 0196125 1182609 0623112 140467216 1196153 0766246 2380951 minus2220469 minus075246717 0444318 minus1710613 minus0296543 0035004 minus024189318 2229371 1055205 minus0176544 minus1425232 039542119

20 gtgt

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 38: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

PKG

1 gtgt pkg describe bim minusverbose2 minusminusminus3 Package name 4 bim5 Version 6 1 1 17 Short description 8 Package f o r solving Diffusion Advection Reaction ( DAR ) Partial larr

Differential Equations9 Status

10 Not loaded11 minusminusminus12 Provides 13 Matrix assembly14 bim1a_advection_diffusion15 bim1a_advection_upwind16 bim2a_advection_diffusion17 18 Preminusprocessing and Postminusprocessing computations19 bim2c_mesh_properties20 21 gtgt

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2335

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2535

What is Octave Octave and

Broadcasting

Since 360 Octave automatically broadcasts arrays when usingelementwise binary operators

Corresponding array dimensions must either be equal or one ofthem must be 1

In case all dimensions are equal ordinary element-by-elementarithmetic takes place

When one of the dimensions is 1 the array with that singletondimension gets copied along that dimension until it matches thedimension of the other array

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2635

What is Octave Octave and

Broadcasting

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Without broadcasting x + y would be an error because dimensions do not agree

With broadcasting it is as if the following operation were performed

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 10 20 3 0 10 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Other notable differences with Matlab listed in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2735

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2835

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 include lto c t a v e o c t hgt2

3 DEFUN_DLD ( dld args nargout dld (array) nreturn the elements of larrthe array in reverse ordern )

4 5 octave_value_list retval 6 int nargin = args length ( ) 7

8 if ( nargin = 1)9 print_usage ( )

10 else11 12 Arrayltdoublegt a = args ( 0 ) array_value ( ) 13 if ( error_state )14 15 Arrayltdoublegt b ( a )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

16 doublelowast ap = a fortran_vec ( ) 17 doublelowast bp = b fortran_vec ( ) 18 for ( octave_idx_type i = a numel ( ) minus 1 j = 0 i gt= 0 larr

iminusminus j++)19 bp [ i ] = ap [ j ] 20 retval = octave_value ( b ) 21 22 23 return retval 24

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 gtgt mkoctfile dld cc2 gtgt a = randn ( 5 )3 a =4

5 0395421 minus1425232 minus0176544 1055205 22293716 minus0241893 0035004 minus0296543 minus1710613 04443187 minus0752467 minus2220469 2380951 0766246 11961538 1404672 0623112 1182609 0196125 06093259 minus0687019 0646079 2239012 minus0495169 1488314

10

11 gtgt b = dld ( a )12 b =13

14 1488314 minus0495169 2239012 0646079 minus068701915 0609325 0196125 1182609 0623112 140467216 1196153 0766246 2380951 minus2220469 minus075246717 0444318 minus1710613 minus0296543 0035004 minus024189318 2229371 1055205 minus0176544 minus1425232 039542119

20 gtgt

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 39: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2535

What is Octave Octave and

Broadcasting

Since 360 Octave automatically broadcasts arrays when usingelementwise binary operators

Corresponding array dimensions must either be equal or one ofthem must be 1

In case all dimensions are equal ordinary element-by-elementarithmetic takes place

When one of the dimensions is 1 the array with that singletondimension gets copied along that dimension until it matches thedimension of the other array

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2635

What is Octave Octave and

Broadcasting

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Without broadcasting x + y would be an error because dimensions do not agree

With broadcasting it is as if the following operation were performed

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 10 20 3 0 10 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Other notable differences with Matlab listed in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2735

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2835

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 include lto c t a v e o c t hgt2

3 DEFUN_DLD ( dld args nargout dld (array) nreturn the elements of larrthe array in reverse ordern )

4 5 octave_value_list retval 6 int nargin = args length ( ) 7

8 if ( nargin = 1)9 print_usage ( )

10 else11 12 Arrayltdoublegt a = args ( 0 ) array_value ( ) 13 if ( error_state )14 15 Arrayltdoublegt b ( a )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

16 doublelowast ap = a fortran_vec ( ) 17 doublelowast bp = b fortran_vec ( ) 18 for ( octave_idx_type i = a numel ( ) minus 1 j = 0 i gt= 0 larr

iminusminus j++)19 bp [ i ] = ap [ j ] 20 retval = octave_value ( b ) 21 22 23 return retval 24

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 gtgt mkoctfile dld cc2 gtgt a = randn ( 5 )3 a =4

5 0395421 minus1425232 minus0176544 1055205 22293716 minus0241893 0035004 minus0296543 minus1710613 04443187 minus0752467 minus2220469 2380951 0766246 11961538 1404672 0623112 1182609 0196125 06093259 minus0687019 0646079 2239012 minus0495169 1488314

10

11 gtgt b = dld ( a )12 b =13

14 1488314 minus0495169 2239012 0646079 minus068701915 0609325 0196125 1182609 0623112 140467216 1196153 0766246 2380951 minus2220469 minus075246717 0444318 minus1710613 minus0296543 0035004 minus024189318 2229371 1055205 minus0176544 minus1425232 039542119

20 gtgt

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 40: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2535

What is Octave Octave and

Broadcasting

Since 360 Octave automatically broadcasts arrays when usingelementwise binary operators

Corresponding array dimensions must either be equal or one ofthem must be 1

In case all dimensions are equal ordinary element-by-elementarithmetic takes place

When one of the dimensions is 1 the array with that singletondimension gets copied along that dimension until it matches thedimension of the other array

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2635

What is Octave Octave and

Broadcasting

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Without broadcasting x + y would be an error because dimensions do not agree

With broadcasting it is as if the following operation were performed

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 10 20 3 0 10 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Other notable differences with Matlab listed in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2735

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2835

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 include lto c t a v e o c t hgt2

3 DEFUN_DLD ( dld args nargout dld (array) nreturn the elements of larrthe array in reverse ordern )

4 5 octave_value_list retval 6 int nargin = args length ( ) 7

8 if ( nargin = 1)9 print_usage ( )

10 else11 12 Arrayltdoublegt a = args ( 0 ) array_value ( ) 13 if ( error_state )14 15 Arrayltdoublegt b ( a )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

16 doublelowast ap = a fortran_vec ( ) 17 doublelowast bp = b fortran_vec ( ) 18 for ( octave_idx_type i = a numel ( ) minus 1 j = 0 i gt= 0 larr

iminusminus j++)19 bp [ i ] = ap [ j ] 20 retval = octave_value ( b ) 21 22 23 return retval 24

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 gtgt mkoctfile dld cc2 gtgt a = randn ( 5 )3 a =4

5 0395421 minus1425232 minus0176544 1055205 22293716 minus0241893 0035004 minus0296543 minus1710613 04443187 minus0752467 minus2220469 2380951 0766246 11961538 1404672 0623112 1182609 0196125 06093259 minus0687019 0646079 2239012 minus0495169 1488314

10

11 gtgt b = dld ( a )12 b =13

14 1488314 minus0495169 2239012 0646079 minus068701915 0609325 0196125 1182609 0623112 140467216 1196153 0766246 2380951 minus2220469 minus075246717 0444318 minus1710613 minus0296543 0035004 minus024189318 2229371 1055205 minus0176544 minus1425232 039542119

20 gtgt

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 41: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

Some interesting packages

usage examples in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2435

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2535

What is Octave Octave and

Broadcasting

Since 360 Octave automatically broadcasts arrays when usingelementwise binary operators

Corresponding array dimensions must either be equal or one ofthem must be 1

In case all dimensions are equal ordinary element-by-elementarithmetic takes place

When one of the dimensions is 1 the array with that singletondimension gets copied along that dimension until it matches thedimension of the other array

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2635

What is Octave Octave and

Broadcasting

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Without broadcasting x + y would be an error because dimensions do not agree

With broadcasting it is as if the following operation were performed

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 10 20 3 0 10 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Other notable differences with Matlab listed in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2735

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2835

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 include lto c t a v e o c t hgt2

3 DEFUN_DLD ( dld args nargout dld (array) nreturn the elements of larrthe array in reverse ordern )

4 5 octave_value_list retval 6 int nargin = args length ( ) 7

8 if ( nargin = 1)9 print_usage ( )

10 else11 12 Arrayltdoublegt a = args ( 0 ) array_value ( ) 13 if ( error_state )14 15 Arrayltdoublegt b ( a )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

16 doublelowast ap = a fortran_vec ( ) 17 doublelowast bp = b fortran_vec ( ) 18 for ( octave_idx_type i = a numel ( ) minus 1 j = 0 i gt= 0 larr

iminusminus j++)19 bp [ i ] = ap [ j ] 20 retval = octave_value ( b ) 21 22 23 return retval 24

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 gtgt mkoctfile dld cc2 gtgt a = randn ( 5 )3 a =4

5 0395421 minus1425232 minus0176544 1055205 22293716 minus0241893 0035004 minus0296543 minus1710613 04443187 minus0752467 minus2220469 2380951 0766246 11961538 1404672 0623112 1182609 0196125 06093259 minus0687019 0646079 2239012 minus0495169 1488314

10

11 gtgt b = dld ( a )12 b =13

14 1488314 minus0495169 2239012 0646079 minus068701915 0609325 0196125 1182609 0623112 140467216 1196153 0766246 2380951 minus2220469 minus075246717 0444318 minus1710613 minus0296543 0035004 minus024189318 2229371 1055205 minus0176544 minus1425232 039542119

20 gtgt

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 42: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2535

What is Octave Octave and

Broadcasting

Since 360 Octave automatically broadcasts arrays when usingelementwise binary operators

Corresponding array dimensions must either be equal or one ofthem must be 1

In case all dimensions are equal ordinary element-by-elementarithmetic takes place

When one of the dimensions is 1 the array with that singletondimension gets copied along that dimension until it matches thedimension of the other array

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2635

What is Octave Octave and

Broadcasting

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Without broadcasting x + y would be an error because dimensions do not agree

With broadcasting it is as if the following operation were performed

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 10 20 3 0 10 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Other notable differences with Matlab listed in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2735

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2835

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 include lto c t a v e o c t hgt2

3 DEFUN_DLD ( dld args nargout dld (array) nreturn the elements of larrthe array in reverse ordern )

4 5 octave_value_list retval 6 int nargin = args length ( ) 7

8 if ( nargin = 1)9 print_usage ( )

10 else11 12 Arrayltdoublegt a = args ( 0 ) array_value ( ) 13 if ( error_state )14 15 Arrayltdoublegt b ( a )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

16 doublelowast ap = a fortran_vec ( ) 17 doublelowast bp = b fortran_vec ( ) 18 for ( octave_idx_type i = a numel ( ) minus 1 j = 0 i gt= 0 larr

iminusminus j++)19 bp [ i ] = ap [ j ] 20 retval = octave_value ( b ) 21 22 23 return retval 24

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 gtgt mkoctfile dld cc2 gtgt a = randn ( 5 )3 a =4

5 0395421 minus1425232 minus0176544 1055205 22293716 minus0241893 0035004 minus0296543 minus1710613 04443187 minus0752467 minus2220469 2380951 0766246 11961538 1404672 0623112 1182609 0196125 06093259 minus0687019 0646079 2239012 minus0495169 1488314

10

11 gtgt b = dld ( a )12 b =13

14 1488314 minus0495169 2239012 0646079 minus068701915 0609325 0196125 1182609 0623112 140467216 1196153 0766246 2380951 minus2220469 minus075246717 0444318 minus1710613 minus0296543 0035004 minus024189318 2229371 1055205 minus0176544 minus1425232 039542119

20 gtgt

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 43: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

Broadcasting

Since 360 Octave automatically broadcasts arrays when usingelementwise binary operators

Corresponding array dimensions must either be equal or one ofthem must be 1

In case all dimensions are equal ordinary element-by-elementarithmetic takes place

When one of the dimensions is 1 the array with that singletondimension gets copied along that dimension until it matches thedimension of the other array

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2635

What is Octave Octave and

Broadcasting

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Without broadcasting x + y would be an error because dimensions do not agree

With broadcasting it is as if the following operation were performed

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 10 20 3 0 10 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Other notable differences with Matlab listed in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2735

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2835

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 include lto c t a v e o c t hgt2

3 DEFUN_DLD ( dld args nargout dld (array) nreturn the elements of larrthe array in reverse ordern )

4 5 octave_value_list retval 6 int nargin = args length ( ) 7

8 if ( nargin = 1)9 print_usage ( )

10 else11 12 Arrayltdoublegt a = args ( 0 ) array_value ( ) 13 if ( error_state )14 15 Arrayltdoublegt b ( a )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

16 doublelowast ap = a fortran_vec ( ) 17 doublelowast bp = b fortran_vec ( ) 18 for ( octave_idx_type i = a numel ( ) minus 1 j = 0 i gt= 0 larr

iminusminus j++)19 bp [ i ] = ap [ j ] 20 retval = octave_value ( b ) 21 22 23 return retval 24

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 gtgt mkoctfile dld cc2 gtgt a = randn ( 5 )3 a =4

5 0395421 minus1425232 minus0176544 1055205 22293716 minus0241893 0035004 minus0296543 minus1710613 04443187 minus0752467 minus2220469 2380951 0766246 11961538 1404672 0623112 1182609 0196125 06093259 minus0687019 0646079 2239012 minus0495169 1488314

10

11 gtgt b = dld ( a )12 b =13

14 1488314 minus0495169 2239012 0646079 minus068701915 0609325 0196125 1182609 0623112 140467216 1196153 0766246 2380951 minus2220469 minus075246717 0444318 minus1710613 minus0296543 0035004 minus024189318 2229371 1055205 minus0176544 minus1425232 039542119

20 gtgt

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 44: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

Broadcasting

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Without broadcasting x + y would be an error because dimensions do not agree

With broadcasting it is as if the following operation were performed

1 x = [ 1 2 3 4 5 6 7 8 9 ] 2 y = [ 1 0 20 3 0 10 20 3 0 10 20 3 0 ] 3 x + y4 11 22 335 14 25 366 17 28 39

Other notable differences with Matlab listed in the wiki

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2735

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2835

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 include lto c t a v e o c t hgt2

3 DEFUN_DLD ( dld args nargout dld (array) nreturn the elements of larrthe array in reverse ordern )

4 5 octave_value_list retval 6 int nargin = args length ( ) 7

8 if ( nargin = 1)9 print_usage ( )

10 else11 12 Arrayltdoublegt a = args ( 0 ) array_value ( ) 13 if ( error_state )14 15 Arrayltdoublegt b ( a )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

16 doublelowast ap = a fortran_vec ( ) 17 doublelowast bp = b fortran_vec ( ) 18 for ( octave_idx_type i = a numel ( ) minus 1 j = 0 i gt= 0 larr

iminusminus j++)19 bp [ i ] = ap [ j ] 20 retval = octave_value ( b ) 21 22 23 return retval 24

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 gtgt mkoctfile dld cc2 gtgt a = randn ( 5 )3 a =4

5 0395421 minus1425232 minus0176544 1055205 22293716 minus0241893 0035004 minus0296543 minus1710613 04443187 minus0752467 minus2220469 2380951 0766246 11961538 1404672 0623112 1182609 0196125 06093259 minus0687019 0646079 2239012 minus0495169 1488314

10

11 gtgt b = dld ( a )12 b =13

14 1488314 minus0495169 2239012 0646079 minus068701915 0609325 0196125 1182609 0623112 140467216 1196153 0766246 2380951 minus2220469 minus075246717 0444318 minus1710613 minus0296543 0035004 minus024189318 2229371 1055205 minus0176544 minus1425232 039542119

20 gtgt

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 45: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2835

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 include lto c t a v e o c t hgt2

3 DEFUN_DLD ( dld args nargout dld (array) nreturn the elements of larrthe array in reverse ordern )

4 5 octave_value_list retval 6 int nargin = args length ( ) 7

8 if ( nargin = 1)9 print_usage ( )

10 else11 12 Arrayltdoublegt a = args ( 0 ) array_value ( ) 13 if ( error_state )14 15 Arrayltdoublegt b ( a )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

16 doublelowast ap = a fortran_vec ( ) 17 doublelowast bp = b fortran_vec ( ) 18 for ( octave_idx_type i = a numel ( ) minus 1 j = 0 i gt= 0 larr

iminusminus j++)19 bp [ i ] = ap [ j ] 20 retval = octave_value ( b ) 21 22 23 return retval 24

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 gtgt mkoctfile dld cc2 gtgt a = randn ( 5 )3 a =4

5 0395421 minus1425232 minus0176544 1055205 22293716 minus0241893 0035004 minus0296543 minus1710613 04443187 minus0752467 minus2220469 2380951 0766246 11961538 1404672 0623112 1182609 0196125 06093259 minus0687019 0646079 2239012 minus0495169 1488314

10

11 gtgt b = dld ( a )12 b =13

14 1488314 minus0495169 2239012 0646079 minus068701915 0609325 0196125 1182609 0623112 140467216 1196153 0766246 2380951 minus2220469 minus075246717 0444318 minus1710613 minus0296543 0035004 minus024189318 2229371 1055205 minus0176544 minus1425232 039542119

20 gtgt

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 46: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 include lto c t a v e o c t hgt2

3 DEFUN_DLD ( dld args nargout dld (array) nreturn the elements of larrthe array in reverse ordern )

4 5 octave_value_list retval 6 int nargin = args length ( ) 7

8 if ( nargin = 1)9 print_usage ( )

10 else11 12 Arrayltdoublegt a = args ( 0 ) array_value ( ) 13 if ( error_state )14 15 Arrayltdoublegt b ( a )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

16 doublelowast ap = a fortran_vec ( ) 17 doublelowast bp = b fortran_vec ( ) 18 for ( octave_idx_type i = a numel ( ) minus 1 j = 0 i gt= 0 larr

iminusminus j++)19 bp [ i ] = ap [ j ] 20 retval = octave_value ( b ) 21 22 23 return retval 24

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 gtgt mkoctfile dld cc2 gtgt a = randn ( 5 )3 a =4

5 0395421 minus1425232 minus0176544 1055205 22293716 minus0241893 0035004 minus0296543 minus1710613 04443187 minus0752467 minus2220469 2380951 0766246 11961538 1404672 0623112 1182609 0196125 06093259 minus0687019 0646079 2239012 minus0495169 1488314

10

11 gtgt b = dld ( a )12 b =13

14 1488314 minus0495169 2239012 0646079 minus068701915 0609325 0196125 1182609 0623112 140467216 1196153 0766246 2380951 minus2220469 minus075246717 0444318 minus1710613 minus0296543 0035004 minus024189318 2229371 1055205 minus0176544 minus1425232 039542119

20 gtgt

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 47: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

16 doublelowast ap = a fortran_vec ( ) 17 doublelowast bp = b fortran_vec ( ) 18 for ( octave_idx_type i = a numel ( ) minus 1 j = 0 i gt= 0 larr

iminusminus j++)19 bp [ i ] = ap [ j ] 20 retval = octave_value ( b ) 21 22 23 return retval 24

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 gtgt mkoctfile dld cc2 gtgt a = randn ( 5 )3 a =4

5 0395421 minus1425232 minus0176544 1055205 22293716 minus0241893 0035004 minus0296543 minus1710613 04443187 minus0752467 minus2220469 2380951 0766246 11961538 1404672 0623112 1182609 0196125 06093259 minus0687019 0646079 2239012 minus0495169 1488314

10

11 gtgt b = dld ( a )12 b =13

14 1488314 minus0495169 2239012 0646079 minus068701915 0609325 0196125 1182609 0623112 140467216 1196153 0766246 2380951 minus2220469 minus075246717 0444318 minus1710613 minus0296543 0035004 minus024189318 2229371 1055205 minus0176544 minus1425232 039542119

20 gtgt

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 48: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

dld-functions

Implement an Octave interpreter function in C++

1 gtgt mkoctfile dld cc2 gtgt a = randn ( 5 )3 a =4

5 0395421 minus1425232 minus0176544 1055205 22293716 minus0241893 0035004 minus0296543 minus1710613 04443187 minus0752467 minus2220469 2380951 0766246 11961538 1404672 0623112 1182609 0196125 06093259 minus0687019 0646079 2239012 minus0495169 1488314

10

11 gtgt b = dld ( a )12 b =13

14 1488314 minus0495169 2239012 0646079 minus068701915 0609325 0196125 1182609 0623112 140467216 1196153 0766246 2380951 minus2220469 minus075246717 0444318 minus1710613 minus0296543 0035004 minus024189318 2229371 1055205 minus0176544 minus1425232 039542119

20 gtgt

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 2935

include ltoctaveocthgtDEFUN_DLD(dldargsnargoutdld (array) nreturn the elements of the array in reverse ordern) octave_value_list retval int nargin = argslength () if (nargin = 1) print_usage () else Arrayltdoublegt a = args(0)array_value () if ( error_state) Arrayltdoublegt b (a) double ap = afortran_vec () double bp = bfortran_vec () for (octave_idx_type i = anumel () - 1 j = 0 i gt= 0 i-- j++) bp[i] = ap[j] retval = octave_value (b) return retval

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 49: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3

4 int main ( void )5 6

7 Matrix A ( 4 4) 8 for ( octave_idx_type i = 0 i lt 4 i++)9 for ( octave_idx_type j = 0 j lt 4 j++)

10 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +11 static_castltdoublegt ( j ) + 1 0 ) 12

13 ColumnVector b ( 4 1 0 ) 14 ColumnVector x = A solve ( b ) 15

16 std cout ltlt A = ltlt std endl ltlt A ltlt std endl17 ltlt b = ltlt std endl ltlt b ltlt std endl18 ltlt x = ltlt std endl ltlt x ltlt std endl 19

20 return 0 21

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 50: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

liboctave

Use Octaversquos MatrixArray Classes in a C++ application

1 $ mkoctfile minusminuslinkminusstandminusalone standalone cc2 $ a out3 A =4 1 0 5 0 333333 0 2 55 0 5 0 333333 0 2 5 0 26 0333333 0 2 5 0 2 0 1666677 0 2 5 0 2 0 166667 01428578 b =9 1

10 111 112 113 x =14 minus415 6016 minus18017 140

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3035

include ltiostreamgtinclude ltoctaveocthgtint main (void) Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 10) ColumnVector b (4 10) ColumnVector x = Asolve (b) stdcout ltlt A = ltlt stdendl ltlt A ltlt stdendl ltlt b = ltlt stdendl ltlt b ltlt stdendl ltlt x = ltlt stdendl ltlt x ltlt stdendl return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 51: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

1 include lti o s t r e a mgt2 include lto c t a v e o c t hgt3 include lto c t a v e o c t a v e hgt4 include lto c t a v e p a r s e hgt5

6 int main ( void )7 8 string_vector octave_argv ( 2 ) 9 octave_argv ( 0 ) = embedded

10 octave_argv ( 1 ) = -q 11

12 octave_main ( 2 octave_argv c_str_vec ( ) 1) 13

14

15 octave_value_list out = feval ( version octave_value_list ( ) larr1)

16 std cout ltlt out ( 0 ) string_value ( ) ltlt std endl

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 52: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

Embedding Octave

You can embed the Octave interpreter in your C++ application

18 Matrix A ( 4 4) 19 for ( octave_idx_type i = 0 i lt 4 i++)20 for ( octave_idx_type j = 0 j lt 4 j++)21 A (i j ) = 1 0 ( static_castltdoublegt ( i ) +22 static_castltdoublegt ( j ) + 1) 23

24 ColumnVector b ( 4 1 0 ) 25

26 out = feval ( mldivide octave_value ( A ) octave_value ( b ) 1) 27

28 return 0 29

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3135

include ltiostreamgtinclude ltoctaveocthgtinclude ltoctaveoctavehgtinclude ltoctaveparsehgtint main (void) string_vector octave_argv (2) octave_argv(0) = embedded octave_argv(1) = -q octave_main (2 octave_argvc_str_vec () 1) octave_value_list out = feval (version octave_value_list () 1) stdcout ltlt out(0)string_value () ltlt stdendl Matrix A (4 4) for (octave_idx_type i = 0 i lt 4 i++) for (octave_idx_type j = 0 j lt 4 j++) A(ij) = 10 (static_castltdoublegt (i) + static_castltdoublegt (j) + 1) ColumnVector b (4 10) out = feval (mldivide octave_value (A) octave_value (b) 1) return 0

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 53: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

An advanced example

Add a new class to the Octave interpreter and work around Octaversquospass-by-value semantics

source code of the example (cc)

source code of the example (h)

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3235

examplesmyobjectcc

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt

This program is free software you can redistribute it andor modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation either version 3 of the License or (at your option) any later
version

This program is distributed in the hope that it will be useful but WITHOUT
ANY WARRANTY without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more
details

You should have received a copy of the GNU General Public License along with
this program if not see lthttpwwwgnuorglicensesgt

include lt octave oct h gt
include lt myobject h gt

void load_myobject_type ()

myobject register_type ()
myobject_type_loaded = true
mlock ()
std cout ltlt myobject_type_loaded ltlt std endl


const std string amp myobject get_str () const
return str


void myobject set_str ( std string amp _str )
str = _str


PKG_ADD autoload (myobject_get_str myobjectoct)
DEFUN_DLD ( myobject_get_str args
get the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 1 || nargin gt 1 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject amp mo = static_cast lt const myobject ampgt ( args ( 0 ) get_rep ())
retval = octave_value ( mo get_str ())


return retval


PKG_ADD autoload (myobject_init myobjectoct)
DEFUN_DLD ( myobject_init args initialize a myobject )

octave_value retval = 0

octave_idx_type nargin = args length ()
if ( nargin = 3 )
print_usage ()
else

if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 0 ) string_value ()
int i = args ( 1 ) int_value ()
double dbl = args ( 2 ) double_value ()

if ( error_state )

retval = new myobject ( str i dbl )


return retval



PKG_ADD autoload (myobject_set_str myobjectoct)
DEFUN_DLD ( myobject_set_str args nargout
set the str field )

octave_value retval
octave_idx_type nargin = args length ()
if ( nargin lt 2 || nargin gt 2 )
print_usage ()
else


if ( myobject_type_loaded )
load_myobject_type ()

std string str = args ( 1 ) string_value ()
if ( args ( 0 ) type_id () == myobject static_type_id ())

const myobject mo ( static_cast lt const myobject ampgt ( args ( 0 ) get_rep ()))
( mo p_str ) = str


return retval

Copyright (C) 2012 Carlo de Falco ltcarlodefalcogmailcomgt This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with this program if not see lthttpwwwgnuorglicensesgtinclude ltoctaveocthgtclass myobject public octave_base_value public Constructor myobject (const stdstring _str = const int _intgr = 0 const double _dbl = 00) octave_base_value () str (_str) intgr (_intgr) dbl (_dbl) p_str = ampstr void print (stdostreamamp os bool pr_as_read_syntax = false) const os ltlt str ltlt str ltlt stdendl ltlt intgr ltlt intgr ltlt stdendl ltlt dbl ltlt dbl ltlt stdendl ~myobject(void) bool is_defined (void) const return true const stdstring amp get_str (void) const const int amp get_intgr (void) const const double amp get_dbl (void) const stdstring p_str void set_str (stdstring amp str) void set_intgr (int amp intgr) void set_dbl (double amp dbl) private stdstring str int intgr double dbl DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATADEFINE_OCTAVE_ALLOCATOR (myobject)DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (myobject myobject myobject)static bool myobject_type_loaded = false

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 54: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

Outline

2 Octave and Octave and Octave-ForgeOctave and MatlabOctave and C++Octave and Parallel Computing

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3335

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 55: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 tic ( ) 2 nel = 1 0 0 3 U0 = randn (2 00 1) 4 us = zeros (1 01 200) 5 for ii=1numel ( U0 )6

7 x = transpose ( linspace ( 0 1 nel+1) ) 8 A = bim1a_laplacian (x 1 1) 9 b = bim1a_rhs (x 1 1)

10

11 us ( ii ) = zeros ( size ( x ) ) 12 us ( 1 ii ) = U0 ( ii ) 13

14 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast us ( [ 1 end ] ii ) )

15 us ( 2 endminus1ii ) = fsolve ( res us ( 2 endminus1ii ) ) 16

17 endfor18 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 56: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

parcellfun and pararrayfun

Parcellfun is distributed in the package ldquogeneralrdquo it implements parallelization via fork () andpipe ()

1 function u = poisson1d ( u0 )2 nel = 1 0 0 3 x = transpose ( linspace ( 0 1 nel+1) ) 4 A = bim1a_laplacian (x 1 1) 5 b = bim1a_rhs (x 1 1) 6

7 u = zeros ( size ( x ) ) 8 u ( 1 ) = u0 9

10 res = ( X ) A ( 2 endminus1 2 endminus1) lowast X minus ( b ( 2 endminus1) minus A ( 2 endminus1 [ 1larrend ] ) lowast u ( [ 1 end ] ) )

11 u ( 2 endminus1) = fsolve ( res u ( 2 endminus1) ) 12 endfunction13 tic ( ) 14 U0 = num2cell ( randn ( 1 200) ) 15 up = parcellfun ( 2 poisson1d U0 UniformOutput true larr

VerboseLevel 2) 16 toc ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3435

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 57: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 58: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 T=clock 2 MPI_ANY_SOURCE = minus13 MPI_Init ( ) 4 MPI_COMM_WORLD = MPI_Comm_Load ( NEWORLD ) 5 rnk = MPI_Comm_rank ( MPI_COMM_WORLD ) 6 siz = MPI_Comm_size ( MPI_COMM_WORLD ) 7 SLV = logical ( rnk ) 8 MST = ˜ SLV 9 width=1N lsum=0

10 i=rnk siz Nminus111 x=(i+05)lowastwidth 12 lsum=sum (4(1+ x ˆ 2 ) ) 13 TAG=714 if SLV15 MPI_Send ( lsum 0 TAG MPI_COMM_WORLD ) 16 else17 Sum =lsum 18 for slv=1sizminus119 lsum = MPI_Recv ( MPI_ANY_SOURCE TAG MPI_COMM_WORLD ) 20 Sum += lsum 21 endfor22 endif23 MPI_Finalize ( )

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing
Page 59: GNU Octave A free high-level tool for Scientific Computing · 2012-11-08 · GNU Octave A free high-level tool for Scienti c Computing Carlo de Falco, Jordi Guti errez Hermoso November

What is Octave Octave and

openmpi ext

The package openmpi ext provides wrappers for the main MPI functions in openmpi

1 mpirun minusminushostfile $HOSTFILE minusnp $NUMBER_OF_MPI_NODES octave minusminusevallarrpkg load openmpi_ext Pi ()

source code of the example

cdf jgh mdash GNU Octave A free high-level tool for Scientific Computing 3535

Copyright (C) 2011 Carlo de Falco This program is free software you can redistribute it andor modify it under the terms of the GNU General Public License as published by the Free Software Foundation either version 3 of the License or (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details You should have received a copy of the GNU General Public License along with Octave see the file COPYING If not see lthttpwwwgnuorglicensesgt Author Carlo de Falco ltcarloguglielmolocalgt Created 2011-12-24 you need at least version 34 of Octave to run this scriptclear allclose all uncomment the following line if you dont have the required packages installed pkg install -forge general bim fpl msh splinespkg load general bim fpl msh splines SERIAL VERSIONtic ()nel = 100U0 = randn (200 1)us = zeros (101 200)for ii=1numel (U0) x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) us(ii) = zeros (size (x)) us(1ii) = U0(ii) res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) us([1 end] ii)) us(2end-1ii) = fsolve (res us(2end-1ii))endfortoc () PARALLEL VERSION solve - u + exp (u) = 1 in (0 1) with u(0)=u0 and u(1)=0function u = poisson1d (u0) nel = 100 x = transpose (linspace (0 1 nel+1)) A = bim1a_laplacian (x 1 1) b = bim1a_rhs (x 1 1) u = zeros (size (x)) u(1) = u0 res = (X) A(2end-1 2end-1) X - (b(2end-1) - A(2end-1 [1 end]) u([1 end])) u(2end-1) = fsolve (res u(2end-1))endfunctiontic ()U0 = num2cell (randn (1 200))up = parcellfun (2 poisson1d U0 UniformOutput true VerboseLevel 2)toc ()subplot (1 2 1)plot (x us)subplot (1 2 2)plot (x up)

  • What is Octave
    • Definition
    • History
    • Community dynamics
      • Octave and
        • Octave and Octave-Forge
        • Octave and Matlab
        • Octave and C++
        • Octave and Parallel Computing