SILC User's Manual

The SSI Project

Revision: October 31, 2007 (for SILC v1.3)


Table of Contents

1. Introduction
2. SILC server
2.1. Compiling a SILC server
2.2. Running and stopping a SILC server
3. User programs for SILC
3.1. Writing user programs
3.2. Compiling user programs
3.3. Data types and precisions
3.4. Matrix storage formats
4. The command language
4.1. Assignment statements
4.2. Procedure calls
4.3. System statements
4.4. Operands of operators
4.5. Rules for precision conversion
4.6. Subscript
4.7. Modules
5. API reference
5.1. Client routines for C
5.2. Client routines for Fortran
5.3. Built-in functions and procedures
A. Revision history

1. Introduction

This document provides technical details required to create application programs (referred to as user programs) for SILC. The document first explains how to compile and run a SILC server and how to create user programs in C and Fortran. Then, the specifications of SILC's mathematical expressions are described, and finally the details of APIs are summarized.

2. SILC server

2.1. Compiling a SILC server

The following pieces of software are required to compile a SILC server and run it in a Unix-like or Microsoft Windows environment:

  • C and Fortran compilers

  • GNU Make

  • GNU Bison

  • GNU Flex

You are able to use the following matrix computation libraries by building them into the SILC server.

SILC has been tested in the following computing environments (in the parentheses, templates of the make.inc file (described below) for each environment are shown), together with the operating systems and compilers shown in Table 1. The column "OpenMP" shows whether support for OpenMP is available in each platform.

Table 1. Tested platforms

Computing environmentOSCompilersOpenMP
Sun Fire 3800 (make.sunfire)Solaris 9 (sparc)Sun ONE Studio 7Yes
SGI Altix 3700 (make.altix)Red Hat Linux Advanced Server 2.1Intel C 9.1
Intel Fortran 9.1
Yes
IBM eServer xSeries 335 (make.linux-icc-32)Red Hat Linux 8.0Intel C 9.0
Intel Fortran 9.0
Yes
Dell PowerEdge SC 1420 (make.linux-icc-64)Fedora Core 4Intel C 9.0 (EM64T)
Intel Fortran 9.0 (EM64T)
Yes
IBM OpenPower 710 (make.openpower)SuSE Linux Enterprise Server 9 (ppc)IBM XL C 7.0
IBM XL Fortran 9.1
Yes
Apple PowerMac G5 (make.g5)Mac OS X 10.4.2IBM XL C 6.0
IBM XL Fortran 8.1
Yes
NEC SX-6i (make.sx)SUPER-UX 13.1 SX-6C++/SX 1.0 for SX-6
FORTRAN90/SX 2.0 for SX-6
No
Panasonic CF-R3 (make.gcc)Fedora Core 3GCC 3.4.2No
IBM ThinkPad T42 (make.gcc)KNOPPIX 4.0 LinuxTag Japanese EditionGCC 3.3.6No
Dell Dimension 84000 (make.mingw)Microsoft Windows XP Professional SP2MinGW (GCC 3.2.3)No

You can obtain the source code of SILC (in a compressed archive file named silc-1.3.tar.gz) from the following location:

The contents of the compressed archive file can be extracted as follows. The source code of SILC is stored in the silc-1.3/src/ directory in the current working directory.

$ gzip -cd silc-1.3.tar.gz | tar xvf -

To compile the source code of SILC, you need to create a file named make.inc in the silc-1.3/src/ directory. This file defines environment-specific compiler options, locations of library files, and so on. There are template files for several computing environments in the silc-1.3/src/inc/ directory. See Table 1 for the names of the template files, target platforms, operating systems, and compilers to be used.

In the make.inc file, you define a series of macros that are referenced from Makefile, the input file of the make command. The macros are roughly divided into two groups, namely a group of general macros that do not depend on SILC (Table 2) and another of SILC-specific macros (Table 3).

Table 2. General macros

CCCommand name of a C compiler.
FCCommand name of a Fortran compiler.
LINK.fCommand name of a linker to be used for linking Fortran programs (default: the command name specified by FC).
BISONCommand name of GNU Bison.
FLEXCommand name of GNU Flex.
CFLAGSCompiler options for the C compiler.
FFLAGSCompiler options for the Fortran compiler.
LDFLAGSLinker options for the C and Fortran compilers.
SHAREDCFLAGS C compiler options required when compiling shared libraries.
SHAREDFFLAGS Fortran compiler options required when compiling shared libraries.
SHAREDLDFLAGSC/Fortran compiler options required when linking shared libraries.
RANLIBName of the ranlib command (for example, the echo command can be specified if the target computing environment does not have the ranlib command).
RMName of the rm command (usually not needed defining).

Table 3. SILC-specific macros

OMPFLAGSC/Fortran compiler options for enabling OpenMP-based parallelization.
LIBSLinker options for linking the SILC server and sample user programs (e.g., libraries to be linked).
PLATFORM_MODULESA list of environment-specific arithmetic matrix storage modules modules that you want to build into the SILC server. The following modules can be specified (the libraries that each module depends on, if any, are shown in the parentheses). See Section 4.7 for the details of the modules.
  • $(FORMAT_DIR)/sparse_band.so (BLAS, LAPACK)

  • $(MODULE_DIR)/blasmodule.so (BLAS, LAPACK)

  • $(MODULE_DIR)/leq_lis.so (Lis)

  • $(MODULE_DIR)/fftss.so (FFTSS)

  • $(MODULE_DIR)/linpackmodule.so (LINPACK)

PLATFORM_TESTSA list of environment-specific sample user programs that you want to build. The following programs can be specified (the libraries that each program depends on, if any, are shown in the parentheses).
  • test_dense (BLAS)

  • test_dense_sa (BLAS)

  • test_dot

  • test_dot_sa (BLAS)

  • test_band

  • test_band_sa (BLAS, LAPACK)

  • mm_band (BLAS)

  • mm_band_sa (BLAS, LAPACK)

  • mm_lis (Lis)

