Chapter 8. NetSolve Request Farming

Table of Contents
How to call farming
An example
Catching errors
Current Implementation and Future Improvements

Farming is a new 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. Previously, the way to do this in NetSolve was to write non-blocking calls to netslnb() in C for instance. However, this becomes very cumbersome. Not only because the user must manage all of the requests himself, but also because the NetSolve system is at a loss trying to manage such a large number of requests without flooding the servers. This is the motivation for distributing a new call in NetSolve: netsl_farm(). In the present distribution, this call is only available from C, but will soon be made available from Matlab, Mathematica, and Java. A Fortran interface will most likely not be provided because of pointer management. For now, linking to the C NetSolve client library (generated as explained in the section called Installation on Unix Systems in Chapter 3) makes netsl_farm() available from the user's program.

How to call farming

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:

  1. a pointer to an integer array (int *);

  2. 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:

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

  2. 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.