Skip to content

Commit b72cc86

Browse files
Merge pull request #236 from PFLAREProject/ilu_factors
Ilu factors
2 parents 6db2dcd + c0e58b9 commit b72cc86

6 files changed

Lines changed: 601 additions & 3 deletions

File tree

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ export TEST_TARGETS = ex12f \
162162
ex12f_gmres_poly \
163163
mat_diag \
164164
adv_dg_upwind \
165-
ex6_two_airg
165+
ex6_two_airg \
166+
ilu_factors
166167
# Include kokkos examples
167168
ifeq ($(PETSC_HAVE_KOKKOS),1)
168169
export TEST_TARGETS := $(TEST_TARGETS) adv_1dk

include/pflare.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ PETSC_EXTERN void PCRegister_PFLARE();
4545
PETSC_EXTERN void compute_cf_splitting(Mat, int, double, int, int, int, double, IS*, IS*);
4646
PETSC_EXTERN void compute_diag_dom_submatrix(Mat, double, Mat*);
4747

48+
/* Restrict input_mat onto output_mat's existing sparsity pattern.
49+
With alpha_int = 1, performs output_mat += alpha * input_mat on output_mat's
50+
pattern; with alpha_int = 0, performs output_mat = input_mat on output's pattern.
51+
lump_int = 1 adds dropped entries to the diagonal. Auto-dispatches between the
52+
CPU and Kokkos implementations based on the input matrix type. */
53+
PETSC_EXTERN void remove_from_sparse_match(Mat, Mat, int, int, PetscReal);
54+
4855
/* Define PCPFLAREINV get routines */
4956
PETSC_EXTERN PetscErrorCode PCPFLAREINVGetPolyOrder(PC, PetscInt *);
5057
PETSC_EXTERN PetscErrorCode PCPFLAREINVGetSparsityOrder(PC, PetscInt *);

src/C_Fortran_Bindings.F90

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module c_fortran_bindings
77
use approx_inverse_setup, only: calculate_and_build_approximate_inverse, reset_inverse_mat
88
use cf_splitting, only: compute_cf_splitting
99
use matdiagdomsubmatrix, only: compute_diag_dom_submatrix
10+
use petsc_helper, only: remove_from_sparse_match
1011
use air_data_type_routines, only: create_air_data
1112

1213
#include "petsc/finclude/petscksp.h"
@@ -281,5 +282,43 @@ end subroutine compute_diag_dom_submatrix_c
281282

282283
!------------------------------------------------------------------------------------------------------------------------
283284

285+
subroutine remove_from_sparse_match_c(input_mat_ptr, output_mat_ptr, lump_int, alpha_int, alpha) &
286+
bind(C, name='remove_from_sparse_match_c')
287+
288+
! Restrict input_mat onto output_mat's sparsity pattern. The underlying
289+
! Fortran remove_from_sparse_match auto-dispatches between the CPU and
290+
! Kokkos implementations based on the matrix type, so this C entry point
291+
! works for both paths.
292+
293+
! ~~~~~~~~
294+
integer(c_long_long), intent(in) :: input_mat_ptr
295+
integer(c_long_long), intent(inout) :: output_mat_ptr
296+
integer(c_int), value, intent(in) :: lump_int
297+
integer(c_int), value, intent(in) :: alpha_int
298+
real(c_double), value, intent(in) :: alpha
299+
300+
type(tMat) :: input_mat, output_mat
301+
logical :: lump
302+
! ~~~~~~~~
303+
304+
input_mat%v = input_mat_ptr
305+
output_mat%v = output_mat_ptr
306+
lump = (lump_int /= 0)
307+
308+
if (alpha_int /= 0) then
309+
call remove_from_sparse_match(input_mat, output_mat, lump, alpha)
310+
else
311+
call remove_from_sparse_match(input_mat, output_mat, lump)
312+
end if
313+
314+
! The matrix's identity isn't replaced by remove_from_sparse_match (only
315+
! its values), but pass the handle back through anyway to match the
316+
! pattern used by the other C wrappers in this module.
317+
output_mat_ptr = output_mat%v
318+
319+
end subroutine remove_from_sparse_match_c
320+
321+
!------------------------------------------------------------------------------------------------------------------------
322+
284323
end module c_fortran_bindings
285324

