Actual source code: petscdevicetestcommon.h

  1: #pragma once

  3: /* this file needs to be the one to include petsc/private/deviceimpl.h since it needs to define
  4:  * a special macro to ensure that the error checking macros stay defined even in optimized
  5:  * builds
  6:  */
  7: #if defined(PETSCDEVICEIMPL_H)
  8:   #error "must #include this file before petsc/private/deviceimpl.h"
  9: #endif

 11: #if !defined(PETSC_DEVICE_KEEP_ERROR_CHECKING_MACROS)
 12:   #define PETSC_DEVICE_KEEP_ERROR_CHECKING_MACROS 1
 13: #endif
 14: #include <petsc/private/deviceimpl.h>

 16: static inline PetscErrorCode AssertDeviceExists(PetscDevice device)
 17: {
 18:   PetscFunctionBegin;
 20:   PetscFunctionReturn(PETSC_SUCCESS);
 21: }

 23: static inline PetscErrorCode AssertDeviceDoesNotExist(PetscDevice device)
 24: {
 25:   PetscFunctionBegin;
 26:   PetscCheck(!device, PETSC_COMM_SELF, PETSC_ERR_PLIB, "PetscDevice was not destroyed for type %s", PetscDeviceTypes[device->type]);
 27:   PetscFunctionReturn(PETSC_SUCCESS);
 28: }

 30: static inline PetscErrorCode AssertDeviceContextExists(PetscDeviceContext dctx)
 31: {
 32:   PetscFunctionBegin;
 34:   PetscFunctionReturn(PETSC_SUCCESS);
 35: }

 37: static inline PetscErrorCode AssertDeviceContextDoesNotExist(PetscDeviceContext dctx)
 38: {
 39:   PetscFunctionBegin;
 40:   PetscCheck(!dctx, PETSC_COMM_SELF, PETSC_ERR_PLIB, "PetscDeviceContext was not destroyed");
 41:   PetscFunctionReturn(PETSC_SUCCESS);
 42: }

 44: static inline PetscErrorCode AssertPetscStreamTypesValidAndEqual(PetscStreamType left, PetscStreamType right, const char *errStr)
 45: {
 46:   PetscFunctionBegin;
 49:   PetscCheck(left == right, PETSC_COMM_SELF, PETSC_ERR_ARG_CORRUPT, errStr, PetscStreamTypes[left], PetscStreamTypes[right]);
 50:   PetscFunctionReturn(PETSC_SUCCESS);
 51: }

 53: static inline PetscErrorCode AssertPetscDeviceTypesValidAndEqual(PetscDeviceType left, PetscDeviceType right, const char *errStr)
 54: {
 55:   PetscFunctionBegin;
 58:   PetscCheck(left == right, PETSC_COMM_SELF, PETSC_ERR_ARG_CORRUPT, errStr, PetscDeviceTypes[left], PetscDeviceTypes[right]);
 59:   PetscFunctionReturn(PETSC_SUCCESS);
 60: }

 62: static inline PetscErrorCode AssertPetscDevicesValidAndEqual(PetscDevice left, PetscDevice right, const char *errStr)
 63: {
 64:   PetscFunctionBegin;
 65:   PetscCheckCompatibleDevices(left, 1, right, 2);
 66:   PetscCheck(left == right, PETSC_COMM_SELF, PETSC_ERR_ARG_CORRUPT, "%s: %p != %p", errStr, (void *)left, (void *)right);
 67:   PetscFunctionReturn(PETSC_SUCCESS);
 68: }

 70: static inline PetscErrorCode AssertPetscDeviceContextsValidAndEqual(PetscDeviceContext left, PetscDeviceContext right, const char *errStr)
 71: {
 72:   PetscFunctionBegin;
 73:   PetscCheckCompatibleDeviceContexts(left, 1, right, 2);
 74:   PetscCheck(left == right, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "%s", errStr);
 75:   PetscFunctionReturn(PETSC_SUCCESS);
 76: }