Actual source code: ex50.c
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>
11: int main(int argc,char **argv)
12: {
13: PetscViewer viewer,subviewer,subsubviewer;
14: PetscViewerFormat format;
15: PetscBool flg;
16: PetscSubcomm psubcomm,psubsubcomm;
17: MPI_Comm comm,subcomm,subsubcomm;
18: PetscMPIInt size;
20: /*
21: Every PETSc routine should begin with the PetscInitialize() routine.
22: argc, argv - These command line arguments are taken to extract the options
23: supplied to PETSc and options supplied to MPI.
24: help - When PETSc executable is invoked with the option -help,
25: it prints the various options that can be applied at
26: runtime. The user can use the "help" variable place
27: additional help messages in this printout.
28: */
29: PetscInitialize(&argc,&argv,(char*)0,help);
30: comm = PETSC_COMM_WORLD;
31: MPI_Comm_size(comm,&size);
33: PetscOptionsGetViewer(comm,NULL,NULL,"-viewer",&viewer,&format,&flg);
36: PetscViewerASCIIPrintf(viewer,"Print called on original full viewer %d\n",PetscGlobalRank);
38: PetscSubcommCreate(comm,&psubcomm);
39: PetscSubcommSetNumber(psubcomm,2);
40: PetscSubcommSetType(psubcomm,PETSC_SUBCOMM_CONTIGUOUS);
41: /* enable runtime switch of psubcomm type, e.g., '-psubcomm_type interlaced */
42: PetscSubcommSetFromOptions(psubcomm);
43: subcomm = PetscSubcommChild(psubcomm);
45: PetscViewerGetSubViewer(viewer,subcomm,&subviewer);
47: PetscViewerASCIIPrintf(subviewer," Print called on sub viewers %d\n",PetscGlobalRank);
49: PetscSubcommCreate(subcomm,&psubsubcomm);
50: PetscSubcommSetNumber(psubsubcomm,2);
51: PetscSubcommSetType(psubsubcomm,PETSC_SUBCOMM_CONTIGUOUS);
52: /* enable runtime switch of psubcomm type, e.g., '-psubcomm_type interlaced */
53: PetscSubcommSetFromOptions(psubsubcomm);
54: subsubcomm = PetscSubcommChild(psubsubcomm);
56: PetscViewerGetSubViewer(subviewer,subsubcomm,&subsubviewer);
58: PetscViewerASCIIPrintf(subsubviewer," Print called on sub sub viewers %d\n",PetscGlobalRank);
60: PetscViewerRestoreSubViewer(subviewer,subsubcomm,&subsubviewer);
61: PetscViewerRestoreSubViewer(viewer,subcomm,&subviewer);
63: PetscSubcommDestroy(&psubsubcomm);
64: PetscSubcommDestroy(&psubcomm);
65: PetscViewerDestroy(&viewer);
66: PetscFinalize();
67: return 0;
68: }
70: /*TEST
72: test:
73: nsize: 4
74: args: -viewer
76: TEST*/