This tutorial shows how to use sparse matrices. It also demonstrates how to include an existing application into NetSolve. The application to be used is called Pebbles and provides a solver for large sparse linear systems. It was developed at the University of Linz, Austria and you have to obtain a copy of this software. But even if you don't have Pebbles you should be able after reading through this tutorial to handle sparse matrices within NetSolve. The tutorial includes the following steps:
Building and configuring the library
Installing the problem to the NetSolve repository
Testing the software from C and Matlab
Requirements on each server:
interface.cc - the wrapper function for Pebbles to NetSolve
outback.cc, extern.h - a modification of Pebbles on how to pass options
pebbles.idl - a modification of Pebbles on how to pass options into the NetSolve repository (Interface Definition Language)
Pebbles - information about how to obtain Pebbles at http://www.numa.uni-linz.ac.at/Research/Projects/pebbles.html
Requirements on the client:
test_pebbles.c - the client program which allows performing a simple test
Instructions
1. Building the Library
First install and compile Pebbles as described in the documentation. Then copy the file outback.cc to your /pebbles/libsrc/prepro directory. Next, replace the file pebbles/pebbles/extern.hh with the version of extern.hh provided here. In the following it is assumed that Pebbles is installed in ~/pebbles, i.e., the statically linked libraries after compiling Pebbles should be in ~/pebbles/lib/$MACHINE/
Build libpebbles.a within the Pebbles source tree
UNIX> cp interface.cc ~/pebbles/pebbles; cd ~/pebbles/pebbles
UNIX> c++ -c -fpic -o interface.o -I$HOME/pebbles/libsrc \
-DFORTRANDOUBLEUNDERSCORE -w interface.cc
UNIX> mkdir ~/pebbles/libpebbles
UNIX> cp ~/pebbles/libsrc/*/*.o ~/pebbles/libpebbles
UNIX> cp ~/pebbles/pebbles/interface.o ~/pebbles/libpebbles
UNIX> cd ~/pebbles/libpebbles; ar rc libpebbles.a *.o |
You should now have a file ~/pebbles/libpebbles/libpebbles.a
NOTES:
Since Pebbles is written in C++ and NetSolve in C we have to provide the line 'extern "C" void pebbles(...)' at the beginning of interface.cc to make sure that the internal nameing convention for the linker are fullfilled.
NetSolve and Pebbles use the same storage convention for sparse matrices (called the compressed sparse row format - CSR) which uses the 3 vectors:
double *A - the values of the nonzero entries (length: nnz)
int *col_index - the column index of each entry of the vector A (length: nnz)
int *row_ptr - index to first nonzero entry at each row in col_index (length: size+1 with row_ptr[size+1]=nnz)
2. Installing the Problem to the NetSolve Repository
Use idltopdf to convert pebbles.idl to pebbles.pdf and add the function to the problems list in the file $NETSOLVE_ROOT/server_config. Set NSPEBBLES_LIB to $HOME/pebbles/libpebbles and recompile the server with the command
UNIX> make server |
3. Testing the Software from C and Matlab The file test_pebbles.c, demonstrates how to invoke the newly created function pebbles via NetSolve. Compile it with with the following command:
UNIX> gcc test_pebbles.c -o test_pebbles -I$NETSOLVE_ROOT/include -lnetsolve \
-L$NETSOLVE_ROOT/lib/$NETSOLVE_ARCH |
UNIX> ./test_pebbles |
Initializing NetSolve... Initializing NetSolve Complete Sending Input to Server visitor1.cs.utk.edu Downloading Output from Server visitor1.cs.utk.edu +++ PEBBLES started size: 4 nnz: 4 maxrowsize: 1 $$$ setup phase $$$ solution phase $$$ writting the solution +++ PEBBLES finished Solution: --> 1.000000 --> 0.500000 --> 0.333333 --> 0.250000 |
In Matlab run the follwing commnds (assuming you have compiled the Matlab libraries with "make matlab"):
MATLAB>> addpath /path/to/$NETSOLVE_ROOT/bin/$NETSOLVE_ARCH |
MATLAB>> x=netsolve('pebbles',A,b,x,'EPS_PCG=1e-6;SOLVE=1;ELEMENT_PRECOND=0'); |