xref: /petsc/src/sys/objects/device/tests/ex2.c (revision 759190395b54fdd00f8c2c9057722ad57da9afab)
1 static const char help[] = "Tests creation and destruction of PetscDeviceContext.\n\n";
2 
3 #include <petsc/private/deviceimpl.h>
4 #include "petscdevicetestcommon.h"
5 
6 int main(int argc, char *argv[])
7 {
8   PetscDeviceContext dctx = NULL,ddup = NULL;
9 
10   PetscFunctionBeginUser;
11   PetscCall(PetscInitialize(&argc,&argv,NULL,help));
12 
13   /* basic creation and destruction */
14   PetscCall(PetscDeviceContextCreate(&dctx));
15   PetscCall(AssertDeviceContextExists(dctx));
16   PetscCall(PetscDeviceContextDestroy(&dctx));
17   PetscCall(AssertDeviceContextDoesNotExist(dctx));
18   /* double free is no-op */
19   PetscCall(PetscDeviceContextDestroy(&dctx));
20   PetscCall(AssertDeviceContextDoesNotExist(dctx));
21 
22   /* test global context returns a valid context */
23   dctx = NULL;
24   PetscCall(PetscDeviceContextGetCurrentContext(&dctx));
25   PetscCall(AssertDeviceContextExists(dctx));
26   /* test locally setting to null doesn't clobber the global */
27   dctx = NULL;
28   PetscCall(PetscDeviceContextGetCurrentContext(&dctx));
29   PetscCall(AssertDeviceContextExists(dctx));
30 
31   /* test duplicate */
32   PetscCall(PetscDeviceContextDuplicate(dctx,&ddup));
33   /* both device contexts should exist */
34   PetscCall(AssertDeviceContextExists(dctx));
35   PetscCall(AssertDeviceContextExists(ddup));
36 
37   /* destroying the dup should leave the original untouched */
38   PetscCall(PetscDeviceContextDestroy(&ddup));
39   PetscCall(AssertDeviceContextDoesNotExist(ddup));
40   PetscCall(AssertDeviceContextExists(dctx));
41 
42   PetscCall(PetscPrintf(PETSC_COMM_WORLD,"EXIT_SUCCESS\n"));
43   PetscCall(PetscFinalize());
44   return 0;
45 }
46 
47 /*TEST
48 
49  build:
50    requires: defined(PETSC_HAVE_CXX)
51 
52  test:
53    TODO: broken in ci
54    requires: !device
55    suffix: no_device
56    filter: Error: grep -E -o -e ".*No support for this operation for this object type" -e ".*PETSc is not configured with device support.*" -e "^\[0\]PETSC ERROR:.*[0-9]{1} [A-z]+\(\)"
57 
58  testset:
59    output_file: ./output/ExitSuccess.out
60    nsize: {{1 2 4}}
61    test:
62      requires: cuda
63      suffix: cuda
64    test:
65      requires: hip
66      suffix: hip
67 
68 TEST*/
69