BLAS_DRIVERBLAS driver name (described below).
BLAS_CFLAGSC compiler options for compiling the programs that use BLAS.
BLAS_LIBSLinker options for linking the programs that use BLAS (e.g., libraries to be linked).
LAPACK_DRIVERLAPACK driver name (described below).
LAPACK_CFLAGSC compiler options for compiling the programs that use LAPACK.
LAPACK_LIBSLinker options for linking the programs that use LAPACK (e.g., libraries to be linked).
LIS_CFLAGSC compiler options for compiling the programs that use Lis.
LIS_LDName of a linker for linking the programs that use Lis.
LIS_LIBSLinker options for linking the programs that use Lis (e.g., libraries to be linked).
LINPACK_LIBSLinker options for linking the programs that use LINPACK (e.g., libraries to be linked).

Subroutines of BLAS and LAPACK are used through a driver file. There are three pairs of BLAS and LAPACK drivers shown below. Choose one of them according to the implementations of BLAS and LAPACK you want to use.

  • Drivers for Intel Math Kernel Library (MKL)

    blas_intelmkl.c, lapack_intelmkl.c

  • Drivers for Sun Performance Library

    blas_sunperf.c, lapack_sunperf.c

  • Dumb (generic) drivers

    blas_dumb.c, lapack_dumb.c

You have to define the following macros in the make.inc file to specify the drivers, compiler options and linker options.

BLAS_DRIVERBLAS driver file name
BLAS_CFLAGSC compiler options for BLAS
BLAS_LIBSLinker options for BLAS
LAPACK_DRIVERLAPACK driver file name
LAPACK_CFLAGSC compiler options for LAPACK
LAPACK_LIBSLinker options for LAPACK

Examples of macro definitions for the dumb drivers are shown below.

BLAS_DRIVER=    blas_dumb.c
BLAS_CFLAGS=
BLAS_LIBS=      /opt/LAPACK/blas.a

LAPACK_DRIVER=  lapack_dumb.c
LAPACK_CFLAGS=  $(BLAS_CFLAGS)
LAPACK_LIBS=    /opt/LAPACK/lapack.a $(BLAS_LIBS)

The SILC server and user programs will generate a lot of debugging messages, since the template files in the silc-1.3/src/inc/ directory define the CFLAGS macro with the -DDEBUG option enabled by default. You can suppress the messages by editing make.inc and removing the option.

After you have created make.inc in the silc-1.3/src/ directory, run the make command to compile the SILC server and related programs as follows.

$ make

2.2. Running and stopping a SILC server

Before you run a user program for SILC, you need to start a SILC server. Type the following command to run a SILC server (you also need to change the current working directory to the directory where the executable file of the SILC server exists). The server starts in the foreground.

$ cd src/server
$ ./server

In shared-memory parallel computing environments, you can use an OpenMP-based parallel SILC server. The OMP_NUM_THREADS environment variable is used to specify the number of threads as follows.

$ env OMP_NUM_THREADS=4 ./server

Unless explicitly specified, the port number through which the server accepts connections from user programs will vary every time you restart the server. The SILC_PORT environment variable is used to specify the port number as illustrated below.

$ env SILC_PORT=32000 ./server

The server creates a plain text file ~/.silc (if it does not exist) in your home directory and writes out the server's host name and port number. The SILC_INIT routine (Section 3.1) reads the file and establishes a connection to the server according to the host name and port number in the file. The contents of the file is as follows.

hostName portNumber [EOF]

If the SILC server and user programs run in different computing environments with separate file systems, you have to manually create ~/.silc in the file system from which the user programs (or precisely speaking, the SILC_INIT routine) will read the file. The echo command will do for this task, as shown in the following example.

$ echo hostName portNumber > ~/.silc

To stop the SILC server, simply type Ctrl-C or use the kill command as follows.

$ kill -9 processNumber

3. User programs for SILC

3.1. Writing user programs

User programs for SILC establish a connection to a SILC server over networks, and make use of matrix computation libraries the SILC server maintains, by calling the following routines. These routines are referred as client routines in this document. The arguments of the client routines are described in detail in Section 5.

Client routines for C:

  • SILC_INIT

    Establishes a connection to a SILC server.

  • SILC_PUT

    Sends data (such as matrices and vectors) to the server.

  • SILC_EXEC

    Sends a request for computation by means of mathematical expressions in the form of text. The mathematical expressions are written in SILC's command language (described in Section 4).

  • SILC_GET

    Receives the results of the computation.

  • SILC_FINALIZE

    Closes the connection to the server.

Client routines for Fortran:

  • SILC_INIT

    Establishes a connection to a SILC server.

  • SILC_PUT_SCALAR, SILC_PUT_MATRIX, SILC_PUT_MATRIX_CRS, etc.

    Send data (such as matrices and vectors) to the server. Unlike the client routines for C, there is a separate PUT routine for each data type.

  • SILC_EXEC

    Sends a request for computation by means of mathematical expressions in the form of text. The mathematical expressions are written in SILC's command language (described in Section 4).

  • SILC_GET_SCALAR, SILC_GET_MATRIX, SILC_GET_MATRIX_CRS, etc.

    Receive the results of the computation. Like the PUT routines above, there is a separate GET routine for each data type.

  • SILC_FINALIZE

    Closes the connection to the server.

The client routines for both C and Fortran are defined in silc-1.3/src/client/libsilc.a. By linking the library file to user programs, these client routines are made available. libsilc.a is built together with the SILC server.

In addition, data structures and constants used with the client routines (see Section 5). are defined in silc-1.3/src/client/client.h (for C) and silc-1.3/src/client/fortran/client.h (for Fortran).

Although user programs can be either sequential or multithreading parallel programs, all calls for client routines must be made in the same thread.

An example of a user program in C (solve.c) is shown below. This program solves a system of linear equation Ax = b, where A is a sparse matrix in the Compressed Row Storage (CRS) format.

#include "client.h"

