Appendix A. NetSolve Tutorials

Table of Contents
Tutorial for basic data types (int, double, char)
Tutorial for Handling Files
Tutorial for Matrix and Vector Operations
Tutorial for Sparse Matrices

The $NETSOLVE_ROOT/Tutorial directory contains several tutorials which should demonstrate the use of NetSolve. It should be a starting point for new users to write their own programs and also shows how to enhance the capabilities of NetSolve by adding new functions to the repository. The tutorials do not depend on each other and can be performed in any order. However, if you are completly new to NetSolve it is recommended to perform the tutorials in the order described below, since some explanations are given in more detail in the first sections.

The first three examples include code sections for blocking and non-blocking calls as well as the task-farming feature. The last example (sparse) demonstrates how to include an existing application into NetSolve and uses only blocking codes, although it should be easy with the information from the previous tutorials to build non-blocking and farming calls too.

If some additional software is required to build the example a link to the sources is provided. The examples are designed that they can be performed in userspace (this includes the additional software that may be necessary).

Before you start a tutorial make sure that NetSolve is properply installed by running C_test and farm_test. If these functions do not work consult the NetSolve User Guide and fix the issue.

The following tutorials are included:

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

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: The following files are needed (they should be in the current directory).

Instructions

1. Building the Library

NetSolve provides all functions through statically linked libraries. Execute the following steps on the server to build libcalc.a
UNIX> gcc -c libcalc.c
UNIX> ar rc libcalc.a libcalc.o

2. Installing the Problem to the NetSolve Repository

Use idltopdf to convert povray.idl to povray.pdf. Then copy povray.pdf to your problems subdirectory and add an entry in the file NETSOLVE_ROOT/server_config. Set NSPOVRAY_LIB to the path where libpovray.a is located and recompile the server with the command:

UNIX> make server

NoteNote:
 

Since the library makes an external call to a program it can not take advantage of the Hardware/Software server feature of NetSolve (i.e., it cannot be transfered from one server to another). To mark a problem as non-moveable use the keyword NONMOVEABLE in the IDL.

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 or similar shell script to set it).
UNIX> export NETSOLVE_ARCH=`$NETSOLVE_ROOT/conf/config.guess | sed 's/[-|.]/_/g'`
Then use the following command to compile:
UNIX> 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:
UNIX> myprog 1 2.1 +
To use non-blocking calls use:
UNIX>myprog 0 <number of requests>
and for task-farming:
UNIX>myprog 1 <number of requests>

NoteNote:
 

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