[SSAMG] Interpolation paths mishandle parts with cdir == -1
> This is generated from an LLM code audit. This bug appears plausible to me, but it may be a false positive. Feedback is appreciated.
## Summary
Several interpolation and non-Galerkin RAP paths do not consistently handle a part whose coarsening direction is `-1`. That state is valid: it is used when a part is not coarsened on a level while another part is. The structured interpolation path sets a domain stride of two for such a part, and the unstructured interpolation and non-Galerkin RAP paths index `hypre_IndexD(..., cdir)` with `cdir == -1`.
## Reason
In `hypre_SSAMGCreateInterpOp`, the `cdir == -1` branch is labeled "This part is not coarsened", but sets `strides[part][0] = 2` at `src/sstruct_ls/ssamg_interp.c:116-120`. A non-coarsened part should keep identity stride.
In `hypre_SSAMGSetupUInterpOp`, the code has a TODO at `src/sstruct_ls/ssamg_uinterp.c:411-412` saying `cdir` can be `-1`, but it immediately uses `cdir` as an index at `src/sstruct_ls/ssamg_uinterp.c:447`, `452`, and `459`.
In `hypre_SSAMGComputeRAPNonGlk`, the code also indexes with `cdir` without guarding the `-1` case at `src/sstruct_ls/ssamg_setup_rap.c:121-128`, then passes `cdir` to PFMG RAP setup at `src/sstruct_ls/ssamg_setup_rap.c:139-141`.
## Proposed Patch
Treat `cdir < 0` as "all fine points are coarse points" for that part: keep domain stride one, skip F-point marking in unstructured interpolation, and either use a safe generic RAP path or reject non-Galerkin RAP for partially uncoarsened levels.
```diff
diff --git a/src/sstruct_ls/ssamg_interp.c b/src/sstruct_ls/ssamg_interp.c
@@
else
{
/* This part is not coarsened */
- hypre_IndexD(strides[part], 0) = 2;
stencil_size_P = 1;
diff --git a/src/sstruct_ls/ssamg_uinterp.c b/src/sstruct_ls/ssamg_uinterp.c
@@
cdir = cdir_p[part];
+ if (cdir < 0)
+ {
+ /* No F-points on an uncoarsened part. */
+ continue;
+ }
/* Loop over variables */
diff --git a/src/sstruct_ls/ssamg_setup_rap.c b/src/sstruct_ls/ssamg_setup_rap.c
@@
cdir = cdir_p[part];
+ if (cdir < 0)
+ {
+ hypre_error_w_msg(HYPRE_ERROR_GENERIC,
+ "Non-Galerkin RAP does not support uncoarsened SSAMG parts");
+ goto cleanup;
+ }
pA = hypre_SStructMatrixPMatrix(A, part);
```
The RAP patch above is the conservative option. A more complete fix is to assemble the identity-stride part through generic SStruct matrix multiplication when `cdir < 0`, while keeping the optimized PFMG RAP path for coarsened parts.
0 条评论