int main(int argc, char *argv[])
{
  silc_envelope_t object;  /* a structure used for data communications */
  double *value, *b, *x;
  int *index, *row;

  /* Create sparse matrix A (in the CRS format) and vector b */

  SILC_INIT();

  object.v = value;
  object.type = SILC_MATRIX_TYPE;
  object.format = SILC_FORMAT_CRS;
  object.precision = SILC_DOUBLE;
  object.m = object.n = N;  /* dimensions */
  object.nnz = NNZ;  /* the number of non-zero elements */
  object.row = row;
  object.index = index;
  SILC_PUT("A", &object);

  object.v = b;
  object.type = SILC_COLUMN_VECTOR_TYPE;
  object.precision = SILC_DOUBLE;
  object.length = N;
  SILC_PUT("b", &object);

  /* Solve a system of linear equations Ax = b */
  SILC_EXEC("x = A \\ b");

  object.v = x;
  SILC_GET(&object, "x");

  SILC_FINALIZE();

  /* Output the solution (vector x) */
}

A Fortran program (solve.f) that carries out the same computation as the C program above is shown below.

    INCLUDE 'client.h'

    REAL *8 VALUE(NNZ), B(N), X(N)
    INTEGER *4 ROW(N+1), INDEX(NNZ), IERR

C   Create sparse matrix A (in the CRS format) and vector b

    CALL SILC_INIT(IERR)

    CALL SILC_PUT_MATRIX_CRS('A', VALUE, N, N, NNZ, ROW, INDEX,
   &                         SILC_DOUBLE, IERR)

    CALL SILC_PUT_COLUMN_VECTOR('b', B, N, SILC_DOUBLE, IERR)

C   Solve a system of linear equations Ax = b
    CALL SILC_EXEC('x = A \ b', IERR)

    CALL SILC_GET_COLUMN_VECTOR('x', X, IERR)

    CALL SILC_FINALIZE(IERR)

C   Output the solution (vector x)

3.2. Compiling user programs

To compile user programs for SILC with a C/Fortran compiler, you need to specify (1) compiler options for locating the header file (client.h) and library file (libsilc.a), and (2) linker options for specifying the libraries to be linked (libsilc.a and additional libraries described below).

For example, GNU C compiler is used to compile the C program (solve.c) in the previous section by running the gcc command as follows. In this example, it is assumed that the source code of SILC is placed in the ~/silc-1.3/src/ directory in your home directory.

$ gcc -I~/silc-1.3/src/client -c solve.c
$ gcc -L~/silc-1.3/src/client -o solve solve.o -lsilc

The -I and -L options specify the locations of client.h and libsilc.a respectively, and -lsilc is a linker option for linking libsilc.a to the user program.

For your convenience, if you repeatedly modify the user program and compile it, it is worth creating Makefile like the one shown below.

all: solve

CC=      gcc
CFLAGS=  -I$$HOME/silc-1.3/src/client
LDFLAGS= -L$$HOME/silc-1.3/src/client
LIBS=    

solve: solve.c
	$(CC) $(CFLAGS) -c solve.c
	$(CC) $(LDFLAGS) -o $@ solve.o -lsilc $(LIBS)

To compile solve.c using Makefile above, run the make command as follows:

$ make

GNU Fortran compiler is used to compile the Fortran program (solve.f) in the previous section by running the g77 command as follows:

$ g77 -I~/silc-1.3/src/client/fortran -fno-second-underscore -c solve.f
$ g77 -L~/silc-1.3/src/client -o solve solve.o -lsilc

As it is in the case of the aforementioned C program, it is convenient to create Makefile like the following one:

all: solve

FC=      g77 -fno-second-underscore
FFLAGS=  -I$$HOME/silc-1.3/src/client/fortran
LDFLAGS= -L$$HOME/silc-1.3/src/client
LIBS=    

solve: solve.f
	$(FC) $(FFLAGS) -c solve.f
	$(FC) $(LDFLAGS) -o $@ solve.o -lsilc $(LIBS)

Some computing environments require additional libraries to be linked to user programs together with libsilc.a in order to use networking facilities. Several computing environments and additional libraries to be required are shown below. In the case of Makefile for C and Fortran shown above, specify the additional libraries with the LIBS macro.

Table 4. Several computing environments and additional libraries for networking.

Computing environmentAdditional libraries
Solaris-lsocket -lnsl
GNU/LinuxNone
Microsoft Windows (MinGW)-lws2_32
Mac OS XNone

3.3. Data types and precisions

There are five types of data that are transferred between a SILC server and user programs. The constants (shown in the parentheses) are used to specify the data types when calling the PUT/GET routines. These constants are defined in client.h (see Section 5).

  • Scalar (SILC_SCALAR_TYPE)

  • Column vector (SILC_COLUMN_VECTOR_TYPE)

  • Row vector (SILC_ROW_VECTOR_TYPE)

  • Matrix (SILC_MATRIX_TYPE)

  • Cubic (3-dimensional) array (SILC_CUBIC_ARRAY_TYPE)

The table below summarizes precisions supported in SILC. The constants (shown in the parentheses) are used to specify the precisions when calling the PUT/GET routines. The corresponding data types in C and Fortran for each precision are also shown.

Table 5. Precisions in SILC.

PrecisionCFortran
Single precision integer (SILC_INT)intINTEGER*4
Double precision integer (SILC_LONG)longINTEGER*8
Single precision real (SILC_FLOAT)floatREAL*4
Double precision real (SILC_DOUBLE)doubleREAL*8
Single precision complex (SILC_COMPLEX)float[a]COMPLEX*8
Double precision complex (SILC_DOUBLE_COMPLEX)double[a]COMPLEX*16

[a] In C, both the real and imaginary parts of a complex number are represented by a real number. An array of N complex numbers are represented as an array of 2N real numbers that stores real and imaginary parts alternatively.


3.4. Matrix storage formats

