@@ -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+
284323end module c_fortran_bindings
285324
0 commit comments