Actual source code: ex1.c
1: static const char help[] = "Tests creation and destruction of PetscDevice.\n\n";
3: #include <petsc/private/deviceimpl.h>
4: #include "petscdevicetestcommon.h"
6: int main(int argc, char *argv[])
7: {
8: const PetscInt n = 10;
9: PetscDevice device = NULL;
10: PetscDevice devices[n];
12: PetscInitialize(&argc,&argv,NULL,help);
14: /* normal create and destroy */
15: PetscDeviceCreate(PETSC_DEVICE_DEFAULT,PETSC_DECIDE,&device);
16: AssertDeviceExists(device);
17: PetscDeviceDestroy(&device);
18: AssertDeviceDoesNotExist(device);
19: /* should not destroy twice */
20: PetscDeviceDestroy(&device);
21: AssertDeviceDoesNotExist(device);
23: /* test reference counting */
24: device = NULL;
25: PetscArrayzero(devices,n);
26: PetscDeviceCreate(PETSC_DEVICE_DEFAULT,PETSC_DECIDE,&device);
27: AssertDeviceExists(device);
28: for (int i = 0; i < n; ++i) {
29: PetscDeviceReference_Internal(device);
30: devices[i] = device;
31: }
32: AssertDeviceExists(device);
33: for (int i = 0; i < n; ++i) {
34: PetscDeviceDestroy(&devices[i]);
35: AssertDeviceExists(device);
36: AssertDeviceDoesNotExist(devices[i]);
37: }
38: PetscDeviceDestroy(&device);
39: AssertDeviceDoesNotExist(device);
41: /* test the default devices exist */
42: device = NULL;
43: PetscArrayzero(devices,n);
44: {
45: PetscDeviceContext dctx;
46: /* global context will have the default device */
47: PetscDeviceContextGetCurrentContext(&dctx);
48: PetscDeviceContextGetDevice(dctx,&device);
49: }
50: AssertDeviceExists(device);
51: /* test reference counting for default device */
52: for (int i = 0; i < n; ++i) {
53: PetscDeviceReference_Internal(device);
54: devices[i] = device;
55: }
56: AssertDeviceExists(device);
57: for (int i = 0; i < n; ++i) {
58: PetscDeviceDestroy(&devices[i]);
59: AssertDeviceExists(device);
60: AssertDeviceDoesNotExist(devices[i]);
61: }
63: PetscPrintf(PETSC_COMM_WORLD,"EXIT_SUCCESS\n");
64: PetscFinalize();
65: return 0;
66: }
68: /*TEST
70: build:
71: requires: defined(PETSC_HAVE_CXX)
73: testset:
74: TODO: broken in ci
75: requires: !device
76: suffix: no_device
77: 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]+\(\)"
78: test:
79: requires: debug
80: suffix: debug
81: test:
82: requires: !debug
83: suffix: opt
85: testset:
86: output_file: ./output/ExitSuccess.out
87: nsize: {{1 2 5}}
88: test:
89: requires: cuda
90: suffix: cuda
91: test:
92: requires: hip
93: suffix: hip
94: test:
95: requires: sycl
96: suffix: sycl
98: TEST*/