When transferring a matrix, you have to specify the storage format of the matrix together with the data type (SILC_MATRIX_TYPE). Two matrix storage formats are currently supported as described below.

  • SILC_FORMAT_DENSE

    This format is used to represent dense matrices. Elements of a dense matrix are stored in a 2-dimensional array in the Fortran style. The format consists of the following attributes and array.

    m

    The number of rows (integer).

    n

    The number of columns (integer).

    value

    An array of m-by-n elements (any precision).

    The elements are stored in the Fortran style (i.e., stored column by column). Note that 2-dimensional arrays in the C style store elements row by row.

  • SILC_FORMAT_CRS

    This format, called the Compressed Row Storage (CRS) format, is used to represent sparse matrices compactly by storing only non-zero elements (those whose values are not zero) row by row. The format consists of the following attributes and arrays.

    m

    The number of rows (integer).

    n

    The number of columns (integer).

    nnz

    The number of non-zero elements (integer).

    value

    An array of nnz elements (any precision).

    This array stores non-zero elements row by row, leaving no space.

    row

    An array of m+1 elements (single precision integer).

    This array stores a pointer (i.e., an index in the value array) to the first element of each row; that is, row[0] stores a pointer to the first element of row 1, row[1] stores a pointer to the first element of row 2, and so forth. row[m] stores the number of non-zero elements (i.e., nnz).

    index

    An array of nnz elements (single precision integer).

    Each element of this array represents a column number of the non-zero element stored in the corresponding index in the value array. For example, if value[7] holds the non-zero element at column 5 of a row in a matrix, then index[7] holds the column number 5.

    Example: The following 4-by-4 matrix is represented by the three arrays value, row, index, as shown below.

      | 11  0  0  0 |
      |  0 22  0  0 |
      |  0 32 33  0 |
      | 41  0  0 44 |
    
    • value: 11, 22, 32, 33, 41, 44 (length 6)

    • row: 0, 1, 2, 4, 6 (length 5)

    • index: 1, 2, 2, 3, 1, 4 (length 6)

4. The command language

The argument of the SILC_EXEC routine is a mathematical expression in the form of text that instructs a SILC server to carry out matrix computations. A mathematical expression is a kind of programs written in SILC's command language.

The unit of computation to be carried out at once is a statement, which is an assignment statement, a procedure call, or a system statement.

  • Assignment statement

    An assignment statement stores a value to a variable. A variable name is specified in the left-hand side of an equal sign (=), while an expression that yields the assigned value is written in the right-hand side. Variables are used without type declaration, and they can retain any types of values. If a new value is stored in an existing variable, its old value is deleted.

  • Procedure call

    A procedure call instructs a call for a procedure.

  • System statement

    System statements are used to control a SILC server's behavior. There is only the prefer statement (Section 4.3) at the moment.

You can pass multiple statements to SILC_EXEC at once by concatenating them with semicolon (;).

4.1. Assignment statements

There are two types of assignment statements.

  • Simple assignment

    This is an assignment in the form of "name = expression". The value of the expression is stored into the variable of the specified name. A new variable is defined unless already defined; otherwise, the value of the variable is replaced with the new value. When expression is a variable name as in "A = B", the value of B is duplicated and assigned to A.

  • Augmented assignment

    This is an assignment with a binary operation. There are seven augmented assignments as listed below. For example, "name += expression" is equivalent to "name = name + expression". The variable name in the left-hand side must be defined in advance.

    name += expression

    Addition.

    name -= expression

    Subtraction.

    name *= expression

    Multiplication.

    name /= expression

    Division.

    name %= expression

    Remainder.

    name *@= expression

    Elementwise multiplication.

    name /@= expression

    Elementwise division.

The right-hand side of an assignment statement is an expression, whose components are described below. In the following descriptions, x, y, e1, e2, ..., and eN are arbitrary expressions. See Section 4.4 for the data types that are acceptable as operands of unary and binary operators, and Section 5.3 for available built-in functions and procedures.

  • Unary operators

    x~

    Complex conjugates.

    x'

    Conjugate transposes.

    x'~ or x~'

    Transposes.

    -x

    Negation.

  • Binary operators

    x + y

    Addition.

    x - y

    Subtraction.

    x * y

    Multiplication.

    x / y

    Division.

    x % y

    Remainder.

    A \ b

    Solution of systems of linear equations Ax = b, where A is an N-by-N matrix, and b is either a vector of length N or an N-by-M matrix.

    x *@ y

    Elementwise multiplication.

    x /@ y

    Elementwise division.

  • Function calls

    f(e1, e2, ..., eN)

    f is a function name, and e1, e2, ..., eN are arbitrary expressions (i.e., arguments).

  • Concatenation

    {e1, e2, ..., eN}

    The values of the expressions are concatenated vertically. If all e1, e2, ..., eN are scalars, the result of concatenation is a column vector.

    {e1; e2; ...; eN}

    The values of the expressions are concatenated horizontally. If all e1, e2, ..., eN are scalars, the result of concatenation is a row vector.

    {e1;; e2;; ...;; eN}

    This always results in a cubic array.

  • Range

    {e1:e2}

    This generates a column vector whose elements are integer scalars from e1 to e2. The values of the two expressions must be integer scalars.

  • Literals

    Numbers are treated as double precision real (SILC_DOUBLE) if they have a dot; otherwise, numbers are treated as single precision integer (SILC_INT).

  • Constants

    e

    Napier's constant.

    i

    The imaginary unit (complex numbers can be obtained by binary operators as in "3 - 5 * i".)

    pi

    The ratio of a circle's circumference to its diameter.

    inf

    Infinity.

  • Miscellaneous

    • Variable names are expressions.

    • You can use parentheses in compound expressions to specify which part of an expression should be evaluated first.

    • You can also use subscript (Section 4.6) to refer to part of data.

4.2. Procedure calls

A procedure call consists of a procedure name and a list of arguments, as illustrated below.

split(A, L, D, U)

This procedure divides matrix A into the three parts of lower triangle, main diagonal, and upper triangle. These parts are stored in variables L, D, and U, respectively.

Procedures have three types of arguments as follows.

in

The arguments of this type deliver input data to procedures. The value of these arguments are never modified.

out

The arguments of this type are used to receive output data from procedures.

inout

The arguments of this type are used for both delivering input data and receiving output data.

In the case of the procedure split above, the first argument is an in-argument, and the other three are out-arguments.

4.3. System statements

