Actual source code: ex50.c


  2: static char help[] = "Tests using PetscViewerGetSubViewer() recursively\n\n";

  4: #include <petscsys.h>
  5: #include <petscviewer.h>

  7: int main(int argc, char **argv)
  8: {
  9:   PetscViewer       viewer, subviewer, subsubviewer;
 10:   PetscViewerFormat format;
 11:   PetscBool         flg;
 12:   PetscSubcomm      psubcomm, psubsubcomm;
 13:   MPI_Comm          comm, subcomm, subsubcomm;
 14:   PetscMPIInt       size;

 16:   /*
 17:     Every PETSc routine should begin with the PetscInitialize() routine.
 18:     argc, argv - These command line arguments are taken to extract the options
 19:                  supplied to PETSc and options supplied to MPI.
 20:     help       - When PETSc executable is invoked with the option -help,
 21:                  it prints the various options that can be applied at
 22:                  runtime.  The user can use the "help" variable place
 23:                  additional help messages in this printout.
 24:   */
 26:   PetscInitialize(&argc, &argv, (char *)0, help);
 27:   comm = PETSC_COMM_WORLD;
 28:   MPI_Comm_size(comm, &size);
 30:   PetscOptionsGetViewer(comm, NULL, NULL, "-viewer", &viewer, &format, &flg);

 33:   PetscViewerASCIIPrintf(viewer, "Print called on original full viewer %d\n", PetscGlobalRank);

 35:   PetscSubcommCreate(comm, &psubcomm);
 36:   PetscSubcommSetNumber(psubcomm, 2);
 37:   PetscSubcommSetType(psubcomm, PETSC_SUBCOMM_CONTIGUOUS);
 38:   /* enable runtime switch of psubcomm type, e.g., '-psubcomm_type interlaced */
 39:   PetscSubcommSetFromOptions(psubcomm);
 40:   subcomm = PetscSubcommChild(psubcomm);

 42:   PetscViewerGetSubViewer(viewer, subcomm, &subviewer);

 44:   PetscViewerASCIIPrintf(subviewer, "  Print called on sub viewers %d\n", PetscGlobalRank);

 46:   PetscSubcommCreate(subcomm, &psubsubcomm);
 47:   PetscSubcommSetNumber(psubsubcomm, 2);
 48:   PetscSubcommSetType(psubsubcomm, PETSC_SUBCOMM_CONTIGUOUS);
 49:   /* enable runtime switch of psubcomm type, e.g., '-psubcomm_type interlaced */
 50:   PetscSubcommSetFromOptions(psubsubcomm);
 51:   subsubcomm = PetscSubcommChild(psubsubcomm);

 53:   PetscViewerGetSubViewer(subviewer, subsubcomm, &subsubviewer);

 55:   PetscViewerASCIIPrintf(subsubviewer, "  Print called on sub sub viewers %d\n", PetscGlobalRank);

 57:   PetscViewerRestoreSubViewer(subviewer, subsubcomm, &subsubviewer);
 58:   PetscViewerRestoreSubViewer(viewer, subcomm, &subviewer);

 60:   PetscSubcommDestroy(&psubsubcomm);
 61:   PetscSubcommDestroy(&psubcomm);
 62:   PetscViewerDestroy(&viewer);
 63:   PetscFinalize();
 64:   return 0;
 65: }

 67: /*TEST

 69:    test:
 70:       nsize: 4
 71:       args: -viewer

 73: TEST*/