Commit 9566063d authored by Jacob Faibussowitsch's avatar Jacob Faibussowitsch
Browse files

The great renaming:

- CHKERRQ() -> PetscCall()
- CHKERRV() -> PetscCallVoid()
- CHKERRMPI() -> PetscCallMPI()
- CHKERRABORT() -> PetscCallAbort()
- CHKERRCONTINUE() -> PetscCallContinue()
- CHKERRXX() -> PetscCallThrow()
- CHKERRCXX() -> PetscCallCXX()
- CHKERRCUDA() -> PetscCallCUDA()
- CHKERRCUBLAS() -> PetscCallCUBLAS()
- CHKERRCUSPARSE() -> PetscCallCUSPARSE()
- CHKERRCUSOLVER() -> PetscCallCUSOLVER()
- CHKERRCUFFT() -> PetscCallCUFFT()
- CHKERRCURAND() -> PetscCallCURAND()
- CHKERRHIP() -> PetscCallHIP()
- CHKERRHIPBLAS() -> PetscCallHIPBLAS()
- CHKERRHIPSOLVER() -> PetscCallHIPSOLVER()
- CHKERRQ_CEED() -> PetscCallCEED()
- CHKERR_FORTRAN_VOID_FUNCTION() -> PetscCallFortranVoidFunction()
- CHKERRMKL() -> PetscCallMKL()
- CHKERRMMG() -> PetscCallMMG()
- CHKERRMMG_NONSTANDARD() -> PetscCallMMG_NONSTANDARD()
- CHKERRCGNS() -> PetscCallCGNS()
- CHKERRPTSCOTCH() -> PetscCallPTSCOTCH()
- CHKERRSTR() -> PetscCallSTR()
- CHKERRTC() -> PetscCallTC()
parent b122ec5a
......@@ -274,7 +274,7 @@ class Configure(config.base.Configure):
def checkWorkingLink(self):
'''Checking that we can link a PETSc executable'''
self.pushLanguage(self.languages.clanguage)
if not self.checkPETScLink('#include <petsctime.h>\n', 'PetscLogDouble time;\nPetscErrorCode ierr;\n\nierr = PetscTime(&time);CHKERRQ(ierr);\n'):
if not self.checkPETScLink('#include <petsctime.h>\n', 'PetscLogDouble time;\n\nPetscCall(PetscTime(&time));\n'):
self.logPrint('PETSc cannot link, which indicates a problem with the PETSc installation')
return 0
self.logPrint('PETSc can link with '+self.languages.clanguage)
......@@ -283,7 +283,7 @@ class Configure(config.base.Configure):
if hasattr(self.compilers, 'CXX') and self.languages.clanguage == 'C':
self.pushLanguage('C++')
self.sourceExtension = '.C'
if not self.checkPETScLink('#include <petsctime.h>\n', 'PetscLogDouble time;\nPetscErrorCode ierr;\n\nierr = PetscTime(&time);CHKERRQ(ierr);\n'):
if not self.checkPETScLink('#include <petsctime.h>\n', 'PetscLogDouble time;\n\nPetscCall(PetscTime(&time));\n'):
self.logPrint('PETSc cannot link C++ but can link C, which indicates a problem with the PETSc installation')
self.popLanguage()
return 0
......
......@@ -65,7 +65,11 @@ Changes: Development
- Change ``SETERRABORT()`` to be variadic
- Add ``PetscCheck()`` and ``PetscAssert()`` for checking a boolean condition is true. The former is always enabled, while the latter is enabled only in debug builds.
- ``PetscDevice`` initialization for CUDA and HIP will now respect ``CUDA_VISIBILE_DEVICES`` and ``HIP_VISIBLE_DEVICES`` environment variables respectively
- Add ``PetscCall()``, ``PetscCallVoid()``, ``PetscCallMPI()``, ``PetscCallAbort()``, ``PetscCallContinue()``, ``PetscCallThrow()``, and ``PetscCallCXX()``. These supersede ``CHKERRQ()``, ``CHKERRV()``, ``CHKERRMPI()``, ``CHKERRABORT()``, ``CHKERRCONTINUE()``, ``CHKERRXX()``, and ``CHKERRCXX()`` respectively
- Add ``PetscCallCUDA()``, ``PetscCallCUBLAS()``, ``PetscCallCUSPARSE()``, ``PetscCallCUSOLVER()``, ``PetscCallCUFFT()``, and ``PetscCallCURAND()``. These supersede ``CHKERRCUDA()``, ``CHKERRCUBLAS()``, ``CHKERRCUSPARSE()``, ``CHKERRCUSOLVER()``, ``CHKERRCUFFT()``, and ``CHKERRCURAND()`` respectively
- Add ``PetscCallHIP()``, ``PetscCallHIPBLAS()``, and ``PetscCallHIPSOLVER()``. These supersede ``CHKERRHIP()``, ``CHKERRHIPBLAS()``, and ``CHKERRHIPSOLVER()`` respectively
- Add ``PetscCallCEED()`` which supersedes ``CHKERRQ_CEED()``
- Soft-deprecate ``CHKERR`` variants listed above. New code should prefer the ``PetscCall`` variants, but no compiler diagnostics will be emitted if the old versions are used
.. rubric:: PetscViewer:
......
......@@ -80,7 +80,7 @@ We next create a label marking each cell in the mesh with an action, such as `DM
.. literalinclude:: /../src/dm/impls/plex/tutorials/ex10.c
:start-at: while (adapt) {
:end-at: CHKERRQ(DMLabelDestroy(&adaptLabel));
:end-at: PetscCall(DMLabelDestroy(&adaptLabel));
:append: }
Test 3 from `ex10` constrains the headwater cells (with marker 1) to have volume less than 0.01, and the river channel cells (with marker 2) to be smaller than 0.000625
......
......@@ -97,8 +97,8 @@ which is implemented in our ``f0_quadratic_u`` pointwise function
We let PETSc know about these solutions
.. literalinclude:: /../src/snes/tutorials/ex62.c
:start-at: CHKERRQ(PetscDSSetExactSolution(ds, 0
:end-at: CHKERRQ(PetscDSSetExactSolution(ds, 1
:start-at: PetscCall(PetscDSSetExactSolution(ds, 0
:end-at: PetscCall(PetscDSSetExactSolution(ds, 1
These solutions will be captured exactly by the :math:`P_2-P_1` finite element space. We can use the ``-dmsnes_check`` option to activate function space checks. It gives the :math:`L_2` error, or *discretization* error, of the exact solution, the residual computed using the interpolation of the exact solution into our finite element space, and uses a Taylor test to check that our Jacobian matches the residual. It should converge at order 2, or be exact in the case of linear equations like Stokes. Our :math:`P_2-P_1` runs in the PETSc test section at the bottom of the source file
......@@ -168,8 +168,8 @@ We can now use ``-snes_convergence_estimate`` to determine the convergence expon
However, the test needs an accurate linear solver. Sparse LU factorizations do not, in general, do full pivoting. Thus we must deal with the zero pressure block explicitly. We use the ``PCFIELDSPLIT`` preconditioner and the full Schur complement factorization, but we still need a preconditioner for the Schur complement :math:`B^T A^{-1} B`. We can have PETSc construct that matrix automatically, but the cost rises steeply as the problem size increases. Instead, we use the fact that the Schur complement is spectrally equivalent to the pressure mass matrix :math:`M_p`. We can make a preconditioning matrix, which has the diagonal blocks we will use to build the preconditioners, letting PETSc know that we get the off-diagonal blocks from the original system with ``-pc_fieldsplit_off_diag_use_amat`` and to build the Schur complement from the original matrix using ``-pc_use_amat``,
.. literalinclude:: /../src/snes/tutorials/ex62.c
:start-at: CHKERRQ(PetscDSSetJacobianPreconditioner(ds, 0
:end-at: CHKERRQ(PetscDSSetJacobianPreconditioner(ds, 1
:start-at: PetscCall(PetscDSSetJacobianPreconditioner(ds, 0
:end-at: PetscCall(PetscDSSetJacobianPreconditioner(ds, 1
Putting this all together, and using exact solvers on the subblocks, we have
......
......@@ -170,9 +170,9 @@
#define SETERRQ(c,ierr,s) call PetscError(c,ierr,0,s); return
#define SETERRA(c,ierr,s) call PetscError(c,ierr,0,s); call MPIU_Abort(c,ierr)
#define SETERRABORT(c,ierr,s) call PetscError(c,ierr,0,s); call MPI_Abort(c,ierr)
#define CHKERRQ(ierr) if (ierr .ne. 0) then;call PetscErrorF(ierr);return;endif
#define PetscCall(ierr) if (ierr .ne. 0) then;call PetscErrorF(ierr);return;endif
#define CHKERRA(ierr) if (ierr .ne. 0) then;call PetscErrorF(ierr);call MPIU_Abort(PETSC_COMM_SELF,ierr);endif
#define CHKERRABORT(c,ierr) if (ierr .ne. 0) then;call PetscErrorF(ierr);call MPI_Abort(c,ierr);endif
#define PetscCallAbort(c,ierr) if (ierr .ne. 0) then;call PetscErrorF(ierr);call MPI_Abort(c,ierr);endif
#define CHKMEMQ call chkmemfortran(__LINE__,__FILE__,ierr)
#define PetscMatlabEngine PetscFortranAddr
......
......@@ -25,7 +25,7 @@ namespace CUPM
namespace Impl
{
#define CHKERRCUPMBLAS(...) do { \
#define PetscCallCUPMBLAS(...) do { \
const cupmBlasError_t cberr_p_ = __VA_ARGS__; \
if (PetscUnlikely(cberr_p_ != CUPMBLAS_STATUS_SUCCESS)) { \
if (((cberr_p_ == CUPMBLAS_STATUS_NOT_INITIALIZED) || \
......@@ -329,9 +329,9 @@ struct BlasInterface<DeviceType::CUDA> : BlasInterfaceBase<DeviceType::CUDA>
for (auto i = 0; i < 3; ++i) {
const auto cerr = cusolverDnCreate(&handle);
if (PetscLikely(cerr == CUSOLVER_STATUS_SUCCESS)) break;
if ((cerr != CUSOLVER_STATUS_NOT_INITIALIZED) && (cerr != CUSOLVER_STATUS_ALLOC_FAILED)) CHKERRCUSOLVER(cerr);
if ((cerr != CUSOLVER_STATUS_NOT_INITIALIZED) && (cerr != CUSOLVER_STATUS_ALLOC_FAILED)) PetscCallCUSOLVER(cerr);
if (i < 2) {
CHKERRQ(PetscSleep(3));
PetscCall(PetscSleep(3));
continue;
}
PetscCheck(cerr == CUSOLVER_STATUS_SUCCESS,PETSC_COMM_SELF,PETSC_ERR_GPU_RESOURCE,"Unable to initialize cuSolverDn");
......@@ -344,8 +344,8 @@ struct BlasInterface<DeviceType::CUDA> : BlasInterfaceBase<DeviceType::CUDA>
cupmStream_t cupmStream;
PetscFunctionBegin;
CHKERRCUSOLVER(cusolverDnGetStream(handle,&cupmStream));
if (cupmStream != stream) CHKERRCUSOLVER(cusolverDnSetStream(handle,stream));
PetscCallCUSOLVER(cusolverDnGetStream(handle,&cupmStream));
if (cupmStream != stream) PetscCallCUSOLVER(cusolverDnSetStream(handle,stream));
PetscFunctionReturn(0);
}
......@@ -353,7 +353,7 @@ struct BlasInterface<DeviceType::CUDA> : BlasInterfaceBase<DeviceType::CUDA>
{
PetscFunctionBegin;
if (handle) {
CHKERRCUSOLVER(cusolverDnDestroy(handle));
PetscCallCUSOLVER(cusolverDnDestroy(handle));
handle = nullptr;
}
PetscFunctionReturn(0);
......@@ -417,7 +417,7 @@ struct BlasInterface<DeviceType::HIP> : BlasInterfaceBase<DeviceType::HIP>
PETSC_CXX_COMPAT_DECL(PetscErrorCode InitializeHandle(cupmSolverHandle_t &handle))
{
PetscFunctionBegin;
if (!handle) CHKERRHIPSOLVER(hipsolverCreate(&handle));
if (!handle) PetscCallHIPSOLVER(hipsolverCreate(&handle));
PetscFunctionReturn(0);
}
......@@ -426,8 +426,8 @@ struct BlasInterface<DeviceType::HIP> : BlasInterfaceBase<DeviceType::HIP>
cupmStream_t cupmStream;
PetscFunctionBegin;
CHKERRHIPSOLVER(hipsolverGetStream(handle,&cupmStream));
if (cupmStream != stream) CHKERRHIPSOLVER(hipsolverSetStream(handle,stream));
PetscCallHIPSOLVER(hipsolverGetStream(handle,&cupmStream));
if (cupmStream != stream) PetscCallHIPSOLVER(hipsolverSetStream(handle,stream));
PetscFunctionReturn(0);
}
......@@ -435,7 +435,7 @@ struct BlasInterface<DeviceType::HIP> : BlasInterfaceBase<DeviceType::HIP>
{
PetscFunctionBegin;
if (handle) {
CHKERRHIPSOLVER(hipsolverDestroy(handle));
PetscCallHIPSOLVER(hipsolverDestroy(handle));
handle = nullptr;
}
PetscFunctionReturn(0);
......
......@@ -52,20 +52,12 @@ static constexpr std::array<const char*const,5> DeviceTypes = {
namespace Impl
{
// A backend agnostic CHKERRCUPM() function, this will only work inside the member
// functions of a class inheriting from CUPM::Interface. Can use it in the usual trailing
// CHKERRQ() form:
// A backend agnostic PetscCallCUPM() function, this will only work inside the member
// functions of a class inheriting from CUPM::Interface. Thanks to __VA_ARGS__ templated
// functions can also be wrapped inline:
//
// CHKERRCUPM(foo());
//
// or wrap it around the function:
//
// CHKERRCUPOBM(foo());
//
// thanks to __VA_ARGS__ templated functions can also be wrapped inline:
//
// CHKERRCUPM(foo<int,char,bool>());
#define CHKERRCUPM(...) do { \
// PetscCallCUPM(foo<int,char,bool>());
#define PetscCallCUPM(...) do { \
const cupmError_t cerr_p_ = __VA_ARGS__; \
if (PetscUnlikely(cerr_p_ != cupmSuccess)) { \
SETERRQ(PETSC_COMM_SELF,PETSC_ERR_GPU,"%s error %d (%s) : %s", \
......
......@@ -234,8 +234,8 @@ static inline PetscErrorCode PetscDeviceContextSetDefaultDeviceForType_Internal(
PetscDevice device;
PetscFunctionBegin;
CHKERRQ(PetscDeviceGetDefaultForType_Internal(type,&device));
CHKERRQ(PetscDeviceContextSetDevice(dctx,device));
PetscCall(PetscDeviceGetDefaultForType_Internal(type,&device));
PetscCall(PetscDeviceContextSetDevice(dctx,device));
PetscFunctionReturn(0);
}
......@@ -248,7 +248,7 @@ static inline PetscErrorCode PetscDeviceContextGetCurrentContextAssertType_Inter
PetscFunctionBegin;
PetscValidPointer(dctx,1);
PetscValidDeviceType(type,2);
CHKERRQ(PetscDeviceContextGetCurrentContext(dctx));
PetscCall(PetscDeviceContextGetCurrentContext(dctx));
PetscAssert((*dctx)->device->type == type,PETSC_COMM_SELF,PETSC_ERR_PLIB,"Expected current global PetscDeviceContext (id %" PetscInt_FMT ") to have PetscDeviceType '%s' but has '%s' instead",(*dctx)->id,PetscDeviceTypes[type],PetscDeviceTypes[(*dctx)->device->type]);
PetscFunctionReturn(0);
}
......@@ -259,7 +259,7 @@ static inline PetscErrorCode PetscDeviceContextGetBLASHandle_Internal(PetscDevic
/* we do error checking here as this routine is an entry-point */
PetscValidDeviceContext(dctx,1);
PetscValidPointer(handle,2);
CHKERRQ((*dctx->ops->getblashandle)(dctx,handle));
PetscCall((*dctx->ops->getblashandle)(dctx,handle));
PetscFunctionReturn(0);
}
......@@ -269,7 +269,7 @@ static inline PetscErrorCode PetscDeviceContextGetSOLVERHandle_Internal(PetscDev
/* we do error checking here as this routine is an entry-point */
PetscValidDeviceContext(dctx,1);
PetscValidPointer(handle,2);
CHKERRQ((*dctx->ops->getsolverhandle)(dctx,handle));
PetscCall((*dctx->ops->getsolverhandle)(dctx,handle));
PetscFunctionReturn(0);
}
......@@ -279,7 +279,7 @@ static inline PetscErrorCode PetscDeviceContextGetStreamHandle_Internal(PetscDev
/* we do error checking here as this routine is an entry-point */
PetscValidDeviceContext(dctx,1);
PetscValidPointer(handle,2);
CHKERRQ((*dctx->ops->getstreamhandle)(dctx,handle));
PetscCall((*dctx->ops->getstreamhandle)(dctx,handle));
PetscFunctionReturn(0);
}
......@@ -288,7 +288,7 @@ static inline PetscErrorCode PetscDeviceContextBeginTimer_Internal(PetscDeviceCo
PetscFunctionBegin;
/* we do error checking here as this routine is an entry-point */
PetscValidDeviceContext(dctx,1);
CHKERRQ((*dctx->ops->begintimer)(dctx));
PetscCall((*dctx->ops->begintimer)(dctx));
PetscFunctionReturn(0);
}
......@@ -298,7 +298,7 @@ static inline PetscErrorCode PetscDeviceContextEndTimer_Internal(PetscDeviceCont
/* we do error checking here as this routine is an entry-point */
PetscValidDeviceContext(dctx,1);
PetscValidRealPointer(elapsed,2);
CHKERRQ((*dctx->ops->endtimer)(dctx,elapsed));
PetscCall((*dctx->ops->endtimer)(dctx,elapsed));
PetscFunctionReturn(0);
}
#else /* PETSC_HAVE_CXX for PetscDeviceContext Internal Functions */
......
......@@ -400,8 +400,8 @@ static inline PetscErrorCode DMGetLocalOffset_Private(DM dm, PetscInt point, Pet
*start = *end = 0; /* Silence overzealous compiler warning */
PetscCheck(dm->localSection,PetscObjectComm((PetscObject) dm), PETSC_ERR_ARG_WRONG, "DM must have a local section, see DMSetLocalSection()");
CHKERRQ(PetscSectionGetOffset(dm->localSection, point, start));
CHKERRQ(PetscSectionGetDof(dm->localSection, point, &dof));
PetscCall(PetscSectionGetOffset(dm->localSection, point, start));
PetscCall(PetscSectionGetDof(dm->localSection, point, &dof));
*end = *start + dof;
}
#else
......@@ -422,8 +422,8 @@ static inline PetscErrorCode DMGetLocalFieldOffset_Private(DM dm, PetscInt point
PetscInt dof;
*start = *end = 0; /* Silence overzealous compiler warning */
PetscCheck(dm->localSection,PetscObjectComm((PetscObject) dm), PETSC_ERR_ARG_WRONG, "DM must have a local section, see DMSetLocalSection()");
CHKERRQ(PetscSectionGetFieldOffset(dm->localSection, point, field, start));
CHKERRQ(PetscSectionGetFieldDof(dm->localSection, point, field, &dof));
PetscCall(PetscSectionGetFieldOffset(dm->localSection, point, field, start));
PetscCall(PetscSectionGetFieldDof(dm->localSection, point, field, &dof));
*end = *start + dof;
}
#else
......@@ -445,9 +445,9 @@ static inline PetscErrorCode DMGetGlobalOffset_Private(DM dm, PetscInt point, Pe
*start = *end = 0; /* Silence overzealous compiler warning */
PetscCheck(dm->localSection,PetscObjectComm((PetscObject) dm), PETSC_ERR_ARG_WRONG, "DM must have a local section, see DMSetLocalSection()");
PetscCheck(dm->globalSection,PetscObjectComm((PetscObject) dm), PETSC_ERR_ARG_WRONG, "DM must have a global section. It will be created automatically by DMGetGlobalSection()");
CHKERRQ(PetscSectionGetOffset(dm->globalSection, point, start));
CHKERRQ(PetscSectionGetDof(dm->globalSection, point, &dof));
CHKERRQ(PetscSectionGetConstraintDof(dm->globalSection, point, &cdof));
PetscCall(PetscSectionGetOffset(dm->globalSection, point, start));
PetscCall(PetscSectionGetDof(dm->globalSection, point, &dof));
PetscCall(PetscSectionGetConstraintDof(dm->globalSection, point, &cdof));
*end = *start + dof - cdof + (dof < 0 ? 1 : 0);
}
#else
......@@ -471,14 +471,14 @@ static inline PetscErrorCode DMGetGlobalFieldOffset_Private(DM dm, PetscInt poin
*start = *end = 0; /* Silence overzealous compiler warning */
PetscCheck(dm->localSection,PetscObjectComm((PetscObject) dm), PETSC_ERR_ARG_WRONG, "DM must have a local section, see DMSetLocalSection()");
PetscCheck(dm->globalSection,PetscObjectComm((PetscObject) dm), PETSC_ERR_ARG_WRONG, "DM must have a global section. It will be crated automatically by DMGetGlobalSection()");
CHKERRQ(PetscSectionGetOffset(dm->globalSection, point, start));
CHKERRQ(PetscSectionGetOffset(dm->localSection, point, &loff));
CHKERRQ(PetscSectionGetFieldOffset(dm->localSection, point, field, &lfoff));
CHKERRQ(PetscSectionGetFieldDof(dm->localSection, point, field, &fdof));
CHKERRQ(PetscSectionGetFieldConstraintDof(dm->localSection, point, field, &fcdof));
PetscCall(PetscSectionGetOffset(dm->globalSection, point, start));
PetscCall(PetscSectionGetOffset(dm->localSection, point, &loff));
PetscCall(PetscSectionGetFieldOffset(dm->localSection, point, field, &lfoff));
PetscCall(PetscSectionGetFieldDof(dm->localSection, point, field, &fdof));
PetscCall(PetscSectionGetFieldConstraintDof(dm->localSection, point, field, &fcdof));
*start = *start < 0 ? *start - (lfoff-loff) : *start + lfoff-loff;
for (f = 0; f < field; ++f) {
CHKERRQ(PetscSectionGetFieldConstraintDof(dm->localSection, point, f, &ffcdof));
PetscCall(PetscSectionGetFieldConstraintDof(dm->localSection, point, f, &ffcdof));
*start = *start < 0 ? *start + ffcdof : *start - ffcdof;
}
*end = *start < 0 ? *start - (fdof-fcdof) : *start + fdof-fcdof;
......
......@@ -205,19 +205,19 @@ typedef PETSC_UINTPTR_T PetscFortranAddr;
} \
} while (0)
#define CHKERR_FORTRAN_VOID_FUNCTION(...) do { \
#define PetscCallFortranVoidFunction(...) do { \
PetscErrorCode ierr = 0; \
/* the function may or may not access ierr */ \
__VA_ARGS__; \
CHKERRQ(ierr); \
PetscCall(ierr); \
} while (0)
/* Entire function body, _ctx is a "special" variable that can be passed along */
#define PetscObjectUseFortranCallback_Private(obj,cid,types,args,cbclass) { \
void (*func) types,*_ctx; \
PetscFunctionBegin; \
CHKERRQ(PetscObjectGetFortranCallback((PetscObject)(obj),(cbclass),(cid),(PetscVoidFunction*)&func,&_ctx)); \
if (func) CHKERR_FORTRAN_VOID_FUNCTION((*func)args); \
PetscCall(PetscObjectGetFortranCallback((PetscObject)(obj),(cbclass),(cid),(PetscVoidFunction*)&func,&_ctx)); \
if (func) PetscCallFortranVoidFunction((*func)args); \
PetscFunctionReturn(0); \
}
#define PetscObjectUseFortranCallback(obj,cid,types,args) PetscObjectUseFortranCallback_Private(obj,cid,types,args,PETSC_FORTRAN_CALLBACK_CLASS)
......
......@@ -130,8 +130,8 @@ PETSC_EXTERN PetscErrorCode PetscKernel_A_gets_inverse_A_15(MatScalar*,PetscInt*
#define PetscKernel_A_gets_A_times_B(bs,A,B,W) do { \
PetscBLASInt _bbs; \
PetscScalar _one = 1.0,_zero = 0.0; \
CHKERRQ(PetscBLASIntCast(bs,&_bbs)); \
CHKERRQ(PetscArraycpy((W),(A),(bs)*(bs))); \
PetscCall(PetscBLASIntCast(bs,&_bbs)); \
PetscCall(PetscArraycpy((W),(A),(bs)*(bs))); \
PetscDisableStaticAnalyzerForExpressionUnderstandingThatThisIsDangerousAndBugprone(PetscValidScalarPointer(A,2)); \
PetscDisableStaticAnalyzerForExpressionUnderstandingThatThisIsDangerousAndBugprone(PetscValidScalarPointer(B,3)); \
PetscDisableStaticAnalyzerForExpressionUnderstandingThatThisIsDangerousAndBugprone(PetscValidScalarPointer(W,4)); \
......@@ -147,7 +147,7 @@ PETSC_EXTERN PetscErrorCode PetscKernel_A_gets_inverse_A_15(MatScalar*,PetscInt*
#define PetscKernel_A_gets_A_minus_B_times_C(bs,A,B,C) do { \
PetscScalar _mone = -1.0,_one = 1.0; \
PetscBLASInt _bbs; \
CHKERRQ(PetscBLASIntCast(bs,&_bbs)); \
PetscCall(PetscBLASIntCast(bs,&_bbs)); \
PetscDisableStaticAnalyzerForExpressionUnderstandingThatThisIsDangerousAndBugprone(PetscValidScalarPointer(A,2)); \
PetscDisableStaticAnalyzerForExpressionUnderstandingThatThisIsDangerousAndBugprone(PetscValidScalarPointer(B,3)); \
PetscDisableStaticAnalyzerForExpressionUnderstandingThatThisIsDangerousAndBugprone(PetscValidScalarPointer(C,4)); \
......@@ -163,7 +163,7 @@ PETSC_EXTERN PetscErrorCode PetscKernel_A_gets_inverse_A_15(MatScalar*,PetscInt*
#define PetscKernel_A_gets_A_plus_Btranspose_times_C(bs,A,B,C) do { \
PetscScalar _one = 1.0; \
PetscBLASInt _bbs; \
CHKERRQ(PetscBLASIntCast(bs,&_bbs)); \
PetscCall(PetscBLASIntCast(bs,&_bbs)); \
PetscDisableStaticAnalyzerForExpressionUnderstandingThatThisIsDangerousAndBugprone(PetscValidScalarPointer(A,2)); \
PetscDisableStaticAnalyzerForExpressionUnderstandingThatThisIsDangerousAndBugprone(PetscValidScalarPointer(B,3)); \
PetscDisableStaticAnalyzerForExpressionUnderstandingThatThisIsDangerousAndBugprone(PetscValidScalarPointer(C,4)); \
......@@ -180,7 +180,7 @@ PETSC_EXTERN PetscErrorCode PetscKernel_A_gets_inverse_A_15(MatScalar*,PetscInt*
#define PetscKernel_v_gets_v_plus_Atranspose_times_w(bs,v,A,w) do { \
PetscScalar _one = 1.0; \
PetscBLASInt _ione = 1, _bbs; \
CHKERRQ(PetscBLASIntCast(bs,&_bbs)); \
PetscCall(PetscBLASIntCast(bs,&_bbs)); \
PetscDisableStaticAnalyzerForExpressionUnderstandingThatThisIsDangerousAndBugprone(PetscValidScalarPointer(v,2)); \
PetscDisableStaticAnalyzerForExpressionUnderstandingThatThisIsDangerousAndBugprone(PetscValidScalarPointer(A,3)); \
PetscDisableStaticAnalyzerForExpressionUnderstandingThatThisIsDangerousAndBugprone(PetscValidScalarPointer(w,4)); \
......@@ -197,7 +197,7 @@ PETSC_EXTERN PetscErrorCode PetscKernel_A_gets_inverse_A_15(MatScalar*,PetscInt*
#define PetscKernel_v_gets_v_minus_A_times_w(bs,v,A,w) do { \
PetscScalar _mone = -1.0,_one = 1.0; \
PetscBLASInt _ione = 1,_bbs; \
CHKERRQ(PetscBLASIntCast(bs,&_bbs)); \
PetscCall(PetscBLASIntCast(bs,&_bbs)); \
PetscDisableStaticAnalyzerForExpressionUnderstandingThatThisIsDangerousAndBugprone(PetscValidScalarPointer(v,2)); \
PetscDisableStaticAnalyzerForExpressionUnderstandingThatThisIsDangerousAndBugprone(PetscValidScalarPointer(A,3)); \
PetscDisableStaticAnalyzerForExpressionUnderstandingThatThisIsDangerousAndBugprone(PetscValidScalarPointer(w,4)); \
......@@ -214,7 +214,7 @@ PETSC_EXTERN PetscErrorCode PetscKernel_A_gets_inverse_A_15(MatScalar*,PetscInt*
#define PetscKernel_v_gets_v_minus_transA_times_w(bs,v,A,w) do { \
PetscScalar _mone = -1.0,_one = 1.0; \
PetscBLASInt _ione = 1,_bbs; \
CHKERRQ(PetscBLASIntCast(bs,&_bbs)); \
PetscCall(PetscBLASIntCast(bs,&_bbs)); \
PetscDisableStaticAnalyzerForExpressionUnderstandingThatThisIsDangerousAndBugprone(PetscValidScalarPointer(v,2)); \
PetscDisableStaticAnalyzerForExpressionUnderstandingThatThisIsDangerousAndBugprone(PetscValidScalarPointer(A,3)); \
PetscDisableStaticAnalyzerForExpressionUnderstandingThatThisIsDangerousAndBugprone(PetscValidScalarPointer(w,4)); \
......@@ -231,7 +231,7 @@ PETSC_EXTERN PetscErrorCode PetscKernel_A_gets_inverse_A_15(MatScalar*,PetscInt*
#define PetscKernel_v_gets_v_plus_A_times_w(bs,v,A,w) do { \
PetscScalar _one = 1.0; \
PetscBLASInt _ione = 1,_bbs; \
CHKERRQ(PetscBLASIntCast(bs,&_bbs)); \
PetscCall(PetscBLASIntCast(bs,&_bbs)); \
PetscDisableStaticAnalyzerForExpressionUnderstandingThatThisIsDangerousAndBugprone(PetscValidScalarPointer(v,2)); \
PetscDisableStaticAnalyzerForExpressionUnderstandingThatThisIsDangerousAndBugprone(PetscValidScalarPointer(A,3)); \
PetscDisableStaticAnalyzerForExpressionUnderstandingThatThisIsDangerousAndBugprone(PetscValidScalarPointer(w,4)); \
......@@ -248,8 +248,8 @@ PETSC_EXTERN PetscErrorCode PetscKernel_A_gets_inverse_A_15(MatScalar*,PetscInt*
#define PetscKernel_w_gets_w_plus_Ar_times_v(bs,ncols,v,A,w) do { \
PetscScalar _one = 1.0; \
PetscBLASInt _ione = 1,_bbs,_bncols; \
CHKERRQ(PetscBLASIntCast(bs,&_bbs)); \
CHKERRQ(PetscBLASIntCast(ncols,&_bncols)); \
PetscCall(PetscBLASIntCast(bs,&_bbs)); \
PetscCall(PetscBLASIntCast(ncols,&_bncols)); \
PetscDisableStaticAnalyzerForExpressionUnderstandingThatThisIsDangerousAndBugprone(PetscValidScalarPointer(v,3)); \
PetscDisableStaticAnalyzerForExpressionUnderstandingThatThisIsDangerousAndBugprone(PetscValidScalarPointer(A,4)); \
PetscDisableStaticAnalyzerForExpressionUnderstandingThatThisIsDangerousAndBugprone(PetscValidScalarPointer(w,5)); \
......@@ -266,8 +266,8 @@ PETSC_EXTERN PetscErrorCode PetscKernel_A_gets_inverse_A_15(MatScalar*,PetscInt*
#define PetscKernel_w_gets_w_minus_Ar_times_v(bs,ncols,w,A,v) do { \
PetscScalar _one = 1.0,_mone = -1.0; \
PetscBLASInt _ione = 1,_bbs,_bncols; \
CHKERRQ(PetscBLASIntCast(bs,&_bbs)); \
CHKERRQ(PetscBLASIntCast(ncols,&_bncols)); \
PetscCall(PetscBLASIntCast(bs,&_bbs)); \
PetscCall(PetscBLASIntCast(ncols,&_bncols)); \
PetscDisableStaticAnalyzerForExpressionUnderstandingThatThisIsDangerousAndBugprone(PetscValidScalarPointer(w,3)); \
PetscDisableStaticAnalyzerForExpressionUnderstandingThatThisIsDangerousAndBugprone(PetscValidScalarPointer(A,4)); \
PetscDisableStaticAnalyzerForExpressionUnderstandingThatThisIsDangerousAndBugprone(PetscValidScalarPointer(v,5)); \
......@@ -284,7 +284,7 @@ CHKERRQ(PetscBLASIntCast(ncols,&_bncols));
#define PetscKernel_w_gets_A_times_v(bs,v,A,w) do { \
PetscScalar _zero = 0.0,_one = 1.0; \
PetscBLASInt _ione = 1,_bbs; \
CHKERRQ(PetscBLASIntCast(bs,&_bbs)); \
PetscCall(PetscBLASIntCast(bs,&_bbs)); \
PetscDisableStaticAnalyzerForExpressionUnderstandingThatThisIsDangerousAndBugprone(PetscValidScalarPointer(v,2)); \
PetscDisableStaticAnalyzerForExpressionUnderstandingThatThisIsDangerousAndBugprone(PetscValidScalarPointer(A,3)); \
PetscDisableStaticAnalyzerForExpressionUnderstandingThatThisIsDangerousAndBugprone(PetscValidScalarPointer(w,4)); \
......@@ -301,7 +301,7 @@ CHKERRQ(PetscBLASIntCast(ncols,&_bncols));
#define PetscKernel_w_gets_transA_times_v(bs,v,A,w) do { \
PetscScalar _zero = 0.0,_one = 1.0; \
PetscBLASInt _ione = 1,_bbs; \
CHKERRQ(PetscBLASIntCast(bs,&_bbs)); \
PetscCall(PetscBLASIntCast(bs,&_bbs)); \
PetscDisableStaticAnalyzerForExpressionUnderstandingThatThisIsDangerousAndBugprone(PetscValidScalarPointer(v,2)); \
PetscDisableStaticAnalyzerForExpressionUnderstandingThatThisIsDangerousAndBugprone(PetscValidScalarPointer(A,3)); \
PetscDisableStaticAnalyzerForExpressionUnderstandingThatThisIsDangerousAndBugprone(PetscValidScalarPointer(w,4)); \
......@@ -314,8 +314,8 @@ CHKERRQ(PetscBLASIntCast(ncols,&_bncols));
#define PetscKernel_w_gets_Ar_times_v(bs,ncols,x,A,z) do { \
PetscScalar _one = 1.0,_zero = 0.0; \
PetscBLASInt _ione = 1,_bbs,_bncols; \
CHKERRQ(PetscBLASIntCast(bs,&_bbs)); \
CHKERRQ(PetscBLASIntCast(ncols,&_bncols)); \
PetscCall(PetscBLASIntCast(bs,&_bbs)); \
PetscCall(PetscBLASIntCast(ncols,&_bncols)); \
PetscDisableStaticAnalyzerForExpressionUnderstandingThatThisIsDangerousAndBugprone(PetscValidScalarPointer(x,3)); \
PetscDisableStaticAnalyzerForExpressionUnderstandingThatThisIsDangerousAndBugprone(PetscValidScalarPointer(A,4)); \
PetscDisableStaticAnalyzerForExpressionUnderstandingThatThisIsDangerousAndBugprone(PetscValidScalarPointer(z,5)); \
......@@ -328,8 +328,8 @@ CHKERRQ(PetscBLASIntCast(ncols,&_bncols));
#define PetscKernel_w_gets_w_plus_trans_Ar_times_v(bs,ncols,x,A,z) do { \
PetscScalar _one = 1.0; \
PetscBLASInt _ione = 1,_bbs,_bncols; \
CHKERRQ(PetscBLASIntCast(bs,&_bbs)); \
CHKERRQ(PetscBLASIntCast(ncols,&_bncols)); \
PetscCall(PetscBLASIntCast(bs,&_bbs)); \
PetscCall(PetscBLASIntCast(ncols,&_bncols)); \
PetscDisableStaticAnalyzerForExpressionUnderstandingThatThisIsDangerousAndBugprone(PetscValidScalarPointer(x,3)); \
PetscDisableStaticAnalyzerForExpressionUnderstandingThatThisIsDangerousAndBugprone(PetscValidScalarPointer(A,4)); \
PetscDisableStaticAnalyzerForExpressionUnderstandingThatThisIsDangerousAndBugprone(PetscValidScalarPointer(z,5)); \
......@@ -381,7 +381,7 @@ PETSC_EXTERN void msgemm_(PetscInt*,MatScalar*,MatScalar*,MatScalar*);
*/
#define PetscKernel_A_gets_A_times_B(bs,A,B,W) do { \
CHKERRQ(PetscArraycpy((W),(A),(bs)*(bs))); \
PetscCall(PetscArraycpy((W),(A),(bs)*(bs))); \
msgemmi_(&bs,A,B,W); \
} while (0)
......
......@@ -200,11 +200,11 @@ typedef struct {
static inline PetscErrorCode KSPLogResidualHistory(KSP ksp,PetscReal norm)
{
PetscFunctionBegin;
CHKERRQ(PetscObjectSAWsTakeAccess((PetscObject)ksp));
PetscCall(PetscObjectSAWsTakeAccess((PetscObject)ksp));
if (ksp->res_hist && ksp->res_hist_max > ksp->res_hist_len) {
ksp->res_hist[ksp->res_hist_len++] = norm;
}
CHKERRQ(PetscObjectSAWsGrantAccess((PetscObject)ksp));
PetscCall(PetscObjectSAWsGrantAccess((PetscObject)ksp));
PetscFunctionReturn(0);
}
......@@ -213,8 +213,8 @@ static inline PetscErrorCode KSPLogErrorHistory(KSP ksp)
DM dm;
PetscFunctionBegin;
CHKERRQ(PetscObjectSAWsTakeAccess((PetscObject) ksp));
CHKERRQ(KSPGetDM(ksp, &dm));
PetscCall(PetscObjectSAWsTakeAccess((PetscObject) ksp));
PetscCall(KSPGetDM(ksp, &dm));
if (dm && ksp->err_hist && ksp->err_hist_max > ksp->err_hist_len) {
PetscSimplePointFunc exactSol;
void *exactCtx;
......@@ -223,23 +223,23 @@ static inline PetscErrorCode KSPLogErrorHistory(KSP ksp)
PetscReal error;
PetscInt Nf;
CHKERRQ(KSPBuildSolution(ksp, NULL, &u));
PetscCall(KSPBuildSolution(ksp, NULL, &u));
/* TODO Was needed to correct for Newton solution, but I just need to set a solution */
//CHKERRQ(VecScale(u, -1.0));
//PetscCall(VecScale(u, -1.0));
/* TODO Case when I have a solution */
if (0) {
CHKERRQ(DMGetDS(dm, &ds));
CHKERRQ(PetscDSGetNumFields(ds, &Nf));
PetscCall(DMGetDS(dm, &ds));
PetscCall(PetscDSGetNumFields(ds, &Nf));
PetscCheck(Nf <= 1,PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Cannot handle number of fields %D > 1 right now", Nf);
CHKERRQ(PetscDSGetExactSolution(ds, 0, &exactSol, &exactCtx));
CHKERRQ(DMComputeL2FieldDiff(dm, 0.0, &exactSol, &exactCtx, u, &error));
PetscCall(PetscDSGetExactSolution(ds, 0, &exactSol, &exactCtx));
PetscCall(DMComputeL2FieldDiff(dm, 0.0, &exactSol, &exactCtx, u, &error));
} else {
/* The null solution A 0 = 0 */
CHKERRQ(VecNorm(u, NORM_2, &error));
PetscCall(VecNorm(u, NORM_2, &error));
}
ksp->err_hist[ksp->err_hist_len++] = error;
}
CHKERRQ(PetscObjectSAWsGrantAccess((PetscObject) ksp));
PetscCall(PetscObjectSAWsGrantAccess((PetscObject) ksp));
PetscFunctionReturn(0);
}
......@@ -258,11 +258,11 @@ static inline PetscErrorCode KSPSetNoisy_Private(Vec v)
PetscInt n, istart;
PetscFunctionBegin;
CHKERRQ(VecGetOwnershipRange(v, &istart, NULL));
CHKERRQ(VecGetLocalSize(v, &n));
CHKERRQ(VecGetArrayWrite(v, &a));
PetscCall(VecGetOwnershipRange(v, &istart, NULL));
PetscCall(VecGetLocalSize(v, &n));
PetscCall(VecGetArrayWrite(v, &a));
for (PetscInt i = 0; i < n; ++i) a[i] = KSPNoisyHash_Private(i+istart);
CHKERRQ(VecRestoreArrayWrite(v, &a));
PetscCall(VecRestoreArrayWrite(v, &a));
PetscFunctionReturn(0);
}
......@@ -312,9 +312,9 @@ static inline PetscErrorCode KSP_RemoveNullSpace(KSP ksp,Vec y)
Mat A;
MatNullSpace nullsp;
CHKERRQ(PCGetOperators(ksp->pc,&A,NULL));
CHKERRQ(MatGetNullSpace(A,&nullsp));
if (nullsp) CHKERRQ(MatNullSpaceRemove(nullsp,y));
PetscCall(PCGetOperators(ksp->pc,&A,NULL));
PetscCall(MatGetNullSpace(A,&nullsp));
if (nullsp) PetscCall(MatNullSpaceRemove(nullsp,y));
}
PetscFunctionReturn(0);
}
......@@ -326,9 +326,9 @@ static inline PetscErrorCode KSP_RemoveNullSpaceTranspose(KSP ksp,Vec y)
Mat A;
MatNullSpace nullsp;
CHKERRQ(PCGetOperators(ksp->pc,&A,NULL));
CHKERRQ(MatGetTransposeNullSpace(A,&nullsp));
if (nullsp) CHKERRQ(MatNullSpaceRemove(nullsp,y));
PetscCall(PCGetOperators(ksp->pc,&A,NULL));
PetscCall(MatGetTransposeNullSpace(A,&nullsp));
if (nullsp) PetscCall(MatNullSpaceRemove(nullsp,y));
}
PetscFunctionReturn(0);
}
......@@ -336,32 +336,32 @@ static inline PetscErrorCode KSP_RemoveNullSpaceTranspose(KSP ksp,Vec y)
static inline PetscErrorCode KSP_MatMult(KSP ksp,Mat A,Vec x,Vec y)
{
PetscFunctionBegin;
if (ksp->transpose_solve) CHKERRQ(MatMultTranspose(A,x,y));
else CHKERRQ(MatMult(A,x,y));
if (ksp->transpose_solve) PetscCall(MatMultTranspose(A,x,y));
else PetscCall(MatMult(A,x,y));
PetscFunctionReturn(0);
}
static inline PetscErrorCode KSP_MatMultTranspose(KSP ksp,Mat A,Vec x,Vec y)
{
PetscFunctionBegin;
if (ksp->transpose_solve) CHKERRQ(MatMult(A,x,y));
else CHKERRQ(MatMultTranspose(A,x,y));
if (ksp->transpose_solve) PetscCall(MatMult(A,x,y));
else PetscCall(MatMultTranspose(A,x,y));
PetscFunctionReturn(0);
}
static inline PetscErrorCode KSP_MatMultHermitianTranspose(KSP ksp,Mat A,Vec x,Vec y)
{
PetscFunctionBegin;
if (!ksp->transpose_solve) CHKERRQ(MatMultHermitianTranspose(A,x,y));
if (!ksp->transpose_solve) PetscCall(MatMultHermitianTranspose(A,x,y));
else {
Vec w;
CHKERRQ(VecDuplicate(x,&w));
CHKERRQ(VecCopy(x,w));
CHKERRQ(VecConjugate(w));
CHKERRQ(MatMult(A,w,y));
CHKERRQ(VecDestroy(&w));
CHKERRQ(VecConjugate(y));
PetscCall(VecDuplicate(x,&w));
PetscCall(VecCopy(x,w));
PetscCall(VecConjugate(w));
PetscCall(MatMult(A,w,y));
PetscCall(VecDestroy(&w));
PetscCall(VecConjugate(y));