System statements are used to control a SILC server's behavior. There is only one system statement at the moment.

prefer moduleName

This statement reorders the search path of module functions by bringing the specified module to the beginning of the list of modules. See Section 4.7 for more information on the way of looking up module functions.

4.4. Operands of operators

Although operands of an operator can be arbitrary expressions, valid data types of the operands vary according to the operator. The acceptable combinations of data types for each operator are summarized as follows. The same restrictions on binary operators are applied to augmented assignments (Section 4.1).

Table 6. Unary operators.

Complex conjugates[a]Scalar, column/row vector, matrix, cubic array
Conjugate transposes[a][b]Scalar, column/row vector, matrix
Transposes[b]Scalar, column/row vector, matrix
NegationScalar, column/row vector, matrix, cubic array

[a] If the precision of the operand is either integer or real, the result equals to the operand.

[b] If the operand is a scalar, the result equals to the operand.


Table 7. Binary operators.

OperatorLeft operandRight operandResult
Addition/subtractionScalar Scalar Scalar
Column vectorColumn vectorColumn vector
Row vector Row vector Row vector
Matrix Matrix Matrix
Cubic array Cubic array Cubic array
MultiplicationScalar Scalar Scalar
Scalar Column vectorColumn vector
Scalar Row vector Row vector
Scalar Matrix Matrix
Column vectorScalar Column vector
Column vectorRow vector Matrix
Row vector Scalar Row vector
Row vector Column vectorScalar[a]
Row vector Matrix Row vector
Matrix Scalar Matrix
Matrix Column vectorColumn vector
Matrix Matrix Matrix
Cubic array Scalar Cubic array
DivisionScalar Scalar Scalar
Row vector Matrix Column vector
Matrix Matrix Matrix
Remainder[b]ScalarScalarScalar
Solution of systems of linear equationsScalar Scalar Scalar
Matrix Column vectorColumn vector
Matrix Matrix Matrix
Elementwise multiplication/divisionScalar Scalar Scalar
Column vectorColumn vectorColumn vector
Row vector Row vector Row vector
Matrix Matrix Matrix
Cubic array Cubic array Cubic array

[a] The result represents the inner product of the two vectors.

[b] The precisions of the two operands must be integer.


4.5. Rules for precision conversion

If the two operands of a binary operator have a different precision, they are converted to the same precision before computation. The following rules are applied to precision conversion.

  • The following relation (i.e., a partial order) is defined among the six precisions. If X → Y, then Y is said a precision higher than X. Moreover, if X → Y and Y → Z, then X → Z.

      SILC_LONGSILC_DOUBLESILC_DOUBLE_COMPLEX
    
          ↑              ↑               ↑
    
      SILC_INTSILC_FLOATSILC_COMPLEX
    
  • If the precision of one operand is higher than that of the other, then the latter operand is converted to the precision of the former.

    For example, if one operand is of SILC_DOUBLE and the other is of SILC_FLOAT, then the latter is converted to SILC_DOUBLE since it is a higher precision than SILC_FLOAT.

  • If neither operand has a precision higher than that of the other, then both operands are converted to a common higher precision.

    For example, if one operand is of SILC_DOUBLE and the other is of SILC_COMPLEX, then both operands are converted to a common higher precision, that is SILC_DOUBLE_COMPLEX.

4.6. Subscript

You can use subscript with either a variable name on the left-hand side of an assignment statement, or arbitrary expressions (including variable names). A variable name with subscript takes one of the following three forms:

  • A[x]

    A must be a column/row vector.

  • A[x,y]

    A must be a matrix.

  • A[x,y,z]

    A must be a cubic array.

where x, y, and z are expressions whose values are either an integer scalar or an integer column vector. Expressions with other kinds of values result in a runtime error.

When you use a range as a subscript expression, you can omit the initial and/or end value(s) of the range. For example, if A is a vector of length N, then A[:5] equals to A[1:5], A[5:] to A[5:N], and A[:] to A[1:N], respectively.

The following table summarizes the functions of subscript, the contexts in which subscript can be used, and some examples of mathematical expressions with subscript.

Table 8. Functions of subscript in various contexts.

FunctionContextExample
Partial referenceThe right-hand side of an assignment
B = A[1:5]

A partial vector (length 5) of A is stored to B.

In-arguments of functions and procedures
Y = F(A[1:5,1:5])

Only a 5-by-5 submatrix of A is passed to function F. Matrix A does not change.

Restricted assignmentThe left-hand side of an assignment
A[1:5,1:5] = B

A 5-by-5 submatrix of A is replaced with the elements of matrix B.

Out-arguments of procedures
P1(x, A[1:5])

Procedure P1 partially modifies vector A.

Partial reference + restricted assignmentInout-arguments of procedures
P2(A[1:5,1:5])

Procedure P2 takes a 5-by-5 submatrix of A and modifies its elements.


4.7. Modules

Every operator, function, and procedure in the command language of SILC is carried out through a call for a module function, which is a "wrapper" that actually calls a library function. Related module functions are grouped into a module. There are several standard modules as shown below.

  • coremodule

    Contains module functions for all data types except matrices.

  • dense

    Contains module functions for dense matrices.

  • sparse_crs

    Contains module functions for sparse matrices in the CRS format.

  • leq_lis

    Provides access to the Lis iterative solvers library.

  • leq_cg

    Implements the CG method for dense matrices and sparse matrices in the CRS format.

  • leq_gs

    Implements the Gauss-Seidel method for dense matrices.

  • leq_lu

    Implements the LU decomposition method for dense matrices.

  • blasmodule

    Contains module functions for matrix-vector product and other operators based on BLAS (Basic Linear Algebra Subprograms).

  • fftss

    Contains module functions for the FFTSS fast Fourier Transform library.

There are also a few experimental modules.

  • sparse_band

    Implements the banded matrix storage format and the LU decomposition method based on LAPACK (Linear Algebra PACKage).

  • sparse_jds

    Implements the the Jagged Diagonal Storage (JDS) format.

  • leq_smsamg

    Contains module functions for VINAS Super Matrix Solver AMG version 3.

  • leq_mp

    Contains module functions for the mp_crs multiple precision iterative solvers library. This module requires the GNU MP library.

  • linpackmodule

    Contains module functions for the LINPACK benchmark.

