From 00347d9a3b339be58002be1bdcd21ae8531e6a54 Mon Sep 17 00:00:00 2001 From: sdargavi Date: Mon, 2 Feb 2026 20:53:10 +0000 Subject: [PATCH 1/4] Bug fix where PCReset was not being called if any of the Set routines were called from Fortran --- src/PCAIR.c | 158 +----------- src/PCAIR_Interfaces.F90 | 538 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 499 insertions(+), 197 deletions(-) diff --git a/src/PCAIR.c b/src/PCAIR.c index 252ef55..0f1ed4a 100644 --- a/src/PCAIR.c +++ b/src/PCAIR.c @@ -491,10 +491,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetPrintStatsTimings(PC pc, PetscBool input_boo PETSC_EXTERN PetscErrorCode PCAIRSetMaxLevels(PC pc, PetscInt input_int) { PetscFunctionBegin; - PetscInt old_int; - PetscCall(PCAIRGetMaxLevels(pc, &old_int)); - if (old_int == input_int) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetMaxLevels_c(&pc, input_int); PetscFunctionReturn(PETSC_SUCCESS); } @@ -504,10 +500,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetMaxLevels(PC pc, PetscInt input_int) PETSC_EXTERN PetscErrorCode PCAIRSetCoarseEqLimit(PC pc, PetscInt input_int) { PetscFunctionBegin; - PetscInt old_int; - PetscCall(PCAIRGetCoarseEqLimit(pc, &old_int)); - if (old_int == input_int) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetCoarseEqLimit_c(&pc, input_int); PetscFunctionReturn(PETSC_SUCCESS); } @@ -518,10 +510,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetCoarseEqLimit(PC pc, PetscInt input_int) PETSC_EXTERN PetscErrorCode PCAIRSetAutoTruncateStartLevel(PC pc, PetscInt input_int) { PetscFunctionBegin; - PetscInt old_int; - PetscCall(PCAIRGetAutoTruncateStartLevel(pc, &old_int)); - if (old_int == input_int) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetAutoTruncateStartLevel_c(&pc, input_int); PetscFunctionReturn(PETSC_SUCCESS); } @@ -531,10 +519,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetAutoTruncateStartLevel(PC pc, PetscInt input PETSC_EXTERN PetscErrorCode PCAIRSetAutoTruncateTol(PC pc, PetscReal input_real) { PetscFunctionBegin; - PetscReal old_real; - PetscCall(PCAIRGetAutoTruncateTol(pc, &old_real)); - if (old_real == input_real) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetAutoTruncateTol_c(&pc, input_real); PetscFunctionReturn(PETSC_SUCCESS); } @@ -549,10 +533,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetAutoTruncateTol(PC pc, PetscReal input_real) PETSC_EXTERN PetscErrorCode PCAIRSetProcessorAgglom(PC pc, PetscBool input_bool) { PetscFunctionBegin; - PetscBool old_bool; - PetscCall(PCAIRGetProcessorAgglom(pc, &old_bool)); - if (old_bool == input_bool) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetProcessorAgglom_c(&pc, input_bool); PetscFunctionReturn(PETSC_SUCCESS); } @@ -563,10 +543,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetProcessorAgglom(PC pc, PetscBool input_bool) PETSC_EXTERN PetscErrorCode PCAIRSetProcessorAgglomRatio(PC pc, PetscReal input_real) { PetscFunctionBegin; - PetscReal old_real; - PetscCall(PCAIRGetProcessorAgglomRatio(pc, &old_real)); - if (old_real == input_real) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetProcessorAgglomRatio_c(&pc, input_real); PetscFunctionReturn(PETSC_SUCCESS); } @@ -577,10 +553,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetProcessorAgglomRatio(PC pc, PetscReal input_ PETSC_EXTERN PetscErrorCode PCAIRSetProcessorAgglomFactor(PC pc, PetscInt input_int) { PetscFunctionBegin; - PetscInt old_int; - PetscCall(PCAIRGetProcessorAgglomFactor(pc, &old_int)); - if (old_int == input_int) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetProcessorAgglomFactor_c(&pc, input_int); PetscFunctionReturn(PETSC_SUCCESS); } @@ -591,10 +563,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetProcessorAgglomFactor(PC pc, PetscInt input_ PETSC_EXTERN PetscErrorCode PCAIRSetProcessEqLimit(PC pc, PetscInt input_int) { PetscFunctionBegin; - PetscInt old_int; - PetscCall(PCAIRGetProcessEqLimit(pc, &old_int)); - if (old_int == input_int) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetProcessEqLimit_c(&pc, input_int); PetscFunctionReturn(PETSC_SUCCESS); } @@ -618,10 +586,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetSubcomm(PC pc, PetscBool input_bool) PETSC_EXTERN PetscErrorCode PCAIRSetStrongThreshold(PC pc, PetscReal input_real) { PetscFunctionBegin; - PetscReal old_real; - PetscCall(PCAIRGetStrongThreshold(pc, &old_real)); - if (old_real == input_real) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetStrongThreshold_c(&pc, input_real); PetscFunctionReturn(PETSC_SUCCESS); } @@ -631,10 +595,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetStrongThreshold(PC pc, PetscReal input_real) PETSC_EXTERN PetscErrorCode PCAIRSetDDCIts(PC pc, PetscInt input_int) { PetscFunctionBegin; - PetscInt old_int; - PetscCall(PCAIRGetDDCIts(pc, &old_int)); - if (old_int == input_int) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetDDCIts_c(&pc, input_int); PetscFunctionReturn(PETSC_SUCCESS); } @@ -645,10 +605,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetDDCIts(PC pc, PetscInt input_int) PETSC_EXTERN PetscErrorCode PCAIRSetMaxDDRatio(PC pc, PetscReal input_real) { PetscFunctionBegin; - PetscReal old_real; - PetscCall(PCAIRGetMaxDDRatio(pc, &old_real)); - if (old_real == input_real) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetMaxDDRatio_c(&pc, input_real); PetscFunctionReturn(PETSC_SUCCESS); } @@ -658,11 +614,7 @@ PETSC_EXTERN PetscErrorCode PCAIRSetMaxDDRatio(PC pc, PetscReal input_real) // -pc_air_ddc_fraction PETSC_EXTERN PetscErrorCode PCAIRSetDDCFraction(PC pc, PetscReal input_real) { - PetscFunctionBegin; - PetscReal old_real; - PetscCall(PCAIRGetDDCFraction(pc, &old_real)); - if (old_real == input_real) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); + PetscFunctionBegin; PCAIRSetDDCFraction_c(&pc, input_real); PetscFunctionReturn(PETSC_SUCCESS); } @@ -675,10 +627,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetDDCFraction(PC pc, PetscReal input_real) PETSC_EXTERN PetscErrorCode PCAIRSetCFSplittingType(PC pc, CFSplittingType input_int) { PetscFunctionBegin; - CFSplittingType old_int; - PetscCall(PCAIRGetCFSplittingType(pc, &old_int)); - if (old_int == input_int) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetCFSplittingType_c(&pc, input_int); PetscFunctionReturn(PETSC_SUCCESS); } @@ -690,10 +638,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetCFSplittingType(PC pc, CFSplittingType input PETSC_EXTERN PetscErrorCode PCAIRSetMaxLubySteps(PC pc, PetscInt input_int) { PetscFunctionBegin; - PetscInt old_int; - PetscCall(PCAIRGetMaxLubySteps(pc, &old_int)); - if (old_int == input_int) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetMaxLubySteps_c(&pc, input_int); PetscFunctionReturn(PETSC_SUCCESS); } @@ -703,10 +647,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetMaxLubySteps(PC pc, PetscInt input_int) PETSC_EXTERN PetscErrorCode PCAIRSetSmoothType(PC pc, const char* input_string) { PetscFunctionBegin; - char old_string[PETSC_MAX_PATH_LEN]; - PetscCall(PCAIRGetSmoothType(pc, old_string)); - if (strcmp(input_string, old_string) == 0) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetSmoothType_c(&pc, input_string); PetscFunctionReturn(PETSC_SUCCESS); } @@ -716,10 +656,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetSmoothType(PC pc, const char* input_string) PETSC_EXTERN PetscErrorCode PCAIRSetMatrixFreePolys(PC pc, PetscBool input_bool) { PetscFunctionBegin; - PetscBool old_bool; - PetscCall(PCAIRGetMatrixFreePolys(pc, &old_bool)); - if (old_bool == input_bool) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetMatrixFreePolys_c(&pc, input_bool); PetscFunctionReturn(PETSC_SUCCESS); } @@ -729,10 +665,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetMatrixFreePolys(PC pc, PetscBool input_bool) PETSC_EXTERN PetscErrorCode PCAIRSetOnePointClassicalProlong(PC pc, PetscBool input_bool) { PetscFunctionBegin; - PetscBool old_bool; - PetscCall(PCAIRGetOnePointClassicalProlong(pc, &old_bool)); - if (old_bool == input_bool) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetOnePointClassicalProlong_c(&pc, input_bool); PetscFunctionReturn(PETSC_SUCCESS); } @@ -742,10 +674,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetOnePointClassicalProlong(PC pc, PetscBool in PETSC_EXTERN PetscErrorCode PCAIRSetFullSmoothingUpAndDown(PC pc, PetscBool input_bool) { PetscFunctionBegin; - PetscBool old_bool; - PetscCall(PCAIRGetFullSmoothingUpAndDown(pc, &old_bool)); - if (old_bool == input_bool) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetFullSmoothingUpAndDown_c(&pc, input_bool); PetscFunctionReturn(PETSC_SUCCESS); } @@ -755,10 +683,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetFullSmoothingUpAndDown(PC pc, PetscBool inpu PETSC_EXTERN PetscErrorCode PCAIRSetSymmetric(PC pc, PetscBool input_bool) { PetscFunctionBegin; - PetscBool old_bool; - PetscCall(PCAIRGetSymmetric(pc, &old_bool)); - if (old_bool == input_bool) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetSymmetric_c(&pc, input_bool); PetscFunctionReturn(PETSC_SUCCESS); } @@ -772,10 +696,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetSymmetric(PC pc, PetscBool input_bool) PETSC_EXTERN PetscErrorCode PCAIRSetConstrainW(PC pc, PetscBool input_bool) { PetscFunctionBegin; - PetscBool old_bool; - PetscCall(PCAIRGetConstrainW(pc, &old_bool)); - if (old_bool == input_bool) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetConstrainW_c(&pc, input_bool); PetscFunctionReturn(PETSC_SUCCESS); } @@ -789,10 +709,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetConstrainW(PC pc, PetscBool input_bool) PETSC_EXTERN PetscErrorCode PCAIRSetConstrainZ(PC pc, PetscBool input_bool) { PetscFunctionBegin; - PetscBool old_bool; - PetscCall(PCAIRGetConstrainZ(pc, &old_bool)); - if (old_bool == input_bool) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetConstrainZ_c(&pc, input_bool); PetscFunctionReturn(PETSC_SUCCESS); } @@ -803,10 +719,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetConstrainZ(PC pc, PetscBool input_bool) PETSC_EXTERN PetscErrorCode PCAIRSetImproveWIts(PC pc, PetscInt input_int) { PetscFunctionBegin; - PetscInt old_int; - PetscCall(PCAIRGetImproveWIts(pc, &old_int)); - if (old_int == input_int) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetImproveWIts_c(&pc, input_int); PetscFunctionReturn(PETSC_SUCCESS); } @@ -817,10 +729,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetImproveWIts(PC pc, PetscInt input_int) PETSC_EXTERN PetscErrorCode PCAIRSetImproveZIts(PC pc, PetscInt input_int) { PetscFunctionBegin; - PetscInt old_int; - PetscCall(PCAIRGetImproveZIts(pc, &old_int)); - if (old_int == input_int) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetImproveZIts_c(&pc, input_int); PetscFunctionReturn(PETSC_SUCCESS); } @@ -833,10 +741,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetImproveZIts(PC pc, PetscInt input_int) PETSC_EXTERN PetscErrorCode PCAIRSetStrongRThreshold(PC pc, PetscReal input_real) { PetscFunctionBegin; - PetscReal old_real; - PetscCall(PCAIRGetStrongRThreshold(pc, &old_real)); - if (old_real == input_real) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetStrongRThreshold_c(&pc, input_real); PetscFunctionReturn(PETSC_SUCCESS); } @@ -857,10 +761,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetStrongRThreshold(PC pc, PetscReal input_real PETSC_EXTERN PetscErrorCode PCAIRSetInverseType(PC pc, PCPFLAREINVType input_int) { PetscFunctionBegin; - PCPFLAREINVType old_int; - PetscCall(PCAIRGetInverseType(pc, &old_int)); - if (old_int == input_int) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetInverseType_c(&pc, input_int); PetscFunctionReturn(PETSC_SUCCESS); } @@ -871,10 +771,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetInverseType(PC pc, PCPFLAREINVType input_int PETSC_EXTERN PetscErrorCode PCAIRSetCInverseType(PC pc, PCPFLAREINVType input_int) { PetscFunctionBegin; - PCPFLAREINVType old_int; - PetscCall(PCAIRGetCInverseType(pc, &old_int)); - if (old_int == input_int) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetCInverseType_c(&pc, input_int); PetscFunctionReturn(PETSC_SUCCESS); } @@ -887,10 +783,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetCInverseType(PC pc, PCPFLAREINVType input_in PETSC_EXTERN PetscErrorCode PCAIRSetZType(PC pc, PCAIRZType input_int) { PetscFunctionBegin; - PCAIRZType old_int; - PetscCall(PCAIRGetZType(pc, &old_int)); - if (old_int == input_int) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetZType_c(&pc, input_int); PetscFunctionReturn(PETSC_SUCCESS); } @@ -903,10 +795,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetZType(PC pc, PCAIRZType input_int) PETSC_EXTERN PetscErrorCode PCAIRSetLairDistance(PC pc, PetscInt input_int) { PetscFunctionBegin; - PetscInt old_int; - PetscCall(PCAIRGetLairDistance(pc, &old_int)); - if (old_int == input_int) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetLairDistance_c(&pc, input_int); PetscFunctionReturn(PETSC_SUCCESS); } @@ -917,10 +805,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetLairDistance(PC pc, PetscInt input_int) PETSC_EXTERN PetscErrorCode PCAIRSetPolyOrder(PC pc, PetscInt input_int) { PetscFunctionBegin; - PetscInt old_int; - PetscCall(PCAIRGetPolyOrder(pc, &old_int)); - if (old_int == input_int) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetPolyOrder_c(&pc, input_int); PetscFunctionReturn(PETSC_SUCCESS); } @@ -932,10 +816,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetPolyOrder(PC pc, PetscInt input_int) PETSC_EXTERN PetscErrorCode PCAIRSetInverseSparsityOrder(PC pc, PetscInt input_int) { PetscFunctionBegin; - PetscInt old_int; - PetscCall(PCAIRGetInverseSparsityOrder(pc, &old_int)); - if (old_int == input_int) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetInverseSparsityOrder_c(&pc, input_int); PetscFunctionReturn(PETSC_SUCCESS); } @@ -947,10 +827,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetInverseSparsityOrder(PC pc, PetscInt input_i PETSC_EXTERN PetscErrorCode PCAIRSetCPolyOrder(PC pc, PetscInt input_int) { PetscFunctionBegin; - PetscInt old_int; - PetscCall(PCAIRGetCPolyOrder(pc, &old_int)); - if (old_int == input_int) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetCPolyOrder_c(&pc, input_int); PetscFunctionReturn(PETSC_SUCCESS); } @@ -962,10 +838,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetCPolyOrder(PC pc, PetscInt input_int) PETSC_EXTERN PetscErrorCode PCAIRSetCInverseSparsityOrder(PC pc, PetscInt input_int) { PetscFunctionBegin; - PetscInt old_int; - PetscCall(PCAIRGetCInverseSparsityOrder(pc, &old_int)); - if (old_int == input_int) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetCInverseSparsityOrder_c(&pc, input_int); PetscFunctionReturn(PETSC_SUCCESS); } @@ -975,10 +847,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetCInverseSparsityOrder(PC pc, PetscInt input_ PETSC_EXTERN PetscErrorCode PCAIRSetCoarsestInverseType(PC pc, PCPFLAREINVType input_int) { PetscFunctionBegin; - PCPFLAREINVType old_int; - PetscCall(PCAIRGetCoarsestInverseType(pc, &old_int)); - if (old_int == input_int) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetCoarsestInverseType_c(&pc, input_int); PetscFunctionReturn(PETSC_SUCCESS); } @@ -988,10 +856,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetCoarsestInverseType(PC pc, PCPFLAREINVType i PETSC_EXTERN PetscErrorCode PCAIRSetCoarsestPolyOrder(PC pc, PetscInt input_int) { PetscFunctionBegin; - PetscInt old_int; - PetscCall(PCAIRGetCoarsestPolyOrder(pc, &old_int)); - if (old_int == input_int) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetCoarsestPolyOrder_c(&pc, input_int); PetscFunctionReturn(PETSC_SUCCESS); } @@ -1001,10 +865,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetCoarsestPolyOrder(PC pc, PetscInt input_int) PETSC_EXTERN PetscErrorCode PCAIRSetCoarsestInverseSparsityOrder(PC pc, PetscInt input_int) { PetscFunctionBegin; - PetscInt old_int; - PetscCall(PCAIRGetCoarsestInverseSparsityOrder(pc, &old_int)); - if (old_int == input_int) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetCoarsestInverseSparsityOrder_c(&pc, input_int); PetscFunctionReturn(PETSC_SUCCESS); } @@ -1014,10 +874,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetCoarsestInverseSparsityOrder(PC pc, PetscInt PETSC_EXTERN PetscErrorCode PCAIRSetCoarsestMatrixFreePolys(PC pc, PetscBool input_bool) { PetscFunctionBegin; - PetscBool old_bool; - PetscCall(PCAIRGetCoarsestMatrixFreePolys(pc, &old_bool)); - if (old_bool == input_bool) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetCoarsestMatrixFreePolys_c(&pc, input_bool); PetscFunctionReturn(PETSC_SUCCESS); } @@ -1037,10 +893,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetCoarsestSubcomm(PC pc, PetscBool input_bool) PETSC_EXTERN PetscErrorCode PCAIRSetRDrop(PC pc, PetscReal input_real) { PetscFunctionBegin; - PetscReal old_real; - PetscCall(PCAIRGetRDrop(pc, &old_real)); - if (old_real == input_real) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetRDrop_c(&pc, input_real); PetscFunctionReturn(PETSC_SUCCESS); } @@ -1050,10 +902,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetRDrop(PC pc, PetscReal input_real) PETSC_EXTERN PetscErrorCode PCAIRSetADrop(PC pc, PetscReal input_real) { PetscFunctionBegin; - PetscReal old_real; - PetscCall(PCAIRGetADrop(pc, &old_real)); - if (old_real == input_real) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetADrop_c(&pc, input_real); PetscFunctionReturn(PETSC_SUCCESS); } @@ -1063,10 +911,6 @@ PETSC_EXTERN PetscErrorCode PCAIRSetADrop(PC pc, PetscReal input_real) PETSC_EXTERN PetscErrorCode PCAIRSetALump(PC pc, PetscBool input_bool) { PetscFunctionBegin; - PetscBool old_bool; - PetscCall(PCAIRGetALump(pc, &old_bool)); - if (old_bool == input_bool) PetscFunctionReturn(PETSC_SUCCESS); - PetscCall(PCReset_AIR_c(pc)); PCAIRSetALump_c(&pc, input_bool); PetscFunctionReturn(PETSC_SUCCESS); } diff --git a/src/PCAIR_Interfaces.F90 b/src/PCAIR_Interfaces.F90 index c828059..8207fe9 100644 --- a/src/PCAIR_Interfaces.F90 +++ b/src/PCAIR_Interfaces.F90 @@ -93,7 +93,33 @@ subroutine PCAIRGetOptions(pc, options) ! Return the options options => pc_air_data%air_data%options - end subroutine PCAIRGetOptions + end subroutine PCAIRGetOptions + +! ------------------------------------------------------------------------------------------------------------------------------- + + subroutine PCAIRGetOptionsAndShell(pc, options, pc_shell) + + ! Gets the air options and PCSHELL that lives in our PCAIR + + ! ~~~~~~~~ + type(tPC), intent(inout) :: pc + type(air_options), pointer, intent(inout) :: options + type(tPC), intent(inout) :: pc_shell + + type(pc_air_multigrid_data), pointer :: pc_air_data=>null() + PetscErrorCode :: ierr + ! ~~~~~~~~ + + ! Get the underlying PCShell + call PCAIRGetPCShell(pc, pc_shell) + + ! Get the PC shell context + call PCShellGetContext(pc_shell, pc_air_data, ierr) + + ! Return the options + options => pc_air_data%air_data%options + + end subroutine PCAIRGetOptionsAndShell ! ------------------------------------------------------------------------------------------------------------------------------- @@ -1204,10 +1230,25 @@ subroutine PCAIRSetMaxLevels(pc, max_levels, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscInt :: old_int ! ~~~~~~~~ + call PCAIRGetMaxLevels(pc, old_int, ierr) + if (old_int == max_levels) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + ! Call the underlying reset - this won't touch the context + ! in our pcshell though as pcshell doesn't offer a way to + ! give a custom reset function + call PCReset(pc_shell, ierr) + ! Call the destroy routine + call PCReset_AIR_Shell(pc_shell, ierr) + options%max_levels = int(max_levels) ierr = 0 @@ -1223,10 +1264,21 @@ subroutine PCAIRSetCoarseEqLimit(pc, coarse_eq_limit, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscInt :: old_int ! ~~~~~~~~ + call PCAIRGetCoarseEqLimit(pc, old_int, ierr) + if (old_int == coarse_eq_limit) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + options%coarse_eq_limit = coarse_eq_limit ierr = 0 @@ -1242,10 +1294,21 @@ subroutine PCAIRSetAutoTruncateStartLevel(pc, start_level, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscInt :: old_int ! ~~~~~~~~ + call PCAIRGetAutoTruncateStartLevel(pc, old_int, ierr) + if (old_int == start_level) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + options%auto_truncate_start_level = int(start_level) ierr = 0 @@ -1261,10 +1324,21 @@ subroutine PCAIRSetAutoTruncateTol(pc, tol, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscReal :: old_real ! ~~~~~~~~ + call PCAIRGetAutoTruncateTol(pc, old_real, ierr) + if (old_real == tol) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + options%auto_truncate_tol = tol ierr = 0 @@ -1280,10 +1354,21 @@ subroutine PCAIRSetProcessorAgglom(pc, processor_agglom, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscBool :: old_bool ! ~~~~~~~~ + call PCAIRGetProcessorAgglom(pc, old_bool, ierr) + if (old_bool .eqv. processor_agglom) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + options%processor_agglom = processor_agglom ierr = 0 @@ -1299,10 +1384,21 @@ subroutine PCAIRSetProcessorAgglomRatio(pc, ratio, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscReal :: old_real ! ~~~~~~~~ + call PCAIRGetProcessorAgglomRatio(pc, old_real, ierr) + if (old_real == ratio) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + options%processor_agglom_ratio = ratio ierr = 0 @@ -1318,10 +1414,21 @@ subroutine PCAIRSetProcessorAgglomFactor(pc, factor, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscInt :: old_int ! ~~~~~~~~ + call PCAIRGetProcessorAgglomFactor(pc, old_int, ierr) + if (old_int == factor) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + options%processor_agglom_factor = int(factor) ierr = 0 @@ -1337,10 +1444,21 @@ subroutine PCAIRSetProcessEqLimit(pc, limit, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscInt :: old_int ! ~~~~~~~~ + call PCAIRGetProcessEqLimit(pc, old_int, ierr) + if (old_int == limit) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + options%process_eq_limit = limit ierr = 0 @@ -1375,10 +1493,21 @@ subroutine PCAIRSetStrongThreshold(pc, thresh, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscReal :: old_real ! ~~~~~~~~ + call PCAIRGetStrongThreshold(pc, old_real, ierr) + if (old_real == thresh) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + options%strong_threshold = thresh ierr = 0 @@ -1394,10 +1523,21 @@ subroutine PCAIRSetDDCIts(pc, its, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscInt :: old_int ! ~~~~~~~~ + call PCAIRGetDDCIts(pc, old_int, ierr) + if (old_int == its) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + options%ddc_its = int(its) ierr = 0 @@ -1413,10 +1553,21 @@ subroutine PCAIRSetMaxDDRatio(pc, ratio, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscReal :: old_real ! ~~~~~~~~ + call PCAIRGetMaxDDRatio(pc, old_real, ierr) + if (old_real == ratio) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + options%max_dd_ratio = ratio ierr = 0 @@ -1432,10 +1583,21 @@ subroutine PCAIRSetDDCFraction(pc, frac, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscReal :: old_real ! ~~~~~~~~ + call PCAIRGetDDCFraction(pc, old_real, ierr) + if (old_real == frac) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + options%ddc_fraction = frac ierr = 0 @@ -1451,10 +1613,21 @@ subroutine PCAIRSetCFSplittingType(pc, algo, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + CFSplittingType :: old_type ! ~~~~~~~~ + call PCAIRGetCFSplittingType(pc, old_type, ierr) + if (old_type == algo) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + options%cf_splitting_type = int(algo) ierr = 0 @@ -1470,10 +1643,21 @@ subroutine PCAIRSetMaxLubySteps(pc, steps, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscInt :: old_int ! ~~~~~~~~ + call PCAIRGetMaxLubySteps(pc, old_int, ierr) + if (old_int == steps) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + options%max_luby_steps = int(steps) ierr = 0 @@ -1489,13 +1673,23 @@ subroutine PCAIRSetSmoothType(pc, input_string, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell character(len = 1) :: current_char, old_char + character(len = PETSC_MAX_PATH_LEN) :: old_string integer :: smooth_order_index integer :: errorcode, n, i ! ~~~~~~~~ + call PCAIRGetSmoothType(pc, old_string, ierr) + if (trim(old_string) == trim(input_string)) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) n = len_trim(input_string) if (n == 0) then @@ -1598,10 +1792,21 @@ subroutine PCAIRSetMatrixFreePolys(pc, mf, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscBool :: old_bool ! ~~~~~~~~ + call PCAIRGetMatrixFreePolys(pc, old_bool, ierr) + if (old_bool .eqv. mf) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + options%matrix_free_polys = mf ierr = 0 @@ -1617,10 +1822,21 @@ subroutine PCAIRSetOnePointClassicalProlong(pc, onep, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscBool :: old_bool ! ~~~~~~~~ + call PCAIRGetOnePointClassicalProlong(pc, old_bool, ierr) + if (old_bool .eqv. onep) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + options%one_point_classical_prolong = onep ierr = 0 @@ -1636,10 +1852,21 @@ subroutine PCAIRSetFullSmoothingUpAndDown(pc, full, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscBool :: old_bool ! ~~~~~~~~ + call PCAIRGetFullSmoothingUpAndDown(pc, old_bool, ierr) + if (old_bool .eqv. full) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + options%full_smoothing_up_and_down = full ierr = 0 @@ -1655,10 +1882,21 @@ subroutine PCAIRSetSymmetric(pc, sym, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscBool :: old_bool ! ~~~~~~~~ + call PCAIRGetSymmetric(pc, old_bool, ierr) + if (old_bool .eqv. sym) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + options%symmetric = sym ierr = 0 @@ -1674,10 +1912,21 @@ subroutine PCAIRSetConstrainW(pc, constrain, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscBool :: old_bool ! ~~~~~~~~ + call PCAIRGetConstrainW(pc, old_bool, ierr) + if (old_bool .eqv. constrain) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + options%constrain_w = constrain ierr = 0 @@ -1693,10 +1942,21 @@ subroutine PCAIRSetConstrainZ(pc, constrain, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscBool :: old_bool ! ~~~~~~~~ + call PCAIRGetConstrainZ(pc, old_bool, ierr) + if (old_bool .eqv. constrain) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + options%constrain_z = constrain ierr = 0 @@ -1712,10 +1972,21 @@ subroutine PCAIRSetImproveWIts(pc, its, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscInt :: old_int ! ~~~~~~~~ + call PCAIRGetImproveWIts(pc, old_int, ierr) + if (old_int == its) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + options%improve_w_its = int(its) ierr = 0 @@ -1731,10 +2002,21 @@ subroutine PCAIRSetImproveZIts(pc, its, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscInt :: old_int ! ~~~~~~~~ + call PCAIRGetImproveZIts(pc, old_int, ierr) + if (old_int == its) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + options%improve_z_its = int(its) ierr = 0 @@ -1750,10 +2032,21 @@ subroutine PCAIRSetStrongRThreshold(pc, thresh, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscReal :: old_real ! ~~~~~~~~ + call PCAIRGetStrongRThreshold(pc, old_real, ierr) + if (old_real == thresh) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + options%strong_r_threshold = thresh ierr = 0 @@ -1769,10 +2062,21 @@ subroutine PCAIRSetInverseType(pc, inv_type, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PCPFLAREINVType :: old_type ! ~~~~~~~~ + call PCAIRGetInverseType(pc, old_type, ierr) + if (old_type == inv_type) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + options%inverse_type = inv_type ierr = 0 @@ -1788,10 +2092,21 @@ subroutine PCAIRSetCInverseType(pc, inv_type, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PCPFLAREINVType :: old_type ! ~~~~~~~~ + call PCAIRGetCInverseType(pc, old_type, ierr) + if (old_type == inv_type) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + options%c_inverse_type = inv_type ierr = 0 @@ -1807,10 +2122,21 @@ subroutine PCAIRSetZType(pc, z_type, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PCAIRZType :: old_type ! ~~~~~~~~ + call PCAIRGetZType(pc, old_type, ierr) + if (old_type == z_type) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + options%z_type = z_type ierr = 0 @@ -1826,10 +2152,21 @@ subroutine PCAIRSetLairDistance(pc, distance, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscInt :: old_int ! ~~~~~~~~ + call PCAIRGetLairDistance(pc, old_int, ierr) + if (old_int == distance) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + options%lair_distance = int(distance) ierr = 0 @@ -1845,10 +2182,21 @@ subroutine PCAIRSetPolyOrder(pc, order, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscInt :: old_int ! ~~~~~~~~ + call PCAIRGetPolyOrder(pc, old_int, ierr) + if (old_int == order) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + options%poly_order = int(order) ierr = 0 @@ -1864,10 +2212,21 @@ subroutine PCAIRSetInverseSparsityOrder(pc, order, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscInt :: old_int ! ~~~~~~~~ + call PCAIRGetInverseSparsityOrder(pc, old_int, ierr) + if (old_int == order) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + options%inverse_sparsity_order = int(order) ierr = 0 @@ -1883,10 +2242,21 @@ subroutine PCAIRSetCPolyOrder(pc, order, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscInt :: old_int ! ~~~~~~~~ + call PCAIRGetCPolyOrder(pc, old_int, ierr) + if (old_int == order) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + options%c_poly_order = int(order) ierr = 0 @@ -1902,10 +2272,21 @@ subroutine PCAIRSetCInverseSparsityOrder(pc, order, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscInt :: old_int ! ~~~~~~~~ + call PCAIRGetCInverseSparsityOrder(pc, old_int, ierr) + if (old_int == order) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + options%c_inverse_sparsity_order = int(order) ierr = 0 @@ -1921,10 +2302,21 @@ subroutine PCAIRSetCoarsestInverseType(pc, inv_type, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PCPFLAREINVType :: old_type ! ~~~~~~~~ + call PCAIRGetCoarsestInverseType(pc, old_type, ierr) + if (old_type == inv_type) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + options%coarsest_inverse_type = inv_type ierr = 0 @@ -1940,10 +2332,21 @@ subroutine PCAIRSetCoarsestPolyOrder(pc, order, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscInt :: old_int ! ~~~~~~~~ + call PCAIRGetCoarsestPolyOrder(pc, old_int, ierr) + if (old_int == order) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + options%coarsest_poly_order = int(order) ierr = 0 @@ -1959,10 +2362,21 @@ subroutine PCAIRSetCoarsestInverseSparsityOrder(pc, order, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscInt :: old_int ! ~~~~~~~~ + call PCAIRGetCoarsestInverseSparsityOrder(pc, old_int, ierr) + if (old_int == order) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + options%coarsest_inverse_sparsity_order = int(order) ierr = 0 @@ -1978,10 +2392,21 @@ subroutine PCAIRSetCoarsestMatrixFreePolys(pc, mf, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscBool :: old_bool ! ~~~~~~~~ + call PCAIRGetCoarsestMatrixFreePolys(pc, old_bool, ierr) + if (old_bool .eqv. mf) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + options%coarsest_matrix_free_polys = mf ierr = 0 @@ -2016,10 +2441,21 @@ subroutine PCAIRSetRDrop(pc, rdrop, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscReal :: old_real ! ~~~~~~~~ + call PCAIRGetRDrop(pc, old_real, ierr) + if (old_real == rdrop) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + options%r_drop = rdrop ierr = 0 @@ -2035,10 +2471,21 @@ subroutine PCAIRSetADrop(pc, adrop, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscReal :: old_real ! ~~~~~~~~ + call PCAIRGetADrop(pc, old_real, ierr) + if (old_real == adrop) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + options%a_drop = adrop ierr = 0 @@ -2054,10 +2501,21 @@ subroutine PCAIRSetALump(pc, lump, ierr) PetscErrorCode, intent(out) :: ierr type(air_options), pointer :: options + type(tPC) :: pc_shell + PetscBool :: old_bool ! ~~~~~~~~ + call PCAIRGetALump(pc, old_bool, ierr) + if (old_bool .eqv. lump) then + ierr = 0 + return + end if + ! Set the options - call PCAIRGetOptions(pc, options) + call PCAIRGetOptionsAndShell(pc, options, pc_shell) + call PCReset(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + options%a_lump = lump ierr = 0 From 43d6f1db91f0697e53c14147acd66d42313c477f Mon Sep 17 00:00:00 2001 From: sdargavi Date: Mon, 2 Feb 2026 21:52:28 +0000 Subject: [PATCH 2/4] When parameter change occurs the PC is now marked as requiring setup again. Also added in new test to check this occurs without errors --- Makefile | 2 +- src/C_PETSc_Interfaces.F90 | 10 +++ src/C_PETSc_Routines.c | 6 ++ src/PCAIR_Interfaces.F90 | 120 +++++++++++++++++++++----------- tests/Makefile | 3 + tests/matrandom_check_reset.F90 | 78 +++++++++++++++++++++ 6 files changed, 178 insertions(+), 41 deletions(-) create mode 100644 tests/matrandom_check_reset.F90 diff --git a/Makefile b/Makefile index 7a83732..3fcd41a 100644 --- a/Makefile +++ b/Makefile @@ -138,7 +138,7 @@ OBJS := $(OBJS) $(SRCDIR)/PETSc_Helper.o \ $(SRCDIR)/PCPFLAREINV.o # Define a variable containing all the tests -export TEST_TARGETS = ex12f ex6f ex6f_getcoeffs ex6 adv_1d adv_diff_2d ex6_cf_splitting adv_diff_cg_supg matrandom +export TEST_TARGETS = ex12f ex6f ex6f_getcoeffs ex6 adv_1d adv_diff_2d ex6_cf_splitting adv_diff_cg_supg matrandom matrandom_check_reset # Include kokkos examples ifeq ($(PETSC_HAVE_KOKKOS),1) export TEST_TARGETS := $(TEST_TARGETS) adv_1dk diff --git a/src/C_PETSc_Interfaces.F90 b/src/C_PETSc_Interfaces.F90 index 2a11959..2619d6e 100644 --- a/src/C_PETSc_Interfaces.F90 +++ b/src/C_PETSc_Interfaces.F90 @@ -250,6 +250,16 @@ end subroutine PCGetSetupCalled_c end interface + interface + + subroutine PCMarkNotSetUp_c(A_array) & + bind(c, name="PCMarkNotSetUp_c") + use iso_c_binding + integer(c_long_long) :: A_array + end subroutine PCMarkNotSetUp_c + + end interface + interface subroutine MatGetDiagonalOnly_c(A_array, diag_only) & diff --git a/src/C_PETSc_Routines.c b/src/C_PETSc_Routines.c index 26d2cec..d2e55e5 100644 --- a/src/C_PETSc_Routines.c +++ b/src/C_PETSc_Routines.c @@ -470,6 +470,12 @@ PETSC_INTERN void PCGetSetupCalled_c(PC *pc, PetscInt *setupcalled) *setupcalled = (*pc)->setupcalled; } +// Mark that we need to do setup again (e.g. after a reset) +PETSC_INTERN void PCMarkNotSetUp_c(PC *pc) +{ + (*pc)->setupcalled = 0; +} + // Gets the number of nonzeros in the local PETSC_INTERN PetscErrorCode MatGetNNZs_local_c(Mat *A, PetscInt *nnzs) { diff --git a/src/PCAIR_Interfaces.F90 b/src/PCAIR_Interfaces.F90 index 8207fe9..c54f491 100644 --- a/src/PCAIR_Interfaces.F90 +++ b/src/PCAIR_Interfaces.F90 @@ -1244,10 +1244,12 @@ subroutine PCAIRSetMaxLevels(pc, max_levels, ierr) call PCAIRGetOptionsAndShell(pc, options, pc_shell) ! Call the underlying reset - this won't touch the context ! in our pcshell though as pcshell doesn't offer a way to - ! give a custom reset function + ! give a custom reset function call PCReset(pc_shell, ierr) ! Call the destroy routine - call PCReset_AIR_Shell(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + ! Have to mark that the outer setup must be called again + call PCMarkNotSetUp_c(pc%v) options%max_levels = int(max_levels) ierr = 0 @@ -1277,7 +1279,8 @@ subroutine PCAIRSetCoarseEqLimit(pc, coarse_eq_limit, ierr) ! Set the options call PCAIRGetOptionsAndShell(pc, options, pc_shell) call PCReset(pc_shell, ierr) - call PCReset_AIR_Shell(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) options%coarse_eq_limit = coarse_eq_limit ierr = 0 @@ -1307,7 +1310,8 @@ subroutine PCAIRSetAutoTruncateStartLevel(pc, start_level, ierr) ! Set the options call PCAIRGetOptionsAndShell(pc, options, pc_shell) call PCReset(pc_shell, ierr) - call PCReset_AIR_Shell(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) options%auto_truncate_start_level = int(start_level) ierr = 0 @@ -1337,7 +1341,8 @@ subroutine PCAIRSetAutoTruncateTol(pc, tol, ierr) ! Set the options call PCAIRGetOptionsAndShell(pc, options, pc_shell) call PCReset(pc_shell, ierr) - call PCReset_AIR_Shell(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) options%auto_truncate_tol = tol ierr = 0 @@ -1367,7 +1372,8 @@ subroutine PCAIRSetProcessorAgglom(pc, processor_agglom, ierr) ! Set the options call PCAIRGetOptionsAndShell(pc, options, pc_shell) call PCReset(pc_shell, ierr) - call PCReset_AIR_Shell(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) options%processor_agglom = processor_agglom ierr = 0 @@ -1397,7 +1403,8 @@ subroutine PCAIRSetProcessorAgglomRatio(pc, ratio, ierr) ! Set the options call PCAIRGetOptionsAndShell(pc, options, pc_shell) call PCReset(pc_shell, ierr) - call PCReset_AIR_Shell(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) options%processor_agglom_ratio = ratio ierr = 0 @@ -1427,7 +1434,8 @@ subroutine PCAIRSetProcessorAgglomFactor(pc, factor, ierr) ! Set the options call PCAIRGetOptionsAndShell(pc, options, pc_shell) call PCReset(pc_shell, ierr) - call PCReset_AIR_Shell(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) options%processor_agglom_factor = int(factor) ierr = 0 @@ -1457,7 +1465,8 @@ subroutine PCAIRSetProcessEqLimit(pc, limit, ierr) ! Set the options call PCAIRGetOptionsAndShell(pc, options, pc_shell) call PCReset(pc_shell, ierr) - call PCReset_AIR_Shell(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) options%process_eq_limit = limit ierr = 0 @@ -1506,7 +1515,8 @@ subroutine PCAIRSetStrongThreshold(pc, thresh, ierr) ! Set the options call PCAIRGetOptionsAndShell(pc, options, pc_shell) call PCReset(pc_shell, ierr) - call PCReset_AIR_Shell(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) options%strong_threshold = thresh ierr = 0 @@ -1536,7 +1546,8 @@ subroutine PCAIRSetDDCIts(pc, its, ierr) ! Set the options call PCAIRGetOptionsAndShell(pc, options, pc_shell) call PCReset(pc_shell, ierr) - call PCReset_AIR_Shell(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) options%ddc_its = int(its) ierr = 0 @@ -1566,7 +1577,8 @@ subroutine PCAIRSetMaxDDRatio(pc, ratio, ierr) ! Set the options call PCAIRGetOptionsAndShell(pc, options, pc_shell) call PCReset(pc_shell, ierr) - call PCReset_AIR_Shell(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) options%max_dd_ratio = ratio ierr = 0 @@ -1596,7 +1608,8 @@ subroutine PCAIRSetDDCFraction(pc, frac, ierr) ! Set the options call PCAIRGetOptionsAndShell(pc, options, pc_shell) call PCReset(pc_shell, ierr) - call PCReset_AIR_Shell(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) options%ddc_fraction = frac ierr = 0 @@ -1626,7 +1639,8 @@ subroutine PCAIRSetCFSplittingType(pc, algo, ierr) ! Set the options call PCAIRGetOptionsAndShell(pc, options, pc_shell) call PCReset(pc_shell, ierr) - call PCReset_AIR_Shell(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) options%cf_splitting_type = int(algo) ierr = 0 @@ -1656,7 +1670,8 @@ subroutine PCAIRSetMaxLubySteps(pc, steps, ierr) ! Set the options call PCAIRGetOptionsAndShell(pc, options, pc_shell) call PCReset(pc_shell, ierr) - call PCReset_AIR_Shell(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) options%max_luby_steps = int(steps) ierr = 0 @@ -1689,7 +1704,8 @@ subroutine PCAIRSetSmoothType(pc, input_string, ierr) ! Set the options call PCAIRGetOptionsAndShell(pc, options, pc_shell) call PCReset(pc_shell, ierr) - call PCReset_AIR_Shell(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) n = len_trim(input_string) if (n == 0) then @@ -1805,7 +1821,8 @@ subroutine PCAIRSetMatrixFreePolys(pc, mf, ierr) ! Set the options call PCAIRGetOptionsAndShell(pc, options, pc_shell) call PCReset(pc_shell, ierr) - call PCReset_AIR_Shell(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) options%matrix_free_polys = mf ierr = 0 @@ -1835,7 +1852,8 @@ subroutine PCAIRSetOnePointClassicalProlong(pc, onep, ierr) ! Set the options call PCAIRGetOptionsAndShell(pc, options, pc_shell) call PCReset(pc_shell, ierr) - call PCReset_AIR_Shell(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) options%one_point_classical_prolong = onep ierr = 0 @@ -1865,7 +1883,8 @@ subroutine PCAIRSetFullSmoothingUpAndDown(pc, full, ierr) ! Set the options call PCAIRGetOptionsAndShell(pc, options, pc_shell) call PCReset(pc_shell, ierr) - call PCReset_AIR_Shell(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) options%full_smoothing_up_and_down = full ierr = 0 @@ -1895,7 +1914,8 @@ subroutine PCAIRSetSymmetric(pc, sym, ierr) ! Set the options call PCAIRGetOptionsAndShell(pc, options, pc_shell) call PCReset(pc_shell, ierr) - call PCReset_AIR_Shell(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) options%symmetric = sym ierr = 0 @@ -1925,7 +1945,8 @@ subroutine PCAIRSetConstrainW(pc, constrain, ierr) ! Set the options call PCAIRGetOptionsAndShell(pc, options, pc_shell) call PCReset(pc_shell, ierr) - call PCReset_AIR_Shell(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) options%constrain_w = constrain ierr = 0 @@ -1955,7 +1976,8 @@ subroutine PCAIRSetConstrainZ(pc, constrain, ierr) ! Set the options call PCAIRGetOptionsAndShell(pc, options, pc_shell) call PCReset(pc_shell, ierr) - call PCReset_AIR_Shell(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) options%constrain_z = constrain ierr = 0 @@ -1985,7 +2007,8 @@ subroutine PCAIRSetImproveWIts(pc, its, ierr) ! Set the options call PCAIRGetOptionsAndShell(pc, options, pc_shell) call PCReset(pc_shell, ierr) - call PCReset_AIR_Shell(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) options%improve_w_its = int(its) ierr = 0 @@ -2015,7 +2038,8 @@ subroutine PCAIRSetImproveZIts(pc, its, ierr) ! Set the options call PCAIRGetOptionsAndShell(pc, options, pc_shell) call PCReset(pc_shell, ierr) - call PCReset_AIR_Shell(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) options%improve_z_its = int(its) ierr = 0 @@ -2045,7 +2069,8 @@ subroutine PCAIRSetStrongRThreshold(pc, thresh, ierr) ! Set the options call PCAIRGetOptionsAndShell(pc, options, pc_shell) call PCReset(pc_shell, ierr) - call PCReset_AIR_Shell(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) options%strong_r_threshold = thresh ierr = 0 @@ -2075,7 +2100,8 @@ subroutine PCAIRSetInverseType(pc, inv_type, ierr) ! Set the options call PCAIRGetOptionsAndShell(pc, options, pc_shell) call PCReset(pc_shell, ierr) - call PCReset_AIR_Shell(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) options%inverse_type = inv_type ierr = 0 @@ -2105,7 +2131,8 @@ subroutine PCAIRSetCInverseType(pc, inv_type, ierr) ! Set the options call PCAIRGetOptionsAndShell(pc, options, pc_shell) call PCReset(pc_shell, ierr) - call PCReset_AIR_Shell(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) options%c_inverse_type = inv_type ierr = 0 @@ -2135,7 +2162,8 @@ subroutine PCAIRSetZType(pc, z_type, ierr) ! Set the options call PCAIRGetOptionsAndShell(pc, options, pc_shell) call PCReset(pc_shell, ierr) - call PCReset_AIR_Shell(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) options%z_type = z_type ierr = 0 @@ -2165,7 +2193,8 @@ subroutine PCAIRSetLairDistance(pc, distance, ierr) ! Set the options call PCAIRGetOptionsAndShell(pc, options, pc_shell) call PCReset(pc_shell, ierr) - call PCReset_AIR_Shell(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) options%lair_distance = int(distance) ierr = 0 @@ -2195,7 +2224,8 @@ subroutine PCAIRSetPolyOrder(pc, order, ierr) ! Set the options call PCAIRGetOptionsAndShell(pc, options, pc_shell) call PCReset(pc_shell, ierr) - call PCReset_AIR_Shell(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) options%poly_order = int(order) ierr = 0 @@ -2225,7 +2255,8 @@ subroutine PCAIRSetInverseSparsityOrder(pc, order, ierr) ! Set the options call PCAIRGetOptionsAndShell(pc, options, pc_shell) call PCReset(pc_shell, ierr) - call PCReset_AIR_Shell(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) options%inverse_sparsity_order = int(order) ierr = 0 @@ -2255,7 +2286,8 @@ subroutine PCAIRSetCPolyOrder(pc, order, ierr) ! Set the options call PCAIRGetOptionsAndShell(pc, options, pc_shell) call PCReset(pc_shell, ierr) - call PCReset_AIR_Shell(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) options%c_poly_order = int(order) ierr = 0 @@ -2285,7 +2317,8 @@ subroutine PCAIRSetCInverseSparsityOrder(pc, order, ierr) ! Set the options call PCAIRGetOptionsAndShell(pc, options, pc_shell) call PCReset(pc_shell, ierr) - call PCReset_AIR_Shell(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) options%c_inverse_sparsity_order = int(order) ierr = 0 @@ -2315,7 +2348,8 @@ subroutine PCAIRSetCoarsestInverseType(pc, inv_type, ierr) ! Set the options call PCAIRGetOptionsAndShell(pc, options, pc_shell) call PCReset(pc_shell, ierr) - call PCReset_AIR_Shell(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) options%coarsest_inverse_type = inv_type ierr = 0 @@ -2345,7 +2379,8 @@ subroutine PCAIRSetCoarsestPolyOrder(pc, order, ierr) ! Set the options call PCAIRGetOptionsAndShell(pc, options, pc_shell) call PCReset(pc_shell, ierr) - call PCReset_AIR_Shell(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) options%coarsest_poly_order = int(order) ierr = 0 @@ -2375,7 +2410,8 @@ subroutine PCAIRSetCoarsestInverseSparsityOrder(pc, order, ierr) ! Set the options call PCAIRGetOptionsAndShell(pc, options, pc_shell) call PCReset(pc_shell, ierr) - call PCReset_AIR_Shell(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) options%coarsest_inverse_sparsity_order = int(order) ierr = 0 @@ -2405,7 +2441,8 @@ subroutine PCAIRSetCoarsestMatrixFreePolys(pc, mf, ierr) ! Set the options call PCAIRGetOptionsAndShell(pc, options, pc_shell) call PCReset(pc_shell, ierr) - call PCReset_AIR_Shell(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) options%coarsest_matrix_free_polys = mf ierr = 0 @@ -2454,7 +2491,8 @@ subroutine PCAIRSetRDrop(pc, rdrop, ierr) ! Set the options call PCAIRGetOptionsAndShell(pc, options, pc_shell) call PCReset(pc_shell, ierr) - call PCReset_AIR_Shell(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) options%r_drop = rdrop ierr = 0 @@ -2484,7 +2522,8 @@ subroutine PCAIRSetADrop(pc, adrop, ierr) ! Set the options call PCAIRGetOptionsAndShell(pc, options, pc_shell) call PCReset(pc_shell, ierr) - call PCReset_AIR_Shell(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) options%a_drop = adrop ierr = 0 @@ -2514,7 +2553,8 @@ subroutine PCAIRSetALump(pc, lump, ierr) ! Set the options call PCAIRGetOptionsAndShell(pc, options, pc_shell) call PCReset(pc_shell, ierr) - call PCReset_AIR_Shell(pc_shell, ierr) + call PCReset_AIR_Shell(pc_shell, ierr) + call PCMarkNotSetUp_c(pc%v) options%a_lump = lump ierr = 0 diff --git a/tests/Makefile b/tests/Makefile index 3b5b1ba..e2777ae 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -165,6 +165,9 @@ run_tests_no_load_serial: @echo "Test AIRG with random diagonally dominant matrix" ./matrandom -ksp_max_it 5 @echo "" + @echo "Test AIRG with parameter resets on random diagonally dominant matrix" + ./matrandom_check_reset -ksp_max_it 7 + @echo "" @echo "Test AIRG with SUPG CG FEM in 2D" ./adv_diff_cg_supg -adv_diff_petscspace_degree 1 -dm_plex_simplex 0 -dm_refine 1 -pc_type air -pc_air_a_drop 1e-3 -pc_air_inverse_type power \ -ksp_type richardson -ksp_norm_type unpreconditioned -ksp_max_it 4 diff --git a/tests/matrandom_check_reset.F90 b/tests/matrandom_check_reset.F90 new file mode 100644 index 0000000..753b317 --- /dev/null +++ b/tests/matrandom_check_reset.F90 @@ -0,0 +1,78 @@ +#include +#include "finclude/pflare.h" + use petscksp + implicit none + +! Test fortran interface of pflare with small solve of random matrix + + PetscErrorCode :: ierr + Mat :: A + PetscInt :: m, n, nnzs + PetscInt, parameter :: one = 1, two = 2, three = 3 + Vec :: x,b + KSP :: ksp + PC :: pc + PetscBool :: flg + KSPConvergedReason reason + + call PetscInitialize(PETSC_NULL_CHARACTER,ierr) + ! Register the pflare types + call PCRegister_PFLARE() + + m = 5 + n = 5 + call PetscOptionsGetInt(PETSC_NULL_OPTIONS,PETSC_NULL_CHARACTER,'-m',m,flg,ierr) + call PetscOptionsGetInt(PETSC_NULL_OPTIONS,PETSC_NULL_CHARACTER,'-n',n,flg,ierr) + + ! Create matrix + call MatCreate(PETSC_COMM_WORLD,A,ierr) + call MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,m*n,m*n,ierr) + call MatSetFromOptions(A,ierr) + nnzs = m * 2; + call MatSeqAIJSetPreallocation(A, nnzs, PETSC_NULL_INTEGER_ARRAY, ierr) + call MatMPIAIJSetPreallocation(A, nnzs, PETSC_NULL_INTEGER_ARRAY, nnzs, PETSC_NULL_INTEGER_ARRAY, ierr) + call MatSetUp(A,ierr) + + call MatCreateVecs(A,b,x,ierr) + call VecSet(x, 0d0, ierr) + call VecSet(b, 2d0, ierr) + + ! Set random values in matrix + call MatSetRandom(A, PETSC_NULL_RANDOM, ierr) + call MatSetOption(A, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE, ierr) + call MatDiagonalSet(A, b, ADD_VALUES, ierr) ! make it diagonally dominant + + call KSPCreate(PETSC_COMM_WORLD,ksp,ierr) + call KSPSetOperators(ksp,A,A,ierr) + call KSPGetPC(ksp,pc,ierr) + ! Set AIRG as pc + call PCSetType(pc, PCAIR, ierr) + ! Set an initial option to test it persists after reset + call PCAIRSetCoarseEqLimit(pc, 9, ierr) + call KSPSetPC(ksp, pc, ierr) + call KSPSetFromOptions(ksp,ierr) + call KSPSetUp(ksp,ierr) + + ! Do the solve + call KSPSolve(ksp,b,x,ierr) + call KSPGetConvergedReason(ksp, reason, ierr) + if (reason%v < 0) then + error stop 1 + end if + + ! Do a second solve with some changed parameters to test reset + call PCAIRSetMaxLevels(pc, 2, ierr) + call PCAIRSetStrongThreshold(pc, 0.4d0, ierr) + call VecSet(x, 0d0, ierr) + call KSPSolve(ksp,b,x,ierr) + call KSPGetConvergedReason(ksp, reason, ierr) + if (reason%v < 0) then + error stop 1 + end if + + call MatDestroy(A, ierr) + call VecDestroy(b, ierr) + call VecDestroy(x, ierr) + call KSPDestroy(ksp, ierr) + call PetscFinalize(ierr) + end \ No newline at end of file From 9472bf0e94a4d38c92a1dcb2c7f12793a69eab4a Mon Sep 17 00:00:00 2001 From: sdargavi Date: Mon, 2 Feb 2026 22:10:20 +0000 Subject: [PATCH 3/4] Parameter changes were also not correctly calling reset/setup for PCPFLAREINV. Fixed and added a new test --- src/C_PETSc_Routines.c | 2 +- src/PCPFLAREINV.c | 8 ++++++-- tests/Makefile | 2 ++ tests/matrandom_check_reset.F90 | 28 +++++++++++++++++++++------- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/C_PETSc_Routines.c b/src/C_PETSc_Routines.c index d2e55e5..e3cacdf 100644 --- a/src/C_PETSc_Routines.c +++ b/src/C_PETSc_Routines.c @@ -473,7 +473,7 @@ PETSC_INTERN void PCGetSetupCalled_c(PC *pc, PetscInt *setupcalled) // Mark that we need to do setup again (e.g. after a reset) PETSC_INTERN void PCMarkNotSetUp_c(PC *pc) { - (*pc)->setupcalled = 0; + (*pc)->setupcalled = PETSC_FALSE; } // Gets the number of nonzeros in the local diff --git a/src/PCPFLAREINV.c b/src/PCPFLAREINV.c index 8c0b716..b7f3a8e 100644 --- a/src/PCPFLAREINV.c +++ b/src/PCPFLAREINV.c @@ -164,7 +164,8 @@ PetscErrorCode PCPFLAREINVSetOrder(PC pc, PetscInt poly_order) PetscCall(PCPFLAREINVGetOrder(pc, &old_order)); if (old_order == poly_order) PetscFunctionReturn(PETSC_SUCCESS); PetscCall(PCReset_PFLAREINV_c(pc)); - inv_data->poly_order = (int)poly_order; + inv_data->poly_order = (int)poly_order; + pc->setupcalled = PETSC_FALSE; PetscFunctionReturn(PETSC_SUCCESS); } @@ -190,7 +191,8 @@ PetscErrorCode PCPFLAREINVSetSparsityOrder(PC pc, PetscInt inverse_sparsity_orde PetscCall(PCPFLAREINVGetSparsityOrder(pc, &old_order)); if (old_order == inverse_sparsity_order) PetscFunctionReturn(PETSC_SUCCESS); PetscCall(PCReset_PFLAREINV_c(pc)); - inv_data->inverse_sparsity_order = (int)inverse_sparsity_order; + inv_data->inverse_sparsity_order = (int)inverse_sparsity_order; + pc->setupcalled = PETSC_FALSE; PetscFunctionReturn(PETSC_SUCCESS); } @@ -217,6 +219,7 @@ PetscErrorCode PCPFLAREINVSetType(PC pc, PCPFLAREINVType type) if (old_type == type) PetscFunctionReturn(PETSC_SUCCESS); PetscCall(PCReset_PFLAREINV_c(pc)); inv_data->inverse_type = type; + pc->setupcalled = PETSC_FALSE; PetscFunctionReturn(PETSC_SUCCESS); } @@ -244,6 +247,7 @@ static PetscErrorCode PCPFLAREINVSetMatrixFree_PFLAREINV(PC pc, PetscBool flg) if (old_flag == flg) PetscFunctionReturn(PETSC_SUCCESS); PetscCall(PCReset_PFLAREINV_c(pc)); inv_data->matrix_free = flg; + pc->setupcalled = PETSC_FALSE; PetscFunctionReturn(PETSC_SUCCESS); } diff --git a/tests/Makefile b/tests/Makefile index e2777ae..5dd2e45 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -167,6 +167,8 @@ run_tests_no_load_serial: @echo "" @echo "Test AIRG with parameter resets on random diagonally dominant matrix" ./matrandom_check_reset -ksp_max_it 7 + @echo "Test PCPFLAREINV with parameter resets on random diagonally dominant matrix" + ./matrandom_check_reset -ksp_max_it 12 -check_airg 0 @echo "" @echo "Test AIRG with SUPG CG FEM in 2D" ./adv_diff_cg_supg -adv_diff_petscspace_degree 1 -dm_plex_simplex 0 -dm_refine 1 -pc_type air -pc_air_a_drop 1e-3 -pc_air_inverse_type power \ diff --git a/tests/matrandom_check_reset.F90 b/tests/matrandom_check_reset.F90 index 753b317..91e430d 100644 --- a/tests/matrandom_check_reset.F90 +++ b/tests/matrandom_check_reset.F90 @@ -3,7 +3,7 @@ use petscksp implicit none -! Test fortran interface of pflare with small solve of random matrix +! Test changing parameters after a solve triggers a reset PetscErrorCode :: ierr Mat :: A @@ -12,7 +12,7 @@ Vec :: x,b KSP :: ksp PC :: pc - PetscBool :: flg + PetscBool :: flg, check_airg, check KSPConvergedReason reason call PetscInitialize(PETSC_NULL_CHARACTER,ierr) @@ -23,6 +23,10 @@ n = 5 call PetscOptionsGetInt(PETSC_NULL_OPTIONS,PETSC_NULL_CHARACTER,'-m',m,flg,ierr) call PetscOptionsGetInt(PETSC_NULL_OPTIONS,PETSC_NULL_CHARACTER,'-n',n,flg,ierr) + check_airg = PETSC_TRUE + call PetscOptionsGetBool(PETSC_NULL_OPTIONS,PETSC_NULL_CHARACTER, & + '-check_airg', check,flg,ierr) + if (flg) check_airg = check ! Create matrix call MatCreate(PETSC_COMM_WORLD,A,ierr) @@ -46,9 +50,15 @@ call KSPSetOperators(ksp,A,A,ierr) call KSPGetPC(ksp,pc,ierr) ! Set AIRG as pc - call PCSetType(pc, PCAIR, ierr) - ! Set an initial option to test it persists after reset - call PCAIRSetCoarseEqLimit(pc, 9, ierr) + if (check_airg) then + call PCSetType(pc, PCAIR, ierr) + ! Set an initial option to test it persists after reset + call PCAIRSetCoarseEqLimit(pc, 9, ierr) + else + call PCSetType(pc, PCPFLAREINV, ierr) + call PCPFLAREINVSetOrder(pc, 2, ierr) + end if + call KSPSetPC(ksp, pc, ierr) call KSPSetFromOptions(ksp,ierr) call KSPSetUp(ksp,ierr) @@ -61,8 +71,12 @@ end if ! Do a second solve with some changed parameters to test reset - call PCAIRSetMaxLevels(pc, 2, ierr) - call PCAIRSetStrongThreshold(pc, 0.4d0, ierr) + if (check_airg) then + call PCAIRSetMaxLevels(pc, 2, ierr) + call PCAIRSetStrongThreshold(pc, 0.4d0, ierr) + else + call PCPFLAREINVSetMatrixFree(pc, PETSC_TRUE, ierr) + end if call VecSet(x, 0d0, ierr) call KSPSolve(ksp,b,x,ierr) call KSPGetConvergedReason(ksp, reason, ierr) From d18755b5c75955841929daf96fb1a97423cf8947 Mon Sep 17 00:00:00 2001 From: sdargavi Date: Mon, 2 Feb 2026 23:04:07 +0000 Subject: [PATCH 4/4] Fix for 64 bit int in new test --- tests/matrandom_check_reset.F90 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/matrandom_check_reset.F90 b/tests/matrandom_check_reset.F90 index 91e430d..8ee8037 100644 --- a/tests/matrandom_check_reset.F90 +++ b/tests/matrandom_check_reset.F90 @@ -8,7 +8,7 @@ PetscErrorCode :: ierr Mat :: A PetscInt :: m, n, nnzs - PetscInt, parameter :: one = 1, two = 2, three = 3 + PetscInt, parameter :: one = 1, two = 2, three = 3, nine = 9 Vec :: x,b KSP :: ksp PC :: pc @@ -53,10 +53,10 @@ if (check_airg) then call PCSetType(pc, PCAIR, ierr) ! Set an initial option to test it persists after reset - call PCAIRSetCoarseEqLimit(pc, 9, ierr) + call PCAIRSetCoarseEqLimit(pc, nine, ierr) else call PCSetType(pc, PCPFLAREINV, ierr) - call PCPFLAREINVSetOrder(pc, 2, ierr) + call PCPFLAREINVSetOrder(pc, two, ierr) end if call KSPSetPC(ksp, pc, ierr) @@ -72,7 +72,7 @@ ! Do a second solve with some changed parameters to test reset if (check_airg) then - call PCAIRSetMaxLevels(pc, 2, ierr) + call PCAIRSetMaxLevels(pc, two, ierr) call PCAIRSetStrongThreshold(pc, 0.4d0, ierr) else call PCPFLAREINVSetMatrixFree(pc, PETSC_TRUE, ierr)