Actual source code: ex2.c

  1: static const char help[] = "Tests creation and destruction of PetscDeviceContext.\n\n";

  3: #include "petscdevicetestcommon.h"

  5: int main(int argc, char *argv[])
  6: {
  7:   PetscDeviceContext dctx = NULL, ddup = NULL;

 10:   PetscInitialize(&argc, &argv, NULL, help);

 12:   /* basic creation and destruction */
 13:   PetscDeviceContextCreate(&dctx);
 14:   AssertDeviceContextExists(dctx);
 15:   PetscDeviceContextDestroy(&dctx);
 16:   AssertDeviceContextDoesNotExist(dctx);
 17:   /* double free is no-op */
 18:   PetscDeviceContextDestroy(&dctx);
 19:   AssertDeviceContextDoesNotExist(dctx);

 21:   /* test global context returns a valid context */
 22:   dctx = NULL;
 23:   PetscDeviceContextGetCurrentContext(&dctx);
 24:   AssertDeviceContextExists(dctx);
 25:   /* test locally setting to null doesn't clobber the global */
 26:   dctx = NULL;
 27:   PetscDeviceContextGetCurrentContext(&dctx);
 28:   AssertDeviceContextExists(dctx);

 30:   /* test duplicate */
 31:   PetscDeviceContextDuplicate(dctx, &ddup);
 32:   /* both device contexts should exist */
 33:   AssertDeviceContextExists(dctx);
 34:   AssertDeviceContextExists(ddup);

 36:   /* destroying the dup should leave the original untouched */
 37:   PetscDeviceContextDestroy(&ddup);
 38:   AssertDeviceContextDoesNotExist(ddup);
 39:   AssertDeviceContextExists(dctx);

 41:   PetscPrintf(PETSC_COMM_WORLD, "EXIT_SUCCESS\n");
 42:   PetscFinalize();
 43:   return 0;
 44: }

 46: /*TEST

 48:  build:
 49:    requires: defined(PETSC_HAVE_CXX)

 51:  testset:
 52:    output_file: ./output/ExitSuccess.out
 53:    nsize: {{1 2 4}}
 54:    args: -device_enable {{lazy eager}}
 55:    test:
 56:      requires: !device
 57:      suffix: host_no_device
 58:    test:
 59:      requires: device
 60:      args: -root_device_context_device_type host
 61:      suffix: host_with_device
 62:    test:
 63:      requires: cuda
 64:      args: -root_device_context_device_type cuda
 65:      suffix: cuda
 66:    test:
 67:      requires: hip
 68:      args: -root_device_context_device_type hip
 69:      suffix: hip

 71: TEST*/