Actual source code: ex1.c
2: static char help = "Introductory example that illustrates printing.\n\n";
5: Concepts: introduction to PETSc;
6: Concepts: printing^in parallel
7: Processors: n
10: #include <petscsys.h>
11: int main(int argc,char **argv)
14: PetscMPIInt rank,size;
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.
28: The following MPI calls return the number of processes
29: being used and the rank of this process in the group.
35: Here we would like to print only one message that represents
36: all the processes in the group. We use PetscPrintf() with the
37: communicator PETSC_COMM_WORLD. Thus, only one message is
38: printed representng PETSC_COMM_WORLD, i.e., all the processors.
40: PetscPrintf(PETSC_COMM_WORLD,"Number of processors = %d, rank = %d\n",size,rank);
43: Here a barrier is used to separate the two program states.
48: Here we simply use PetscPrintf() with the communicator PETSC_COMM_SELF,
49: where each process is considered separately and prints independently
50: to the screen. Thus, the output from different processes does not
51: appear in any particular order.
54: PetscPrintf(PETSC_COMM_SELF,"[%d] Jumbled Hello World\n",rank);
57: Always call PetscFinalize() before exiting a program. This routine
58: - finalizes the PETSc libraries as well as MPI
59: - provides summary and diagnostic information if certain runtime
60: options are chosen (e.g., -log_summary). See PetscFinalize()
61: manpage for more information.
64: return 0;