Actual source code: ex6.c

  1: static const char help[] = "Tests PetscDeviceContextView().\n\n";

  3: #include "petscdevicetestcommon.h"

  5: static PetscErrorCode TestView(PetscDeviceContext dctx)
  6: {
  7:   PetscViewer viewer;

  9:   PetscFunctionBegin;
 10:   /* test stdout world */
 11:   PetscCall(PetscDeviceContextView(dctx, NULL));

 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(PETSC_SUCCESS);
 19: }

 21: int main(int argc, char *argv[])
 22: {
 23:   PetscDeviceContext dctx, dup;

 25:   PetscFunctionBeginUser;
 26:   PetscCall(PetscInitialize(&argc, &argv, NULL, help));

 28:   PetscCall(PetscDeviceContextGetCurrentContext(&dctx));
 29:   PetscCall(TestView(dctx));

 31:   PetscCall(PetscDeviceContextDuplicate(dctx, &dup));
 32:   PetscCall(TestView(dup));
 33:   PetscCall(PetscDeviceContextDestroy(&dup));

 35:   PetscCall(TestView(PetscDeviceContextDefault));

 37:   PetscCall(PetscPrintf(PETSC_COMM_WORLD, "EXIT_SUCCESS\n"));
 38:   PetscCall(PetscFinalize());
 39:   return 0;
 40: }

 42: /*TEST

 44:   testset:
 45:     requires: defined(PETSC_DEVICELANGUAGE_CXX)
 46:     args: -root_device_context_stream_type \
 47:       {{default default_with_barrier nonblocking}separate output}
 48:     filter: grep -ve "ex6 on a" -ve "\[0\] "
 49:     test:
 50:       requires: !device
 51:       suffix: host_no_device
 52:     test:
 53:       requires: device
 54:       args: -root_device_context_device_type host
 55:       suffix: host_with_device
 56:     test:
 57:       requires: cuda
 58:       args: -root_device_context_device_type cuda
 59:       suffix: cuda
 60:     test:
 61:       requires: hip
 62:       args: -root_device_context_device_type hip
 63:       suffix: hip
 64:     test:
 65:       requires: sycl
 66:       args: -root_device_context_device_type sycl
 67:       suffix: sycl

 69:   testset:
 70:     requires: !defined(PETSC_DEVICELANGUAGE_CXX)
 71:     output_file: output/ExitSuccess.out
 72:     suffix: no_cxx

 74: TEST*/