src/PCAIR.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ PETSC_EXTERN void compute_cf_splitting_c(Mat *input_mat, int symmetric_int,
1818
int ddc_its, double fraction_swap,
1919
IS *is_fine, IS *is_coarse);
2020
PETSC_EXTERN void compute_diag_dom_submatrix_c(Mat *input_mat, double max_dd_ratio, Mat *output_mat);
21+
PETSC_EXTERN void remove_from_sparse_match_c(Mat *input_mat, Mat *output_mat,
22+
int lump_int, int alpha_int, PetscReal alpha);
2123
// Defined in PCAIR_C_Fortran_Bindings.F90
2224
// External users should use the get/set routines without _c which have
2325
// PetscErrorCode defined as return type, those routines are defined below this
@@ -208,6 +210,15 @@ PETSC_EXTERN void compute_diag_dom_submatrix(Mat input_mat, double max_dd_ratio,
208210
compute_diag_dom_submatrix_c(&input_mat, max_dd_ratio, output_mat);
209211
}
210212

213+
// Restrict input_mat onto output_mat's existing sparsity pattern.
214+
// Auto-dispatches between the CPU and Kokkos implementations based on the
215+
// matrix type, so callers can mix kokkos and non-kokkos matrices freely.
216+
PETSC_EXTERN void remove_from_sparse_match(Mat input_mat, Mat output_mat,
217+
int lump_int, int alpha_int, PetscReal alpha)
218+
{
219+
remove_from_sparse_match_c(&input_mat, &output_mat, lump_int, alpha_int, alpha);
220+
}
221+
211222
// Get routines
212223

213224
PETSC_EXTERN PetscErrorCode PCAIRGetPrintStatsTimings(PC pc, PetscBool *input_bool)

tests/Makefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,12 @@ run_tests_load_serial:
8383
./ex6 -f data/mat_stream_2364 -pc_air_a_drop 1e-3 -pc_air_inverse_type power -ksp_max_it 5
8484
#
8585
@echo ""
86-
@echo "Test two concurrent AIRG solves don't corrupt per-level IS state"
86+
@echo "Test two concurrent AIRG solves"
8787
./ex6_two_airg -f data/mat_stream_2364
88+
#
89+
@echo ""
90+
@echo "Test AIRG can solve triangle factors from ILU factorisations"
91+
./ilu_factors -f data/mat_stream_2364
8892
#
8993
@echo ""
9094
@echo "Test lAIR with GMRES polynomial smoothing for hyperbolic streaming problem"
@@ -186,8 +190,11 @@ run_tests_load_parallel:
186190
@echo "Test AIRG with GMRES polynomials for hyperbolic streaming problem, matrix-free smoothing in C in parallel"
187191
$(MPIEXEC) -n 2 ./ex6 -f data/mat_stream_2364 -pc_air_a_drop 1e-3 -pc_air_inverse_type power -pc_air_matrix_free_polys -ksp_max_it 5
188192
#
189-
@echo "Test two concurrent AIRG solves don't corrupt per-level IS state in parallel"
193+
@echo "Test two concurrent AIRG solves in parallel"
190194
$(MPIEXEC) -n 2 ./ex6_two_airg -f data/mat_stream_2364
195+
#
196+
@echo "Test AIRG can solve triangle factors from ILU factorisations in parallel"
197+
$(MPIEXEC) -n 2 ./ilu_factors -f data/mat_stream_2364
191198
#
192199
@echo "Test single level GMRES polynomial preconditioning for hyperbolic streaming problem in C in parallel"
193200
$(MPIEXEC) -n 2 ./ex6 -f data/mat_stream_2364 -pc_type pflareinv -pc_pflareinv_type power -ksp_max_it 21

0 commit comments

Comments
 (0)