An example

In this example, the Matlab task farming interface is invoked to make multiple requests to a NetSolve problem, totalarea. The inputs to the problem are the name of a function which is a string, the starting point on the x-axis which is an integer and the ending point on the x-axis which is another integer value. The problem computes the area of the function under the curve bounded within a region and gives back the total area under the curve. Thus, using the normal NetSolve call, the user would invoke this problem as
area = netsolve('totalarea', xstart, xend);

One way to solve this problem is to divide the function into many sub areas and make multiple requests to the 'totalarea' problem passing different start and end points on the x-axis. The NetSolve program that uses the task farming interface for this method is given below.

function [total_area] =  totalarea ( func, a, b, num_strips )

strip_length = (b-a)/num_strips

x1 = cell(num_strips, 1);
x2 = cell(num_strips, 1);

x1{1} = a;
for i=1:num_strips
  funcs{i} = func;
  x2{i} = x1{i}+strip_length;
  if i < num_strips
    x1{i+1} = x2{i};

str1 = 'i=0,';
str2 = int2str(num_strips-1);

str = [str1,str2];

area = netsolve_farm(str, 'area', funcs, x1, x2);

total_area = 0.0;
for i=1:num_strips
  total_area = total_area+area{i};

fprintf(2, 'total_area: %f\n', total_area);