Skip to content

Commit

Permalink
Maintenance: Add Maybe Unused Macro (#491)
Browse files Browse the repository at this point in the history
Add `SUNDIALS_MAYBE_UNUSED` macro to suppresses warnings on unused
entities.
  • Loading branch information
gardner48 authored May 30, 2024
1 parent b0981b7 commit f7abeaf
Show file tree
Hide file tree
Showing 103 changed files with 715 additions and 354 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ EmptyLineAfterAccessModifier : Never
EmptyLineBeforeAccessModifier : Always
ExperimentalAutoDetectBinPacking : false
FixNamespaceComments : true
IncludeBlocks : Regroup
IncludeBlocks : Preserve
IncludeCategories :
- Regex : '^(<|"(gtest|gmock|isl|json)/)'
Priority : 1
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/macos-latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ jobs:
- uses: actions/checkout@v3

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
# Configure CMake in a 'build' subdirectory.
run: |
cmake \
-B ${{github.workspace}}/build \
-D CMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} \
-D ENABLE_ALL_WARNINGS=ON \
-D ENABLE_WARNINGS_AS_ERRORS=ON
- name: Build
# Build your program with the given configuration
Expand Down
31 changes: 23 additions & 8 deletions .github/workflows/ubuntu-clang-latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ jobs:
fail-fast: false
max-parallel: 2
matrix:
# 2 is what all other builds use (its the default), so skip it here
logging_level: [0, 1, 3, 4, 5]
# Level 2 is also used in other builds (it's the default) but include it
# here to ensure it's tested with all warning flags
logging_level: [0, 1, 2, 3, 4, 5]

steps:
- name: Install LLVM and Clang
Expand All @@ -33,9 +34,16 @@ jobs:
- uses: actions/checkout@v3

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_C_COMPILER=$(which clang) -DCMAKE_CXX_COMPILER=$(which clang++) -DSUNDIALS_LOGGING_LEVEL=${{matrix.logging_level}}
# Configure CMake in a 'build' subdirectory.
run: |
cmake \
-B ${{github.workspace}}/build \
-D CMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} \
-D CMAKE_C_COMPILER=$(which clang) \
-D CMAKE_CXX_COMPILER=$(which clang++) \
-D SUNDIALS_LOGGING_LEVEL=${{matrix.logging_level}} \
-D ENABLE_ALL_WARNINGS=ON \
-D ENABLE_WARNINGS_AS_ERRORS=ON
- name: Build
# Build your program with the given configuration
Expand All @@ -57,9 +65,16 @@ jobs:
- uses: actions/checkout@v3

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_C_COMPILER=$(which clang) -DCMAKE_CXX_COMPILER=$(which clang++) -DSUNDIALS_BUILD_WITH_PROFILING=${{matrix.profiling}}
# Configure CMake in a 'build' subdirectory.
run: |
cmake \
-B ${{github.workspace}}/build \
-D CMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} \
-D CMAKE_C_COMPILER=$(which clang) \
-D CMAKE_CXX_COMPILER=$(which clang++) \
-D SUNDIALS_BUILD_WITH_PROFILING=${{matrix.profiling}} \
-D ENABLE_ALL_WARNINGS=ON \
-D ENABLE_WARNINGS_AS_ERRORS=ON
- name: Build
# Build your program with the given configuration
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ Deprecated the `ARKStepSetOptimalParams` function. Since this function does not
ARKODE-wide equivalent, instructions have been added to the user guide for how
to retain the current functionality using other user-callable functions.

The unsupported implementations of `N_VGetArrayPointer` and `N_VSetArrayPointer`
for the *hypre* and PETSc vectors are now deprecated. Users should access the
underlying wrapped external library vector objects instead with
`N_VGetVector_ParHyp` and `N_VGetVector_Petsc`, respectively.

## Changes to SUNDIALS in release v7.0.0

### Major Feature
Expand Down
6 changes: 6 additions & 0 deletions benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ endif()

sundials_option(BENCHMARK_NVECTOR BOOL "NVector benchmarks are on" ON)

# Disable some warnings for benchmarks
if(ENABLE_ALL_WARNINGS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-parameter")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter")
endif()

