xref: /petsc/src/sys/objects/device/tests/ex2.c (revision b122ec5aa1bd4469eb4e0673542fb7de3f411254)
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   CHKERRQ(PetscInitialize(&argc,&argv,NULL,help));
11 
12   /* basic creation and destruction */
13   CHKERRQ(PetscDeviceContextCreate(&dctx));
14   CHKERRQ(AssertDeviceContextExists(dctx));
15   CHKERRQ(PetscDeviceContextDestroy(&dctx));
16   CHKERRQ(AssertDeviceContextDoesNotExist(dctx));
17   /* double free is no-op */
18   CHKERRQ(PetscDeviceContextDestroy(&dctx));
19   CHKERRQ(AssertDeviceContextDoesNotExist(dctx));
20 
21   /* test global context returns a valid context */
22   dctx = NULL;
23   CHKERRQ(PetscDeviceContextGetCurrentContext(&dctx));
24   CHKERRQ(AssertDeviceContextExists(dctx));
25   /* test locally setting to null doesn't clobber the global */
26   dctx = NULL;
27   CHKERRQ(PetscDeviceContextGetCurrentContext(&dctx));
28   CHKERRQ(AssertDeviceContextExists(dctx));
29 
30   /* test duplicate */
31   CHKERRQ(PetscDeviceContextDuplicate(dctx,&ddup));
32   /* both device contexts should exist */
33   CHKERRQ(AssertDeviceContextExists(dctx));
34   CHKERRQ(AssertDeviceContextExists(ddup));
35 
36   /* destroying the dup should leave the original untouched */
37   CHKERRQ(PetscDeviceContextDestroy(&ddup));
38   CHKERRQ(AssertDeviceContextDoesNotExist(ddup));
39   CHKERRQ(AssertDeviceContextExists(dctx));
40 
41   CHKERRQ(PetscPrintf(PETSC_COMM_WORLD,"EXIT_SUCCESS\n"));
42   CHKERRQ(PetscFinalize());
43   return 0;
44 }
45 
46 /*TEST
47 
48  build:
49    requires: defined(PETSC_HAVE_CXX)
50 
51  test:
52    TODO: broken in ci
53    requires: !device
54    suffix: no_device
55    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]+\(\)"
56 
57  testset:
58    output_file: ./output/ExitSuccess.out
59    nsize: {{1 2 4}}
60    test:
61      requires: cuda
62      suffix: cuda
63    test:
64      requires: hip
65      suffix: hip
66 
67 TEST*/
68