Last modified: | October 31, 2007 |
---|
This document describes the extensions of SILC's command language in the console program (src/client/console.c). The console program allows you to (1) interactively execute mathematical expressions and (2) execute a sequence of mathematical expressions stored in a file. The program has made several language extensions to the command language so that conditional branching and loops can be written. Using this program you can write user programs without compilers of other programming languages such as C and Fortran.
Conditional branching is written in the following form:
if (cond_expr) { stmt; ... } else if (cond_expr) { stmt; ... } else { stmt; ... }
where cond_expr is a conditional expression (described below) and stmt is a statement. Else clauses may be omitted. Braces cannot be omitted.
Loops are written in the following form:
while (cond_expr) { stmt; ... }
where cond_expr is a conditional expression (described below) and stmt is a statement. Braces cannot be omitted. Within loops you can use continue and break statements.
Conditional expressions (cond_expr) are composed of the following comparison operators.
where expr is a mathematical expression in SILC's command language. The value of the expression must be a scalar value. Values of other data types (such as vectors and matrices) result in a runtime error. In addition, conditional expressions can be combined with the following boolean operators and parentheses.
These comparison and boolean operators yield boolean values. Any expressions that do not have boolean values cannot be used as conditional expressions. Moreover, true and false can be used as boolean constants.
Conditional expressions are handled in the console program as follows:
Execute an assignment statement for each of the two expressions specified as the left- and right-hand sides of a comparison operator, and store the value of the expression to a temporary variable _ as follows:
SILC_EXEC("_ = expr")
Fetch the value of the temporary variable from the SILC server:
SILC_GET(&tmp, "_")
Compare the values of the two expressions (fetched one after another) on the client side.
In addition to the system statements defined in SILC's command language, the following extended system statements can be used.
load "filename", variable
Read data (such as matrices and vectors) from a specified file in the Matrix Market format, and deposit the data to the SILC server with a specified variable name. Examples:
load "filename.mtx", A load "filename.mtx", b
save "filename", variable
Fetch the data of a specified variable name from the server, and store the data into a file in the Matrix Market format. Example:
save "filename.mtx", x
pprint expr
Fetch the value of a specified mathematical expression expr from the server, and pretty-print it on the client's standard output.
message "string"
Print a specified string on the client's standard output.
Conditional branching, loops, and the extended system statements are carried out on the client side. Any other statements (namely, ordinary statements in SILC's command language) are carried out in the SILC server. This implies that all data are maintained by the server (that is, the console program has no mechanism for data management).
Statements can be concatenated by semicolons. The last semicolon at the end of a line can be omitted.
Lines can be concatenated by placing \ at the end of a line. For example, the following statement is treated as written in a single line:
B = {1, 2, 3; \ 4, 5, 6; \ 7, 8, 9}
Any input from # to the end of a line is treated as a comment (simply ignored).
The following is a script that realizes the Conjugate Gradient (CG) method using the aforementioned extended command language:
# create tridiagonal matrix A and vector b n = 400 A = diag(2.0 * ones(n, 1)) - diag(ones(n-1, 1), 1) - diag(ones(n-1, 1), -1) b = A * (-ones(n, 1)) # solve the linear system Ax=b with the CG method rho_old = 1.0 p = zeros(n, 1) x = zeros(n, 1) r = b bnrm2 = 1.0 / norm2(b) iter = 1 while (iter <= n) { rho = r' * r beta = rho / rho_old p = r + beta * p q = A * p alpha = rho / (p' * q) r = r - alpha * q nrm2 = norm2(r) * bnrm2 x = x + alpha * p if (nrm2 <= 1.0e-12) { break } rho_old = rho iter += 1 } # store the solution x into a file save "sol.mtx", x # print the iteration count message "number of iterations:" pprint iter
To run this script, store the script into a file (silc_cg.txt for example), start a SILC server, and run the console program as follows:
console silc_cg.txt
If everything works fine, the script terminates when the number of iterations reaches 200.
$Id: README.console.en,v 1.5 2007/10/31 05:18:48 kajiyama Exp $