#----------------------------------------
# Add specific benchmarks
#----------------------------------------
Expand Down
15 changes: 13 additions & 2 deletions cmake/SundialsSetupCompilers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ if(ENABLE_ALL_WARNINGS)
set(CMAKE_CXX_FLAGS "-Wmissing-declarations -Wcast-qual ${CMAKE_CXX_FLAGS}")
endif()

set(CMAKE_C_FLAGS "-Wall -Wpedantic -Wextra -Wshadow -Wno-unused-parameter -Wno-unused-function ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "-Wall -Wpedantic -Wextra -Wshadow -Wno-unused-parameter -Wno-unused-function ${CMAKE_CXX_FLAGS}")
set(CMAKE_C_FLAGS "-Wall -Wpedantic -Wextra -Wshadow ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "-Wall -Wpedantic -Wextra -Wshadow ${CMAKE_CXX_FLAGS}")

# TODO(DJG): Add -fcheck=all,no-pointer,no-recursion once Jenkins is updated
# to use gfortran > 5.5 which segfaults with -fcheck=array-temps,bounds,do,mem
Expand Down Expand Up @@ -218,6 +218,17 @@ if(NOT (SUNDIALS_C_COMPILER_HAS_ATTRIBUTE_ASSUME OR SUNDIALS_C_COMPILER_HAS_BUIL
" SUNDIALS_C_COMPILER_HAS_ASSUME)
endif()

# ---------------------------------------------------------------
# Check for unused extension
# ---------------------------------------------------------------

check_c_source_compiles("
int main(void) {
__attribute__((unused)) double a = 0.0;
return 0;
}
" SUNDIALS_C_COMPILER_HAS_ATTRIBUTE_UNUSED)

# ---------------------------------------------------------------
# Check for POSIX timers
# ---------------------------------------------------------------
Expand Down
7 changes: 6 additions & 1 deletion doc/shared/RecentChanges.rst
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,9 @@ ARKODE-wide functions.

Deprecated the `ARKStepSetOptimalParams` function. Since this function does not have an
ARKODE-wide equivalent, instructions have been added to the user guide for how
to retain the current functionality using other user-callable functions.
to retain the current functionality using other user-callable functions.

The unsupported implementations of ``N_VGetArrayPointer`` and
``N_VSetArrayPointer`` for the *hypre* and PETSc vectors are now deprecated.
Users should access the underlying wrapped external library vector objects
instead with ``N_VGetVector_ParHyp`` and ``N_VGetVector_Petsc``, respectively.
6 changes: 6 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ foreach(lang ${_SUNDIALS_ENABLED_LANGS})
endif()
endforeach()

# Disable some warnings for examples
if(ENABLE_ALL_WARNINGS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-parameter")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter")
endif()

# Set variables used in generating CMake and Makefiles for examples
if(EXAMPLES_INSTALL)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ int main(int argc, char* argv[])
sunrealtype* data = NULL;
SUNContext sunctx = NULL;

/* Check if a acceleration/dampling values were provided */
if (argc > 1) { maa = (long int)atoi(argv[1]); }
/* Check if a acceleration/damping values were provided */
if (argc > 1) { maa = atoi(argv[1]); }
if (argc > 2) { damping = (sunrealtype)atof(argv[2]); }

/* Print problem description */
Expand Down
6 changes: 2 additions & 4 deletions include/nvector/nvector_parallel.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,8 @@ void N_VPrint_Parallel(N_Vector v);
SUNDIALS_EXPORT
void N_VPrintFile_Parallel(N_Vector v, FILE* outfile);

static inline N_Vector_ID N_VGetVectorID_Parallel(N_Vector v)
{
return SUNDIALS_NVEC_PARALLEL;
}
SUNDIALS_EXPORT
N_Vector_ID N_VGetVectorID_Parallel(N_Vector v);

SUNDIALS_EXPORT
N_Vector N_VCloneEmpty_Parallel(N_Vector w);
Expand Down
8 changes: 6 additions & 2 deletions include/nvector/nvector_parhyp.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ SUNDIALS_EXPORT N_Vector N_VClone_ParHyp(N_Vector w);
SUNDIALS_EXPORT void N_VDestroy_ParHyp(N_Vector v);
SUNDIALS_EXPORT void N_VSpace_ParHyp(N_Vector v, sunindextype* lrw,
sunindextype* liw);
SUNDIALS_EXPORT sunrealtype* N_VGetArrayPointer_ParHyp(N_Vector v);
SUNDIALS_EXPORT void N_VSetArrayPointer_ParHyp(sunrealtype* v_data, N_Vector v);
SUNDIALS_EXPORT MPI_Comm N_VGetCommunicator_ParHyp(N_Vector v);
SUNDIALS_EXPORT sunindextype N_VGetLength_ParHyp(N_Vector v);

Expand Down Expand Up @@ -214,6 +212,12 @@ SUNErrCode N_VEnableLinearCombinationVectorArray_ParHyp(N_Vector v,
SUNDIALS_EXPORT SUNErrCode N_VEnableDotProdMultiLocal_ParHyp(N_Vector v,
sunbooleantype tf);

SUNDIALS_DEPRECATED_EXPORT_MSG("Not supported, use N_VGetVector_ParHyp")
sunrealtype* N_VGetArrayPointer_ParHyp(N_Vector v);

SUNDIALS_DEPRECATED_EXPORT_MSG("Not supported, use N_VGetVector_ParHyp")
void N_VSetArrayPointer_ParHyp(sunrealtype* v_data, N_Vector v);

#ifdef __cplusplus
}
#endif
Expand Down
9 changes: 6 additions & 3 deletions include/nvector/nvector_petsc.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ SUNDIALS_EXPORT N_Vector N_VNewEmpty_Petsc(MPI_Comm comm,

SUNDIALS_EXPORT N_Vector N_VMake_Petsc(Vec v, SUNContext sunctx);

SUNDIALS_EXPORT sunrealtype* N_VGetArrayPointer_Petsc(N_Vector v);

SUNDIALS_EXPORT Vec N_VGetVector_Petsc(N_Vector v);

SUNDIALS_EXPORT void N_VSetVector_Petsc(N_Vector v, Vec p);
Expand All @@ -93,7 +91,6 @@ SUNDIALS_EXPORT N_Vector N_VClone_Petsc(N_Vector w);
SUNDIALS_EXPORT void N_VDestroy_Petsc(N_Vector v);
SUNDIALS_EXPORT void N_VSpace_Petsc(N_Vector v, sunindextype* lrw,
sunindextype* liw);
SUNDIALS_EXPORT void N_VSetArrayPointer_Petsc(sunrealtype* v_data, N_Vector v);
SUNDIALS_EXPORT MPI_Comm N_VGetCommunicator_Petsc(N_Vector v);
SUNDIALS_EXPORT sunindextype N_VGetLength_Petsc(N_Vector v);

Expand Down Expand Up @@ -208,6 +205,12 @@ SUNErrCode N_VEnableLinearCombinationVectorArray_Petsc(N_Vector v,
SUNDIALS_EXPORT SUNErrCode N_VEnableDotProdMultiLocal_Petsc(N_Vector v,
sunbooleantype tf);

SUNDIALS_DEPRECATED_EXPORT_MSG("Not supported, use N_VGetVector_Petsc")
sunrealtype* N_VGetArrayPointer_Petsc(N_Vector v);

SUNDIALS_DEPRECATED_EXPORT_MSG("Not supported, use N_VGetVector_Petsc")
void N_VSetArrayPointer_Petsc(sunrealtype* v_data, N_Vector v);

#ifdef __cplusplus
}
#endif
Expand Down
6 changes: 2 additions & 4 deletions include/nvector/nvector_serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,8 @@ void N_VPrint_Serial(N_Vector v);
SUNDIALS_EXPORT
void N_VPrintFile_Serial(N_Vector v, FILE* outfile);

static inline N_Vector_ID N_VGetVectorID_Serial(N_Vector v)
{
return SUNDIALS_NVEC_SERIAL;
}
SUNDIALS_EXPORT
N_Vector_ID N_VGetVectorID_Serial(N_Vector v);

SUNDIALS_EXPORT
N_Vector N_VCloneEmpty_Serial(N_Vector w);
Expand Down
1 change: 1 addition & 0 deletions include/sundials/sundials_config.in
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#cmakedefine SUNDIALS_C_COMPILER_HAS_ATTRIBUTE_ASSUME
#cmakedefine SUNDIALS_C_COMPILER_HAS_BUILTIN_ASSUME
#cmakedefine SUNDIALS_C_COMPILER_HAS_ASSUME
#cmakedefine SUNDIALS_C_COMPILER_HAS_ATTRIBUTE_UNUSED

/* Define precision of SUNDIALS data type 'sunrealtype'
* Depending on the precision level, one of the following
Expand Down
19 changes: 11 additions & 8 deletions src/arkode/arkode.c
Original file line number Diff line number Diff line change
Expand Up @@ -642,10 +642,13 @@ int ARKodeEvolve(void* arkode_mem, sunrealtype tout, N_Vector yout,
sunrealtype troundoff, nrm;
sunbooleantype inactive_roots;
sunrealtype dsm;
int nflag, attempts, ncf, nef, constrfails;
int nflag, ncf, nef, constrfails;
int relax_fails;
ARKodeMem ark_mem;

/* used only with debugging logging */
SUNDIALS_MAYBE_UNUSED int attempts;

/* Check and process inputs */

/* Check if ark_mem exists */
Expand Down Expand Up @@ -897,7 +900,7 @@ int ARKodeEvolve(void* arkode_mem, sunrealtype tout, N_Vector yout,
- on fatal error, returns negative error flag */
if (ark_mem->relax_enabled && (kflag == ARK_SUCCESS))
{
kflag = arkRelax(ark_mem, &relax_fails, &dsm, &nflag);
kflag = arkRelax(ark_mem, &relax_fails, &dsm);
if (kflag < 0) { break; }
}

Expand Down Expand Up @@ -2751,7 +2754,8 @@ int arkEwtSetSV(N_Vector ycur, N_Vector weight, void* arkode_mem)
a fixed step size to avoid a potential too much error return
to the user.
---------------------------------------------------------------*/
int arkEwtSetSmallReal(N_Vector ycur, N_Vector weight, void* arkode_mem)
int arkEwtSetSmallReal(SUNDIALS_MAYBE_UNUSED N_Vector ycur, N_Vector weight,
SUNDIALS_MAYBE_UNUSED void* arkode_mem)
{
N_VConst(SUN_SMALL_REAL, weight);
return (ARK_SUCCESS);
Expand Down Expand Up @@ -2804,7 +2808,9 @@ int arkRwtSetSV(ARKodeMem ark_mem, N_Vector My, N_Vector weight)
/*---------------------------------------------------------------
arkExpStab is the default explicit stability estimation function
---------------------------------------------------------------*/
int arkExpStab(N_Vector y, sunrealtype t, sunrealtype* hstab, void* data)
int arkExpStab(SUNDIALS_MAYBE_UNUSED N_Vector y,
SUNDIALS_MAYBE_UNUSED sunrealtype t, sunrealtype* hstab,
SUNDIALS_MAYBE_UNUSED void* data)
{
/* explicit stability not used by default,
set to zero to disable */
Expand Down Expand Up @@ -3106,7 +3112,6 @@ int arkCheckTemporalError(ARKodeMem ark_mem, int* nflagPtr, int* nefPtr,
{
int retval;
sunrealtype ttmp;
long int nsttmp;
ARKodeHAdaptMem hadapt_mem;

/* Access hadapt_mem structure */
Expand All @@ -3121,9 +3126,7 @@ int arkCheckTemporalError(ARKodeMem ark_mem, int* nflagPtr, int* nefPtr,
/* consider change of step size for next step attempt (may be
larger/smaller than current step, depending on dsm) */
ttmp = (dsm <= ONE) ? ark_mem->tn + ark_mem->h : ark_mem->tn;
nsttmp = (dsm <= ONE) ? ark_mem->nst + 1 : ark_mem->nst;
retval = arkAdapt(ark_mem, hadapt_mem, ark_mem->ycur, ttmp, ark_mem->h, dsm,
nsttmp);
retval = arkAdapt(ark_mem, hadapt_mem, ark_mem->ycur, ttmp, ark_mem->h, dsm);
if (retval != ARK_SUCCESS) { return (ARK_ERR_FAILURE); }

/* if we've made it here then no nonrecoverable failures occurred; someone above
Expand Down
2 changes: 1 addition & 1 deletion src/arkode/arkode_adapt.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void arkPrintAdaptMem(ARKodeHAdaptMem hadapt_mem, FILE* outfile)
data structure.
---------------------------------------------------------------*/
int arkAdapt(ARKodeMem ark_mem, ARKodeHAdaptMem hadapt_mem, N_Vector ycur,
sunrealtype tcur, sunrealtype hcur, sunrealtype dsm, long int nst)
sunrealtype tcur, sunrealtype hcur, sunrealtype dsm)
{
int retval;
sunrealtype h_acc, h_cfl, int_dir;
Expand Down
2 changes: 1 addition & 1 deletion src/arkode/arkode_adapt_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ typedef struct ARKodeHAdaptMemRec
ARKodeHAdaptMem arkAdaptInit(void);
void arkPrintAdaptMem(ARKodeHAdaptMem hadapt_mem, FILE* outfile);
int arkAdapt(ARKodeMem ark_mem, ARKodeHAdaptMem hadapt_mem, N_Vector ycur,
sunrealtype tcur, sunrealtype hcur, sunrealtype dsm, long int nst);
sunrealtype tcur, sunrealtype hcur, sunrealtype dsm);

#ifdef __cplusplus
}
Expand Down
9 changes: 6 additions & 3 deletions src/arkode/arkode_arkstep.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,10 @@ int ARKStepCreateMRIStepInnerStepper(void* inner_arkode_mem,
This routine resizes the memory within the ARKStep module.
---------------------------------------------------------------*/
int arkStep_Resize(ARKodeMem ark_mem, N_Vector y0, sunrealtype hscale,
sunrealtype t0, ARKVecResizeFn resize, void* resize_data)
int arkStep_Resize(ARKodeMem ark_mem, N_Vector y0,
SUNDIALS_MAYBE_UNUSED sunrealtype hscale,
SUNDIALS_MAYBE_UNUSED sunrealtype t0, ARKVecResizeFn resize,
void* resize_data)
{
ARKodeARKStepMem step_mem;
SUNNonlinearSolver NLS;
Expand Down Expand Up @@ -3089,7 +3091,8 @@ int arkStep_ComputeSolutions_MassFixed(ARKodeMem ark_mem, sunrealtype* dsmPtr)
ODE IVP.
----------------------------------------------------------------------------*/

int arkStep_MRIStepInnerEvolve(MRIStepInnerStepper stepper, sunrealtype t0,
int arkStep_MRIStepInnerEvolve(MRIStepInnerStepper stepper,
SUNDIALS_MAYBE_UNUSED sunrealtype t0,
sunrealtype tout, N_Vector y)
{
void* arkode_mem; /* arkode memory */
Expand Down
3 changes: 2 additions & 1 deletion src/arkode/arkode_arkstep_nls.c
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,8 @@ int arkStep_NlsFPFunction_MassTDep(N_Vector zcor, N_Vector g, void* arkode_mem)
implicit, then we just declare 'success' no matter what
is provided.
---------------------------------------------------------------*/
int arkStep_NlsConvTest(SUNNonlinearSolver NLS, N_Vector y, N_Vector del,
int arkStep_NlsConvTest(SUNNonlinearSolver NLS,
SUNDIALS_MAYBE_UNUSED N_Vector y, N_Vector del,
sunrealtype tol, N_Vector ewt, void* arkode_mem)
{
/* temporary variables */
Expand Down
9 changes: 6 additions & 3 deletions src/arkode/arkode_bandpre.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,12 @@ static int ARKBandPrecSetup(sunrealtype t, N_Vector y, N_Vector fy,
The value returned by the ARKBandPrecSolve function is always 0,
indicating success.
---------------------------------------------------------------*/
static int ARKBandPrecSolve(sunrealtype t, N_Vector y, N_Vector fy, N_Vector r,
N_Vector z, sunrealtype gamma, sunrealtype delta,
int lr, void* bp_data)
static int ARKBandPrecSolve(SUNDIALS_MAYBE_UNUSED sunrealtype t,
SUNDIALS_MAYBE_UNUSED N_Vector y,
SUNDIALS_MAYBE_UNUSED N_Vector fy, N_Vector r,
N_Vector z, SUNDIALS_MAYBE_UNUSED sunrealtype gamma,
SUNDIALS_MAYBE_UNUSED sunrealtype delta,
SUNDIALS_MAYBE_UNUSED int lr, void* bp_data)
{
ARKBandPrecData pdata;
int retval;
Expand Down
Loading

0 comments on commit f7abeaf

Please sign in to comment.