PaStiX Handbook  6.2.1
refinement.c File Reference

A refinement example that runs iterative methods without applying the preconditioner (factorization and solve steps are not called). Based on the step-by-step example. More...

Go to the source code of this file.

Detailed Description

A refinement example that runs iterative methods without applying the preconditioner (factorization and solve steps are not called). Based on the step-by-step example.

Version
6.2.0
Author
Pierre Ramet
Mathieu Faverge
Tony Delarue
Date
2021-04-07
/
#include <pastix.h>
#include <spm.h>
int main (int argc, char **argv)
{
pastix_data_t *pastix_data = NULL; /*< Pointer to the storage structure required by pastix */
pastix_int_t iparm[IPARM_SIZE]; /*< Integer in/out parameters for pastix */
double dparm[DPARM_SIZE]; /*< Floating in/out parameters for pastix */
spm_driver_t driver;
char *filename;
pastix_spm_t *spm, spm2;
void *x, *b, *x0 = NULL;
size_t size;
int check = 1;
int nrhs = 1;
int rc = 0;
/**
* Initialize parameters to default values
*/
pastixInitParam( iparm, dparm );
/**
* Get options from command line
*/
pastixGetOptions( argc, argv,
iparm, dparm,
&check, &driver, &filename );
/**
* Startup PaStiX
*/
pastixInit( &pastix_data, MPI_COMM_WORLD, iparm, dparm );
/**
* Read the sparse matrix with the driver
*/
spm = malloc( sizeof( pastix_spm_t ) );
spmReadDriver( driver, filename, spm );
free( filename );
spmPrintInfo( spm, stdout );
rc = spmCheckAndCorrect( spm, &spm2 );
if ( rc != 0 ) {
spmExit( spm );
*spm = spm2;
rc = 0;
}
/**
* Generate a Fake values array if needed for the numerical part
*/
if ( spm->flttype == PastixPattern ) {
spmGenFakeValues( spm );
}
/**
* Perform ordering, symbolic factorization, and analyze steps
*/
pastix_subtask_order( pastix_data, spm, NULL );
pastix_subtask_symbfact( pastix_data );
pastix_subtask_reordering( pastix_data );
pastix_subtask_blend( pastix_data );
/**
* Normalize A matrix (optional, but recommended for low-rank functionality)
*/
double normA = spmNorm( SpmFrobeniusNorm, spm );
spmScalMatrix( 1./normA, spm );
size = pastix_size_of( spm->flttype ) * spm->n * nrhs;
x = malloc( size );
b = malloc( size );
if ( check > 1 ) {
x0 = malloc( size );
}
pastix_subtask_spm2bcsc( pastix_data, spm );
/**
* Generates the b and x vector such that A * x = b
* Compute the norms of the initial vectors if checking purpose.
*/
if ( check )
{
spmGenRHS( SpmRhsRndX, nrhs, spm, x0, spm->n, b, spm->n );
memcpy( x, b, size );
}
else
{
spmGenRHS( SpmRhsRndB, nrhs, spm, NULL, spm->n, x, spm->n );
/* Apply also normalization to b vectors */
spmScalVector( spm->flttype, 1./normA, spm->n * nrhs, b, 1 );
/* Save b for refinement */
memcpy( b, x, size );
}
/**
* Refine the linear system
*/
pastix_task_refine( pastix_data, spm->n, nrhs, b, spm->n, x, spm->n );
if ( check ) {
rc |= spmCheckAxb( dparm[DPARM_EPSILON_REFINEMENT], nrhs, spm, x0, spm->n, b, spm->n, x, spm->n );
}
if (iparm[IPARM_NBITER]>=iparm[IPARM_ITERMAX]) {
rc |= 1;
}
spmExit( spm );
free( spm );
free( b );
free( x );
if ( x0 ) {
free( x0 );
}
pastixFinalize( &pastix_data );
return rc;
}
/**
*

Definition in file refinement.c.

IPARM_NBITER
@ IPARM_NBITER
Definition: api.h:111
IPARM_ITERMAX
@ IPARM_ITERMAX
Definition: api.h:112
DPARM_EPSILON_REFINEMENT
@ DPARM_EPSILON_REFINEMENT
Definition: api.h:154
pastix_subtask_reordering
int pastix_subtask_reordering(pastix_data_t *pastix_data)
Apply the reordering step to compact off-diagonal blocks.
Definition: pastix_subtask_reordering.c:60
pastixGetOptions
void pastixGetOptions(int argc, char **argv, pastix_int_t *iparm, double *dparm, int *check, spm_driver_t *driver, char **filename)
PaStiX helper function to read command line options in examples.
Definition: get_options.c:142
pastix.h
pastix_subtask_spm2bcsc
int pastix_subtask_spm2bcsc(pastix_data_t *pastix_data, spmatrix_t *spm)
Fill the internal block CSC structure.
Definition: pastix_task_sopalin.c:85
pastix_subtask_symbfact
int pastix_subtask_symbfact(pastix_data_t *pastix_data)
Computes the symbolic factorization step.
Definition: pastix_subtask_symbfact.c:90
pastix_subtask_blend
int pastix_subtask_blend(pastix_data_t *pastix_data)
Compute the proportional mapping and the final solver structure.
Definition: pastix_subtask_blend.c:121
pastixInit
void pastixInit(pastix_data_t **pastix_data, PASTIX_Comm pastix_comm, pastix_int_t *iparm, double *dparm)
Initialize the solver instance.
Definition: api.c:857
main
int main(int argc, char *argv[])
Definition: binding_for_multimpi.c:49
pastixInitParam
void pastixInitParam(pastix_int_t *iparm, double *dparm)
Initialize the iparm and dparm arrays to their default values.
Definition: api.c:401
pastixFinalize
void pastixFinalize(pastix_data_t **pastix_data)
Finalize the solver instance.
Definition: api.c:880
pastix_subtask_order
int pastix_subtask_order(pastix_data_t *pastix_data, const spmatrix_t *spm, pastix_order_t *myorder)
Computes the ordering of the given graph in parameters.
Definition: pastix_subtask_order.c:97
pastix_task_refine
int pastix_task_refine(pastix_data_t *pastix_data, pastix_int_t n, pastix_int_t nrhs, void *b, pastix_int_t ldb, void *x, pastix_int_t ldx)
Perform iterative refinement.
Definition: pastix_task_refine.c:226