GALAHAD SSLS package#
purpose#
Given a (possibly rectangular) matrix \(A\) and symmetric matrices \(H\) and \(C\), form and factorize the block, symmetric matrix
SLS
Full advantage is taken of any zero coefficients in the matrices
\(H\), \(A\) and \(C\).
See Section 4 of $GALAHAD/doc/ssls.pdf for additional details.
method#
The method simply assembles \(K\) from its components, and then relies
on SLS
for analysis, factorization and solves.
matrix storage#
The unsymmetric \(m\) by \(n\) matrix \(A\) may be presented and stored in a variety of convenient input formats.
Dense storage format: The matrix \(A\) is stored as a compact dense matrix by rows, that is, the values of the entries of each row in turn are stored in order within an appropriate real one-dimensional array. In this case, component \(n \ast i + j\) of the storage array A_val will hold the value \(A_{ij}\) for \(0 \leq i \leq m-1\), \(0 \leq j \leq n-1\). The string A_type = ‘dense’ should be specified.
Dense by columns storage format: The matrix \(A\) is stored as a compact dense matrix by columns, that is, the values of the entries of each column in turn are stored in order within an appropriate real one-dimensional array. In this case, component \(m \ast j + i\) of the storage array A_val will hold the value \(A_{ij}\) for \(0 \leq i \leq m-1\), $0 \leq j \leq n-1 The string A_type = ‘dense_by_columns’ should be specified.
Sparse co-ordinate storage format: Only the nonzero entries of the matrices are stored. For the \(l\)-th entry, \(0 \leq l \leq ne-1\), of \(A\), its row index i, column index j and value \(A_{ij}\), \(0 \leq i \leq m-1\), \(0 \leq j \leq n-1\), are stored as the \(l\)-th components of the integer arrays A_row and A_col and real array A_val, respectively, while the number of nonzeros is recorded as A_ne = \(ne\). The string A_type = ‘coordinate’should be specified.
Sparse row-wise storage format: Again only the nonzero entries are stored, but this time they are ordered so that those in row i appear directly before those in row i+1. For the i-th row of \(A\) the i-th component of the integer array A_ptr holds the position of the first entry in this row, while A_ptr(m) holds the total number of entries. The column indices j, \(0 \leq j \leq n-1\), and values \(A_{ij}\) of the nonzero entries in the i-th row are stored in components l = A_ptr(i), \(\ldots\), A_ptr(i+1)-1, \(0 \leq i \leq m-1\), of the integer array A_col, and real array A_val, respectively. For sparse matrices, this scheme almost always requires less storage than its predecessor. The string A_type = ‘sparse_by_rows’ should be specified.
Sparse column-wise storage format: Once again only the nonzero entries are stored, but this time they are ordered so that those in column j appear directly before those in column j+1. For the j-th column of \(A\) the j-th component of the integer array A_ptr holds the position of the first entry in this column, while A_ptr(n) holds the total number of entries. The row indices i, \(0 \leq i \leq m-1\), and values \(A_{ij}\) of the nonzero entries in the j-th columnsare stored in components l = A_ptr(j), \(\ldots\), A_ptr(j+1)-1, \(0 \leq j \leq n-1\), of the integer array A_row, and real array A_val, respectively. As before, for sparse matrices, this scheme almost always requires less storage than the co-ordinate format. The string A_type = ‘sparse_by_columns’ should be specified.
The symmetric \(n\) by \(n\) matrix \(H\), as well as the \(m\) by \(m\) matrix \(C\), may also be presented and stored in a variety of formats. But crucially symmetry is exploited by only storing values from the lower triangular part (i.e, those entries that lie on or below the leading diagonal). We focus on \(H\), but everything we say applied equally to \(C\).
Dense storage format: The matrix \(H\) is stored as a compact dense matrix by rows, that is, the values of the entries of each row in turn are stored in order within an appropriate real one-dimensional array. Since \(H\) is symmetric, only the lower triangular part (that is the part \(H_{ij}\) for \(0 \leq j \leq i \leq n-1\)) need be held. In this case the lower triangle should be stored by rows, that is component \(i * i / 2 + j\) of the storage array H_val will hold the value \(H_{ij}\) (and, by symmetry, \(H_{ji}\)) for \(0 \leq j \leq i \leq n-1\). The string H_type = ‘dense’ should be specified.
Sparse co-ordinate storage format: Only the nonzero entries of the matrices are stored. For the \(l\)-th entry, \(0 \leq l \leq ne-1\), of \(H\), its row index i, column index j and value \(H_{ij}\), \(0 \leq j \leq i \leq n-1\), are stored as the \(l\)-th components of the integer arrays H_row and H_col and real array H_val, respectively, while the number of nonzeros is recorded as H_ne = \(ne\). Note that only the entries in the lower triangle should be stored. The string H_type = ‘coordinate’ should be specified.
Sparse row-wise storage format: Again only the nonzero entries are stored, but this time they are ordered so that those in row i appear directly before those in row i+1. For the i-th row of \(H\) the i-th component of the integer array H_ptr holds the position of the first entry in this row, while H_ptr(n) holds the total number of entries. The column indices j, \(0 \leq j \leq i\), and values \(H_{ij}\) of the entries in the i-th row are stored in components l = H_ptr(i), …, H_ptr(i+1)-1 of the integer array H_col, and real array H_val, respectively. Note that as before only the entries in the lower triangle should be stored. For sparse matrices, this scheme almost always requires less storage than its predecessor. The string H_type = ‘sparse_by_rows’ should be specified.
Diagonal storage format: If \(H\) is diagonal (i.e., \(H_{ij} = 0\) for all \(0 \leq i \neq j \leq n-1\)) only the diagonals entries \(H_{ii}\), \(0 \leq i \leq n-1\) need be stored, and the first n components of the array H_val may be used for the purpose. The string H_type = ‘diagonal’ should be specified.
Multiples of the identity storage format: If \(H\) is a multiple of the identity matrix, (i.e., \(H = \alpha I\) where \(I\) is the n by n identity matrix and \(\alpha\) is a scalar), it suffices to store \(\alpha\) as the first component of H_val. The string H_type = ‘scaled_identity’ should be specified.
The identity matrix format: If \(H\) is the identity matrix, no values need be stored. The string H_type = ‘identity’ should be specified.
The zero matrix format: The same is true if \(H\) is the zero matrix, but now the string H_type = ‘zero’ or ‘none’ should be specified.
introduction to function calls#
To solve a given problem, functions from the ssls package must be called in the following order:
ssls_initialize - provide default control parameters and set up initial data structures
ssls_read_specfile (optional) - override control values by reading replacement values from a file
ssls_import - assemble and analyse the structure of \(K\) prior to factorization
ssls_reset_control (optional) - possibly change control parameters if a sequence of problems are being solved
ssls_factorize_matrix - form and factorize the block matrix \(K\) from its components
ssls_solve_system - solve block linear system of equations involving \(K\)
ssls_information (optional) - recover information about the solution and solution process
ssls_terminate - deallocate data structures
See the examples section for illustrations of use.
callable functions#
overview of functions provided#
// namespaces namespace conf; // typedefs typedef float spc_; typedef double rpc_; typedef int ipc_; // structs struct ssls_control_type; struct ssls_inform_type; struct ssls_time_type; // global functions void ssls_initialize( void **data, struct ssls_control_type* control, ipc_ *status ); void ssls_read_specfile( struct ssls_control_type* control, const char specfile[] ); void ssls_import( struct ssls_control_type* control, void **data, ipc_ *status, ipc_ n, ipc_ m, const char H_type[], ipc_ H_ne, const ipc_ H_row[], const ipc_ H_col[], const ipc_ H_ptr[], const char A_type[], ipc_ A_ne, const ipc_ A_row[], const ipc_ A_col[], const ipc_ A_ptr[], const char C_type[], ipc_ C_ne, const ipc_ C_row[], const ipc_ C_col[], const ipc_ C_ptr[] ); void ssls_reset_control( struct ssls_control_type* control, void **data, ipc_ *status ); void ssls_factorize_matrix( void **data, ipc_ *status, ipc_ n, ipc_ h_ne, const rpc_ H_val[], ipc_ a_ne, const rpc_ A_val[], ipc_ c_ne, const rpc_ C_val[] ); void ssls_solve_system(void **data, ipc_ *status, ipc_ n, ipc_ m, rpc_ sol[]); void ssls_information(void **data, struct ssls_inform_type* inform, ipc_ *status); void ssls_terminate( void **data, struct ssls_control_type* control, struct ssls_inform_type* inform );
typedefs#
typedef float spc_
spc_
is real single precision
typedef double rpc_
rpc_
is the real working precision used, but may be changed to float
by
defining the preprocessor variable REAL_32
or (if supported) to
__real128
using the variable REAL_128
.
typedef int ipc_
ipc_
is the default integer word length used, but may be changed to
int64_t
by defining the preprocessor variable INTEGER_64
.
function and structure names#
The function and structure names described below are appropriate for the
default real working precision (double
) and integer word length
(int32_t
). To use the functions and structures with different precisions
and integer word lengths, an additional suffix must be added to their names
(and the arguments set accordingly). The appropriate suffices are:
_s
for single precision (float
) reals and
standard 32-bit (int32_t
) integers;
_q
for quadruple precision (__real128
) reals (if supported) and
standard 32-bit (int32_t
) integers;
_64
for standard precision (double
) reals and
64-bit (int64_t
) integers;
_s_64
for single precision (float
) reals and
64-bit (int64_t
) integers; and
_q_64
for quadruple precision (__real128
) reals (if supported) and
64-bit (int64_t
) integers.
Thus a call to ssls_initialize
below will instead be
void ssls_initialize_s_64(void **data, struct ssls_control_type_s_64* control, int64_t *status)
if single precision (float
) reals and 64-bit (int64_t
) integers are
required. Thus it is possible to call functions for this package
with more that one precision and/or integer word length at same time. An
example is provided for the package expo
,
and the obvious modifications apply equally here.
function calls#
void ssls_initialize( void **data, struct ssls_control_type* control, ipc_ *status )
Set default control values and initialize private data
Parameters:
data |
holds private internal data |
control |
is a struct containing control information (see ssls_control_type) |
status |
is a scalar variable of type ipc_, that gives the exit status from the package. Possible values are (currently):
|
void ssls_read_specfile( struct ssls_control_type* control, const char specfile[] )
Read the content of a specification file, and assign values associated with given keywords to the corresponding control parameters. An in-depth discussion of specification files is available, and a detailed list of keywords with associated default values is provided in $GALAHAD/src/ssls/SSLS.template. See also Table 2.1 in the Fortran documentation provided in $GALAHAD/doc/ssls.pdf for a list of how these keywords relate to the components of the control structure.
Parameters:
control |
is a struct containing control information (see ssls_control_type) |
specfile |
is a character string containing the name of the specification file |
void ssls_import( struct ssls_control_type* control, void **data, ipc_ *status, ipc_ n, ipc_ m, const char H_type[], ipc_ H_ne, const ipc_ H_row[], const ipc_ H_col[], const ipc_ H_ptr[], const char A_type[], ipc_ A_ne, const ipc_ A_row[], const ipc_ A_col[], const ipc_ A_ptr[], const char C_type[], ipc_ C_ne, const ipc_ C_row[], const ipc_ C_col[], const ipc_ C_ptr[] )
Assemble and analyse the structure of \(K\) prior to factorization.
Parameters:
control |
is a struct whose members provide control paramters for the remaining prcedures (see ssls_control_type) |
data |
holds private internal data |
status |
is a scalar variable of type ipc_, that gives the exit status from the package. Possible values are:
|
n |
is a scalar variable of type ipc_, that holds the number of rows in the symmetric matrix \(H\). |
m |
is a scalar variable of type ipc_, that holds the number of rows in the symmetric matrix \(C\). |
H_type |
is a one-dimensional array of type char that specifies the symmetric storage scheme used for the matrix \(H\). It should be one of ‘coordinate’, ‘sparse_by_rows’, ‘dense’, ‘diagonal’, ‘scaled_identity’, ‘identity’, ‘zero’ or ‘none’, the latter pair if \(H=0\); lower or upper case variants are allowed. |
H_ne |
is a scalar variable of type ipc_, that holds the number of entries in the lower triangular part of \(H\) in the sparse co-ordinate storage scheme. It need not be set for any of the other schemes. |
H_row |
is a one-dimensional array of size H_ne and type ipc_, that holds the row indices of the lower triangular part of \(H\) in the sparse co-ordinate storage scheme. It need not be set for any of the other three schemes, and in this case can be NULL. |
H_col |
is a one-dimensional array of size H_ne and type ipc_, that holds the column indices of the lower triangular part of \(H\) in either the sparse co-ordinate, or the sparse row-wise storage scheme. It need not be set when the dense, diagonal or (scaled) identity storage schemes are used, and in this case can be NULL. |
H_ptr |
is a one-dimensional array of size n+1 and type ipc_, that holds the starting position of each row of the lower triangular part of \(H\), as well as the total number of entries, in the sparse row-wise storage scheme. It need not be set when the other schemes are used, and in this case can be NULL. |
A_type |
is a one-dimensional array of type char that specifies the symmetric storage scheme used for the matrix \(A\). It should be one of ‘coordinate’, ‘sparse_by_rows’, ‘dense’ or ‘absent’, the latter if access to the Jacobian is via matrix-vector products; lower or upper case variants are allowed. |
A_ne |
is a scalar variable of type ipc_, that holds the number of entries in \(A\) in the sparse co-ordinate storage scheme. It need not be set for any of the other schemes. |
A_row |
is a one-dimensional array of size A_ne and type ipc_, that holds the row indices of \(A\) in the sparse co-ordinate storage scheme. It need not be set for any of the other schemes, and in this case can be NULL. |
A_col |
is a one-dimensional array of size A_ne and type ipc_, that holds the column indices of \(A\) in either the sparse co-ordinate, or the sparse row-wise storage scheme. It need not be set when the dense or diagonal storage schemes are used, and in this case can be NULL. |
A_ptr |
is a one-dimensional array of size n+1 and type ipc_, that holds the starting position of each row of \(A\), as well as the total number of entries, in the sparse row-wise storage scheme. It need not be set when the other schemes are used, and in this case can be NULL. |
C_type |
is a one-dimensional array of type char that specifies the symmetric storage scheme used for the matrix \(C\). It should be one of ‘coordinate’, ‘sparse_by_rows’, ‘dense’, ‘diagonal’, ‘scaled_identity’, ‘identity’, ‘zero’ or ‘none’, the latter pair if \(C=0\); lower or upper case variants are allowed. |
C_ne |
is a scalar variable of type ipc_, that holds the number of entries in the lower triangular part of \(C\) in the sparse co-ordinate storage scheme. It need not be set for any of the other schemes. |
C_row |
is a one-dimensional array of size C_ne and type ipc_, that holds the row indices of the lower triangular part of \(C\) in the sparse co-ordinate storage scheme. It need not be set for any of the other three schemes, and in this case can be NULL. |
C_col |
is a one-dimensional array of size C_ne and type ipc_, that holds the column indices of the lower triangular part of \(C\) in either the sparse co-ordinate, or the sparse row-wise storage scheme. It need not be set when the dense, diagonal or (scaled) identity storage schemes are used, and in this case can be NULL. |
C_ptr |
is a one-dimensional array of size n+1 and type ipc_, that holds the starting position of each row of the lower triangular part of \(C\), as well as the total number of entries, in the sparse row-wise storage scheme. It need not be set when the other schemes are used, and in this case can be NULL. |
void ssls_reset_control( struct ssls_control_type* control, void **data, ipc_ *status )
Reset control parameters after import if required.
Parameters:
control |
is a struct whose members provide control paramters for the remaining prcedures (see ssls_control_type) |
data |
holds private internal data |
status |
is a scalar variable of type ipc_, that gives the exit status from the package. Possible values are:
|
void ssls_factorize_matrix( void **data, ipc_ *status, ipc_ n, ipc_ h_ne, const rpc_ H_val[], ipc_ a_ne, const rpc_ A_val[], ipc_ c_ne, const rpc_ C_val[] )
Fctorize the block matrix
Parameters:
data |
holds private internal data |
status |
is a scalar variable of type ipc_, that gives the exit status from the package. Possible values are:
|
n |
is a scalar variable of type ipc_, that holds the number of rows in the symmetric matrix \(H\). |
h_ne |
is a scalar variable of type ipc_, that holds the number of entries in the lower triangular part of the symmetric matrix \(H\). |
H_val |
is a one-dimensional array of size h_ne and type rpc_, that holds the values of the entries of the lower triangular part of the symmetric matrix \(H\) in any of the available storage schemes |
a_ne |
is a scalar variable of type ipc_, that holds the number of entries in the unsymmetric matrix \(A\). |
A_val |
is a one-dimensional array of size a_ne and type rpc_, that holds the values of the entries of the unsymmetric matrix \(A\) in any of the available storage schemes. |
c_ne |
is a scalar variable of type ipc_, that holds the number of entries in the lower triangular part of the symmetric matrix \(C\). |
C_val |
is a one-dimensional array of size c_ne and type rpc_, that holds the values of the entries of the lower triangular part of the symmetric matrix \(C\) in any of the available storage schemes |
void ssls_solve_system(void **data, ipc_ *status, ipc_ n, ipc_ m, rpc_ sol[])
Solve the block linear system
Parameters:
data |
holds private internal data |
status |
is a scalar variable of type ipc_, that gives the exit status from the package. Possible values are:
|
n |
is a scalar variable of type ipc_, that holds the number of entries in the vector \(a\). |
m |
is a scalar variable of type ipc_, that holds the number of entries in the vector \(b\). |
sol |
is a one-dimensional array of size n + m and type double. on entry, its first n entries must hold the vector \(a\), and the following entries must hold the vector \(b\). On a successful exit, its first n entries contain the solution components \(x\), and the following entries contain the components \(y\). |
void ssls_information(void **data, struct ssls_inform_type* inform, ipc_ *status)
Provides output information
Parameters:
data |
holds private internal data |
inform |
is a struct containing output information (see ssls_inform_type) |
status |
is a scalar variable of type ipc_, that gives the exit status from the package. Possible values are (currently):
|
void ssls_terminate( void **data, struct ssls_control_type* control, struct ssls_inform_type* inform )
Deallocate all internal private storage
Parameters:
data |
holds private internal data |
control |
is a struct containing control information (see ssls_control_type) |
inform |
is a struct containing output information (see ssls_inform_type) |
available structures#
ssls_control_type structure#
#include <galahad_ssls.h> struct ssls_control_type { // fields bool f_indexing; ipc_ error; ipc_ out; ipc_ print_level; bool space_critical; bool deallocate_error_fatal; char symmetric_linear_solver[31]; char prefix[31]; struct sls_control_type sls_control; };
detailed documentation#
control derived type as a C struct
components#
bool f_indexing
use C or Fortran sparse matrix indexing
ipc_ error
unit for error messages
ipc_ out
unit for monitor output
ipc_ print_level
controls level of diagnostic output
bool space_critical
if space is critical, ensure allocated arrays are no bigger than needed
bool deallocate_error_fatal
exit if any deallocation fails
char symmetric_linear_solver[31]
the name of the symmetric-indefinite linear equation solver used. Possible choices are currently: ‘sils’, ‘ma27’, ‘ma57’, ‘ma77’, ‘ma86’, ‘ma97’, ‘ssids’, ‘mumps’, ‘pardiso’, ‘mkl_pardiso’, ‘pastix’, ‘wsmp’, and ‘sytr’, although only ‘sytr’ and, for OMP 4.0-compliant compilers, ‘ssids’ are installed by default; others are easily installed (see README.external). More details of the capabilities of each solver are provided in the documentation for galahad_sls.
char prefix[31]
all output lines will be prefixed by prefix(2:LEN(TRIM(.prefix))-1) where prefix contains the required string enclosed in quotes, e.g. “string” or ‘string’
struct sls_control_type sls_control
control parameters for SLS
ssls_time_type structure#
#include <galahad_ssls.h> struct ssls_time_type { // fields rpc_ total; rpc_ analyse; rpc_ factorize; rpc_ solve; rpc_ clock_total; rpc_ clock_analyse; rpc_ clock_factorize; rpc_ clock_solve; };
detailed documentation#
time derived type as a C struct
components#
rpc_ total
total cpu time spent in the package
rpc_ analyse
cpu time spent forming, and analysing the structure of, \(K\)
rpc_ factorize
cpu time spent factorizing \(K\)
rpc_ solve
cpu time spent solving linear systems inolving \(K\)
rpc_ clock_total
total clock time spent in the package
rpc_ clock_analyse
clock time spent forming, and analysing the structure of, \(K\)
rpc_ clock_factorize
clock time spent factorizing \(K\)
rpc_ clock_solve
clock time spent solving linear systems inolving \(K\)
ssls_inform_type structure#
#include <galahad_ssls.h> struct ssls_inform_type { // fields ipc_ status; ipc_ alloc_status; char bad_alloc[81]; int64_t factorization_integer; int64_t factorization_real; ipc_ rank; bool rank_def; struct ssls_time_type time; struct sls_inform_type sls_inform; };
detailed documentation#
inform derived type as a C struct
components#
ipc_ status
return status. See SSLS_form_and_factorize for details
ipc_ alloc_status
the status of the last attempted allocation/deallocation
char bad_alloc[81]
the name of the array for which an allocation/deallocation error occurred
int64_t factorization_integer
the total integer workspace required for the factorization
int64_t factorization_real
the total real workspace required for the factorization
ipc_ rank
the computed rank of \(A\)
bool rank_def
is the matrix A rank defficient?
struct ssls_time_type time
timings (see above)
struct sls_inform_type sls_inform
inform parameters from the GALAHAD package SLS used
example calls#
This is an example of how to use the package to solve a block system of linear equations; the code is available in $GALAHAD/src/ssls/C/sslst.c . A variety of supported matrix storage formats are shown.
Notice that C-style indexing is used, and that this is flagged by setting
control.f_indexing
to false
. The floating-point type rpc_
is set in galahad_precision.h
to double
by default, but to float
if the preprocessor variable SINGLE
is defined. Similarly, the integer
type ipc_
from galahad_precision.h
is set to int
by default,
but to int64_t
if the preprocessor variable INTEGER_64
is defined.
/* sslst.c */
/* Full test for the SSLS C interface using C sparse matrix indexing */
#include <stdio.h>
#include <math.h>
#include <string.h>
#include "galahad_precision.h"
#include "galahad_cfunctions.h"
#include "galahad_ssls.h"
#ifdef REAL_128
#include <quadmath.h>
#endif
int main(void) {
// Derived types
void *data;
struct ssls_control_type control;
struct ssls_inform_type inform;
// Set problem data
ipc_ n = 3; // dimension of H
ipc_ m = 2; // dimension of C
ipc_ H_ne = 4; // number of elements of H
ipc_ A_ne = 3; // number of elements of A
ipc_ C_ne = 3; // number of elements of C
ipc_ H_dense_ne = 6; // number of elements of H
ipc_ A_dense_ne = 6; // number of elements of A
ipc_ C_dense_ne = 3; // number of elements of C
ipc_ H_row[] = {0, 1, 2, 2}; // row indices, NB lower triangle
ipc_ H_col[] = {0, 1, 2, 0};
ipc_ H_ptr[] = {0, 1, 2, 4};
ipc_ A_row[] = {0, 0, 1};
ipc_ A_col[] = {0, 1, 2};
ipc_ A_ptr[] = {0, 2, 3};
ipc_ C_row[] = {0, 1, 1}; // row indices, NB lower triangle
ipc_ C_col[] = {0, 0, 1};
ipc_ C_ptr[] = {0, 1, 3};
rpc_ H_val[] = {1.0, 2.0, 3.0, 1.0};
rpc_ A_val[] = {2.0, 1.0, 1.0};
rpc_ C_val[] = {4.0, 1.0, 2.0};
rpc_ H_dense[] = {1.0, 0.0, 2.0, 1.0, 0.0, 3.0};
rpc_ A_dense[] = {2.0, 1.0, 0.0, 0.0, 0.0, 1.0};
rpc_ C_dense[] = {4.0, 1.0, 2.0};
rpc_ H_diag[] = {1.0, 1.0, 2.0};
rpc_ C_diag[] = {4.0, 2.0};
rpc_ H_scid[] = {2.0};
rpc_ C_scid[] = {2.0};
rpc_ sol[n+m];
char st = ' ';
ipc_ status;
printf(" C sparse matrix indexing\n\n");
printf(" basic tests of storage formats\n\n");
for( ipc_ d=1; d <= 7; d++){
// Initialize SSLS
ssls_initialize( &data, &control, &status );
//control.print_level = 1;
//control.sls_control.print_level = 1;
strcpy(control.symmetric_linear_solver, "sytr ") ;
// Set user-defined control options
control.f_indexing = false; // C sparse matrix indexing
switch(d){
case 1: // sparse co-ordinate storage
st = 'C';
ssls_import( &control, &data, &status, n, m,
"coordinate", H_ne, H_row, H_col, NULL,
"coordinate", A_ne, A_row, A_col, NULL,
"coordinate", C_ne, C_row, C_col, NULL );
ssls_factorize_matrix( &data, &status,
H_ne, H_val,
A_ne, A_val,
C_ne, C_val );
break;
printf(" case %1" i_ipc_ " break\n",d);
case 2: // sparse by rows
st = 'R';
ssls_import( &control, &data, &status, n, m,
"sparse_by_rows", H_ne, NULL, H_col, H_ptr,
"sparse_by_rows", A_ne, NULL, A_col, A_ptr,
"sparse_by_rows", C_ne, NULL, C_col, C_ptr );
ssls_factorize_matrix( &data, &status,
H_ne, H_val,
A_ne, A_val,
C_ne, C_val );
break;
case 3: // dense
st = 'D';
ssls_import( &control, &data, &status, n, m,
"dense", H_ne, NULL, NULL, NULL,
"dense", A_ne, NULL, NULL, NULL,
"dense", C_ne, NULL, NULL, NULL );
ssls_factorize_matrix( &data, &status,
H_dense_ne, H_dense,
A_dense_ne, A_dense,
C_dense_ne, C_dense );
break;
case 4: // diagonal
st = 'L';
ssls_import( &control, &data, &status, n, m,
"diagonal", H_ne, NULL, NULL, NULL,
"dense", A_ne, NULL, NULL, NULL,
"diagonal", C_ne, NULL, NULL, NULL );
ssls_factorize_matrix( &data, &status,
n, H_diag,
A_dense_ne, A_dense,
m, C_diag );
break;
case 5: // scaled identity
st = 'S';
ssls_import( &control, &data, &status, n, m,
"scaled_identity", H_ne, NULL, NULL, NULL,
"dense", A_ne, NULL, NULL, NULL,
"scaled_identity", C_ne, NULL, NULL, NULL );
ssls_factorize_matrix( &data, &status,
1, H_scid,
A_dense_ne, A_dense,
1, C_scid );
break;
case 6: // identity
st = 'I';
ssls_import( &control, &data, &status, n, m,
"identity", H_ne, NULL, NULL, NULL,
"dense", A_ne, NULL, NULL, NULL,
"identity", C_ne, NULL, NULL, NULL );
ssls_factorize_matrix( &data, &status,
0, H_val,
A_dense_ne, A_dense,
0, C_val );
break;
case 7: // zero
st = 'Z';
ssls_import( &control, &data, &status, n, m,
"identity", H_ne, NULL, NULL, NULL,
"dense", A_ne, NULL, NULL, NULL,
"zero", C_ne, NULL, NULL, NULL );
ssls_factorize_matrix( &data, &status,
0, H_val,
A_dense_ne, A_dense,
0, NULL );
break;
}
// check that the factorization succeeded
if(status != 0){
ssls_information( &data, &inform, &status );
printf("%c: SSLS_solve factorization exit status = %1" i_ipc_ "\n",
st, inform.status);
continue;
}
// Set right-hand side ( a, b ) so that solution is vec(1.0)
switch(d){
case 4: // diagonal
sol[0] = 3.0;
sol[1] = 2.0;
sol[2] = 3.0;
sol[3] = -1.0;
sol[4] = -1.0;
break;
case 5: // scaled identity
sol[0] = 4.0;
sol[1] = 3.0;
sol[2] = 3.0;
sol[3] = 1.0;
sol[4] = -1.0;
break;
case 6: // identity
sol[0] = 3.0;
sol[1] = 2.0;
sol[2] = 2.0;
sol[3] = 2.0;
sol[4] = 0.0;
break;
case 7: // zero
sol[0] = 3.0;
sol[1] = 2.0;
sol[2] = 2.0;
sol[3] = 3.0;
sol[4] = 1.0;
break;
default:
sol[0] = 4.0;
sol[1] = 3.0;
sol[2] = 5.0;
sol[3] = -2.0;
sol[4] = -2.0;
break;
}
ssls_solve_system( &data, &status, n, m, sol );
// check that the factorization succeeded
if(status != 0){
ssls_information( &data, &inform, &status );
printf("%c: SSLS_solve exit status = %1" i_ipc_ "\n",
st, inform.status);
continue;
}
ssls_information( &data, &inform, &status );
if(inform.status == 0){
printf("%c: status = %1" i_ipc_ "", st, inform.status);
printf(" sol = ");
for(int loop = 0; loop < n+m; loop++)
#ifdef REAL_128
printf("%f ", (double)sol[loop]);
#else
printf("%f ", sol[loop]);
#endif
printf("\n");
}else{
printf("%c: SSLS_solve exit status = %1" i_ipc_ "\n",
st, inform.status);
}
// Delete internal workspace
ssls_terminate( &data, &control, &inform );
}
}
This is the same example, but now fortran-style indexing is used; the code is available in $GALAHAD/src/ssls/C/sslstf.c .
/* sslst.c */
/* Full test for the SSLS C interface using Fortran sparse matrix indexing */
#include <stdio.h>
#include <math.h>
#include <string.h>
#include "galahad_precision.h"
#include "galahad_cfunctions.h"
#include "galahad_ssls.h"
#ifdef REAL_128
#include <quadmath.h>
#endif
int main(void) {
// Derived types
void *data;
struct ssls_control_type control;
struct ssls_inform_type inform;
// Set problem data
ipc_ n = 3; // dimension of H
ipc_ m = 2; // dimension of C
ipc_ H_ne = 4; // number of elements of H
ipc_ A_ne = 3; // number of elements of A
ipc_ C_ne = 3; // number of elements of C
ipc_ H_dense_ne = 6; // number of elements of H
ipc_ A_dense_ne = 6; // number of elements of A
ipc_ C_dense_ne = 3; // number of elements of C
ipc_ H_row[] = {1, 2, 3, 3}; // row indices, NB lower triangle
ipc_ H_col[] = {1, 2, 3, 1};
ipc_ H_ptr[] = {1, 2, 3, 5};
ipc_ A_row[] = {1, 1, 2};
ipc_ A_col[] = {1, 2, 3};
ipc_ A_ptr[] = {1, 3, 4};
ipc_ C_row[] = {1, 2, 2}; // row indices, NB lower triangle
ipc_ C_col[] = {1, 1, 2};
ipc_ C_ptr[] = {1, 2, 4};
rpc_ H_val[] = {1.0, 2.0, 3.0, 1.0};
rpc_ A_val[] = {2.0, 1.0, 1.0};
rpc_ C_val[] = {4.0, 1.0, 2.0};
rpc_ H_dense[] = {1.0, 0.0, 2.0, 1.0, 0.0, 3.0};
rpc_ A_dense[] = {2.0, 1.0, 0.0, 0.0, 0.0, 1.0};
rpc_ C_dense[] = {4.0, 1.0, 2.0};
rpc_ H_diag[] = {1.0, 1.0, 2.0};
rpc_ C_diag[] = {4.0, 2.0};
rpc_ H_scid[] = {2.0};
rpc_ C_scid[] = {2.0};
rpc_ sol[n+m];
char st = ' ';
ipc_ status;
printf(" Fortran sparse matrix indexing\n\n");
printf(" basic tests of storage formats\n\n");
for( ipc_ d=1; d <= 7; d++){
// Initialize SSLS
ssls_initialize( &data, &control, &status );
//control.print_level = 1;
//control.sls_control.print_level = 1;
strcpy(control.symmetric_linear_solver, "sytr ") ;
// Set user-defined control options
control.f_indexing = true; // fortran sparse matrix indexing
switch(d){
case 1: // sparse co-ordinate storage
st = 'C';
ssls_import( &control, &data, &status, n, m,
"coordinate", H_ne, H_row, H_col, NULL,
"coordinate", A_ne, A_row, A_col, NULL,
"coordinate", C_ne, C_row, C_col, NULL );
ssls_factorize_matrix( &data, &status,
H_ne, H_val,
A_ne, A_val,
C_ne, C_val );
break;
printf(" case %1" i_ipc_ " break\n",d);
case 2: // sparse by rows
st = 'R';
ssls_import( &control, &data, &status, n, m,
"sparse_by_rows", H_ne, NULL, H_col, H_ptr,
"sparse_by_rows", A_ne, NULL, A_col, A_ptr,
"sparse_by_rows", C_ne, NULL, C_col, C_ptr );
ssls_factorize_matrix( &data, &status,
H_ne, H_val,
A_ne, A_val,
C_ne, C_val );
break;
case 3: // dense
st = 'D';
ssls_import( &control, &data, &status, n, m,
"dense", H_ne, NULL, NULL, NULL,
"dense", A_ne, NULL, NULL, NULL,
"dense", C_ne, NULL, NULL, NULL );
ssls_factorize_matrix( &data, &status,
H_dense_ne, H_dense,
A_dense_ne, A_dense,
C_dense_ne, C_dense );
break;
case 4: // diagonal
st = 'L';
ssls_import( &control, &data, &status, n, m,
"diagonal", H_ne, NULL, NULL, NULL,
"dense", A_ne, NULL, NULL, NULL,
"diagonal", C_ne, NULL, NULL, NULL );
ssls_factorize_matrix( &data, &status,
n, H_diag,
A_dense_ne, A_dense,
m, C_diag );
break;
case 5: // scaled identity
st = 'S';
ssls_import( &control, &data, &status, n, m,
"scaled_identity", H_ne, NULL, NULL, NULL,
"dense", A_ne, NULL, NULL, NULL,
"scaled_identity", C_ne, NULL, NULL, NULL );
ssls_factorize_matrix( &data, &status,
1, H_scid,
A_dense_ne, A_dense,
1, C_scid );
break;
case 6: // identity
st = 'I';
ssls_import( &control, &data, &status, n, m,
"identity", H_ne, NULL, NULL, NULL,
"dense", A_ne, NULL, NULL, NULL,
"identity", C_ne, NULL, NULL, NULL );
ssls_factorize_matrix( &data, &status,
0, H_val,
A_dense_ne, A_dense,
0, C_val );
break;
case 7: // zero
st = 'Z';
ssls_import( &control, &data, &status, n, m,
"identity", H_ne, NULL, NULL, NULL,
"dense", A_ne, NULL, NULL, NULL,
"zero", C_ne, NULL, NULL, NULL );
ssls_factorize_matrix( &data, &status,
0, H_val,
A_dense_ne, A_dense,
0, NULL );
break;
}
// check that the factorization succeeded
if(status != 0){
ssls_information( &data, &inform, &status );
printf("%c: SSLS_solve factorization exit status = %1" i_ipc_ "\n",
st, inform.status);
continue;
}
// Set right-hand side ( a, b ) so that solution is vec(1.0)
switch(d){
case 4: // diagonal
sol[0] = 3.0;
sol[1] = 2.0;
sol[2] = 3.0;
sol[3] = -1.0;
sol[4] = -1.0;
break;
case 5: // scaled identity
sol[0] = 4.0;
sol[1] = 3.0;
sol[2] = 3.0;
sol[3] = 1.0;
sol[4] = -1.0;
break;
case 6: // identity
sol[0] = 3.0;
sol[1] = 2.0;
sol[2] = 2.0;
sol[3] = 2.0;
sol[4] = 0.0;
break;
case 7: // zero
sol[0] = 3.0;
sol[1] = 2.0;
sol[2] = 2.0;
sol[3] = 3.0;
sol[4] = 1.0;
break;
default:
sol[0] = 4.0;
sol[1] = 3.0;
sol[2] = 5.0;
sol[3] = -2.0;
sol[4] = -2.0;
break;
}
ssls_solve_system( &data, &status, n, m, sol );
// check that the factorization succeeded
if(status != 0){
ssls_information( &data, &inform, &status );
printf("%c: SSLS_solve exit status = %1" i_ipc_ "\n",
st, inform.status);
continue;
}
ssls_information( &data, &inform, &status );
if(inform.status == 0){
printf("%c: status = %1" i_ipc_ "", st, inform.status);
printf(" sol = ");
for(int loop = 0; loop < n+m; loop++)
#ifdef REAL_128
printf("%f ", (double)sol[loop]);
#else
printf("%f ", sol[loop]);
#endif
printf("\n");
}else{
printf("%c: SSLS_solve exit status = %1" i_ipc_ "\n",
st, inform.status);
}
// Delete internal workspace
ssls_terminate( &data, &control, &inform );
}
}