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: */
25: PetscInitialize(&argc,&argv,(char*)0,help);
26: comm = PETSC_COMM_WORLD;
27: MPI_Comm_size(comm,&size);
29: PetscOptionsGetViewer(comm,NULL,NULL,"-viewer",&viewer,&format,&flg);
32: PetscViewerASCIIPrintf(viewer,"Print called on original full viewer %d\n",PetscGlobalRank);
34: PetscSubcommCreate(comm,&psubcomm);
35: PetscSubcommSetNumber(psubcomm,2);
36: PetscSubcommSetType(psubcomm,PETSC_SUBCOMM_CONTIGUOUS);
37: /* enable runtime switch of psubcomm type, e.g., '-psubcomm_type interlaced */
38: PetscSubcommSetFromOptions(psubcomm);
39: subcomm = PetscSubcommChild(psubcomm);
41: PetscViewerGetSubViewer(viewer,subcomm,&subviewer);
43: PetscViewerASCIIPrintf(subviewer," Print called on sub viewers %d\n",PetscGlobalRank);
45: PetscSubcommCreate(subcomm,&psubsubcomm);
46: PetscSubcommSetNumber(psubsubcomm,2);
47: PetscSubcommSetType(psubsubcomm,PETSC_SUBCOMM_CONTIGUOUS);
48: /* enable runtime switch of psubcomm type, e.g., '-psubcomm_type interlaced */
49: PetscSubcommSetFromOptions(psubsubcomm);
50: subsubcomm = PetscSubcommChild(psubsubcomm);
52: PetscViewerGetSubViewer(subviewer,subsubcomm,&subsubviewer);
54: PetscViewerASCIIPrintf(subsubviewer," Print called on sub sub viewers %d\n",PetscGlobalRank);
56: PetscViewerRestoreSubViewer(subviewer,subsubcomm,&subsubviewer);
57: PetscViewerRestoreSubViewer(viewer,subcomm,&subviewer);
59: PetscSubcommDestroy(&psubsubcomm);
60: PetscSubcommDestroy(&psubcomm);
61: PetscViewerDestroy(&viewer);
62: PetscFinalize();
63: return 0;
64: }
66: /*TEST
68: test:
69: nsize: 4
70: args: -viewer
72: TEST*/