Actual source code: ex15.c
petsc-3.8.4 2018-03-24
2: static char help[] = "Tests using PetscViewerGetSubViewer() recursively\n\n";
4: /*T
5: Concepts: viewers
6: Processors: n
7: T*/
8: #include <petscsys.h>
9: #include <petscviewer.h>
12: int main(int argc,char **argv)
13: {
14: PetscErrorCode ierr;
15: PetscViewer viewer,subviewer,subsubviewer;
16: PetscViewerFormat format;
17: PetscBool flg;
18: PetscSubcomm psubcomm,psubsubcomm;
19: MPI_Comm comm,subcomm,subsubcomm;
20: PetscMPIInt size;
22: /*
23: Every PETSc routine should begin with the PetscInitialize() routine.
24: argc, argv - These command line arguments are taken to extract the options
25: supplied to PETSc and options supplied to MPI.
26: help - When PETSc executable is invoked with the option -help,
27: it prints the various options that can be applied at
28: runtime. The user can use the "help" variable place
29: additional help messages in this printout.
30: */
31: PetscInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;
32: comm = PETSC_COMM_WORLD;
33: MPI_Comm_size(comm,&size);
34: if (size < 4) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_SUP,"Must run with at least 4 MPI processes");
35: PetscOptionsGetViewer(comm,NULL,"-viewer",&viewer,&format,&flg);
36: if (!viewer) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_SUP,"Must use -viewer option");
38: PetscViewerASCIIPrintf(viewer,"Print called on original full viewer %d\n",PetscGlobalRank);
40: PetscSubcommCreate(comm,&psubcomm);
41: PetscSubcommSetNumber(psubcomm,2);
42: PetscSubcommSetType(psubcomm,PETSC_SUBCOMM_CONTIGUOUS);
43: /* enable runtime switch of psubcomm type, e.g., '-psubcomm_type interlaced */
44: PetscSubcommSetFromOptions(psubcomm);
45: subcomm = PetscSubcommChild(psubcomm);
47: PetscViewerGetSubViewer(viewer,subcomm,&subviewer);
49: PetscViewerASCIIPrintf(subviewer," Print called on sub viewers %d\n",PetscGlobalRank);
51: PetscSubcommCreate(subcomm,&psubsubcomm);
52: PetscSubcommSetNumber(psubsubcomm,2);
53: PetscSubcommSetType(psubsubcomm,PETSC_SUBCOMM_CONTIGUOUS);
54: /* enable runtime switch of psubcomm type, e.g., '-psubcomm_type interlaced */
55: PetscSubcommSetFromOptions(psubsubcomm);
56: subsubcomm = PetscSubcommChild(psubsubcomm);
58: PetscViewerGetSubViewer(subviewer,subsubcomm,&subsubviewer);
60: PetscViewerASCIIPrintf(subsubviewer," Print called on sub sub viewers %d\n",PetscGlobalRank);
62: PetscViewerRestoreSubViewer(subviewer,subsubcomm,&subsubviewer);
63: PetscViewerRestoreSubViewer(viewer,subcomm,&subviewer);
65: PetscSubcommDestroy(&psubsubcomm);
66: PetscSubcommDestroy(&psubcomm);
67: PetscViewerDestroy(&viewer);
68: PetscFinalize();
69: return ierr;
70: }
73: /*TEST
75: test:
76: nsize: 4
77: args: -viewer
79: TEST*/