Actual source code: ex10.c
1: static const char help[] = "Tests PetscDeviceContextSetStreamType().\n\n";
3: #include "petscdevicetestcommon.h"
5: int main(int argc, char *argv[])
6: {
7: const PetscStreamType stypes[] = {
8: #if PetscDefined(HAVE_CXX)
9: PETSC_STREAM_GLOBAL_BLOCKING,
10: PETSC_STREAM_DEFAULT_BLOCKING,
11: PETSC_STREAM_GLOBAL_NONBLOCKING
12: #else
13: PETSC_STREAM_GLOBAL_BLOCKING,
14: #endif
15: };
16: const PetscInt ntypes = PETSC_STATIC_ARRAY_LENGTH(stypes);
18: PetscFunctionBeginUser;
19: PetscCall(PetscInitialize(&argc, &argv, NULL, help));
21: // test that get-set trivially work
22: for (PetscInt i = 0; i < ntypes; ++i) {
23: PetscDeviceContext tmp;
24: PetscStreamType tmp_type;
26: PetscCall(PetscDeviceContextCreate(&tmp));
27: PetscCall(PetscDeviceContextSetStreamType(tmp, stypes[i]));
28: PetscCall(PetscDeviceContextGetStreamType(tmp, &tmp_type));
29: PetscCall(AssertPetscStreamTypesValidAndEqual(tmp_type, stypes[i], "Set PetscDeviceStreamType %s does not match expected %s"));
30: // test that any combination of get-set trivially works
31: for (PetscInt j = 0; j < ntypes; ++j) {
32: PetscCall(PetscDeviceContextSetStreamType(tmp, stypes[j]));
33: PetscCall(PetscDeviceContextGetStreamType(tmp, &tmp_type));
34: PetscCall(AssertPetscStreamTypesValidAndEqual(tmp_type, stypes[j], "Set PetscDeviceStreamType %s does not match expected %s"));
35: // reset it back to original
36: PetscCall(PetscDeviceContextSetStreamType(tmp, stypes[i]));
37: }
38: PetscCall(PetscDeviceContextDestroy(&tmp));
39: }
41: // test that any combination of get-set works when set up
42: for (PetscInt i = 0; i < ntypes; ++i) {
43: for (PetscInt j = 0; j < ntypes; ++j) {
44: PetscDeviceContext tmp;
45: PetscStreamType tmp_type;
47: PetscCall(PetscDeviceContextCreate(&tmp));
48: // check this works through setup
49: PetscCall(PetscDeviceContextSetStreamType(tmp, stypes[i]));
50: PetscCall(PetscDeviceContextSetUp(tmp));
51: PetscCall(PetscDeviceContextGetStreamType(tmp, &tmp_type));
52: PetscCall(AssertPetscStreamTypesValidAndEqual(tmp_type, stypes[i], "Set PetscDeviceStreamType %s does not match expected %s after PetscDeviceContextSetUp"));
53: // now change the stream type
54: PetscCall(PetscDeviceContextSetStreamType(tmp, stypes[j]));
55: PetscCall(PetscDeviceContextGetStreamType(tmp, &tmp_type));
56: PetscCall(AssertPetscStreamTypesValidAndEqual(tmp_type, stypes[j], "Set PetscDeviceStreamType %s does not match expected %s when changing after PetscDeviceContextSetUp"));
57: // reset it back to original
58: PetscCall(PetscDeviceContextSetStreamType(tmp, stypes[i]));
59: // and ensure this works
60: PetscCall(PetscDeviceContextGetStreamType(tmp, &tmp_type));
61: PetscCall(AssertPetscStreamTypesValidAndEqual(tmp_type, stypes[i], "Set PetscDeviceStreamType %s does not match expected %s after setting back to original"));
62: // finally set up again
63: PetscCall(PetscDeviceContextSetUp(tmp));
64: // and ensure it has not changed
65: PetscCall(PetscDeviceContextGetStreamType(tmp, &tmp_type));
66: PetscCall(AssertPetscStreamTypesValidAndEqual(tmp_type, stypes[i], "Set PetscDeviceStreamType %s does not match expected %s after setting back to original and PetscDeviceContextSetUp"));
67: PetscCall(PetscDeviceContextDestroy(&tmp));
68: }
69: }
71: PetscCall(PetscPrintf(PETSC_COMM_WORLD, "EXIT_SUCCESS\n"));
72: PetscCall(PetscFinalize());
73: return 0;
74: }
76: /*TEST
78: testset:
79: requires: cxx
80: output_file: ./output/ExitSuccess.out
81: args: -device_enable {{lazy eager}}
82: test:
83: requires: !device
84: suffix: host_no_device
85: test:
86: requires: device
87: args: -default_device_type host
88: suffix: host_with_device
89: test:
90: requires: cuda
91: args: -default_device_type cuda
92: suffix: cuda
93: test:
94: requires: hip
95: args: -default_device_type hip
96: suffix: hip
97: test:
98: requires: sycl
99: args: -default_device_type sycl
100: suffix: sycl
102: test:
103: requires: !cxx
104: output_file: ./output/ExitSuccess.out
105: suffix: no_cxx
107: TEST*/