Every operator, function, and procedure is handled by one of module functions in the modules above. Some operators have multiple module functions that can handle them. For example, the three modules of leq_cg, leq_gs, and leq_lu contain a module function for the backslash operator (i.e., solution of systems of linear equations). Modules are maintained in a SILC server by means of a serial linked list. When the SILC server needs to handle an operator, the server picks a module function by searching one module after another from the beginning of the module list and selecting the first module function found in the list. Module functions for functions and procedures are also looked up in the same way.

You can change the order of modules in the module list using the prefer statement (Section 4.3) in a call for the SILC_EXEC routine. The prefer statement moves the specified module to the beginning of the list. By changing the order of modules, you can easily specify the relations between operators (functions, or procedures) and module functions.

5. API reference

5.1. Client routines for C

  • Header file: client.h

    You use this header file when creating user programs for SILC.

  • Structure: silc_envelope_t

    This structure is used as an argument of the SILC_PUT and SILC_GET routines. The structure has the following members, and only some of them are used according to the type of data to be transferred.

    • Members common to all data types:

      int type;

      Data type (Section 3.3). The value of this member must be one of the following constants.

      SILC_SCALAR_TYPE (scalar)
      SILC_ROW_VECTOR_TYPE (row vector)
      SILC_COLUMN_VECTOR_TYPE(column vector)
      SILC_MATRIX_TYPE (matrix)
      SILC_CUBIC_ARRAY_TYPE (cubic array)
      int precision;

      Precision (Section 3.3). The value of this member must be one of the following constants.

      SILC_INT (single precision integer)
      SILC_LONG (double precision integer)
      SILC_FLOAT (single precision real)
      SILC_DOUBLE (double precision real)
      SILC_COMPLEX (single precision complex)
      SILC_DOUBLE_COMPLEX(double precision complex)
      const char *format;

      Matrix storage format (Section 3.4). This member is used only when the data type is SILC_MATRIX_TYPE. The value must be one of the following constants.

      SILC_FORMAT_DENSE(dense matrix)
      SILC_FORMAT_CRS(sparse matrix in the CRS format)
    • For SILC_SCALAR_TYPE:

      void *v;

      A pointer to the scalar value. (*)

    • For SILC_ROW_VECTOR_TYPE and SILC_COLUMN_VECTOR_TYPE:

      size_t length;

      The length of the vector.

      void *v;

      A pointer to an array that stores the elements of the vector. (*)

    • For SILC_MATRIX_TYPE (SILC_FORMAT_DENSE):

      size_t m, n;

      The dimensions of the matrix.

      void *v;

      A pointer to a Fortran-style 2-dimensional array that stores the elements of the matrix column by column. (*)

    • For SILC_MATRIX_TYPE (SILC_FORMAT_CRS):

      size_t m, n;

      The dimensions of the matrix.

      size_t nnz;

      The number of non-zero elements.

      void *v;

      A pointer to an array of non-zero elements. (*)

      int *row;

      A pointer to an array of row pointers. (*)

      int *index;

      A pointer to an array of column indexes. (*)

      The base (or origin) of elements in row and index must be zero.

    • For SILC_CUBIC_ARRAY_TYPE:

      size_t l, m, n;

      The dimensions of the cubic array.

      void *v;

      A pointer to a Fortran-style 3-dimensional array that stores the elements of the cubic array. (*)

    When calling SILC_GET, you need to initialize only the members with the asterisk mark (*). When calling SILC_PUT, you have to set a valid value to all members.

The following client routines return 0 if no error occurs; otherwise, they return −1.

  • int SILC_INIT(void);

    This routine establishes a connection to a SILC server. Call this routine before you start using the SILC server (for example, at the beginning of a user program).

  • int SILC_FINALIZE(void);

    This routine closes the connection to the SILC server. Call this routine when you stop using the SILC server (for example, at the end of a user program).

  • int SILC_EXEC(const char *expr);

    This routine sends a request for computation to the SILC server, where expr is a string of a mathematical expression written in the command language (Section 4).

  • int SILC_PUT(const char *name, silc_envelope_t *envelope);

    This routine associates a name with data and deposits the named data to the SILC server. The fist argument is a string that represents the data name, and the second is a pointer to the silc_envelope_t structure that holds the information on the data to be sent.

  • int SILC_GET(silc_envelope_t *envelope, const char *name);

    This routine fetches data from the SILC server by specifying the name of the data to be received. The first argument is a pointer to the silc_envelope_t structure, and the second argument is a string that represents the data name.

    You can allocate buffers for receiving data in either of the following two ways.

    1. Allocating all buffers in advance.

      If the member v of the silc_envelope_t structure is not NULL, then received data are stored in the buffer pointed by v (as well as the buffers pointed by row and index in case of sparse matrices in the CRS format).

    2. Allowing the SILC_GET routine to allocate buffers automatically.

      If the member v of the silc_envelope_t structure is NULL, then the SILC_GET routine automatically allocates buffers of an appropriate size. You have to free the buffer pointed by v (as well as the buffers pointed by row and index in case of sparse matrices in the CRS format) if the received data are no longer needed.

5.2. Client routines for Fortran

  • Header file: client.h

    You use this header file when creating user programs for SILC.

The following arguments are common to the client routines for Fortran.

  • INTEGER*4 precision

    Precision (Section 3.3). The value of this member must be one of the following constants.

    SILC_INT(single precision integer)
    SILC_LONG(double precision integer)
    SILC_FLOAT(single precision real)
    SILC_DOUBLE(double precision real)
    SILC_COMPLEX(single precision complex)
    SILC_DOUBLE_COMPLEX(double precision complex)
  • INTEGER*4 status

    An exit status of a client routine. The value is 0 if no error occurs, and −1 otherwise.

In the following descriptions, type can be one of the following data types.

