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 PetscViewer viewer; 8 9 PetscFunctionBegin; 10 /* test stdout world */ 11 PetscCall(PetscDeviceContextView(dctx, NULL)); 12 13 /* test creating our own viewer */ 14 PetscCall(PetscViewerCreate(PETSC_COMM_WORLD, &viewer)); 15 PetscCall(PetscViewerSetType(viewer, PETSCVIEWERASCII)); 16 PetscCall(PetscDeviceContextView(dctx, viewer)); 17 PetscCall(PetscViewerDestroy(&viewer)); 18 PetscFunctionReturn(0); 19 } 20 21 int main(int argc, char *argv[]) { 22 MPI_Comm comm; 23 PetscDeviceContext dctx, dup; 24 25 PetscFunctionBeginUser; 26 PetscCall(PetscInitialize(&argc, &argv, NULL, help)); 27 comm = PETSC_COMM_WORLD; 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(PetscPrintf(comm, "EXIT_SUCCESS\n")); 37 PetscCall(PetscFinalize()); 38 return 0; 39 } 40 41 /*TEST 42 43 build: 44 requires: defined(PETSC_HAVE_CXX) 45 46 testset: 47 args: -root_device_context_stream_type \ 48 {{global_blocking default_blocking global_nonblocking}separate output} 49 filter: grep -ve "ex6 on a" -ve "\[0\] " 50 test: 51 requires: !device 52 suffix: host_no_device 53 test: 54 requires: device 55 args: -root_device_context_device_type host 56 suffix: host_with_device 57 test: 58 requires: cuda 59 args: -root_device_context_device_type cuda 60 suffix: cuda 61 test: 62 requires: hip 63 args: -root_device_context_device_type hip 64 suffix: hip 65 test: 66 requires: sycl 67 args: -root_device_context_device_type sycl 68 suffix: sycl 69 70 TEST*/ 71