Actual source code: petscdevicetestcommon.h
1: #ifndef PETSCDEVICETESTCOMMON_H
2: #define PETSCDEVICETESTCOMMON_H
4: /* this file needs to be the one to include petsc/private/deviceimpl.h since it needs to define
5: * a special macro to ensure that the error checking macros stay defined even in optimized
6: * builds
7: */
8: #if defined(PETSCDEVICEIMPL_H)
9: #error "must #include this file before petsc/private/deviceimpl.h"
10: #endif
12: #if !defined(PETSC_DEVICE_KEEP_ERROR_CHECKING_MACROS)
13: #define PETSC_DEVICE_KEEP_ERROR_CHECKING_MACROS 1
14: #endif
15: #include <petsc/private/deviceimpl.h>
17: static inline PetscErrorCode AssertDeviceExists(PetscDevice device)
18: {
19: PetscFunctionBegin;
21: PetscFunctionReturn(PETSC_SUCCESS);
22: }
24: static inline PetscErrorCode AssertDeviceDoesNotExist(PetscDevice device)
25: {
26: PetscFunctionBegin;
27: PetscCheck(!device, PETSC_COMM_SELF, PETSC_ERR_PLIB, "PetscDevice was not destroyed for type %s", PetscDeviceTypes[device->type]);
28: PetscFunctionReturn(PETSC_SUCCESS);
29: }
31: static inline PetscErrorCode AssertDeviceContextExists(PetscDeviceContext dctx)
32: {
33: PetscFunctionBegin;
35: PetscFunctionReturn(PETSC_SUCCESS);
36: }
38: static inline PetscErrorCode AssertDeviceContextDoesNotExist(PetscDeviceContext dctx)
39: {
40: PetscFunctionBegin;
41: PetscCheck(!dctx, PETSC_COMM_SELF, PETSC_ERR_PLIB, "PetscDeviceContext was not destroyed");
42: PetscFunctionReturn(PETSC_SUCCESS);
43: }
45: static inline PetscErrorCode AssertPetscStreamTypesValidAndEqual(PetscStreamType left, PetscStreamType right, const char *errStr)
46: {
47: PetscFunctionBegin;
50: PetscCheck(left == right, PETSC_COMM_SELF, PETSC_ERR_ARG_CORRUPT, errStr, PetscStreamTypes[left], PetscStreamTypes[right]);
51: PetscFunctionReturn(PETSC_SUCCESS);
52: }
54: static inline PetscErrorCode AssertPetscDeviceTypesValidAndEqual(PetscDeviceType left, PetscDeviceType right, const char *errStr)
55: {
56: PetscFunctionBegin;
59: PetscCheck(left == right, PETSC_COMM_SELF, PETSC_ERR_ARG_CORRUPT, errStr, PetscDeviceTypes[left], PetscDeviceTypes[right]);
60: PetscFunctionReturn(PETSC_SUCCESS);
61: }
63: static inline PetscErrorCode AssertPetscDevicesValidAndEqual(PetscDevice left, PetscDevice right, const char *errStr)
64: {
65: PetscFunctionBegin;
66: PetscCheckCompatibleDevices(left, 1, right, 2);
67: PetscCheck(left == right, PETSC_COMM_SELF, PETSC_ERR_ARG_CORRUPT, "%s: %p != %p", errStr, (void *)left, (void *)right);
68: PetscFunctionReturn(PETSC_SUCCESS);
69: }
71: static inline PetscErrorCode AssertPetscDeviceContextsValidAndEqual(PetscDeviceContext left, PetscDeviceContext right, const char *errStr)
72: {
73: PetscFunctionBegin;
74: PetscCheckCompatibleDeviceContexts(left, 1, right, 2);
75: PetscCheck(left == right, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "%s", errStr);
76: PetscFunctionReturn(PETSC_SUCCESS);
77: }
78: #endif /* PETSCDEVICETESTCOMMON_H */