INTEGER*4(for SILC_INT)
INTEGER*8(for SILC_LONG)
REAL*4(for SILC_FLOAT)
REAL*8(for SILC_DOUBLE)
COMPLEX*8(for SILC_COMPLEX)
COMPLEX*16(for SILC_DOUBLE_COMPLEX)
  • SILC_INIT(status)

    This routine establishes a connection to a SILC server. Call this routine before you start using the SILC server (for example, at the beginning of a user program).

    Output:

    INTEGER*4 status

    An exit status.

  • SILC_FINALIZE(status)

    This routine closes the connection to the SILC server. Call this routine when you stop using the SILC server (for example, at the end of a user program).

    Output:

    INTEGER*4 status

    An exit status.

  • SILC_EXEC(expr, status)

    This routine sends a request for computation to the SILC server.

    Input:

    CHARACTER*size expr

    A mathematical expression written in the command language (Section 4).

    Output:

    INTEGER*4 status

    An exit status.

  • SILC_PUT_SCALAR(name, value, precision, status)

    This routine associates a name with a scalar value and deposits it to the SILC server.

    Input:

    CHARACTER*size name

    A name.

    type value

    The scalar value.

    INTEGER*4 precision

    The precision of the scalar value.

    Output:

    INTEGER*4 status

    An exit status.

  • SILC_PUT_ROW_VECTOR(name, value, length, precision, status)

    This routine associates a name with a row vector and deposits it to the SILC server.

    Input:

    CHARACTER*size name

    A name.

    type value(length)

    The elements of the vector.

    INTEGER*4 length

    The length of the vector.

    INTEGER*4 precision

    The precision of the elements.

    Output:

    INTEGER*4 status

    An exit status.

  • SILC_PUT_COLUMN_VECTOR(name, value, length, precision, status)

    This routine associates a name with a column vector and deposits it to the SILC server.

    Input:

    CHARACTER*size name

    A name.

    type value(length)

    The elements of the vector.

    INTEGER*4 length

    The length of the vector.

    INTEGER*4 precision

    The precision of the elements.

    Output:

    INTEGER*4 status

    An exit status.

  • SILC_PUT_MATRIX(name, value, m, n, precision, status)

    This routine associates a name with an M-by-N dense matrix and deposits it to the SILC server.

    Input:

    CHARACTER*size name

    A name.

    type value(m, n)

    The elements of the matrix.

    INTEGER*4 m, n

    The dimensions of the matrix.

    INTEGER*4 precision

    The precision of the elements.

    Output:

    INTEGER*4 status

    An exit status.

  • SILC_PUT_MATRIX_CRS(name, value, m, n, nnz, row, index, precision, status)

    This routine associates a name with an M-by-N sparse matrix in the CRS format and deposits it to the SILC server. Unlike the C version of the CRS format, the base (or origin) of elements of the arrays row and index must be one.

    Input:

    CHARACTER*size name

    A name.

    type value(nnz)

    The non-zero elements of the matrix.

    INTEGER*4 m, n

    The dimensions of the matrix.

    INTEGER*4 nnz

    The number of the non-zero elements.

    INTEGER*4 row(m+1)

    An array of row pointers.

    INTEGER*4 index(nnz)

    An array of column indexes.

    INTEGER*4 precision

    The precision of the non-zero elements.

    Output:

    INTEGER*4 status

    An exit status.

  • SILC_PUT_CUBIC_ARRAY(name, value, l, m, n, precision, status)

    This routine associates a name with an L-by-M-by-N cubic array and deposits it to the SILC server.

    Input:

    CHARACTER*size name

    A name.

    type value(l, m, n)

    The elements of the cubic array.

    INTEGER*4 l, m, n

    The dimensions of the cubic array.

    INTEGER*4 precision

    The precision of the elements.

    Output:

    INTEGER*4 status

    An exit status.

  • SILC_GET_SCALAR(name, value, status)

    This routine receives a scalar value from the SILC server by specifying the name of the scalar value to be fetched.

    Input:

    CHARACTER*size name

    A name.

    Output:

    type value

    The received scalar value.

    INTEGER*4 status

    An exit status.

  • SILC_GET_ROW_VECTOR(name, value, status)

    This routine receives a row vector from the SILC server by specifying the name of the vector to be fetched. You need to know the dimension of the vector (i.e., length) in advance in order to prepare the output array value.

    Input:

    CHARACTER*size name

    A name.

    Output:

    type value(length)

    The elements of the received vector.

    INTEGER*4 status

    An exit status.

  • SILC_GET_COLUMN_VECTOR(name, value, status)

    This routine receives a column vector from the SILC server by specifying the name of the vector to be fetched. You need to know the dimension of the vector (i.e., length) in advance in order to prepare the output array value.

    Input:

    CHARACTER*size name

    A name.

    Output:

    type value(length)

    The elements of the received vector.

    INTEGER*4 status

    An exit status.

  • SILC_GET_MATRIX(name, value, status)

    This routine receives a dense matrix from the SILC server by specifying the name of the matrix to be fetched. You need to know the dimensions of the matrix m and n in advance in order to prepare the output array value.

    Input:

    CHARACTER*size name

    A name.

    Output:

    type value(m, n)

    The elements of the received matrix.

    INTEGER*4 status

    An exit status.

  • SILC_GET_MATRIX_CRS(name, value, row, index, status)

    This routine receives a sparse matrix in the CRS format from the SILC server by specifying the name of the matrix to be fetched. You need to know the dimensions of the matrix m and n as well as the number of non-zero elements nnz in advance in order to prepare the output arrays value, row, and index. The base (or origin) of elements of row and index is one.

    Input:

    CHARACTER*size name

    A name.

    Output:

    type value(nnz)

    The non-zero elements of the received matrix.

    INTEGER*4 row(m+1)

    An array of row pointers.

    INTEGER*4 index(nnz)

    An array of column indexes.

    INTEGER*4 status

    An exit status.

  • SILC_GET_CUBIC_ARRAY(name, value, status)

    This routine receives a cubic array from the SILC server by specifying the name of the cubic array to be fetched. You need to know the sizes of the cubic array (i.e., l, m, and n) in order to prepare the output array value.

    Input:

    CHARACTER*size name

    A name.

    Output:

    type value(l, m, n)

    The elements of the received cubic array.

    INTEGER*4 status

    An exit status.

