This file is indexed.

/usr/share/octave/packages/parallel-2.2.0/bw_start.m is in octave-parallel 2.2.0-1build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
## Copyright (C) 2009 Olaf Till <i7tiol@t-online.de>
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR 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 <http://www.gnu.org/licenses/>.

## -*- texinfo -*-
## @deftypefn {Function File} {} bw_start ()
## @deftypefnx {Function File} {} bw_start (@var{f}, @var{argfile})
## Start parallel computation in a beowulf cluster.
##
## With no arguments, restart all unfinished jobs.
##
## With two arguments, (re)start job. String @var{f} names a function to
## be started multiple times in parallel. @var{argfile} names a data-file in
## the configured data directory containing a one-dimensional cell-array
## with arguments for @var{f}, one entry for each invocation of @var{f}. @var{f}
## must be of one of the following forms
##
## @example
## function @var{ret} = f (@var{args})
##
## function @var{ret} = f (@var{args}, @var{idx})
## @end example
##
## where @var{args} is an entry of the argument cell-array, @var{idx} is the
## index of this entry, and @var{ret} contains the result of computation.
##
## Users can put configuration commands into the file "~/.bwrc".
## Variable "data_dir" contains the configured data directory, default
## is "~/bw-data/". Directory given in variable "state_dir", default
## "~/.bw-state/", is used internally to read and write state
## information. If this directory does not exist it is created, which
## will fail if there would be more than one level to create.
## @seealso {bw_list, bw_retrieve, bw_clear}
## @end deftypefn

function bw_start (varargin)

  if ((nargs = length (varargin)) > 2 || nargs == 1)
    error "bw_start: incorrect number of arguments";
  endif
  for id = 1:nargs
    if (! ischar (varargin{id}) || size (varargin{id}, 1) > 1)
      error ("bw_start: argument %i not a (single) string", id);
    endif
  endfor

  ## default directories
  data_dir = tilde_expand ("~/bw-data/");
  state_dir = tilde_expand ("~/.bw-state/");

  ## configuration files
  systemrc = fullfile (OCTAVE_HOME (), "share/octave/site/m/startup/bwrc");
  userrc = "~/.bwrc";

  ## Read system-wide configuration, should provide
  ## "computing_machines", a cell-array with addresses, and
  ## "central_machine", a single address.
  source (systemrc);
  if (! exist ("central_machine"))
    error ("bw_start: system configuration file should give \"central_machine\"");
  endif

  ## Read per-user configuration.
  if (! isempty (stat (userrc)))
    source (userrc);
  endif
  data_dir = tilde_expand (data_dir);
  state_dir = tilde_expand (state_dir);

  if (isempty (stat (state_dir)))
    mkdir (state_dir);
  endif

  if (nargs == 2)
    job_tbl = {varargin{1}, varargin{2}};
    n_j = 1;
    state_files = {(sprintf ("%s-%s.state", job_tbl{1}, job_tbl{2}))};
  else
    n_j = length ...
        ((state_files = glob (fullfile (state_dir, "*.state"))));
    job_tbl = cell (n_j, 2);
    for id = 1:n_j
      [discarded, discarded, discarded, tp] = ...
          regexp (state_files{id}, "[^/]+$");
      state_files{id} = tp{1};
      job_tbl(id, :) = cellstr (split (state_files{id}, "-", 2))';
      job_tbl{id, 2} = regexprep (job_tbl{id, 2}, '\.state$', "");
    endfor
  endif

  n_s = 0;
  for id = 1:n_j
    if (nargs == 2 && ...
        isempty (stat (fullfile (state_dir, state_files{1}))))
      ready = 0;
    elseif (all (__bw_load_variable__ ...
                 (fullfile (state_dir, state_files{id})) . ...
                 ready))
      ready = 1;
    else
      ready = 0;
    endif
    if (! ready)
      if ((tp = exist (job_tbl{id, 1})) < 2 || tp > 5)
        error ("bw_start: no function %s", job_tbl{id, 1});
      endif
      if (isempty (stat (fullfile (data_dir, job_tbl{id, 2}))))
        error ("bw_start: no such file %s", ...
               fullfile (data_dir, job_tb{id, 2}));
      endif
      n_s++;
      [estat, output] = ...
          system (sprintf ("ssh %s \"nohup octave -q --eval \\\"__bw_scheduler__ (\\\\\\\"%s\\\\\\\", \\\\\\\"%s\\\\\\\")\\\" &> /dev/null &\"", ...
                           central_machine, ...
                           job_tbl{id, 1}, ...
                           job_tbl{id, 2}));
      if (estat == 0)
        printf ("function %s, datafile %s: job started\n", ...
                job_tbl{id, 1}, job_tbl{id, 2});
      else
        error ("function %s, datafile %s: ssh returned exit status %i, output: %s", ...
               job_tbl{id, 1}, job_tbl{id, 2}, estat, output);
      endif
    endif
  endfor

  if (nargs == 2 && n_s == 0)
    printf ("bw_start: computation is ready\n");
  endif

endfunction