Chapter 8. NetSolve Request Farming

Farming is a way of calling NetSolve to manage large numbers
of requests for a single NetSolve problem. Many NetSolve users
are confronted by situations when many somewhat similar computations
must be performed in parallel. One way to do this in NetSolve is
to write non-blocking calls to netslnb() in C for instance.
However,
this can become cumbersome. In the present distribution,
this call, netsl_farm(), is only available from C and Matlab. A Fortran
interface will most likely not be provided because of pointer management.

Calling Farming in C

Like netsl() and netslnb(),
the netsl_farm() function takes a variable number of arguments.
Its first argument is a string that describes the iteration range.
This string is of the form "i=%d,%d" (in C string format
symbols). The second argument is a problem name appended
with an opening and a closing parenthesis. The arguments following
are similar in intent to the ones supplied to netsl(), but
are iterators as opposed to integers or pointers. Where the
user was passing, say an integer, to netsl(), he now needs
to pass an array of integers and tell netsl_farm() which
element of this array is to be used for which iteration. This information
is encapsulated in an iterator and we provide three functions to
generate iterators:

ns_int()

ns_int_array()

ns_ptr_array()

Let us review these functions one by one.

ns_int()

This function takes only one argument: a character string that
contains an expression that is evaluated to an integer
at each iteration. The format of that string is based on a Shell
syntax. $i represents the current iteration index, and classic
arithmetic operators are allowed.
For instance:

ns_int("$i+1")

returns an iterator that generates an integer equal to one plus the
current iteration index at each iteration.

ns_int_array()

This function takes two arguments:

a pointer to an integer array (int *);

a character string that contains an expression.

For instance,

ns_int_array(ptr,"$i")

returns an iterator that generates at each iteration an integer equal to the i-th element
of the array ptr where i is the current iteration index.

ns_ptr_array()

This function takes two arguments:

a pointer to an array of
pointers (void **);

a character string that contains an expression.

For instance,

ns_ptr_array(ptr,"$i")

returns an iterator that generates at each iteration a pointer which is the
i-th element of the array ptr
where i is the current iteration index.