5.3. Built-in functions and procedures

Built-in functions and procedures are defined in modules. If two or more functions or procedures have the same name, the function or procedure that is found first is called. By using the prefer statement (Section 4.3) to change the order of modules, you can use specific functions and procedures defined in particular modules.

5.3.1. coremodule

  • scalar dot(rowVector, columnVector) [function]

    This function returns the inner product of the given vectors.

  • scalar sqrt(scalar) [function]

    vector sqrt(vector) [function]

    This function returns the square root of the given scalar value or elements of the given vector.

  • scalar norm2(vector) [function]

    This function returns the 2-norm of the given vector.

  • scalar length(vector) [function]

    This function returns the length (i.e., the number of elements) of the given vector.

  • scalar time() [function]

    This function returns the time in seconds in double precision real.

5.3.2. dense module

  • columnVector diagvec(matrix) [function]

    This function returns a column vector that consists of elements in the main diagonal of the given matrix.

  • matrix zeros(scalar) [function]

  • matrix zeros(scalar, scalar) [function]

    These functions return a dense matrix whose elements are 0 in double precision real. The zeros function taking one argument returns a square matrix. The first and second arguments of the other function specify the number of rows and the number of columns, respectively.

  • matrix ones(scalar) [function]

  • matrix ones(scalar, scalar) [function]

    These functions return a dense matrix whose elements are 1 in double precision real. The ones function taking one argument returns a square matrix. The first and second arguments of the other function specify the number of rows and the number of columns, respectively.

  • matrix rand(scalar) [function]

  • matrix rand(scalar, scalar) [function]

    These functions return a dense matrix whose elements are random numbers in double precision real. The rand function taking one argument returns a square matrix. The first and second arguments of the other function specify the number of rows and the number of columns, respectively. The sequence of random numbers can be initialized with the srand procedure described below.

  • columnVector size(matrix) [function]

    This function returns a column vector of length 2. The elements of the vector represent the dimensions (i.e., the number of rows and the number of columns) of the given matrix.

  • scalar size(matrix, scalar) [function]

    This function returns a dimension of the given matrix. The number of rows is returned if the second argument is 1, while the number of columns is returned if the second argument is 2.

  • matrix full(scalar, scalar) [function]

    This function returns an integer matrix of double precision. The first and second arguments specify the number of rows and the number of columns, respectively. Elements of the matrix have non-zero values (but they are not random numbers).

  • split(matrix IN, matrix OUT, matrix OUT, matrix OUT) [procedure]

    This procedure divides the matrix of the first argument into lower triangle, main diagonal, and upper triangle. These parts are stored in the three variables specified by the second, third, and forth arguments, respectively.

  • srand(scalar IN) [procedure]

    This procedure (re)initializes the Mersenne Twister random number generator, specifying a seed for a new sequence of random numbers.

5.3.3. sparse_crs module

  • matrix sparse(vector r, vector c, vector v, scalar m, scalar n) [function]

  • matrix sparse(vector r, vector c, scalar v, scalar m, scalar n) [function]

    These functions return a sparse matrix in the CRS format. Vector r in the first argument is a list of row indices and vector c in the second argument is a list of column indices. If the third argument v is a vector, the kth elements of r and c represent the row and column indices of the matrix to which the kth element of v is stored. That is, v is a list of non-zero elements. In this case, the length of r, c and v must be the same. If v is scalar, all non-zero elements in the matrix will be the same value. In this case, the length of r and c must be the same. The fourth argument m is the number of rows and th fifth argument m is the number of columns. The precision of the matrix will be the same as the precision of v.

  • matrix zeros(scalar) [function]

  • matrix zeros(scalar, scalar) [function]

    These functions return a sparse matrix (in the CRS format) whose elements are 0 in double precision real. The zeros function taking one argument returns a square matrix. The first and second arguments of the other function specify the number of rows and the number of columns, respectively.

  • matrix eye(scalar) [function]

    This function returns the identity matrix (in the CRS format) of the given dimension.

  • matrix diag(vector) [function]

  • matrix diag(vector, scalar) [function]

    These functions return a sparse diagonal matrix in the CRS format. Let n be the length of the given vector. If only one argument is specified, the diag function generates n-by-n diagonal matrix whose diagonal elements are given by the vector. If the second argument is specified, it represents an offset value (referred to as k). If k = 0, then diag(v, k) is equivalent to diag(v). If k > 0, a square matrix with a diagonal starting from (1, k+1) is generated. If k < 0, the subdiagonal starts from (1-k, 1). The dimension of the generated matrix is n+k.

  • vector diagvec(matrix) [function]

    This function returns a vector that consists of elements in the main diagonal of the given matrix (in the CRS format).

  • matrix fliplr(matrix) [function]

    This function returns the given matrix (in the CRS format) with columns in the reversed order.

  • matrix flipud(matrix) [function]

    This function returns the given matrix (in the CRS format) with rows in the reversed order.

5.3.4. sparse_band module

  • matrix CRS(matrix) [function]

    This function converts the given matrix (in the banded storage format) to the CRS format and returns a new matrix.

  • matrix band(matrix) [function]

    This function converts the given matrix (in the CRS format) to the banded storage format and returns a new matrix.

  • scalar rcond(matrix) [function]

    This function returns the reciprocal of the estimated condition number of the given matrix (in the banded storage format).

A. Revision history

  • October 31, 2007 (SILC v1.3)

    • Descriptions on how to compile a SILC server and user programs were added.

    • Some built-in functions were added to the API reference.

  • November 12, 2006 (SILC v1.2)

    • The source file of this document was converted into the DocBook XML format.

    • Descriptions of some built-in functions and procedures were added.

  • November 25, 2005 (SILC v1.1)

    • The first English edition.

$Id: users_en.xml,v 1.13 2007/10/31 06:31:35 kajiyama Exp $