Tutorial for basic data types (int, double, char)
=================================================

Content
This tutorial develops a little library which performs a basic operation on two
numbers. It shows how to compile and include the problem into the NetSolve
repository and how to invoke the function. This include the following steps:

  1. building the library
  2. installing the problem to the NetSolve repository
  3. invoking the function via NetSolve


Requirements
o the following files are needed (they should be in the current directory)
  o libcalc.c - contains the function which should perform the calculation
  o calc.idl - a file which describes how the problem should be included
               into the NetSolve repository (Interface Definition Language)
  o myprog.c - an example program which invokes the newly created NetSolve
               function



Instructions
------------

1. Building the Library
NetSolve provides all functions through statically linked libraries. Execute the
following steps on the server to build libcalc.a

$ gcc -c libcalc.c
$ ar rc libcalc.a libcalc.o


2. Installing the Problem to the NetSolve Repository
To invoke a new function from the NetSolve client you have to add the function
to the problems list in a NetSolve server and recompile the server. Perform the
following steps:

o create a problem description file with
  $ $NETSOLVE_ROOT/bin/$NETSOLVE_ARCH/idltopdf calc.idl
  which generates the file calc.pdf

o copy the file calc.pdf to the problems subdirectory in your NetSolve directory

o edit the file "server_config" in your NetSolve directory and add the following
  line in the "@PROBLEMS:" section:
  ./problems/calc.pdf

o to rebuild the server, you have to set an environment variable which points to
  the directory of the previously created library (required by the problems
  definition file); depending on you shell execute
  $ export NSCALC_LIB=/path/to/libcalc
  or
  $ setenv NSCALC_LIB /path/to/libcalc

o afterwards rebuild the server with the command
  $ make server
  in your NetSolve directory

Note: All these steps have to be performed at the machine where your server is
running. Also make sure to kill the server if it is currently running.


3. Invoking the Function Via NetSolve
The file myprog.c demonstrates how to invoke the function calc via NetSolve.
When you compile it you have to provide the include and library directory of
NetSolve. Set the NETSOLVE_ROOT environment variable to your NetSolve
directory and NETSOLVE_AGENT to your architecture (you can use the following
shell script
export NETSOLVE_ARCH=`$NETSOLVE_ROOT/conf/config.guess | sed 's/[-|.]/_/g'`
to set it). Use then the following command to compile:

$ gcc myprog.c -o myprog -I$NETSOLVE_ROOT/include -lnetsolve \
      -L$NETSOLVE_ROOT/lib/$NETSOLVE_ARCH

Invoking myprog with 3 arguments uses the blocking call:
$ myprog 1 2.1 +

To use non-blocking calls use "myprog 0 <number of requests>" and for
task-farming "myprog 1 <number of requests>".

Note: Be sure to have an agent and your newly compiled server running. Also
check that the NETSOLVE_AGENT enironment variable is set (it should be the same
value as the "@AGENT:" line in server_config in the NetSolve directory).


Last modified: March 5th, 2003
Christoph L. Fabianek, fabianek@cs.utk.edu
