Julian Mehne

A worker index implementation for octave.

Matlab can identify the current worker id with get(getCurrentTask(), 'ID'). While Octave does not even natively support parallel computing, the parallel package offers some parallel capabilities, but does not support labindex. So, I hacked my own solution (that currently only works on Linux).

tl;dr: give me the code

My oct_labindex package consists of the following pieces:

To use it, add the oct_labindex.init_worker() call to your ~/.octaverc startup file, load the parallel package, call oct_labindex.init() and run a parallel function:

% For proper usage, obviously add the functions to your path.
% Call `oct_labindex.init_worker()` from your `~/.octaverc` startup file
cd src
pkg('load', 'parallel');
n_workers = 2;
oct_labindex.init(n_workers);
pararrayfun(n_workers, @() disp(oct_labindex.get_labindex()), 1:10)

which returns the labindex for each evaluation:

 1
 2
 1
 2
 1
 2
 1
 2
 1
 2