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 MPI_Comm comm; 25 PetscDeviceContext dctx, dup; 26 27 PetscFunctionBeginUser; 28 PetscCall(PetscInitialize(&argc, &argv, NULL, help)); 29 comm = PETSC_COMM_WORLD; 30 31 PetscCall(PetscDeviceContextGetCurrentContext(&dctx)); 32 PetscCall(TestView(dctx)); 33 34 PetscCall(PetscDeviceContextDuplicate(dctx, &dup)); 35 PetscCall(TestView(dup)); 36 PetscCall(PetscDeviceContextDestroy(&dup)); 37 38 PetscCall(PetscPrintf(comm, "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