xref: /petsc/src/sys/objects/device/tests/ex6.c (revision f9fea11e2c44c506c9f9a3f6998afbe8a760174b)
1 static const char help[] = "Tests PetscDeviceContextView().\n\n";
2 
3 #include "petscdevicetestcommon.h"
4 #include <petscviewer.h>
5 
6 static PetscErrorCode TestView(PetscDeviceContext dctx)
7 {
8   PetscViewer viewer;
9 
10   PetscFunctionBegin;
11   /* test stdout world */
12   PetscCall(PetscDeviceContextView(dctx, NULL));
13 
14   /* test creating our own viewer */
15   PetscCall(PetscViewerCreate(PETSC_COMM_WORLD, &viewer));
16   PetscCall(PetscViewerSetType(viewer, PETSCVIEWERASCII));
17   PetscCall(PetscDeviceContextView(dctx, viewer));
18   PetscCall(PetscViewerDestroy(&viewer));
19   PetscFunctionReturn(0);
20 }
21 
22 int main(int argc, char *argv[])
23 {
24   PetscDeviceContext dctx, dup;
25 
26   PetscFunctionBeginUser;
27   PetscCall(PetscInitialize(&argc, &argv, NULL, help));
28 
29   PetscCall(PetscDeviceContextGetCurrentContext(&dctx));
30   PetscCall(TestView(dctx));
31 
32   PetscCall(PetscDeviceContextDuplicate(dctx, &dup));
33   PetscCall(TestView(dup));
34   PetscCall(PetscDeviceContextDestroy(&dup));
35 
36   PetscCall(TestView(NULL));
37 
38   PetscCall(PetscPrintf(PETSC_COMM_WORLD, "EXIT_SUCCESS\n"));
39   PetscCall(PetscFinalize());
40   return 0;
41 }
42 
43 /*TEST
44 
45  build:
46    requires: defined(PETSC_HAVE_CXX)
47 
48  testset:
49    args: -root_device_context_stream_type \
50      {{global_blocking default_blocking global_nonblocking}separate output}
51    filter: grep -ve "ex6 on a" -ve "\[0\] "
52    test:
53      requires: !device
54      suffix: host_no_device
55    test:
56      requires: device
57      args: -root_device_context_device_type host
58      suffix: host_with_device
59    test:
60      requires: cuda
61      args: -root_device_context_device_type cuda
62      suffix: cuda
63    test:
64      requires: hip
65      args: -root_device_context_device_type hip
66      suffix: hip
67    test:
68      requires: sycl
69      args: -root_device_context_device_type sycl
70      suffix: sycl
71 
72 TEST*/
73