High-Performance Computing at the NIH
GitHub YouTube @nih_hpc RSS Feed
Octave on NIH HPC Systems

Octave logo

GNU Octave is a high-level language, primarily intended for numerical computations. It provides a convenient command line interface for solving linear and nonlinear problems numerically, and for performing other numerical experiments using a language that is mostly compatible with Matlab. It may also be used as a batch-oriented language.

Many, but not all, Matlab .m scripts will run in Octave. MEX files (to call custom C or Fortran routines directly from Matlab) can be executed in Octave with some limitations.

Octave runs are typically slower than the equivalent Matlab run. However, Octave is not license-limited, so many more simultaneous runs are possible than with Matlab. Thus, on the Biowulf cluster Octave is most useful for projects which can be split into large numbers of independent simultaneous runs.

Octave has a large set of dependencies, so it is best to set up your Octave environment with module load octave/version, as in the examples below.

Note that the following libraries are currently not available with Octave on Helix/Biowulf. If you need them, let us know by sending email to staff@hpc.nih.gov and we'll look into installing them.

OSMesa library: Offscreen rendering with OpenGL will be disabled.
Qscintilla library: Built-in GUI editor is disabled.

On Helix

By default, if you load the octave module and type 'octave', you will start up the Octave GUI. Sample session:

helix% module load octave
[+] Loading java 1.8.0_11 ...
[+] Loading LAPACK 3.5.0-gcc-4.4.7 libraries...
[+] Loading Octave 4.0.2 ...

helix% octave


Batch Job on Biowulf
  1. Create an Octave script. The following sample script takes a single argument from the command line.
    -------------file array.oct-------------------------------
    #!/bin/env octave -qf
    if( nargin != 1 )
        printf( "Usage: %s <integer>\n", program_name );
    len = str2num( argv(){1} );
    printf( "Working with array size %6d\n", len );
    clear a; 
    for i=1:len
        a(i) = i; 
    time1 = toc();
    a = [1]; 
    for i=2:len 
        a = [a i]; 
    time2 = toc();
    printf( "The time taken for method 1 was %.4f seconds\n", time1 );
    printf( "The time taken for method 2 was %.4f seconds\n", time2 );

  2. Create a batch script for the job. Sample script:
    -------- file array.bat----------------------
    module load octave/4.0.2
    cd /data/user/mydir
    ./array.oct 10000 

  3. Submit this job to the batch system with:
    sbatch  array.bat
The standard output and standard error from the Octave job will appear in the file slurm-#####.out, where ###### is the job number. To redirect only the Octave output into a file, you would use the following command in your array.bat file:
./array.oct 10000 > filename.out
in the batch script above.

Submitting a swarm of Octave jobs

Octave on Biowulf is most useful for running large numbers of simultaneous independent jobs via the swarm program.

  1. Create a swarm command file, with one line for each command you wish to run. In the following example, a swarm of jobs runs the same Octave script array.oct with different input parameters.
    module load octave; /data/user/mydir/array.oct 1000 > array.out.1000
    module load octave; /data/user/mydir/array.oct 2000 > array.out.2000
    module load octave; /data/user/mydir/array.oct 3000 > array.out.3000
    module load octave; /data/user/mydir/array.oct 20000 > array.out.20000
  2. Submit this to the swarm program with the swarm utility. Sample session:
    [user@biowulf octave]$ swarm -f swarm.cmd --module octave
    [user@biowulf octave]$
The swarm program will submit the jobs, the Octave output will appear in the specified files, and the standard error and output will appear in files called swarm_17985924_1.o etc. [More about swarm]

Using Octave interactively on Biowulf

For debugging purposes, it is also possible to run Octave interactively. An interactive node should be allocated for this purpose. Sample session (user input in bold):

[susanc@biowulf ~]$ sinteractive
salloc.exe: Pending job allocation 17961915
salloc.exe: job 17961915 queued and waiting for resources
salloc.exe: job 17961915 has been allocated resources
salloc.exe: Granted job allocation 17961915
salloc.exe: Waiting for resource configuration
salloc.exe: Nodes cn1517 are ready for job

[susanc@cn1517 ~]$ octave --no-gui
warning: function ./test.m shadows a core library function
GNU Octave, version 4.0.2
Copyright (C) 2016 John W. Eaton and others.
This is free software; see the source code for copying conditions.
FITNESS FOR A PARTICULAR PURPOSE.  For details, type 'warranty'.

Octave was configured for "x86_64-unknown-linux-gnu".

Additional information about Octave is available at http://www.octave.org.

Please contribute if you find this software useful.
For more information, visit http://www.octave.org/get-involved.html

Read http://www.octave.org/bugs.html to learn how to submit bug reports.
For information about changes from previous versions, type 'news'.

a =  2
octave:2>  sin(a)
ans = -0.27942
octave:3> a=5*pi
x =  15.708
octave:4> sin(a)
ans =  6.1230e-16
octave:6> quit
[susanc@p226 ~]$ exit

[susanc@cn1517 ~]$ exit
salloc.exe: Relinquishing job allocation 17961915
[susanc@biowulf ~]$

Octave Packages

If you have a particular package from the Octave-Forge project that you need installed, let us know. To see the centrally installed packages, use pkg list e.g.

octave:3> pkg list
Package Name  | Version | Installation directory
     control  |   2.8.2 | /usr/local/apps/octave/4.0.2/share/octave/packages/control-2.8.2
       image  |   2.0.0 | /usr/local/apps/octave/4.0.2/share/octave/packages/image-2.0.0
      signal  |   1.3.2 | /usr/local/apps/octave/4.0.2/share/octave/packages/signal-1.3.2

You can also install your own Octave tool-boxes in your home directory with pkg install. e.g.
octave:1> pkg install -forge fpl
For information about changes from previous versions of the fpl package, run 'news fpl'.

octave:2> pkg list
Package Name  | Version | Installation directory
     control  |   2.8.2 | /usr/local/apps/octave/4.0.2/share/octave/packages/control-2.8.2
         fpl  |   1.3.5 | /home/teacher/octave/fpl-1.3.5
       image  |   2.0.0 | /usr/local/apps/octave/4.0.2/share/octave/packages/image-2.0.0
      signal  |   1.3.2 | /usr/local/apps/octave/4.0.2/share/octave/packages/signal-1.3.2