An example

Let us assume that the user wants to sort an array of integers with NetSolve using the C interface. The default NetSolve server comes with a default problem called iqsort that does a quicksort on an integer vector. The call looks like
status = netsl('iqsort()',size,ptr,sorted);
where size is the size of the array to be sorted, ptr is a pointer to the first element of the array, and sorted is a pointer to the memory space that will hold the sorted array on return. What if the user wants to sort 200 arrays? One way is to write 200 calls as the one above. Not only would it be tedious, but also inefficient as the sorts would be done successively, with no parallelism. In order to obtain some parallelism, one must call netslnb() and make the corresponding calls to netslpr() and netslwt() as explained in Chapter 5. Again, this is tedious and as it is a rather common situation we decided to address it with netsl_farm(). Before calling netsl_farm(), the user needs to construct arrays of pointers and integers that contain the arguments of each of the NetSolve calls. This is straightforward: where the user would have called NetSolve as:
requests1 = netslnb('iqsort',size1,ptr1,sorted1); 
requests2 = netslnb('iqsort',size2,ptr2,sorted2); 
...
requests200 = netslnb('iqsort',size200,array200,sorted200); 
and then to have calls to netslpr() and netslwt() for each request.

With farming, one only needs to construct three arrays as:
int size_array[200];
void *ptr_array[200];
void *sorted_array[200];

size_array[0] = size1;
ptr_array[0] = ptr1;
sorted_array[0] = sorted1;
...

Then, netsl_farm() can be called as:
status_array = netsl_farm("i=0,199",netsl_int_array(size_array,"$i"),
                                    netsl_ptr_array(ptr_array,"$i"),
                                    netsl_ptr_array(sorted_array,"$i"));

In short, netsl_farm() is a concise, convenient way of farming out groups of requests. Of course, it uses netslnb() underneath, thereby ensuring fault-tolerance and load-balancing.