Actual source code: ex1.c
2: static char help[] = "Introductory example that illustrates printing.\n\n";
4: #include <petscsys.h>
5: int main(int argc, char **argv)
6: {
7: PetscMPIInt rank, size;
9: /*
10: Every PETSc program should begin with the PetscInitialize() routine.
11: argc, argv - These command line arguments are taken to extract the options
12: supplied to PETSc and options supplied to MPI.
13: help - When PETSc executable is invoked with the option -help,
14: it prints the various options that can be applied at
15: runtime. The user can use the "help" variable to place
16: additional help messages in this printout.
17: */
19: PetscInitialize(&argc, &argv, (char *)0, help);
21: /*
22: The following MPI calls return the number of processes
23: being used and the rank of this process in the group.
24: */
25: MPI_Comm_size(PETSC_COMM_WORLD, &size);
26: MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
28: /*
29: Here we would like to print only one message that represents
30: all the processes in the group. We use PetscPrintf() with the
31: communicator PETSC_COMM_WORLD. Thus, only one message is
32: printed representng PETSC_COMM_WORLD, i.e., all the processors.
33: */
34: PetscPrintf(PETSC_COMM_WORLD, "Number of processors = %d, rank = %d\n", size, rank);
36: /*
37: Here a barrier is used to separate the two program states.
38: */
39: MPI_Barrier(PETSC_COMM_WORLD);
41: /*
42: Here we simply use PetscPrintf() with the communicator PETSC_COMM_SELF,
43: where each process is considered separately and prints independently
44: to the screen. Thus, the output from different processes does not
45: appear in any particular order.
46: */
48: PetscPrintf(PETSC_COMM_SELF, "[%d] Jumbled Hello World\n", rank);
50: /*
51: Always call PetscFinalize() before exiting a program. This routine
52: - finalizes the PETSc libraries as well as MPI
53: - provides summary and diagnostic information if certain runtime
54: options are chosen (e.g., -log_view). See PetscFinalize()
55: manpage for more information.
56: */
57: PetscFinalize();
58: return 0;
59: }
61: /*TEST
63: test:
65: TEST*/