Example to show how to use the SPM library with a 1-based constant multi-dof sparse matrix allocated through the library but initialized by the user.
/
static inline void
double *values,
{
double alpha = 8.;
double beta = 0.5;
double value;
mdim1 = dim1 - 1;
mdim2 = dim2 - 1;
mdim3 = dim3 - 1;
l = 0;
v = 0;
for( i = 0; i < dim1; i++ )
{
for( j = 0; j < dim2; j++ )
{
for( k = 0; k < dim3; k++ )
{
rowptr[l] = i + dim1 * j + dim1 * dim2 * k + 1;
colptr[l] = i + dim1 * j + dim1 * dim2 * k + 1;
l++;
{
value = 6.;
if ( i == 0 ) { value -= 1.; }
if ( i == mdim1 ) { value -= 1.; }
if ( j == 0 ) { value -= 1.; }
if ( j == mdim2 ) { value -= 1.; }
if ( k == 0 ) { value -= 1.; }
if ( k == mdim3 ) { value -= 1.; }
value *= alpha;
for( d=0; d<(dof*dof); d++ ) {
values[v] = value;
v++;
}
}
if ( i < mdim1 ) {
rowptr[l] = (i+1) + dim1 * j + dim1 * dim2 * k + 1;
colptr[l] = i + dim1 * j + dim1 * dim2 * k + 1;
l++;
for( d=0; d<(dof*dof); d++ ) {
values[v] = - beta;
v++;
}
}
if ( j < mdim2 ) {
rowptr[l] = i + dim1 * (j+1) + dim1 * dim2 * k + 1;
colptr[l] = i + dim1 * j + dim1 * dim2 * k + 1;
l++;
for( d=0; d<(dof*dof); d++ ) {
values[v] = - beta;
v++;
}
}
if ( k < mdim3 ) {
rowptr[l] = i + dim1 * j + dim1 * dim2 * (k+1) + 1;
colptr[l] = i + dim1 * j + dim1 * dim2 * k + 1;
l++;
for( d=0; d<(dof*dof); d++ ) {
values[v] = - beta;
v++;
}
}
}
}
}
assert( l == ((2*(dim1)-1) * dim2 * dim3 + (dim2-1)*dim1*dim3 + dim2*dim1*(dim3-1)) );
}
void
{
double *values;
dim1 = 6;
dim2 = 6;
dim3 = 6;
dof = 3;
n = dim1 * dim2 * dim3;
nnz = dim1 * dim2 * dim3;
nnz += (dim1 - 1) * dim2 * dim3;
nnz += dim1 * (dim2 - 1) * dim3;
nnz += dim1 * dim2 * (dim3 - 1);
values = malloc( nnz * dof * dof * sizeof(double) );
spm_example_fill_ijv_spm( colptr, rowptr, values,
dim1, dim2, dim3, dof );
}
int main (int argc, char **argv)
{
double alpha = 2.;
double epsilon, norm;
void *x, *b;
int rc = 0;
#if defined(SPM_WITH_MPI)
MPI_Init( &argc, &argv );
#endif
spm_example_create_laplacian( &spm );
fprintf( stdout, " || A ||_f: %e\n", norm );
if ( norm > 0. ) {
}
x = malloc( size );
rc =
spmGenMat( SpmRhsRndX, nrhs, &spm, &alpha, 24356, x, ldx );
free( x );
return rc;
}
b = malloc( size );
{
epsilon = 1e-15;
}
else {
epsilon = 1e-7;
}
epsilon = epsilon * spm.
nnzexp / spm.
gN;
rc =
spmCheckAxb( epsilon, nrhs, &spm, NULL, 1, b, ldb, x, ldx );
free( x );
free( b );
#if defined(SPM_WITH_MPI)
MPI_Finalize();
#endif
(void)argc;
(void)argv;
return rc;
}
static size_t spm_size_of(spm_coeftype_t type)
Double datatype that is not converted through precision generator functions.
void spmExit(spmatrix_t *spm)
Cleanup the spm structure but do not free the spm pointer.
void spmUpdateComputedFields(spmatrix_t *spm)
Update all the computed fields based on the static values stored.
struct spmatrix_s spmatrix_t
The sparse matrix data structure.
int spmCheckAxb(double eps, spm_int_t nrhs, const spmatrix_t *spm, void *opt_X0, spm_int_t opt_ldx0, void *B, spm_int_t ldb, const void *X, spm_int_t ldx)
Check the backward error, and the forward error if x0 is provided.
int spmConvert(int ofmttype, spmatrix_t *ospm)
Convert the storage format of the spm.
int spmMatMat(spm_trans_t trans, spm_int_t n, double alpha, const spmatrix_t *A, const void *B, spm_int_t ldb, double beta, void *C, spm_int_t ldc)
Compute a matrix-matrix product.
void spmScal(double alpha, spmatrix_t *spm)
Scale the spm.
double spmNorm(spm_normtype_t ntype, const spmatrix_t *spm)
Compute the norm of the spm.
void spmInit(spmatrix_t *spm)
Init the spm structure.
int spm_int_t
The main integer datatype used in spm arrays.
int spmGenMat(spm_rhstype_t type, spm_int_t nrhs, const spmatrix_t *spm, void *alpha, unsigned long long int seed, void *A, spm_int_t lda)
Generate a set of vectors associated to a given matrix.
void spmPrintInfo(const spmatrix_t *spm, FILE *f)
Print basic informations about the spm matrix into a given stream.