This is the first version of a layer of solvers and preconditioners that
take the Petsc structure Mat with a type of MPIAIJ as a parameter. The code is built on top of distributed_linear_solvers.
This commit is contained in:
parent
c822ea3512
commit
132d594d42
232
PETScMat_linear_solvers/pilut/HYPRE_PETScMatPilutSolver.c
Normal file
232
PETScMat_linear_solvers/pilut/HYPRE_PETScMatPilutSolver.c
Normal file
@ -0,0 +1,232 @@
|
||||
/* Include headers for problem and solver data structure */
|
||||
#include "./PETScMatPilutSolver.h"
|
||||
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
* HYPRE_NewPETScMatPilutSolver
|
||||
*--------------------------------------------------------------------------*/
|
||||
|
||||
HYPRE_PETScMatPilutSolver HYPRE_NewPETScMatPilutSolver(
|
||||
MPI_Comm comm,
|
||||
Mat matrix )
|
||||
/* Allocates and Initializes solver structure */
|
||||
{
|
||||
|
||||
hypre_PETScMatPilutSolver *solver;
|
||||
int ierr;
|
||||
|
||||
/* Allocate structure for holding solver data */
|
||||
solver = (hypre_PETScMatPilutSolver *)
|
||||
hypre_CTAlloc( hypre_PETScMatPilutSolver, 1);
|
||||
|
||||
/* Initialize components of solver */
|
||||
hypre_PETScMatPilutSolverComm(solver) = comm;
|
||||
|
||||
hypre_PETScMatPilutSolverMatrix(solver) = matrix;
|
||||
|
||||
/* DistributedMatrixPilutSolver */
|
||||
hypre_PETScMatPilutSolverDistributedSolver( solver ) =
|
||||
HYPRE_NewDistributedMatrixPilutSolver( comm, NULL );
|
||||
|
||||
/* Return created structure to calling routine */
|
||||
return( (HYPRE_PETScMatPilutSolver) solver );
|
||||
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
* HYPRE_FreePETScMatPilutSolver
|
||||
*--------------------------------------------------------------------------*/
|
||||
|
||||
int HYPRE_FreePETScMatPilutSolver (
|
||||
HYPRE_PETScMatPilutSolver in_ptr )
|
||||
{
|
||||
int ierr=0;
|
||||
|
||||
hypre_PETScMatPilutSolver *solver =
|
||||
(hypre_PETScMatPilutSolver *) in_ptr;
|
||||
|
||||
/* Distributed Matrix was created not by user but by
|
||||
HYPRE_ConvertPETScMatrixToDistributedMatrix, so we must free it */
|
||||
ierr = HYPRE_FreeDistributedMatrix( HYPRE_DistributedMatrixPilutSolverGetMatrix(
|
||||
hypre_PETScMatPilutSolverDistributedSolver ( solver ) ) );
|
||||
|
||||
ierr = HYPRE_FreeDistributedMatrixPilutSolver(
|
||||
hypre_PETScMatPilutSolverDistributedSolver ( solver ) );
|
||||
|
||||
hypre_TFree(solver);
|
||||
|
||||
return(ierr);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
* HYPRE_PETScMatPilutSolverInitialize
|
||||
*--------------------------------------------------------------------------*/
|
||||
|
||||
int HYPRE_PETScMatPilutSolverInitialize (
|
||||
HYPRE_PETScMatPilutSolver in_ptr )
|
||||
{
|
||||
hypre_PETScMatPilutSolver *solver =
|
||||
(hypre_PETScMatPilutSolver *) in_ptr;
|
||||
int ierr = 0;
|
||||
|
||||
HYPRE_DistributedMatrixPilutSolverInitialize(
|
||||
hypre_PETScMatPilutSolverDistributedSolver ( solver ) );
|
||||
|
||||
return(ierr);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
* HYPRE_PETScMatPilutSolverSetMatrix
|
||||
*--------------------------------------------------------------------------*/
|
||||
|
||||
int HYPRE_PETScMatPilutSolverSetMatrix(
|
||||
HYPRE_PETScMatPilutSolver in_ptr,
|
||||
Mat matrix )
|
||||
{
|
||||
int ierr=0;
|
||||
hypre_PETScMatPilutSolver *solver =
|
||||
(hypre_PETScMatPilutSolver *) in_ptr;
|
||||
|
||||
hypre_PETScMatPilutSolverMatrix( solver ) = matrix;
|
||||
return(ierr);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
* HYPRE_PETScMatPilutSolverGetMatrix
|
||||
*--------------------------------------------------------------------------*/
|
||||
|
||||
Mat
|
||||
HYPRE_PETScMatPilutSolverGetMatrix(
|
||||
HYPRE_PETScMatPilutSolver in_ptr )
|
||||
{
|
||||
hypre_PETScMatPilutSolver *solver =
|
||||
(hypre_PETScMatPilutSolver *) in_ptr;
|
||||
|
||||
return( hypre_PETScMatPilutSolverMatrix( solver ) );
|
||||
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
* HYPRE_PETScMatPilutSolverSetFactorRowSize
|
||||
*--------------------------------------------------------------------------*/
|
||||
|
||||
int HYPRE_PETScMatPilutSolverSetFactorRowSize(
|
||||
HYPRE_PETScMatPilutSolver in_ptr,
|
||||
int size )
|
||||
{
|
||||
int ierr=0;
|
||||
hypre_PETScMatPilutSolver *solver =
|
||||
(hypre_PETScMatPilutSolver *) in_ptr;
|
||||
HYPRE_DistributedMatrixPilutSolver distributed_solver =
|
||||
hypre_PETScMatPilutSolverDistributedSolver(solver);
|
||||
|
||||
ierr = HYPRE_DistributedMatrixPilutSolverSetFactorRowSize(distributed_solver, size);
|
||||
|
||||
return(ierr);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
* HYPRE_PETScMatPilutSolverSetDropTolerance
|
||||
*--------------------------------------------------------------------------*/
|
||||
|
||||
int HYPRE_PETScMatPilutSolverSetDropTolerance(
|
||||
HYPRE_PETScMatPilutSolver in_ptr,
|
||||
double tol )
|
||||
{
|
||||
int ierr=0;
|
||||
hypre_PETScMatPilutSolver *solver =
|
||||
(hypre_PETScMatPilutSolver *) in_ptr;
|
||||
HYPRE_DistributedMatrixPilutSolver distributed_solver =
|
||||
hypre_PETScMatPilutSolverDistributedSolver(solver);
|
||||
|
||||
ierr = HYPRE_DistributedMatrixPilutSolverSetDropTolerance(distributed_solver, tol);
|
||||
|
||||
return(ierr);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
* HYPRE_PETScMatPilutSolverSetMaxIts
|
||||
*--------------------------------------------------------------------------*/
|
||||
|
||||
int HYPRE_PETScMatPilutSolverSetMaxIts(
|
||||
HYPRE_PETScMatPilutSolver in_ptr,
|
||||
int its )
|
||||
{
|
||||
int ierr=0;
|
||||
hypre_PETScMatPilutSolver *solver =
|
||||
(hypre_PETScMatPilutSolver *) in_ptr;
|
||||
HYPRE_DistributedMatrixPilutSolver distributed_solver =
|
||||
hypre_PETScMatPilutSolverDistributedSolver(solver);
|
||||
|
||||
ierr = HYPRE_DistributedMatrixPilutSolverSetMaxIts(distributed_solver, its );
|
||||
|
||||
return(ierr);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
* HYPRE_PETScMatPilutSolverSetup
|
||||
*--------------------------------------------------------------------------*/
|
||||
|
||||
int HYPRE_PETScMatPilutSolverSetup( HYPRE_PETScMatPilutSolver in_ptr,
|
||||
Vec x, Vec b )
|
||||
{
|
||||
int ierr=0;
|
||||
|
||||
hypre_PETScMatPilutSolver *solver =
|
||||
(hypre_PETScMatPilutSolver *) in_ptr;
|
||||
HYPRE_DistributedMatrixPilutSolver distributed_solver =
|
||||
hypre_PETScMatPilutSolverDistributedSolver(solver);
|
||||
HYPRE_DistributedMatrix DistributedPreconditionerMatrix;
|
||||
Mat PETScMat = hypre_PETScMatPilutSolverMatrix( solver );
|
||||
|
||||
|
||||
/**** Executable code ****/
|
||||
|
||||
if( !PETScMat ) return(-1);
|
||||
|
||||
/* Convert the matrix into format suitable for
|
||||
the HYPRE_DistributedMatrixPilutSolver preconditioner */
|
||||
|
||||
ierr = HYPRE_ConvertPETScMatrixToDistributedMatrix( PETScMat,
|
||||
&DistributedPreconditionerMatrix );
|
||||
if (ierr) return(ierr);
|
||||
|
||||
distributed_solver =
|
||||
hypre_PETScMatPilutSolverDistributedSolver( solver );
|
||||
|
||||
ierr = HYPRE_DistributedMatrixPilutSolverSetMatrix( distributed_solver,
|
||||
DistributedPreconditionerMatrix );
|
||||
|
||||
/* Complete setup of distributed_solver structure with computation of
|
||||
preconditioner, etc. */
|
||||
ierr = HYPRE_DistributedMatrixPilutSolverSetup ( distributed_solver );
|
||||
|
||||
return(ierr);
|
||||
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
* HYPRE_PETScMatPilutSolverSolve
|
||||
*--------------------------------------------------------------------------*/
|
||||
|
||||
int HYPRE_PETScMatPilutSolverSolve( HYPRE_PETScMatPilutSolver in_ptr,
|
||||
Vec x, Vec b )
|
||||
{
|
||||
int ierr=0, size;
|
||||
double *x_vals, *b_vals;
|
||||
|
||||
hypre_PETScMatPilutSolver *solver =
|
||||
(hypre_PETScMatPilutSolver *) in_ptr;
|
||||
|
||||
ierr = VecGetArray( x, &x_vals ); CHKERRA(ierr);
|
||||
ierr = VecGetLocalSize( x, &size ); CHKERRA(ierr);
|
||||
|
||||
ierr = VecGetArray( b, &b_vals ); CHKERRA(ierr);
|
||||
ierr = VecGetLocalSize( b, &size ); CHKERRA(ierr);
|
||||
|
||||
ierr = HYPRE_DistributedMatrixPilutSolverSolve(
|
||||
hypre_PETScMatPilutSolverDistributedSolver( solver ), x_vals, b_vals );
|
||||
|
||||
return(ierr);
|
||||
}
|
||||
|
||||
26
PETScMat_linear_solvers/pilut/HYPRE_types.h
Normal file
26
PETScMat_linear_solvers/pilut/HYPRE_types.h
Normal file
@ -0,0 +1,26 @@
|
||||
/*BHEADER**********************************************************************
|
||||
* (c) 1997 The Regents of the University of California
|
||||
*
|
||||
* See the file COPYRIGHT_and_DISCLAIMER for a complete copyright
|
||||
* notice, contact person, and disclaimer.
|
||||
*
|
||||
* $Revision$
|
||||
*********************************************************************EHEADER*/
|
||||
/******************************************************************************
|
||||
*
|
||||
* Header info for the hypre_DistributedMatrix structures
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef HYPRE_PETSC_MAT_SOLVER_PILUT_SOLVER_TYPES_HEADER
|
||||
#define HYPRE_PETSC_MAT_SOLVER_PILUT_SOLVER_TYPES_HEADER
|
||||
|
||||
typedef void *HYPRE_PETScMatPilutSolver;
|
||||
|
||||
/* Have to include MPI since MPI types appear in prototypes */
|
||||
#include "mpi.h"
|
||||
|
||||
/* Have to include PETSc since PETSc types appear in prototypes */
|
||||
#include "sles.h"
|
||||
|
||||
#endif
|
||||
64
PETScMat_linear_solvers/pilut/PETScMatPilutSolver.h
Normal file
64
PETScMat_linear_solvers/pilut/PETScMatPilutSolver.h
Normal file
@ -0,0 +1,64 @@
|
||||
/*BHEADER**********************************************************************
|
||||
* (c) 1997 The Regents of the University of California
|
||||
*
|
||||
* See the file COPYRIGHT_and_DISCLAIMER for a complete copyright
|
||||
* notice, contact person, and disclaimer.
|
||||
*
|
||||
* $Revision$
|
||||
*********************************************************************EHEADER*/
|
||||
/******************************************************************************
|
||||
*
|
||||
* Header info for the hypre_StructSolver structures
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef hypre_PETSC_MAT_PILUT_SOLVER_HEADER
|
||||
#define hypre_PETSC_MAT_PILUT_SOLVER_HEADER
|
||||
|
||||
#include "../../includes/general.h"
|
||||
#include "../../utilities/memory.h"
|
||||
#ifdef HYPRE_DEBUG
|
||||
#include <gmalloc.h>
|
||||
#endif
|
||||
|
||||
#include "mpi.h"
|
||||
|
||||
/* Include Petsc matrix and vector headers */
|
||||
#include "mat.h"
|
||||
#include "vec.h"
|
||||
|
||||
#include "HYPRE.h"
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
* hypre_PETScMatPilutSolver
|
||||
*--------------------------------------------------------------------------*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
|
||||
MPI_Comm comm;
|
||||
|
||||
/* Petsc Matrix that defines the system to be solved */
|
||||
Mat Matrix;
|
||||
|
||||
/* This solver is a wrapper for DistributedMatrixPilutSolver; */
|
||||
HYPRE_DistributedMatrixPilutSolver DistributedSolver;
|
||||
|
||||
} hypre_PETScMatPilutSolver;
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
* Accessor macros: hypre_PETScMatPilutSolver
|
||||
*--------------------------------------------------------------------------*/
|
||||
|
||||
#define hypre_PETScMatPilutSolverComm(parilut_data) ((parilut_data) -> comm)
|
||||
#define hypre_PETScMatPilutSolverMatrix(parilut_data)\
|
||||
((parilut_data) -> Matrix)
|
||||
#define hypre_PETScMatPilutSolverDistributedSolver(parilut_data)\
|
||||
((parilut_data) -> DistributedSolver)
|
||||
|
||||
/* Include internal prototypes */
|
||||
#include "./hypre_protos.h"
|
||||
#include "./internal_protos.h"
|
||||
|
||||
|
||||
#endif
|
||||
0
PETScMat_linear_solvers/pilut/hypre.c
Normal file
0
PETScMat_linear_solvers/pilut/hypre.c
Normal file
144
PETScMat_linear_solvers/pilut/makefile
Executable file
144
PETScMat_linear_solvers/pilut/makefile
Executable file
@ -0,0 +1,144 @@
|
||||
#BHEADER***********************************************************************
|
||||
# (c) 1997 The Regents of the University of California
|
||||
#
|
||||
# See the file COPYRIGHT_and_DISCLAIMER for a complete copyright
|
||||
# notice, contact person, and disclaimer.
|
||||
#
|
||||
# $Revision$
|
||||
#EHEADER***********************************************************************
|
||||
|
||||
|
||||
.SUFFIXES:
|
||||
.SUFFIXES: .c .f .o
|
||||
|
||||
#Headers
|
||||
HEADERS=\
|
||||
PETScMatPilutSolver.h
|
||||
|
||||
HYPREFILES =\
|
||||
HYPRE_PETScMatPilutSolver.c
|
||||
|
||||
LOCALFILES =
|
||||
|
||||
FILES = $(HYPREFILES) $(LOCALFILES)
|
||||
|
||||
#Automatically generate prototypes when necessary
|
||||
HYPRE_protos.h: $(HYPREFILES)
|
||||
mkproto HYPRE*.c > HYPRE_protos.h
|
||||
|
||||
hypre_protos.h: $(FILES)
|
||||
mkproto hypre*.c > hypre_protos.h
|
||||
|
||||
internal_protos.h: $(FILES)
|
||||
mkproto *.c > internal_protos.h
|
||||
|
||||
PROTOS =\
|
||||
HYPRE_protos.h\
|
||||
hypre_protos.h\
|
||||
internal_protos.h
|
||||
|
||||
OBJS = ${FILES:.c=.o}
|
||||
|
||||
CC = gcc
|
||||
|
||||
F77 = /home/casc/g77/bin/g77
|
||||
|
||||
PETSC_CFLAGS =\
|
||||
-I${PETSC_DIR}/src/mat/impls/aij/mpi\
|
||||
-I${PETSC_DIR}/src/mat/impls/aij/seq\
|
||||
-I${PETSC_DIR}/src/mat\
|
||||
-I${PETSC_DIR}\
|
||||
-I${PETSC_DIR}/include\
|
||||
-I/usr/local/mpi/mpich/include
|
||||
CFLAGS =\
|
||||
${PETSC_CFLAGS}\
|
||||
${PAR_SOLVER_FLAGS}\
|
||||
${SEQ_SOLVER_FLAGS}\
|
||||
-I/usr/local/include\
|
||||
-I/home/casc/include\
|
||||
-I../../includes\
|
||||
-DHYPRE_MEMORY_CHECK\
|
||||
-DHYPRE_DEBUG\
|
||||
-g
|
||||
|
||||
FFLAGS = -g
|
||||
|
||||
include ${PETSC_DIR}/bmake/${PETSC_ARCH}/base.site
|
||||
PETSC_OPT = g
|
||||
PETSC_LFLAGS =\
|
||||
-L${PETSC_DIR}/lib/lib${PETSC_OPT}/${PETSC_ARCH}\
|
||||
-lpetscsles\
|
||||
-lpetscmat\
|
||||
-lpetscvec\
|
||||
-lpetscsys\
|
||||
${SUPERLU_LIB}\
|
||||
${BS_LIB}\
|
||||
${LAPACK_LIB}\
|
||||
${BLAS_LIB}\
|
||||
${X11_LIB}\
|
||||
${MPE_LIB}\
|
||||
${MPI_LIB}\
|
||||
${SYS_LIB}
|
||||
LFLAGS =\
|
||||
-Wl,"-zmuldefs"\
|
||||
-L/usr/local/lib\
|
||||
-L/home/casc/lib\
|
||||
-L/home/casc/g77/lib\
|
||||
-L../distributed_matrix\
|
||||
-L../distributed_linear_solvers/pilut\
|
||||
-L../seq_linear_solvers/ilut\
|
||||
-L../seq_linear_solvers/ict\
|
||||
-L../seq_linear_solvers/sparskit\
|
||||
-L../seq_matrix_vector \
|
||||
-L.\
|
||||
-lHYPRE\
|
||||
-lHYPREDistributedMatrix\
|
||||
-lHYPREDistributedMatrixPilutSolver\
|
||||
-lHYPREILU -lHYPREIC\
|
||||
-lilu -lic -ldsparskit\
|
||||
-lHYPREseq_mat_vec\
|
||||
${PETSC_LFLAGS}\
|
||||
-lf2c\
|
||||
-lcegdb\
|
||||
-lmalloc\
|
||||
-lm
|
||||
|
||||
|
||||
${OBJS}: ${HEADERS}
|
||||
|
||||
|
||||
|
||||
##################################################################
|
||||
# Main rules
|
||||
##################################################################
|
||||
|
||||
driver: driver.o libHYPREPETScMatPilutSolver.a
|
||||
@echo "Linking" $@ "... "
|
||||
${CC} -o driver driver.o ${LFLAGS}
|
||||
|
||||
link:
|
||||
rm driver
|
||||
make driver
|
||||
|
||||
lib: ${PROTOS} ${OBJS}
|
||||
@echo "Building $@ ... "
|
||||
@ar -ru libHYPREPETScMatPilutSolver.a ${OBJS}
|
||||
@ranlib libHYPREPETScMatPilutSolver.a
|
||||
|
||||
##################################################################
|
||||
# Generic rules
|
||||
##################################################################
|
||||
|
||||
.c.o:
|
||||
@echo "Making (c) " $@
|
||||
${CC} -o $@ -c ${CFLAGS} $<
|
||||
|
||||
# @${CC} -o $@ -c ${CFLAGS} $<
|
||||
|
||||
.f.${AMG_ARCH}.o:
|
||||
@echo "Making (f) " $@
|
||||
@${F77} -o $@ -c ${FFLAGS} $<
|
||||
|
||||
##################################################################
|
||||
# Miscellaneous rules
|
||||
##################################################################
|
||||
232
PETScMat_ls/pilut/HYPRE_PETScMatPilutSolver.c
Normal file
232
PETScMat_ls/pilut/HYPRE_PETScMatPilutSolver.c
Normal file
@ -0,0 +1,232 @@
|
||||
/* Include headers for problem and solver data structure */
|
||||
#include "./PETScMatPilutSolver.h"
|
||||
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
* HYPRE_NewPETScMatPilutSolver
|
||||
*--------------------------------------------------------------------------*/
|
||||
|
||||
HYPRE_PETScMatPilutSolver HYPRE_NewPETScMatPilutSolver(
|
||||
MPI_Comm comm,
|
||||
Mat matrix )
|
||||
/* Allocates and Initializes solver structure */
|
||||
{
|
||||
|
||||
hypre_PETScMatPilutSolver *solver;
|
||||
int ierr;
|
||||
|
||||
/* Allocate structure for holding solver data */
|
||||
solver = (hypre_PETScMatPilutSolver *)
|
||||
hypre_CTAlloc( hypre_PETScMatPilutSolver, 1);
|
||||
|
||||
/* Initialize components of solver */
|
||||
hypre_PETScMatPilutSolverComm(solver) = comm;
|
||||
|
||||
hypre_PETScMatPilutSolverMatrix(solver) = matrix;
|
||||
|
||||
/* DistributedMatrixPilutSolver */
|
||||
hypre_PETScMatPilutSolverDistributedSolver( solver ) =
|
||||
HYPRE_NewDistributedMatrixPilutSolver( comm, NULL );
|
||||
|
||||
/* Return created structure to calling routine */
|
||||
return( (HYPRE_PETScMatPilutSolver) solver );
|
||||
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
* HYPRE_FreePETScMatPilutSolver
|
||||
*--------------------------------------------------------------------------*/
|
||||
|
||||
int HYPRE_FreePETScMatPilutSolver (
|
||||
HYPRE_PETScMatPilutSolver in_ptr )
|
||||
{
|
||||
int ierr=0;
|
||||
|
||||
hypre_PETScMatPilutSolver *solver =
|
||||
(hypre_PETScMatPilutSolver *) in_ptr;
|
||||
|
||||
/* Distributed Matrix was created not by user but by
|
||||
HYPRE_ConvertPETScMatrixToDistributedMatrix, so we must free it */
|
||||
ierr = HYPRE_FreeDistributedMatrix( HYPRE_DistributedMatrixPilutSolverGetMatrix(
|
||||
hypre_PETScMatPilutSolverDistributedSolver ( solver ) ) );
|
||||
|
||||
ierr = HYPRE_FreeDistributedMatrixPilutSolver(
|
||||
hypre_PETScMatPilutSolverDistributedSolver ( solver ) );
|
||||
|
||||
hypre_TFree(solver);
|
||||
|
||||
return(ierr);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
* HYPRE_PETScMatPilutSolverInitialize
|
||||
*--------------------------------------------------------------------------*/
|
||||
|
||||
int HYPRE_PETScMatPilutSolverInitialize (
|
||||
HYPRE_PETScMatPilutSolver in_ptr )
|
||||
{
|
||||
hypre_PETScMatPilutSolver *solver =
|
||||
(hypre_PETScMatPilutSolver *) in_ptr;
|
||||
int ierr = 0;
|
||||
|
||||
HYPRE_DistributedMatrixPilutSolverInitialize(
|
||||
hypre_PETScMatPilutSolverDistributedSolver ( solver ) );
|
||||
|
||||
return(ierr);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
* HYPRE_PETScMatPilutSolverSetMatrix
|
||||
*--------------------------------------------------------------------------*/
|
||||
|
||||
int HYPRE_PETScMatPilutSolverSetMatrix(
|
||||
HYPRE_PETScMatPilutSolver in_ptr,
|
||||
Mat matrix )
|
||||
{
|
||||
int ierr=0;
|
||||
hypre_PETScMatPilutSolver *solver =
|
||||
(hypre_PETScMatPilutSolver *) in_ptr;
|
||||
|
||||
hypre_PETScMatPilutSolverMatrix( solver ) = matrix;
|
||||
return(ierr);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
* HYPRE_PETScMatPilutSolverGetMatrix
|
||||
*--------------------------------------------------------------------------*/
|
||||
|
||||
Mat
|
||||
HYPRE_PETScMatPilutSolverGetMatrix(
|
||||
HYPRE_PETScMatPilutSolver in_ptr )
|
||||
{
|
||||
hypre_PETScMatPilutSolver *solver =
|
||||
(hypre_PETScMatPilutSolver *) in_ptr;
|
||||
|
||||
return( hypre_PETScMatPilutSolverMatrix( solver ) );
|
||||
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
* HYPRE_PETScMatPilutSolverSetFactorRowSize
|
||||
*--------------------------------------------------------------------------*/
|
||||
|
||||
int HYPRE_PETScMatPilutSolverSetFactorRowSize(
|
||||
HYPRE_PETScMatPilutSolver in_ptr,
|
||||
int size )
|
||||
{
|
||||
int ierr=0;
|
||||
hypre_PETScMatPilutSolver *solver =
|
||||
(hypre_PETScMatPilutSolver *) in_ptr;
|
||||
HYPRE_DistributedMatrixPilutSolver distributed_solver =
|
||||
hypre_PETScMatPilutSolverDistributedSolver(solver);
|
||||
|
||||
ierr = HYPRE_DistributedMatrixPilutSolverSetFactorRowSize(distributed_solver, size);
|
||||
|
||||
return(ierr);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
* HYPRE_PETScMatPilutSolverSetDropTolerance
|
||||
*--------------------------------------------------------------------------*/
|
||||
|
||||
int HYPRE_PETScMatPilutSolverSetDropTolerance(
|
||||
HYPRE_PETScMatPilutSolver in_ptr,
|
||||
double tol )
|
||||
{
|
||||
int ierr=0;
|
||||
hypre_PETScMatPilutSolver *solver =
|
||||
(hypre_PETScMatPilutSolver *) in_ptr;
|
||||
HYPRE_DistributedMatrixPilutSolver distributed_solver =
|
||||
hypre_PETScMatPilutSolverDistributedSolver(solver);
|
||||
|
||||
ierr = HYPRE_DistributedMatrixPilutSolverSetDropTolerance(distributed_solver, tol);
|
||||
|
||||
return(ierr);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
* HYPRE_PETScMatPilutSolverSetMaxIts
|
||||
*--------------------------------------------------------------------------*/
|
||||
|
||||
int HYPRE_PETScMatPilutSolverSetMaxIts(
|
||||
HYPRE_PETScMatPilutSolver in_ptr,
|
||||
int its )
|
||||
{
|
||||
int ierr=0;
|
||||
hypre_PETScMatPilutSolver *solver =
|
||||
(hypre_PETScMatPilutSolver *) in_ptr;
|
||||
HYPRE_DistributedMatrixPilutSolver distributed_solver =
|
||||
hypre_PETScMatPilutSolverDistributedSolver(solver);
|
||||
|
||||
ierr = HYPRE_DistributedMatrixPilutSolverSetMaxIts(distributed_solver, its );
|
||||
|
||||
return(ierr);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
* HYPRE_PETScMatPilutSolverSetup
|
||||
*--------------------------------------------------------------------------*/
|
||||
|
||||
int HYPRE_PETScMatPilutSolverSetup( HYPRE_PETScMatPilutSolver in_ptr,
|
||||
Vec x, Vec b )
|
||||
{
|
||||
int ierr=0;
|
||||
|
||||
hypre_PETScMatPilutSolver *solver =
|
||||
(hypre_PETScMatPilutSolver *) in_ptr;
|
||||
HYPRE_DistributedMatrixPilutSolver distributed_solver =
|
||||
hypre_PETScMatPilutSolverDistributedSolver(solver);
|
||||
HYPRE_DistributedMatrix DistributedPreconditionerMatrix;
|
||||
Mat PETScMat = hypre_PETScMatPilutSolverMatrix( solver );
|
||||
|
||||
|
||||
/**** Executable code ****/
|
||||
|
||||
if( !PETScMat ) return(-1);
|
||||
|
||||
/* Convert the matrix into format suitable for
|
||||
the HYPRE_DistributedMatrixPilutSolver preconditioner */
|
||||
|
||||
ierr = HYPRE_ConvertPETScMatrixToDistributedMatrix( PETScMat,
|
||||
&DistributedPreconditionerMatrix );
|
||||
if (ierr) return(ierr);
|
||||
|
||||
distributed_solver =
|
||||
hypre_PETScMatPilutSolverDistributedSolver( solver );
|
||||
|
||||
ierr = HYPRE_DistributedMatrixPilutSolverSetMatrix( distributed_solver,
|
||||
DistributedPreconditionerMatrix );
|
||||
|
||||
/* Complete setup of distributed_solver structure with computation of
|
||||
preconditioner, etc. */
|
||||
ierr = HYPRE_DistributedMatrixPilutSolverSetup ( distributed_solver );
|
||||
|
||||
return(ierr);
|
||||
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
* HYPRE_PETScMatPilutSolverSolve
|
||||
*--------------------------------------------------------------------------*/
|
||||
|
||||
int HYPRE_PETScMatPilutSolverSolve( HYPRE_PETScMatPilutSolver in_ptr,
|
||||
Vec x, Vec b )
|
||||
{
|
||||
int ierr=0, size;
|
||||
double *x_vals, *b_vals;
|
||||
|
||||
hypre_PETScMatPilutSolver *solver =
|
||||
(hypre_PETScMatPilutSolver *) in_ptr;
|
||||
|
||||
ierr = VecGetArray( x, &x_vals ); CHKERRA(ierr);
|
||||
ierr = VecGetLocalSize( x, &size ); CHKERRA(ierr);
|
||||
|
||||
ierr = VecGetArray( b, &b_vals ); CHKERRA(ierr);
|
||||
ierr = VecGetLocalSize( b, &size ); CHKERRA(ierr);
|
||||
|
||||
ierr = HYPRE_DistributedMatrixPilutSolverSolve(
|
||||
hypre_PETScMatPilutSolverDistributedSolver( solver ), x_vals, b_vals );
|
||||
|
||||
return(ierr);
|
||||
}
|
||||
|
||||
26
PETScMat_ls/pilut/HYPRE_types.h
Normal file
26
PETScMat_ls/pilut/HYPRE_types.h
Normal file
@ -0,0 +1,26 @@
|
||||
/*BHEADER**********************************************************************
|
||||
* (c) 1997 The Regents of the University of California
|
||||
*
|
||||
* See the file COPYRIGHT_and_DISCLAIMER for a complete copyright
|
||||
* notice, contact person, and disclaimer.
|
||||
*
|
||||
* $Revision$
|
||||
*********************************************************************EHEADER*/
|
||||
/******************************************************************************
|
||||
*
|
||||
* Header info for the hypre_DistributedMatrix structures
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef HYPRE_PETSC_MAT_SOLVER_PILUT_SOLVER_TYPES_HEADER
|
||||
#define HYPRE_PETSC_MAT_SOLVER_PILUT_SOLVER_TYPES_HEADER
|
||||
|
||||
typedef void *HYPRE_PETScMatPilutSolver;
|
||||
|
||||
/* Have to include MPI since MPI types appear in prototypes */
|
||||
#include "mpi.h"
|
||||
|
||||
/* Have to include PETSc since PETSc types appear in prototypes */
|
||||
#include "sles.h"
|
||||
|
||||
#endif
|
||||
64
PETScMat_ls/pilut/PETScMatPilutSolver.h
Normal file
64
PETScMat_ls/pilut/PETScMatPilutSolver.h
Normal file
@ -0,0 +1,64 @@
|
||||
/*BHEADER**********************************************************************
|
||||
* (c) 1997 The Regents of the University of California
|
||||
*
|
||||
* See the file COPYRIGHT_and_DISCLAIMER for a complete copyright
|
||||
* notice, contact person, and disclaimer.
|
||||
*
|
||||
* $Revision$
|
||||
*********************************************************************EHEADER*/
|
||||
/******************************************************************************
|
||||
*
|
||||
* Header info for the hypre_StructSolver structures
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef hypre_PETSC_MAT_PILUT_SOLVER_HEADER
|
||||
#define hypre_PETSC_MAT_PILUT_SOLVER_HEADER
|
||||
|
||||
#include "../../includes/general.h"
|
||||
#include "../../utilities/memory.h"
|
||||
#ifdef HYPRE_DEBUG
|
||||
#include <gmalloc.h>
|
||||
#endif
|
||||
|
||||
#include "mpi.h"
|
||||
|
||||
/* Include Petsc matrix and vector headers */
|
||||
#include "mat.h"
|
||||
#include "vec.h"
|
||||
|
||||
#include "HYPRE.h"
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
* hypre_PETScMatPilutSolver
|
||||
*--------------------------------------------------------------------------*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
|
||||
MPI_Comm comm;
|
||||
|
||||
/* Petsc Matrix that defines the system to be solved */
|
||||
Mat Matrix;
|
||||
|
||||
/* This solver is a wrapper for DistributedMatrixPilutSolver; */
|
||||
HYPRE_DistributedMatrixPilutSolver DistributedSolver;
|
||||
|
||||
} hypre_PETScMatPilutSolver;
|
||||
|
||||
/*--------------------------------------------------------------------------
|
||||
* Accessor macros: hypre_PETScMatPilutSolver
|
||||
*--------------------------------------------------------------------------*/
|
||||
|
||||
#define hypre_PETScMatPilutSolverComm(parilut_data) ((parilut_data) -> comm)
|
||||
#define hypre_PETScMatPilutSolverMatrix(parilut_data)\
|
||||
((parilut_data) -> Matrix)
|
||||
#define hypre_PETScMatPilutSolverDistributedSolver(parilut_data)\
|
||||
((parilut_data) -> DistributedSolver)
|
||||
|
||||
/* Include internal prototypes */
|
||||
#include "./hypre_protos.h"
|
||||
#include "./internal_protos.h"
|
||||
|
||||
|
||||
#endif
|
||||
0
PETScMat_ls/pilut/hypre.c
Normal file
0
PETScMat_ls/pilut/hypre.c
Normal file
144
PETScMat_ls/pilut/makefile
Executable file
144
PETScMat_ls/pilut/makefile
Executable file
@ -0,0 +1,144 @@
|
||||
#BHEADER***********************************************************************
|
||||
# (c) 1997 The Regents of the University of California
|
||||
#
|
||||
# See the file COPYRIGHT_and_DISCLAIMER for a complete copyright
|
||||
# notice, contact person, and disclaimer.
|
||||
#
|
||||
# $Revision$
|
||||
#EHEADER***********************************************************************
|
||||
|
||||
|
||||
.SUFFIXES:
|
||||
.SUFFIXES: .c .f .o
|
||||
|
||||
#Headers
|
||||
HEADERS=\
|
||||
PETScMatPilutSolver.h
|
||||
|
||||
HYPREFILES =\
|
||||
HYPRE_PETScMatPilutSolver.c
|
||||
|
||||
LOCALFILES =
|
||||
|
||||
FILES = $(HYPREFILES) $(LOCALFILES)
|
||||
|
||||
#Automatically generate prototypes when necessary
|
||||
HYPRE_protos.h: $(HYPREFILES)
|
||||
mkproto HYPRE*.c > HYPRE_protos.h
|
||||
|
||||
hypre_protos.h: $(FILES)
|
||||
mkproto hypre*.c > hypre_protos.h
|
||||
|
||||
internal_protos.h: $(FILES)
|
||||
mkproto *.c > internal_protos.h
|
||||
|
||||
PROTOS =\
|
||||
HYPRE_protos.h\
|
||||
hypre_protos.h\
|
||||
internal_protos.h
|
||||
|
||||
OBJS = ${FILES:.c=.o}
|
||||
|
||||
CC = gcc
|
||||
|
||||
F77 = /home/casc/g77/bin/g77
|
||||
|
||||
PETSC_CFLAGS =\
|
||||
-I${PETSC_DIR}/src/mat/impls/aij/mpi\
|
||||
-I${PETSC_DIR}/src/mat/impls/aij/seq\
|
||||
-I${PETSC_DIR}/src/mat\
|
||||
-I${PETSC_DIR}\
|
||||
-I${PETSC_DIR}/include\
|
||||
-I/usr/local/mpi/mpich/include
|
||||
CFLAGS =\
|
||||
${PETSC_CFLAGS}\
|
||||
${PAR_SOLVER_FLAGS}\
|
||||
${SEQ_SOLVER_FLAGS}\
|
||||
-I/usr/local/include\
|
||||
-I/home/casc/include\
|
||||
-I../../includes\
|
||||
-DHYPRE_MEMORY_CHECK\
|
||||
-DHYPRE_DEBUG\
|
||||
-g
|
||||
|
||||
FFLAGS = -g
|
||||
|
||||
include ${PETSC_DIR}/bmake/${PETSC_ARCH}/base.site
|
||||
PETSC_OPT = g
|
||||
PETSC_LFLAGS =\
|
||||
-L${PETSC_DIR}/lib/lib${PETSC_OPT}/${PETSC_ARCH}\
|
||||
-lpetscsles\
|
||||
-lpetscmat\
|
||||
-lpetscvec\
|
||||
-lpetscsys\
|
||||
${SUPERLU_LIB}\
|
||||
${BS_LIB}\
|
||||
${LAPACK_LIB}\
|
||||
${BLAS_LIB}\
|
||||
${X11_LIB}\
|
||||
${MPE_LIB}\
|
||||
${MPI_LIB}\
|
||||
${SYS_LIB}
|
||||
LFLAGS =\
|
||||
-Wl,"-zmuldefs"\
|
||||
-L/usr/local/lib\
|
||||
-L/home/casc/lib\
|
||||
-L/home/casc/g77/lib\
|
||||
-L../distributed_matrix\
|
||||
-L../distributed_linear_solvers/pilut\
|
||||
-L../seq_linear_solvers/ilut\
|
||||
-L../seq_linear_solvers/ict\
|
||||
-L../seq_linear_solvers/sparskit\
|
||||
-L../seq_matrix_vector \
|
||||
-L.\
|
||||
-lHYPRE\
|
||||
-lHYPREDistributedMatrix\
|
||||
-lHYPREDistributedMatrixPilutSolver\
|
||||
-lHYPREILU -lHYPREIC\
|
||||
-lilu -lic -ldsparskit\
|
||||
-lHYPREseq_mat_vec\
|
||||
${PETSC_LFLAGS}\
|
||||
-lf2c\
|
||||
-lcegdb\
|
||||
-lmalloc\
|
||||
-lm
|
||||
|
||||
|
||||
${OBJS}: ${HEADERS}
|
||||
|
||||
|
||||
|
||||
##################################################################
|
||||
# Main rules
|
||||
##################################################################
|
||||
|
||||
driver: driver.o libHYPREPETScMatPilutSolver.a
|
||||
@echo "Linking" $@ "... "
|
||||
${CC} -o driver driver.o ${LFLAGS}
|
||||
|
||||
link:
|
||||
rm driver
|
||||
make driver
|
||||
|
||||
lib: ${PROTOS} ${OBJS}
|
||||
@echo "Building $@ ... "
|
||||
@ar -ru libHYPREPETScMatPilutSolver.a ${OBJS}
|
||||
@ranlib libHYPREPETScMatPilutSolver.a
|
||||
|
||||
##################################################################
|
||||
# Generic rules
|
||||
##################################################################
|
||||
|
||||
.c.o:
|
||||
@echo "Making (c) " $@
|
||||
${CC} -o $@ -c ${CFLAGS} $<
|
||||
|
||||
# @${CC} -o $@ -c ${CFLAGS} $<
|
||||
|
||||
.f.${AMG_ARCH}.o:
|
||||
@echo "Making (f) " $@
|
||||
@${F77} -o $@ -c ${FFLAGS} $<
|
||||
|
||||
##################################################################
|
||||
# Miscellaneous rules
|
||||
##################################################################
|
||||
Loading…
Reference in New Issue
Block a user