Actual source code: ex4.c
1: static char help = "Introductory example that illustrates running PETSc on a subset of processes.\n\n";
4: Concepts: introduction to PETSc;
5: Concepts: process^subset set PETSC_COMM_WORLD
6: Processors: 2
8: #include <petscsys.h>
10: int main(int argc, char *argv)
13: PetscMPIInt rank, size;
15: /* We must call MPI_Init() first, making us, not PETSc, responsible for MPI */
16: MPI_Init(&argc, &argv);
18: /* We can now change the communicator universe for PETSc */
19: MPI_Comm_rank(MPI_COMM_WORLD, &rank);
20: MPI_Comm_split(MPI_COMM_WORLD, rank%2, 0, &PETSC_COMM_WORLD);
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.
31: PetscInitialize(&argc, &argv, (char*) 0, help);
34: The following MPI calls return the number of processes
35: being used and the rank of this process in the group.
41: Here we would like to print only one message that represents
42: all the processes in the group. We use PetscPrintf() with the
43: communicator PETSC_COMM_WORLD. Thus, only one message is
44: printed representng PETSC_COMM_WORLD, i.e., all the processors.
46: PetscPrintf(PETSC_COMM_WORLD,"Number of processors = %d, rank = %d\n", size, rank);
49: Always call PetscFinalize() before exiting a program. This routine
50: - finalizes the PETSc libraries as well as MPI
51: - provides summary and diagnostic information if certain runtime
52: options are chosen (e.g., -log_summary). See PetscFinalize()
53: manpage for more information.
58: /* Since we initialized MPI, we must call MPI_Finalize() */
60: return 0;